-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Supports new data version 1, pdf upload optional
- Loading branch information
Showing
4 changed files
with
67 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// This takes in matchData | ||
function transformData(matchData) { | ||
let pointsData = matchData.points; | ||
let dataVersion = -1; | ||
|
||
// This is the original Dartfish format we used. | ||
if (pointsData[0].Position) { | ||
dataVersion = 0; | ||
} | ||
// This is the new format Leo made. | ||
else if (pointsData[0].serverName) { | ||
dataVersion = 1; | ||
} | ||
|
||
if (dataVersion === 0) { | ||
// Do nothing, this is the original format | ||
} | ||
else if (dataVersion === 1) { | ||
matchData.points = transformDataVersion1(pointsData); | ||
} | ||
return matchData; | ||
} | ||
|
||
function transformDataVersion1(pointsData) { | ||
const pointsArray = []; | ||
let currentPoint = {}; | ||
let shotCounter = 1; | ||
|
||
pointsData.forEach((shot, index) => { | ||
// Prefix each key with "Shot N:" and add to currentPoint, with special handling for certain keys | ||
for (let key in shot) { | ||
let newKey = `Shot ${shotCounter}: ${key}`; | ||
if (shotCounter === 1) { | ||
if (key === 'isPointStartTime') newKey = 'Position'; | ||
else if (key === 'pointScore') newKey = 'Name'; | ||
} | ||
currentPoint[newKey] = shot[key]; | ||
} | ||
|
||
shotCounter++; | ||
|
||
// If it's the last shot in the data or the end of a point | ||
if (index === pointsData.length - 1 || shot.isPointEnd === 1) { | ||
pointsArray.push(currentPoint); | ||
currentPoint = {}; | ||
shotCounter = 1; | ||
} | ||
}); | ||
|
||
return pointsArray; | ||
} | ||
|
||
export default transformData; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters