diff --git a/js/components/StandingsTable.js b/js/components/StandingsTable.js index 2538ed2..b2db7cb 100644 --- a/js/components/StandingsTable.js +++ b/js/components/StandingsTable.js @@ -8,8 +8,6 @@ import { } from 'reactstrap'; import { rangedmap } from '../utils/rangedmap'; -import { findTeam } from '../utils/findTeam'; -import { Order, sort } from '../utils/sort'; export class StandingsTable extends React.Component { @@ -25,13 +23,6 @@ export class StandingsTable extends React.Component { render() { 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 ( @@ -46,13 +37,13 @@ export class StandingsTable extends React.Component { - { rangedmap(sortedPerformances, (team, index) => ( - + { rangedmap(performances, (team, index) => ( + ), 0, 3) } - { rangedmap(sortedPerformances, (team, index) => ( - + { rangedmap(performances, (team, index) => ( + ), 3) } @@ -82,7 +73,7 @@ class TeamRow extends React.Component { return ( { this.props.teamToShow.rank } - {findTeam(this.props.teams, this.props.teamToShow.team).name} + { this.props.teamToShow.team_name } { this.props.teamToShow.win_loss_differential } { this.props.teamToShow.point_differential } diff --git a/js/redux/tournamentStatistics.js b/js/redux/tournamentStatistics.js index cbed36d..debf75e 100644 --- a/js/redux/tournamentStatistics.js +++ b/js/redux/tournamentStatistics.js @@ -1,4 +1,4 @@ -export const actionTypesTournamentinfo = { +export const actionTypesTournamentStatistics = { 'REQUEST_TOURNAMENT_STATISTICS': 'REQUEST_TOURNAMENT_STATISTICS', 'INT_REQUEST_TOURNAMENT_STATISTICS': 'INT_REQUEST_TOURNAMENT_STATISTICS', @@ -8,7 +8,7 @@ export const actionTypesTournamentinfo = { 'CLEAR': 'TOURNAMENTINFO_CLEAR' }; -export const defaultStateTournamentinfo = { +export const defaultStateTournamentStatistics = { code: '', description: '', id: -1, @@ -55,7 +55,7 @@ export function transformTournamentStatsToStatistics(data) { win_loss_differential: score.group_points, point_differential: score.scored_points - score.received_points, rank: i + 1, - team: score.team.name + team_name: score.team.name } } diff --git a/js/utils/findTeam.js b/js/utils/findTeam.js deleted file mode 100644 index 24d88b0..0000000 --- a/js/utils/findTeam.js +++ /dev/null @@ -1,9 +0,0 @@ - -export function findTeam(teams, id) { - for(var team of teams) { - if(team.id === id) { - return team; - } - } - return null; -} diff --git a/js/utils/sort.js b/js/utils/sort.js deleted file mode 100644 index 04d8a74..0000000 --- a/js/utils/sort.js +++ /dev/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; -}