|
@@ -1,10 +1,10 @@
|
|
|
import React from 'react'
|
|
|
import XLSX from 'xlsx'
|
|
|
-import PlayerList from './player/player-list'
|
|
|
-import MatchList from './match/match-list'
|
|
|
+import player from './player'
|
|
|
+import match from './match'
|
|
|
import Stats from './stats/stats'
|
|
|
import { SheetFromArray, Workbook, saveAs } from './excel/excel'
|
|
|
-
|
|
|
+
|
|
|
class App extends React.Component {
|
|
|
constructor () {
|
|
|
super()
|
|
@@ -49,12 +49,12 @@ class App extends React.Component {
|
|
|
const reader = new FileReader()
|
|
|
reader.onload = (e) => {
|
|
|
const data = e.target.result
|
|
|
- const workbook = XLSX.read(data, {type: 'binary'})
|
|
|
+ const workbook = XLSX.read(data, {type: 'binary', cellDates: true})
|
|
|
console.log(workbook)
|
|
|
if (workbook.SheetNames.length !== 1) {
|
|
|
throw Error(`Expected only one worksheet in the file, but found ${workbook.SheetNames.length}.`)
|
|
|
}
|
|
|
- const worksheet = XLSX.utils.sheet_to_row_object_array(workbook.Sheets[workbook.SheetNames[0]], { header: 1 })
|
|
|
+ const worksheet = XLSX.utils.sheet_to_json(workbook.Sheets[workbook.SheetNames[0]], { header: 1 })
|
|
|
callback(worksheet)
|
|
|
}
|
|
|
reader.readAsBinaryString(file)
|
|
@@ -69,7 +69,7 @@ class App extends React.Component {
|
|
|
if (worksheet[4].length !== 32 & worksheet[3][0] !== 'Konkurrenz' & worksheet[3][31] !== 'bezahlt') {
|
|
|
throw Error('Wrong file structure.')
|
|
|
}
|
|
|
- const players = worksheet.slice(4, worksheet.length)
|
|
|
+ const players = worksheet.slice(4, worksheet.length).map((playerData) => new player.Player(playerData))
|
|
|
this.setState({ players })
|
|
|
this.generateStats()
|
|
|
console.log(this.state)
|
|
@@ -84,7 +84,7 @@ class App extends React.Component {
|
|
|
if (worksheet[2].length !== 8) {
|
|
|
throw Error('Wrong file structure.')
|
|
|
}
|
|
|
- const matches = worksheet.slice(2, worksheet.length)
|
|
|
+ const matches = worksheet.slice(2, worksheet.length).map((matchData) => new match.Match(matchData))
|
|
|
this.setState({ matches })
|
|
|
this.generateStats()
|
|
|
console.log(this.state)
|
|
@@ -103,22 +103,22 @@ class App extends React.Component {
|
|
|
stats.players = this.state.players
|
|
|
|
|
|
this.state.players.forEach((player, key) => {
|
|
|
- if (!stats.playerCategories.includes(player[0])) {
|
|
|
- stats.playerCategories.push(player[0])
|
|
|
+ if (!stats.playerCategories.includes(player.Konkurrenz)) {
|
|
|
+ stats.playerCategories.push(player.Konkurrenz)
|
|
|
}
|
|
|
})
|
|
|
|
|
|
stats.matches = this.state.matches
|
|
|
|
|
|
this.state.matches.forEach((match, key) => {
|
|
|
- if (!!match[1] & !stats.matchDates.includes(match[1])) {
|
|
|
- stats.matchDates.push(match[1])
|
|
|
+ if (!!match.Datum & !stats.matchDates.includes(match.DatumString)) {
|
|
|
+ stats.matchDates.push(match.DatumString)
|
|
|
}
|
|
|
- if (!!match[3] & !stats.matchCategories.includes(match[3])) {
|
|
|
- stats.matchCategories.push(match[3])
|
|
|
+ if (!!match.Konkurrenz & !stats.matchCategories.includes(match.Konkurrenz)) {
|
|
|
+ stats.matchCategories.push(match.Konkurrenz)
|
|
|
}
|
|
|
- if (!!match[0] & !stats.matchPlaces.includes(match[0])) {
|
|
|
- stats.matchPlaces.push(match[0])
|
|
|
+ if (!!match.Ort & !stats.matchPlaces.includes(match.Ort)) {
|
|
|
+ stats.matchPlaces.push(match.Ort)
|
|
|
}
|
|
|
})
|
|
|
|
|
@@ -151,9 +151,9 @@ class App extends React.Component {
|
|
|
['Ort', 'Zeit', 'Kategorie', 'Spieler 1', '', 'Spieler 2', '', '1. Satz', '2. Satz', '3. Satz', 'WO Grund']
|
|
|
]
|
|
|
let matchListPerPlace = this.state.matches.filter((match) => {
|
|
|
- return (match[1] === filter | filter === 'Alle') & (match[0] === place | place === 'Alle')
|
|
|
- }).map((match) =>
|
|
|
- [match[0], match[2], match[3], match[4], match[5], match[6], match[7]]
|
|
|
+ return (match.DatumString === filter | filter === 'Alle') & (match.Ort === place | place === 'Alle')
|
|
|
+ }).map((match) =>
|
|
|
+ [match.Ort, match.ZeitString, match.Konkurrenz, match.Spieler1, match.Spieler1Klassierung, match.Spieler2, match.Spieler2Klassierung]
|
|
|
)
|
|
|
console.log(matchListPerPlace)
|
|
|
worksheets[place] = SheetFromArray(header.concat(matchListPerPlace))
|
|
@@ -177,33 +177,28 @@ class App extends React.Component {
|
|
|
|
|
|
const payerList = {}
|
|
|
this.state.matches.forEach((match) => {
|
|
|
- if (!!match[4] & !payerList.hasOwnProperty(`${match[3]} ${match[4]}`)) {
|
|
|
- let foundPlayer = this.state.players.find((player) => {
|
|
|
- if (!!player[24]) {
|
|
|
- return (`${player[5]} ${player[6]} / ${player[24]} ${player[25]}` === match[4]) & (match[3] === player[0].replace(/\s+/g, ' '))
|
|
|
- } else {
|
|
|
- return (`${player[5]} ${player[6]}` === match[4]) & (match[3] === player[0].replace(/\s+/g, ' '))
|
|
|
- }
|
|
|
- })
|
|
|
+ const id1 = `${match.Konkurrenz} ${match.Spieler1}`
|
|
|
+ if (!!match.Spieler1 & !payerList.hasOwnProperty(id1)) {
|
|
|
+ let foundPlayer = this.state.players.find((player) =>
|
|
|
+ (player.name() === match.Spieler1) & (player.Konkurrenz === match.Konkurrenz)
|
|
|
+ )
|
|
|
if (!foundPlayer) {
|
|
|
console.log(foundPlayer, match)
|
|
|
- throw Error('Player 4 not found. This is an error!')
|
|
|
+ throw Error('Player 1 not found. This is an error!')
|
|
|
}
|
|
|
- payerList[`${match[3]} ${match[4]}`] = [match[0], match[1], match[2], foundPlayer[31]]
|
|
|
+ payerList[id1] = [match.Ort, match.DatumString, match.ZeitString, foundPlayer.bezahlt]
|
|
|
}
|
|
|
- if (!!match[6] & !payerList.hasOwnProperty(`${match[3]} ${match[6]}`)) {
|
|
|
- let foundPlayer = this.state.players.find((player) => {
|
|
|
- if (!!player[24]) {
|
|
|
- return (`${player[5]} ${player[6]} / ${player[24]} ${player[25]}` === match[6]) & (match[3] === player[0].replace(/\s+/g, ' '))
|
|
|
- } else {
|
|
|
- return (`${player[5]} ${player[6]}` === match[6]) & (match[3] === player[0].replace(/\s+/g, ' '))
|
|
|
- }
|
|
|
- })
|
|
|
+
|
|
|
+ const id2 = `${match.Konkurrenz} ${match.Spieler2}`
|
|
|
+ if (!!match.Spieler2 & !payerList.hasOwnProperty(id2)) {
|
|
|
+ let foundPlayer = this.state.players.find((player) =>
|
|
|
+ (player.name() === match.Spieler2) & (player.Konkurrenz === match.Konkurrenz)
|
|
|
+ )
|
|
|
if (!foundPlayer) {
|
|
|
console.log(foundPlayer, match)
|
|
|
- throw Error('Player 6 not found. This is an error!')
|
|
|
+ throw Error('Player 2 not found. This is an error!')
|
|
|
}
|
|
|
- payerList[`${match[3]} ${match[6]}`] = [match[0], match[1], match[2], foundPlayer[31]]
|
|
|
+ payerList[id2] = [match.Ort, match.DatumString, match.ZeitString, foundPlayer.bezahlt]
|
|
|
}
|
|
|
})
|
|
|
console.log(payerList)
|
|
@@ -216,15 +211,15 @@ class App extends React.Component {
|
|
|
['bereits bez.', 'Kategorie', 'Name', 'Betrag bez.', 'Quittung abgeben']
|
|
|
]
|
|
|
|
|
|
- let payListPerPlace = []
|
|
|
+ let payListPerPlace = []
|
|
|
this.state.matches.filter((match) => {
|
|
|
- return (match[1] === filter | filter === 'Alle') & (match[0] === place | place === 'Alle')
|
|
|
+ return (match.DatumString === filter | filter === 'Alle') & (match.Ort === place | place === 'Alle')
|
|
|
}).forEach((match) => {
|
|
|
- if (!!match[4]) {
|
|
|
- payListPerPlace.push(match)
|
|
|
+ if (match.Spieler1) {
|
|
|
+ payListPerPlace.push([match.Ort])
|
|
|
}
|
|
|
- if (!!match[6]) {
|
|
|
- payListPerPlace.push(match)
|
|
|
+ if (match.Spieler2) {
|
|
|
+ payListPerPlace.push([match.Ort])
|
|
|
}
|
|
|
})
|
|
|
console.log(payListPerPlace)
|
|
@@ -238,6 +233,9 @@ class App extends React.Component {
|
|
|
}
|
|
|
|
|
|
render () {
|
|
|
+ const PlayerList = player.components.PlayerList
|
|
|
+ const MatchList = match.components.MatchList
|
|
|
+
|
|
|
return (
|
|
|
<div className='App'>
|
|
|
<form>
|