Skip to content

Commit

Permalink
add roundsTotalNumber and fix bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
antoniokov committed Jan 5, 2017
1 parent f69286b commit f8da92d
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 5 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ It is possible to use this options together with a [preset](#presets): in this c
* [extraColumnsNumber](#extracolumnsnumber)
* [calculatedColumns](#calculatedcolumns)
* [useRoundsNumbers](#useroundsnumbers)
* [roundsTotalNumber](#roundstotalnumber)
* [positionWhenTied](#positionWhenTied)
* [tableName](#tablename)
* [Playback](#playback)
Expand Down Expand Up @@ -327,6 +328,15 @@ If set to `true` ignores rounds' names and uses numbers.
It is useful when you have [list Of matches](#list-of-matches) where rows are dates but you don't care that teams didn't play their Nth game simultaneously.
### `roundsTotalNumber`
| Div attribute | Accepted type | Default value | Examples |
|---------------|---------------|---------------|----------|
| `data-rounds-total-number` | `Number` | `undefined` | `38`, `40` |
Helps to determine the correct value of the progress bar if season is not over yet.
When set to `undefined` counts the number of rounds with at least one result.
### `positionWhenTied`
| Div attribute | Available options | Default value |
|---------------|-------------------|---------------|
Expand Down
5 changes: 4 additions & 1 deletion public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@
<div class="replayTable"
data-csv="%PUBLIC_URL%/1ax-russian-second-division-centre.csv"
data-input-type="listOfMatches"
data-item-name="Team"
data-season-name="Сезон"
data-round-name="Матч"
data-item-name="Команда"
data-use-rounds-numbers="true"
data-rounds-total-number="24"
data-table-name="russian-second-division-centre">
</div>
</body>
2 changes: 1 addition & 1 deletion src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class App extends Component {
if (config[key].validate(value)) {
configObject[key] = value;
} else {
console.log(`Sorry, we cannot accept ${props[key]} as ${key}. Moving on with the default value which is ${configObject[key]}`);
console.log(`Sorry, we cannot accept ${props[key]} as ${key}. Moving on with the default value which is ${JSON.stringify(configObject[key])}`);
}
});

Expand Down
5 changes: 4 additions & 1 deletion src/app/TableContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,10 @@ class TableContainer extends Component {

{!this.props.showProgressBar ? null :
<div className="replay-table-progress-wrap">
<progress className="replay-table-progress" value={this.state.currentRound} max={this.props.roundsNames.length - 1} />
<progress
className="replay-table-progress"
value={this.state.currentRound}
max={this.props.roundsTotalNumber || this.props.roundsNames.length - 1} />
</div>
}

Expand Down
2 changes: 1 addition & 1 deletion src/auxiliary/parseObject.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export default function(input) {
try {
return JSON.parse(input);
return JSON.parse(input.replace(/'/g, '"'));
} catch(e) {
return null;
}
Expand Down
11 changes: 10 additions & 1 deletion src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,10 @@ export const config = {
calculatedColumns: {
default: {},
parse: input => parseObject(input),
validate: obj => validateObject(obj, key => ['rounds', 'wins', 'losses', 'draws'].includes(key), value => isString(value))
validate: obj => {
console.log(obj);
return validateObject(obj, key => ['rounds', 'wins', 'losses', 'draws'].includes(key), value => isString(value))
}
},

useRoundsNumbers: {
Expand All @@ -93,6 +96,12 @@ export const config = {
goesToTransform: true
},

roundsTotalNumber: {
default: undefined,
parse: input => Number.parseInt(input, 10),
validate: value => value === undefined || !Number.isNaN(value),
},

//tieBreaking!

positionWhenTied: {
Expand Down
11 changes: 11 additions & 0 deletions src/transformers/csv/listOfMatches.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,17 @@ function transformMatchesList(jsonList, params) {
return rowResults;
});


itemsNames.forEach(name => {
const stats = itemsCurrentStats.get(name);
for (let round = stats.rounds; round < roundsResults.length; round++) {
const newStats = Object.assign({}, stats);
newStats.rounds = round;
newStats.change = null;
roundsResults[round].set(name, Object.assign({}, newStats));
}
});

const results = params['useRoundsNumbers'] ? roundsResults : rowsResults;

if (params['startRoundName']) {
Expand Down

0 comments on commit f8da92d

Please sign in to comment.