Skip to content

Commit

Permalink
Fixed pad problem, added multiple drop notification for clean
Browse files Browse the repository at this point in the history
  • Loading branch information
Waxo committed Nov 28, 2020
1 parent 1eeb366 commit 7540816
Show file tree
Hide file tree
Showing 12 changed files with 67 additions and 31 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# 0.2.0 (2020-11-28)

- Multiple files drop for qualifications now handled
- Added notification for results cleaning
- Fixed times when seconds or milliseconds start by 0

# 0.1.0 (2020-11-28)

- Updated car list
Expand Down
1 change: 1 addition & 0 deletions app/components/acc-results-import-comp.hbs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<PaperCard>
<FileDropzone @name="acc-json"
@ondrop={{action "importJson"}}
@multiple=true
as |dropzone queue|>
<h4>Import ACC Results {{#if this.isLoaded}}{{paper-icon "done"}}{{/if}}</h4>
</FileDropzone>
Expand Down
7 changes: 6 additions & 1 deletion app/components/acc-results-import-comp.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {tracked} from '@glimmer/tracking';
import {inject as service} from '@ember/service';

const fs = requireNode('fs-extra');
const R = requireNode('ramda');

export default class accResultsImportComp extends Component {
@service applicationStore;
Expand All @@ -14,7 +15,11 @@ export default class accResultsImportComp extends Component {
@action
async importJson(f) {
this.applicationStore.savePath(f.files[0].path, true);
this.resultsStore.save(await fs.readFile(f.files[0].path, 'utf8'));
await R.forEach(
async (file) =>
this.resultsStore.save(await fs.readFile(file.path, 'utf8')),
f.files
);
this.isLoaded = true;
this.paperToaster.show('Results imported');
}
Expand Down
1 change: 1 addition & 0 deletions app/components/export-comp.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,6 @@ export default class ExportComp extends Component {
@action
async clearData() {
this.resultsStore.clear();
this.paperToaster.show(`Cleared all results`);
}
}
2 changes: 1 addition & 1 deletion app/components/toolbar-comp.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
View Results
{{/paper-button}}
<span class="flex"></span>
v0.1.0
v0.2.0
{{/toolbar.tools}}
{{/paper-toolbar}}

Expand Down
3 changes: 0 additions & 3 deletions app/services/results-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,11 @@ export default class ResultsStoreService extends Service {
if (results.sessionType !== 'Q') {
this.jsonImport = results;
} else {
console.log(R.isEmpty(this.jsonImport));
this.jsonImport = R.ifElse(
R.isEmpty,
R.always(results),
mergeResults(results)
)(this.jsonImport);
console.log(results.sessionResult.leaderBoardLines);
console.log(this.jsonImport.sessionResult.leaderBoardLines);
}
}

Expand Down
4 changes: 2 additions & 2 deletions app/utils/parse-results.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const R = requireNode('ramda');

const parseResults = R.pipe(
R.replace(/[^a-zA-Z0-9",{}.\[\]:-]/g, ''),
R.replace(/[^a-zA-Z\u00C0-\u024F\u1E00-\u1EFF0-9",{}.\[\]:-]/g, ''),
JSON.parse
)
);

export default parseResults;
54 changes: 32 additions & 22 deletions app/utils/results-to-csv.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
const R = requireNode('ramda');
const pad = requireNode('pad');

import carModelToName from "./cars";
import carModelToName from './cars';

const columns = ['Place',
const columns = [
'Place',
'FirstName',
'LastName',
'Car Number',
Expand All @@ -12,13 +14,19 @@ const columns = ['Place',
'Best S2',
'Best S3',
'Best lap',
'Best lap (ms)',
'Ideal Best lap',
'SteamId',
'SteamId'
];

const formatTime = (lapTime) => `${Math.floor(
Math.floor(lapTime * 0.001) / 60)}:${Math.floor(lapTime * 0.001) %
60}.${lapTime % 1000}`;
const formatTime = (lapTime) =>
[
Math.floor(Math.floor(lapTime * 0.001) / 60),
':',
pad(2, String(Math.floor(lapTime * 0.001) % 60), '0'),
'.',
pad(3, String(lapTime % 1000), '0')
].join('');

const addBestSplits = R.pipe(
R.path(['timing', 'bestSplits']),
Expand All @@ -31,28 +39,30 @@ const idealTime = R.pipe(
formatTime
);

const formatDriver = (driver, index) => R.pipe(
R.juxt([
R.always(index + 1),
R.path(['currentDriver', 'firstName']),
R.path(['currentDriver', 'lastName']),
R.path(['car', 'raceNumber']),
R.pipe(R.path(['car', 'carModel']), carModelToName),
R.path(['timing', 'lapCount']),
addBestSplits,
R.pipe(R.path(['timing', 'bestLap']), formatTime),
idealTime,
R.path(['currentDriver', 'playerId'])
]),
R.flatten
)(driver);
const formatDriver = (driver, index) =>
R.pipe(
R.juxt([
R.always(index + 1),
R.path(['currentDriver', 'firstName']),
R.path(['currentDriver', 'lastName']),
R.path(['car', 'raceNumber']),
R.pipe(R.path(['car', 'carModel']), carModelToName),
R.path(['timing', 'lapCount']),
addBestSplits,
R.pipe(R.path(['timing', 'bestLap']), formatTime),
R.path(['timing', 'bestLap']),
idealTime,
R.path(['currentDriver', 'playerId'])
]),
R.flatten
)(driver);

const resultsToCSV = R.pipe(
R.path(['sessionResult', 'leaderBoardLines']),
R.addIndex(R.map)(formatDriver),
R.prepend(columns),
R.map(R.join(';')),
R.join('\n')
)
);

export default resultsToCSV;
3 changes: 2 additions & 1 deletion electron-app/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "acc-results-json-to-csv",
"productName": "acc-results-json-to-csv",
"version": "0.1.0",
"version": "0.2.0",
"description": "Import json with ACC bad formatting and export it to CSV",
"main": "src/index.js",
"scripts": {
Expand Down Expand Up @@ -51,6 +51,7 @@
"electron-is-dev": "^1.2.0",
"electron-squirrel-startup": "^1.0.0",
"fs-extra": "^9.0.1",
"pad": "^3.2.0",
"ramda": "^0.27.1"
},
"devDependencies": {
Expand Down
7 changes: 7 additions & 0 deletions electron-app/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2251,6 +2251,13 @@ p-try@^2.0.0:
resolved "https://registry.yarnpkg.com/p-try/-/p-try-2.2.0.tgz#cb2868540e313d61de58fafbe35ce9004d5540e6"
integrity sha512-R4nPAVTAU0B9D35/Gk3uJf/7XYbQcyohSKdvAxIRSNghFl4e71hVoGnBNQz9cWaXxO2I10KTC+3jMdvvoKw6dQ==

pad@^3.2.0:
version "3.2.0"
resolved "https://registry.yarnpkg.com/pad/-/pad-3.2.0.tgz#be7a1d1cb6757049b4ad5b70e71977158fea95d1"
integrity sha512-2u0TrjcGbOjBTJpyewEl4hBO3OeX5wWue7eIFPzQTg6wFSvoaHcBTTUY5m+n0hd04gmTCPuY0kCpVIVuw5etwg==
dependencies:
wcwidth "^1.0.1"

pako@~1.0.2:
version "1.0.11"
resolved "https://registry.yarnpkg.com/pako/-/pako-1.0.11.tgz#6c9599d340d54dfd3946380252a35705a6b992bf"
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "acc-results-json-to-csv",
"version": "0.1.0",
"version": "0.2.0",
"private": true,
"description": "Import json with ACC bad formatting and export it to CSV",
"repository": "",
Expand Down Expand Up @@ -66,6 +66,7 @@
},
"dependencies": {
"fs-extra": "^9.0.1",
"pad": "^3.2.0",
"ramda": "^0.27.1"
},
"xo": {
Expand Down
7 changes: 7 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -10902,6 +10902,13 @@ package-json@^6.3.0:
registry-url "^5.0.0"
semver "^6.2.0"

pad@^3.2.0:
version "3.2.0"
resolved "https://registry.yarnpkg.com/pad/-/pad-3.2.0.tgz#be7a1d1cb6757049b4ad5b70e71977158fea95d1"
integrity sha512-2u0TrjcGbOjBTJpyewEl4hBO3OeX5wWue7eIFPzQTg6wFSvoaHcBTTUY5m+n0hd04gmTCPuY0kCpVIVuw5etwg==
dependencies:
wcwidth "^1.0.1"

pako@~1.0.5:
version "1.0.11"
resolved "https://registry.yarnpkg.com/pako/-/pako-1.0.11.tgz#6c9599d340d54dfd3946380252a35705a6b992bf"
Expand Down

0 comments on commit 7540816

Please sign in to comment.