Adjust the StandingsTable to the new API data format
This commit is contained in:
parent
d24e464f8e
commit
e813726f50
|
|
@ -8,8 +8,6 @@ import {
|
||||||
} from 'reactstrap';
|
} from 'reactstrap';
|
||||||
|
|
||||||
import { rangedmap } from '../utils/rangedmap';
|
import { rangedmap } from '../utils/rangedmap';
|
||||||
import { findTeam } from '../utils/findTeam';
|
|
||||||
import { Order, sort } from '../utils/sort';
|
|
||||||
|
|
||||||
export class StandingsTable extends React.Component {
|
export class StandingsTable extends React.Component {
|
||||||
|
|
||||||
|
|
@ -25,13 +23,6 @@ export class StandingsTable extends React.Component {
|
||||||
render() {
|
render() {
|
||||||
let performances = this.props.data.group_phase_performances;
|
let performances = this.props.data.group_phase_performances;
|
||||||
|
|
||||||
/**
|
|
||||||
* comparison(p1, p2) < 0 => p1 < p2
|
|
||||||
* comparison(p1, p2) = 0 => p1 = p2
|
|
||||||
* comparison(p1, p2) > 0 => p1 > p2
|
|
||||||
*/
|
|
||||||
let sortedPerformances = sort(performances, (p1, p2) => p1.rank - p2.rank, Order.descending);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Card className="shadow-sm">
|
<Card className="shadow-sm">
|
||||||
<CardBody>
|
<CardBody>
|
||||||
|
|
@ -46,13 +37,13 @@ export class StandingsTable extends React.Component {
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
{ rangedmap(sortedPerformances, (team, index) => (
|
{ rangedmap(performances, (team, index) => (
|
||||||
<TeamRow className={(index % 2 === 0)? 'bg-light' : 'bg-white'} key={index} teams={this.props.data.teams} teamToShow={team}/>
|
<TeamRow className={(index % 2 === 0)? 'bg-light' : 'bg-white'} key={index} teamToShow={team}/>
|
||||||
), 0, 3) }
|
), 0, 3) }
|
||||||
</tbody>
|
</tbody>
|
||||||
<Collapse isOpen={ this.state.showFullTable } tag="tbody">
|
<Collapse isOpen={ this.state.showFullTable } tag="tbody">
|
||||||
{ rangedmap(sortedPerformances, (team, index) => (
|
{ rangedmap(performances, (team, index) => (
|
||||||
<TeamRow className={(index % 2 === 0)? 'bg-light' : 'bg-white'} key={index} teams={this.props.data.teams} teamToShow={team}/>
|
<TeamRow className={(index % 2 === 0)? 'bg-light' : 'bg-white'} key={index} teamToShow={team}/>
|
||||||
), 3) }
|
), 3) }
|
||||||
</Collapse>
|
</Collapse>
|
||||||
<tfoot>
|
<tfoot>
|
||||||
|
|
@ -82,7 +73,7 @@ class TeamRow extends React.Component {
|
||||||
return (
|
return (
|
||||||
<tr className={this.props.className}>
|
<tr className={this.props.className}>
|
||||||
<td>{ this.props.teamToShow.rank }</td>
|
<td>{ this.props.teamToShow.rank }</td>
|
||||||
<td className="w-100">{findTeam(this.props.teams, this.props.teamToShow.team).name}</td>
|
<td className="w-100">{ this.props.teamToShow.team_name }</td>
|
||||||
<td className="text-center">{ this.props.teamToShow.win_loss_differential }</td>
|
<td className="text-center">{ this.props.teamToShow.win_loss_differential }</td>
|
||||||
<td className="text-center">{ this.props.teamToShow.point_differential }</td>
|
<td className="text-center">{ this.props.teamToShow.point_differential }</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
export const actionTypesTournamentinfo = {
|
export const actionTypesTournamentStatistics = {
|
||||||
'REQUEST_TOURNAMENT_STATISTICS': 'REQUEST_TOURNAMENT_STATISTICS',
|
'REQUEST_TOURNAMENT_STATISTICS': 'REQUEST_TOURNAMENT_STATISTICS',
|
||||||
'INT_REQUEST_TOURNAMENT_STATISTICS': 'INT_REQUEST_TOURNAMENT_STATISTICS',
|
'INT_REQUEST_TOURNAMENT_STATISTICS': 'INT_REQUEST_TOURNAMENT_STATISTICS',
|
||||||
|
|
||||||
|
|
@ -8,7 +8,7 @@ export const actionTypesTournamentinfo = {
|
||||||
'CLEAR': 'TOURNAMENTINFO_CLEAR'
|
'CLEAR': 'TOURNAMENTINFO_CLEAR'
|
||||||
};
|
};
|
||||||
|
|
||||||
export const defaultStateTournamentinfo = {
|
export const defaultStateTournamentStatistics = {
|
||||||
code: '',
|
code: '',
|
||||||
description: '',
|
description: '',
|
||||||
id: -1,
|
id: -1,
|
||||||
|
|
@ -55,7 +55,7 @@ export function transformTournamentStatsToStatistics(data) {
|
||||||
win_loss_differential: score.group_points,
|
win_loss_differential: score.group_points,
|
||||||
point_differential: score.scored_points - score.received_points,
|
point_differential: score.scored_points - score.received_points,
|
||||||
rank: i + 1,
|
rank: i + 1,
|
||||||
team: score.team.name
|
team_name: score.team.name
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,9 +0,0 @@
|
||||||
|
|
||||||
export function findTeam(teams, id) {
|
|
||||||
for(var team of teams) {
|
|
||||||
if(team.id === id) {
|
|
||||||
return team;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
@ -1,73 +0,0 @@
|
||||||
|
|
||||||
/**
|
|
||||||
* Constants for the ordering in which the sorting
|
|
||||||
* algorithm should bring the elements.
|
|
||||||
*/
|
|
||||||
export const Order = {
|
|
||||||
ascending : 1,
|
|
||||||
descending: 2
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A sorting function that can be used to sort any kind of data
|
|
||||||
* given an applicable comparator. Said comparator will take in two
|
|
||||||
* elements of the given array `data`, and produce an integer result
|
|
||||||
* which can be interpreted as follows:
|
|
||||||
* ```
|
|
||||||
* comparator(a, b) < 0 => a < b
|
|
||||||
* comparator(a, b) = 0 => a = b
|
|
||||||
* comparator(a, b) > 0 => a > b
|
|
||||||
* ```
|
|
||||||
* The parameter order should be given as one of the constants in Order.
|
|
||||||
* Said `order` parameter is optional; it will default to ascending.
|
|
||||||
*
|
|
||||||
* @param {T[]} data The array that is to be sorted.
|
|
||||||
* @param {(T, T) => int} comparator A function which can be used
|
|
||||||
* to compare any two elemments from the given array.
|
|
||||||
* @param {int} order The order in which the data should be sorted,
|
|
||||||
* as defined in Order.
|
|
||||||
* @return An array with the elements from data sorted in the given order.
|
|
||||||
*/
|
|
||||||
export function sort(data, comparator, order) {
|
|
||||||
if(order === undefined) {
|
|
||||||
order = Order.ascending;
|
|
||||||
}
|
|
||||||
let target = data.slice();
|
|
||||||
return sortToTarget(data, target, 0, data.length, comparator, order);
|
|
||||||
}
|
|
||||||
|
|
||||||
function sortToTarget(data, target, start, end, comparator, order) {
|
|
||||||
if(end - start < 2) {
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
let middle = Math.floor((end + start) / 2);
|
|
||||||
|
|
||||||
sortToTarget(target, data, start, middle, comparator, order);
|
|
||||||
sortToTarget(target, data, middle, end, comparator, order);
|
|
||||||
|
|
||||||
return merge(data, target, start, middle, end, comparator, order);
|
|
||||||
}
|
|
||||||
|
|
||||||
function merge(data, target, start, middle, end, comparator, order) {
|
|
||||||
let i = start;
|
|
||||||
let j = middle;
|
|
||||||
|
|
||||||
for(let k = start; k < end; k++) {
|
|
||||||
if(order === Order.ascending) {
|
|
||||||
if(i < middle && (j >= end || comparator(data[i], data[j]) >= 0)) {
|
|
||||||
target[k] = data[i++];
|
|
||||||
} else {
|
|
||||||
target[k] = data[j++];
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if(i < middle && (j >= end || comparator(data[i], data[j]) <= 0)) {
|
|
||||||
target[k] = data[i++];
|
|
||||||
} else {
|
|
||||||
target[k] = data[j++];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return target;
|
|
||||||
}
|
|
||||||
Loading…
Reference in New Issue