Chore: initial commit

This commit is contained in:
Dorian Zedler 2022-07-27 02:55:05 +02:00
parent e28bcbe072
commit cf72fb9356
Signed by: dorian
GPG key ID: 989DE36109AFA354
40 changed files with 31757 additions and 2 deletions

7
.eslintignore Normal file
View file

@ -0,0 +1,7 @@
**/node_modules
**/dist
**/package-lock.json
**/.eslintrc.js
**/build
/src/data/api.ts
/src/data/configuration.ts

40
.eslintrc.js Normal file
View file

@ -0,0 +1,40 @@
module.exports = {
env: {
browser: true,
es2021: true,
},
extends: [
'eslint:recommended',
'plugin:react/recommended',
'google',
'plugin:react/recommended', // Uses the recommended rules from @eslint-plugin-react
'plugin:@typescript-eslint/eslint-recommended', // Uses the recommended rules from the @typescript-eslint/eslint-plugin
'plugin:@typescript-eslint/recommended', // Uses the recommended rules from the @typescript-eslint/eslint-plugin
'plugin:css/recommended',
'plugin:prettier/recommended',
],
parser: '@typescript-eslint/parser',
parserOptions: {
ecmaFeatures: {
jsx: true,
},
ecmaVersion: 'latest',
sourceType: 'module',
},
plugins: ['react', '@typescript-eslint', 'prettier', 'css'],
rules: {
'react/react-in-jsx-scope': 'off',
'react/jsx-indent': ['off'],
},
settings: {
react: {
version: 'detect', // Tells eslint-plugin-react to automatically detect the version of React to use
},
'import/resolver': {
node: {
extensions: ['.js', '.jsx', '.ts', '.tsx', '.css'],
paths: ['./src'],
},
},
},
};

23
.gitignore vendored Normal file
View file

@ -0,0 +1,23 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
# dependencies
/node_modules
/.pnp
.pnp.js
# testing
/coverage
# production
/build
# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local
npm-debug.log*
yarn-debug.log*
yarn-error.log*

4
.prettierignore Normal file
View file

@ -0,0 +1,4 @@
**/node_modules
**/dist
**/package-lock.json
**/build

12
.prettierrc Normal file
View file

@ -0,0 +1,12 @@
{
"semi": true,
"printWidth": 80,
"tabWidth": 2,
"singleQuote": true,
"bracketSpacing": true,
"useTabs": false,
"arrowParens": "avoid",
"jsxSingleQuote": true,
"trailingComma": "all",
"endOfLine": "auto"
}

4
.vscode/settings.json vendored Normal file
View file

@ -0,0 +1,4 @@
{
"editor.formatOnSave": true,
"prettier.configPath": ".prettierrc"
}

View file

@ -1,3 +1,46 @@
# speed-flowchart-web
# Getting Started with Create React App
Implementation of blueROCK in react.
This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
## Available Scripts
In the project directory, you can run:
### `npm start`
Runs the app in the development mode.\
Open [http://localhost:3000](http://localhost:3000) to view it in the browser.
The page will reload if you make edits.\
You will also see any lint errors in the console.
### `npm test`
Launches the test runner in the interactive watch mode.\
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.
### `npm run build`
Builds the app for production to the `build` folder.\
It correctly bundles React in production mode and optimizes the build for the best performance.
The build is minified and the filenames include the hashes.\
Your app is ready to be deployed!
See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.
### `npm run eject`
**Note: this is a one-way operation. Once you `eject`, you cant go back!**
If you arent satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.
Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point youre on your own.
You dont have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldnt feel obligated to use this feature. However we understand that this tool wouldnt be useful if you couldnt customize it when you are ready for it.
## Learn More
You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).
To learn React, check out the [React documentation](https://reactjs.org/).

3
README.old.md Normal file
View file

@ -0,0 +1,3 @@
# speed-flowchart-web
Implementation of blueROCK in react.

1055
allData.json Normal file

File diff suppressed because it is too large Load diff

29622
package-lock.json generated Normal file

File diff suppressed because it is too large Load diff

62
package.json Normal file
View file

@ -0,0 +1,62 @@
{
"name": "speed-flowchart-web",
"version": "0.1.0",
"private": true,
"dependencies": {
"@emotion/react": "^11.9.3",
"@emotion/styled": "^11.9.3",
"@mui/material": "^5.9.2",
"@mui/x-date-pickers": "^5.0.0-beta.2",
"@testing-library/jest-dom": "^5.16.4",
"@testing-library/react": "^13.3.0",
"@testing-library/user-event": "^13.5.0",
"@types/date-fns": "^2.6.0",
"@types/jest": "^27.5.2",
"@types/node": "^16.11.45",
"@types/react": "^18.0.15",
"@types/react-dom": "^18.0.6",
"date-fns": "^2.29.1",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-router-dom": "^6.3.0",
"react-scripts": "5.0.1",
"typescript": "^4.7.4",
"web-vitals": "^2.1.4"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
},
"devDependencies": {
"@typescript-eslint/eslint-plugin": "^5.24.0",
"@typescript-eslint/parser": "^5.24.0",
"eslint": "^8.15.0",
"eslint-config-google": "^0.14.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-css": "^0.6.0",
"eslint-plugin-prettier": "^4.0.0",
"eslint-plugin-react": "^7.29.4",
"prettier": "^2.6.2",
"simple-git-hooks": "^2.7.0"
}
}

BIN
public/favicon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.8 KiB

43
public/index.html Normal file
View file

@ -0,0 +1,43 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
<meta
name="description"
content="Web site created using create-react-app"
/>
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
<!--
manifest.json provides metadata used when your web app is installed on a
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
-->
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
<!--
Notice the use of %PUBLIC_URL% in the tags above.
It will be replaced with the URL of the `public` folder during the build.
Only files inside the `public` folder can be referenced from the HTML.
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`.
-->
<title>React App</title>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
<!--
This HTML file is a template.
If you open it directly in the browser, you will see an empty page.
You can add webfonts, meta tags, or analytics to this file.
The build step will place the bundled scripts into the <body> tag.
To begin the development, run `npm start` or `yarn start`.
To create a production bundle, use `npm run build` or `yarn build`.
-->
</body>
</html>

BIN
public/logo192.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.2 KiB

BIN
public/logo512.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.4 KiB

25
public/manifest.json Normal file
View file

@ -0,0 +1,25 @@
{
"short_name": "React App",
"name": "Create React App Sample",
"icons": [
{
"src": "favicon.ico",
"sizes": "64x64 32x32 24x24 16x16",
"type": "image/x-icon"
},
{
"src": "logo192.png",
"type": "image/png",
"sizes": "192x192"
},
{
"src": "logo512.png",
"type": "image/png",
"sizes": "512x512"
}
],
"start_url": ".",
"display": "standalone",
"theme_color": "#000000",
"background_color": "#ffffff"
}

3
public/robots.txt Normal file
View file

@ -0,0 +1,3 @@
# https://www.robotstxt.org/robotstxt.html
User-agent: *
Disallow:

38
src/App.css Normal file
View file

@ -0,0 +1,38 @@
.App {
text-align: center;
}
.App-logo {
height: 40vmin;
pointer-events: none;
}
@media (prefers-reduced-motion: no-preference) {
.App-logo {
animation: App-logo-spin infinite 20s linear;
}
}
.App-header {
background-color: #282c34;
min-height: 100vh;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
font-size: calc(10px + 2vmin);
color: white;
}
.App-link {
color: #61dafb;
}
@keyframes App-logo-spin {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}

9
src/App.test.tsx Normal file
View file

@ -0,0 +1,9 @@
import React from 'react';
import { render, screen } from '@testing-library/react';
import App from './App';
test('renders learn react link', () => {
render(<App />);
const linkElement = screen.getByText(/learn react/i);
expect(linkElement).toBeInTheDocument();
});

19
src/App.tsx Normal file
View file

@ -0,0 +1,19 @@
import React from 'react';
import logo from './logo.svg';
import './App.css';
import Theme from './utils/Theme';
import Routing from './utils/Routing';
/**
*
* @return {JSX.Element}
*/
function App() {
return (
<Theme>
<Routing />
</Theme>
);
}
export default App;

12
src/data/Context.tsx Normal file
View file

@ -0,0 +1,12 @@
import { createContext } from 'react';
import { DigitalrockAPi } from './DigitalrockApi';
/**
* Creates a Context that is accessible to all nodes wrapped in the context provider
* @return {React.Context}
*/
export const Context = createContext<{
api: DigitalrockAPi;
}>({
api: new DigitalrockAPi(),
});

View file

@ -0,0 +1,56 @@
import {
Competiton,
SpeedCompetitionCategoryResult,
} from '../models/Competition';
/**
* A list of competitions
*/
interface CompetitionList {
competitions: Competiton[];
}
/**
* A class for dealing with the digitalrock api
*/
export class DigitalrockAPi {
private BASE_URL = 'https://www.digitalrock.de/egroupware/ranking/json.php?';
/**
* function to get competitions
* @param {string} nation the nation to get
* @return {Promis<CompetitionList>} competition list
*/
public async getCompetitions(nation: string): Promise<CompetitionList> {
return await this._request([['nation', nation]])
.then(r => r.json())
.then(j => j as CompetitionList);
}
/**
*
* @param {string} competitionId the id of the competition
* @param {string} categoryId the id of the category
* @return {Promise<SpeedCompetitionCategoryResult>}
*/
public async getCompetitionResults(
competitionId: string,
categoryId: string,
): Promise<SpeedCompetitionCategoryResult> {
return await this._request([
['comp', competitionId],
['cat', categoryId],
])
.then(r => r.json())
.then(j => j as SpeedCompetitionCategoryResult);
}
/**
*
* @param {[string][]} params GET query parameters
* @return {Promise<Response>} the response
*/
private async _request(params: string[][]) {
return await fetch(this.BASE_URL + new URLSearchParams(params).toString());
}
}

230
src/data/SpeedFlowchart.tsx Normal file
View file

@ -0,0 +1,230 @@
import { FILE } from 'dns';
import { SpeedCompetitionCategoryResult } from '../models/Competition';
import { Participant } from '../models/Participant';
export interface SpeedRoundPair {
laneA?: Participant;
laneB?: Participant;
}
export interface SpeedRound {
pairs: SpeedRoundPair[];
roundIndex: number;
roundName?: string;
}
/**
* Class for use with speed flowcharts
*/
export class SpeedFlowchart {
private _result: SpeedCompetitionCategoryResult;
/**
*
* @param {SpeedCompetitionCategoryResult} result
*/
constructor(result: SpeedCompetitionCategoryResult) {
this._result = result;
}
/**
*
* @return {SpeedRound[]} list of speed rounds
*/
public _convert() {
const allData: SpeedRound[] = [];
const rounds =
Object.keys(this._result.route_names).length > 2
? this._result.route_names['2']?.includes('8')
? 2
: 1
: 0;
const setAorB = (pair: SpeedRoundPair, participant: Participant) => {
if (pair.laneA === undefined) pair.laneA = participant;
else pair.laneB = participant;
};
// console.log(this._result.route_names);
for (const round in this._result.route_names) {
if (
Object.keys(this._result.route_names).indexOf(round) >= 0 &&
parseInt(round) >= 0
) {
// console.log(round);
if (parseInt(round) === 0) {
// this is the first round
// find pairs (always worse vs. best (1-16; 1-15; ...)) (they are sorted by the rank of the better athlete (1-2-3-4-5-6-7-8)
const qualificationResults: Participant[] = [];
for (let x = 0; x < this._result.participants.length; x++) {
qualificationResults.push(this._result.participants[x]);
}
qualificationResults.sort(function (a, b) {
return (
parseInt(a.result_rank0 ?? '') - parseInt(b.result_rank0 ?? '')
);
});
const nextRoundPairs: SpeedRoundPair[] = [];
const totalMatches =
(Object.keys(this._result.route_names).length > 2
? this._result.route_names['2']?.includes('8')
? 2
: 1
: 0) + 2;
const nextRoundMatches = Math.pow(2, totalMatches - 1);
for (let i = 0; i < nextRoundMatches; i++) {
nextRoundPairs.push({
laneA: qualificationResults[i],
laneB: qualificationResults[nextRoundMatches * 2 - i - 1],
});
}
// build second round pairs (sorted by the rank of the better athlete and worst vs. best (1-8; 2-7; ... ))
const sortedFirstRoundPairs: [SpeedRoundPair?, SpeedRoundPair?][] =
[];
for (let i = 0; i < nextRoundMatches; i += 1) {
sortedFirstRoundPairs.push([
nextRoundPairs.shift(),
nextRoundPairs.pop(),
]);
}
// sort these pairs (containing two pairs of athletes) by the rank of the better athlete (1-4;2-3)
const finalSortedFirstRoundPairs = [];
for (let i = 0; i < nextRoundMatches / 4; i++) {
finalSortedFirstRoundPairs.push(sortedFirstRoundPairs[i]);
finalSortedFirstRoundPairs.push(
sortedFirstRoundPairs[nextRoundMatches / 2 - i - 1],
);
}
// convert the list of pairs of pairs of athletes back to a single list of pairs of athletes
const finalFirstRoundPairs: SpeedRoundPair[] = [];
for (let i = 0; i < finalSortedFirstRoundPairs.length; i++) {
if (finalSortedFirstRoundPairs[i][0] !== undefined)
finalFirstRoundPairs.push(finalSortedFirstRoundPairs[i][0]!);
if (finalSortedFirstRoundPairs[i][1] !== undefined)
finalFirstRoundPairs.push(finalSortedFirstRoundPairs[i][1]!);
}
// push the first round to all data
allData.push({
pairs: finalFirstRoundPairs,
roundIndex: 2,
roundName: this._result.route_names[2] ?? '',
});
// console.log(allData);
} else if (parseInt(round) > 0) {
// this is not the first round
const nextRound: SpeedRound = {
pairs: [],
roundIndex: -1,
roundName: '',
};
// only used when the current round is the 1/2 final
const smallFinal: SpeedRoundPair = {};
const Final: SpeedRoundPair = {};
for (
let i = 0;
i < allData[allData.length - 1].pairs.length;
i += 1
) {
const thisPair: SpeedRoundPair =
allData[allData.length - 1].pairs[i];
let thisWinner;
let thisLooser;
const thisWinnerIsFirstOfNewPair = i % 2 === 0;
if (thisPair.laneA === undefined || thisPair.laneB === undefined) {
continue;
}
if (thisWinnerIsFirstOfNewPair) {
nextRound.pairs.push({});
}
if (
Object.keys(thisPair.laneA).indexOf('result_rank' + round) < 0 ||
Object.keys(thisPair.laneB).indexOf('result_rank' + round) < 0
) {
continue;
}
if (
parseInt(thisPair.laneA['result_rank' + round] as string) <
parseInt(thisPair.laneB['result_rank' + round] as string)
) {
thisWinner = thisPair.laneA;
thisLooser = thisPair.laneB;
} else if (
parseInt(thisPair.laneA['result_rank' + round] as string) >
parseInt(thisPair.laneB['result_rank' + round] as string)
) {
thisWinner = thisPair.laneB;
thisLooser = thisPair.laneA;
} else {
// no result yet!!
/* console.log(
'got no winner yet, rank 0: ' +
thisPair.laneA['result_rank' + round] +
' rank 1: ' +
thisPair.laneB['result_rank' + round],
);*/
continue;
}
// console.log(thisWinner['firstname'] + ' has won in round ' + round);
if (parseInt(round) - rounds === 2) {
// if we are in the 1/2 final
setAorB(Final, thisWinner);
setAorB(smallFinal, thisLooser);
} else {
setAorB(nextRound.pairs[nextRound.pairs.length - 1], thisWinner);
}
}
if (smallFinal.laneA !== undefined && Final.laneA !== undefined) {
// Final
allData.push({
pairs: [Final],
roundIndex: parseInt(round) + 2,
roundName:
this._result.route_names[String(parseInt(round) + 2)] +
' / ' +
this._result.route_names[String(parseInt(round) + 1)],
});
// small Final
allData.push({
pairs: [smallFinal],
roundIndex: parseInt(round) + 1,
});
} else {
nextRound.roundIndex = parseInt(round) + 1;
nextRound.roundName = this._result.route_names[parseInt(round) + 1];
allData.push(nextRound);
}
}
}
}
return allData;
}
}

13
src/index.css Normal file
View file

@ -0,0 +1,13 @@
body {
margin: 0;
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
code {
font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New',
monospace;
}

19
src/index.tsx Normal file
View file

@ -0,0 +1,19 @@
import React from 'react';
import ReactDOM from 'react-dom/client';
import './index.css';
import App from './App';
import reportWebVitals from './reportWebVitals';
const root = ReactDOM.createRoot(
document.getElementById('root') as HTMLElement,
);
root.render(
<React.StrictMode>
<App />
</React.StrictMode>,
);
// If you want to start measuring performance in your app, pass a function
// to log results (for example: reportWebVitals(console.log))
// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
reportWebVitals();

1
src/logo.svg Normal file
View file

@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 841.9 595.3"><g fill="#61DAFB"><path d="M666.3 296.5c0-32.5-40.7-63.3-103.1-82.4 14.4-63.6 8-114.2-20.2-130.4-6.5-3.8-14.1-5.6-22.4-5.6v22.3c4.6 0 8.3.9 11.4 2.6 13.6 7.8 19.5 37.5 14.9 75.7-1.1 9.4-2.9 19.3-5.1 29.4-19.6-4.8-41-8.5-63.5-10.9-13.5-18.5-27.5-35.3-41.6-50 32.6-30.3 63.2-46.9 84-46.9V78c-27.5 0-63.5 19.6-99.9 53.6-36.4-33.8-72.4-53.2-99.9-53.2v22.3c20.7 0 51.4 16.5 84 46.6-14 14.7-28 31.4-41.3 49.9-22.6 2.4-44 6.1-63.6 11-2.3-10-4-19.7-5.2-29-4.7-38.2 1.1-67.9 14.6-75.8 3-1.8 6.9-2.6 11.5-2.6V78.5c-8.4 0-16 1.8-22.6 5.6-28.1 16.2-34.4 66.7-19.9 130.1-62.2 19.2-102.7 49.9-102.7 82.3 0 32.5 40.7 63.3 103.1 82.4-14.4 63.6-8 114.2 20.2 130.4 6.5 3.8 14.1 5.6 22.5 5.6 27.5 0 63.5-19.6 99.9-53.6 36.4 33.8 72.4 53.2 99.9 53.2 8.4 0 16-1.8 22.6-5.6 28.1-16.2 34.4-66.7 19.9-130.1 62-19.1 102.5-49.9 102.5-82.3zm-130.2-66.7c-3.7 12.9-8.3 26.2-13.5 39.5-4.1-8-8.4-16-13.1-24-4.6-8-9.5-15.8-14.4-23.4 14.2 2.1 27.9 4.7 41 7.9zm-45.8 106.5c-7.8 13.5-15.8 26.3-24.1 38.2-14.9 1.3-30 2-45.2 2-15.1 0-30.2-.7-45-1.9-8.3-11.9-16.4-24.6-24.2-38-7.6-13.1-14.5-26.4-20.8-39.8 6.2-13.4 13.2-26.8 20.7-39.9 7.8-13.5 15.8-26.3 24.1-38.2 14.9-1.3 30-2 45.2-2 15.1 0 30.2.7 45 1.9 8.3 11.9 16.4 24.6 24.2 38 7.6 13.1 14.5 26.4 20.8 39.8-6.3 13.4-13.2 26.8-20.7 39.9zm32.3-13c5.4 13.4 10 26.8 13.8 39.8-13.1 3.2-26.9 5.9-41.2 8 4.9-7.7 9.8-15.6 14.4-23.7 4.6-8 8.9-16.1 13-24.1zM421.2 430c-9.3-9.6-18.6-20.3-27.8-32 9 .4 18.2.7 27.5.7 9.4 0 18.7-.2 27.8-.7-9 11.7-18.3 22.4-27.5 32zm-74.4-58.9c-14.2-2.1-27.9-4.7-41-7.9 3.7-12.9 8.3-26.2 13.5-39.5 4.1 8 8.4 16 13.1 24 4.7 8 9.5 15.8 14.4 23.4zM420.7 163c9.3 9.6 18.6 20.3 27.8 32-9-.4-18.2-.7-27.5-.7-9.4 0-18.7.2-27.8.7 9-11.7 18.3-22.4 27.5-32zm-74 58.9c-4.9 7.7-9.8 15.6-14.4 23.7-4.6 8-8.9 16-13 24-5.4-13.4-10-26.8-13.8-39.8 13.1-3.1 26.9-5.8 41.2-7.9zm-90.5 125.2c-35.4-15.1-58.3-34.9-58.3-50.6 0-15.7 22.9-35.6 58.3-50.6 8.6-3.7 18-7 27.7-10.1 5.7 19.6 13.2 40 22.5 60.9-9.2 20.8-16.6 41.1-22.2 60.6-9.9-3.1-19.3-6.5-28-10.2zM310 490c-13.6-7.8-19.5-37.5-14.9-75.7 1.1-9.4 2.9-19.3 5.1-29.4 19.6 4.8 41 8.5 63.5 10.9 13.5 18.5 27.5 35.3 41.6 50-32.6 30.3-63.2 46.9-84 46.9-4.5-.1-8.3-1-11.3-2.7zm237.2-76.2c4.7 38.2-1.1 67.9-14.6 75.8-3 1.8-6.9 2.6-11.5 2.6-20.7 0-51.4-16.5-84-46.6 14-14.7 28-31.4 41.3-49.9 22.6-2.4 44-6.1 63.6-11 2.3 10.1 4.1 19.8 5.2 29.1zm38.5-66.7c-8.6 3.7-18 7-27.7 10.1-5.7-19.6-13.2-40-22.5-60.9 9.2-20.8 16.6-41.1 22.2-60.6 9.9 3.1 19.3 6.5 28.1 10.2 35.4 15.1 58.3 34.9 58.3 50.6-.1 15.7-23 35.6-58.4 50.6zM320.8 78.4z"/><circle cx="420.9" cy="296.5" r="45.7"/><path d="M520.5 78.1z"/></g></svg>

After

Width:  |  Height:  |  Size: 2.6 KiB

6
src/models/Category.tsx Normal file
View file

@ -0,0 +1,6 @@
export interface Category {
GrpId: string;
name: string;
status: number;
url: string;
}

View file

@ -0,0 +1,26 @@
import { Category } from './Category';
import { Participant } from './Participant';
export interface Competiton {
WetId: string;
rkey: string;
name: string;
date_span: string;
discipline?: string;
cats: Category[];
}
export interface SpeedCompetitionCategoryResult extends Competiton {
route_names: {
'0'?: string; // Qualification
'1'?: string; // 1/16 - Final
'2'?: string; // 1/8 - Final
'3'?: string; // 1/4 - Final
'4'?: string; // 1/2 - Final
'5'?: string; // Small final
'6'?: string; // Final
'-1'?: string; // General result
[key: string]: string | undefined;
};
participants: Participant[];
}

View file

@ -0,0 +1,17 @@
/**
* A pariticpant of a competition
*/
export interface Participant {
PerId: string;
firstname: string;
lastname: string;
result_rank?: number;
['result_rank0']?: string;
['result_rank1']?: string;
['result_rank2']?: string;
['result_rank3']?: string;
['result_rank4']?: string;
['result_rank5']?: string;
['result_rank6']?: string;
[key: string]: string | number | undefined;
}

View file

@ -0,0 +1,88 @@
import {
Button,
Card,
CardActions,
CardContent,
Grid,
TextField,
Typography,
} from '@mui/material';
import React from 'react';
import { useNavigate } from 'react-router-dom';
import { Context } from '../data/Context';
import { Competiton } from '../models/Competition';
/**
*
* @return {JSX.Element} calendar page
*/
export default function CalendarPage() {
const [competitions, setCompetitions] = React.useState<Competiton[]>([]);
const { api } = React.useContext(Context);
const navigate = useNavigate();
React.useEffect(() => {
api.getCompetitions('GER').then(result => {
console.log(result.competitions.filter);
setCompetitions(
result.competitions.filter(competition =>
competition.discipline?.includes('speed'),
),
);
});
}, []);
const openCompetition = (competitionId: string, categoryId: string) => {
navigate(`/speed-flowchart/${competitionId}/${categoryId}`);
};
return (
<>
<Grid container spacing={2}>
<Grid item xs={12}>
<TextField
label='search for competition'
variant='outlined'
fullWidth
/>
</Grid>
{competitions.map(competition => (
<Grid item key={`competition-card-${competition.WetId}`} xs={12}>
<Card>
<CardContent>
<Typography gutterBottom variant='h5' component='div'>
{competition.name}
</Typography>
<Typography variant='body2' color='text.secondary'>
{competition.date_span}
</Typography>
</CardContent>
<CardActions>
<Grid container spacing={2}>
{competition.cats.map(category => (
<Grid
item
key={`competition-card-${competition.WetId}-category-button-${category.GrpId}`}
xs
>
<Button
size='small'
fullWidth
sx={{ width: '100%' }}
onClick={() =>
openCompetition(competition.WetId, category.GrpId)
}
>
{category.name}
</Button>
</Grid>
))}
</Grid>
</CardActions>
</Card>
</Grid>
))}
</Grid>
</>
);
}

View file

@ -0,0 +1,61 @@
import { Context } from '../data/Context';
import { useContext, useEffect, useState } from 'react';
import { useParams } from 'react-router-dom';
import { SpeedFlowchart, SpeedRound } from '../data/SpeedFlowchart';
import { Card, CardContent, Grid } from '@mui/material';
/**
*
* @return {JSX.Element} speed flowchart page
*/
export default function SpeedFlowchartPage() {
const { competitionId, categoryId } = useParams();
const { api } = useContext(Context);
const [rounds, setRounds] = useState<SpeedRound[]>([]);
useEffect(() => {
if (competitionId === undefined || categoryId === undefined) {
return;
}
api.getCompetitionResults(competitionId, categoryId).then(r => {
const flowchart = new SpeedFlowchart(r);
const rounds = flowchart
._convert()
.filter(round => round.roundName !== undefined && round.pairs.length);
console.log(rounds);
setRounds(rounds);
});
}, []);
return (
<>
<h1>RESULT:</h1>
<Grid container spacing={2}>
{rounds.map((round, roundKey) => (
<Grid key={`flowchart-column-${roundKey}`} item xs={12 / 5}>
<h3>{round.roundName}</h3>
<Grid container spacing={2}>
{round.pairs.map((pair, pairKey) => (
<Grid
key={`flowchart-column-${roundKey}-pair-${pairKey}`}
item
xs={12}
>
<Card>
<CardContent>
A: {pair.laneA?.firstname} {pair.laneA?.lastname}
<br />
B: {pair.laneB?.firstname} {pair.laneB?.lastname}
</CardContent>
</Card>
</Grid>
))}
</Grid>
</Grid>
))}
</Grid>
</>
);
}

1
src/react-app-env.d.ts vendored Normal file
View file

@ -0,0 +1 @@
/// <reference types="react-scripts" />

15
src/reportWebVitals.ts Normal file
View file

@ -0,0 +1,15 @@
import { ReportHandler } from 'web-vitals';
const reportWebVitals = (onPerfEntry?: ReportHandler) => {
if (onPerfEntry && onPerfEntry instanceof Function) {
import('web-vitals').then(({ getCLS, getFID, getFCP, getLCP, getTTFB }) => {
getCLS(onPerfEntry);
getFID(onPerfEntry);
getFCP(onPerfEntry);
getLCP(onPerfEntry);
getTTFB(onPerfEntry);
});
}
};
export default reportWebVitals;

5
src/setupTests.ts Normal file
View file

@ -0,0 +1,5 @@
// jest-dom adds custom jest matchers for asserting on DOM nodes.
// allows you to do things like:
// expect(element).toHaveTextContent(/react/i)
// learn more: https://github.com/testing-library/jest-dom
import '@testing-library/jest-dom';

View file

@ -0,0 +1,15 @@
import { Context } from '../data/Context';
import { DigitalrockAPi } from '../data/DigitalrockApi';
/**
* Sets Context for its children
* @param {{ children: JSX.Element }} props
* @return {JSX.Element}
*/
export default function ContextWrapper(props: { children: JSX.Element }) {
const { children } = props;
const api = new DigitalrockAPi();
return <Context.Provider value={{ api }}>{children}</Context.Provider>;
}

View file

@ -0,0 +1,20 @@
import { AdapterDateFns } from '@mui/x-date-pickers/AdapterDateFns';
import { LocalizationProvider } from '@mui/x-date-pickers/LocalizationProvider';
import deLocale from 'date-fns/locale/de';
/**
* Sets a Localization Context for TimeInputs
* @param {{ children: JSX.Element }} props
* @return {JSX.Element}
*/
export default function LocalizationProviderWrapper(props: {
children: JSX.Element;
}) {
const { children } = props;
return (
<LocalizationProvider adapterLocale={deLocale} dateAdapter={AdapterDateFns}>
{children}
</LocalizationProvider>
);
}

View file

@ -0,0 +1,24 @@
import Container from '@mui/material/Container';
import LocalizationProviderWrapper from './LocalizationProviderWrapper';
import ContextWrapper from './ContextWrapper';
/**
* Wrapps the page with all necessary utils
* @param {{ children: JSX.Element }} props accepts JSX elements to wrap theme in
* @return {JSX.Element}
*/
export default function PageTemplate(props: { children: JSX.Element }) {
const { children } = props;
return (
<ContextWrapper>
<Container
sx={{ marginTop: '50px' }}
className='root-container'
maxWidth='lg'
>
{children}
</Container>
</ContextWrapper>
);
}

24
src/utils/Routing.tsx Normal file
View file

@ -0,0 +1,24 @@
import { BrowserRouter, Routes, Route } from 'react-router-dom';
import CalendarPage from '../pages/CalendarPage';
import SpeedFlowchartPage from '../pages/SpeedFlowchartPage';
import PageTemplate from './PageTemplate';
/**
*
* @return {JSX.Element}
*/
export default function Routing() {
return (
<BrowserRouter>
<PageTemplate>
<Routes>
<Route path='/' element={<CalendarPage />} />
<Route
path='speed-flowchart/:competitionId/:categoryId'
element={<SpeedFlowchartPage />}
></Route>
</Routes>
</PageTemplate>
</BrowserRouter>
);
}

88
src/utils/Theme.tsx Normal file
View file

@ -0,0 +1,88 @@
import { CssBaseline } from '@mui/material';
import { ThemeProvider, createTheme } from '@mui/material/styles';
/**
* Sets a MaterialUi theme for its children
* @param {any} props accepts JSX elements to wrap theme in
* @return {JSX.Element}
*/
export default function Theme(props: { children: JSX.Element }) {
const { children } = props;
const Theme = createTheme({
components: {
MuiToggleButton: {
defaultProps: {
disableRipple: true,
},
},
},
palette: {
mode: 'light',
primary: {
main: '#81a1c1',
dark: '#5e81ac',
contrastText: '#fff',
},
secondary: {
main: '#88c0d0',
light: '#8fbcbb',
contrastText: '#3b4252',
},
error: {
main: '#bf616a',
},
warning: {
main: '#d08770',
},
info: {
main: '#ebcb8b',
},
success: {
main: '#a3be8c',
},
text: {
primary: '#2e3440',
secondary: '#4c566a',
},
grey: {
A200: '#eceff4',
A400: '#e5e9f0',
A700: '#d8dee9',
},
},
shadows: [
'none',
'rgba(50, 50, 93, 0.125) 0px 3px 8px -1px,rgba(0, 0, 0, 0.13) 0px 2px 4px -2px;',
'rgba(50, 50, 93, 0.125) 0px 2px 5px -1px,rgba(0, 0, 0, 0.13) 0px 1px 3px -1px;',
'rgba(50, 50, 93, 0.125) 0px 4px 11px -2px,rgba(0, 0, 0, 0.13) 0px 3px 6px -3px;',
'rgba(50, 50, 93, 0.125) 0px 5px 14px -2px,rgba(0, 0, 0, 0.13) 0px 4px 7px -4px;',
'rgba(50, 50, 93, 0.125) 0px 6px 17px -3px,rgba(0, 0, 0, 0.13) 0px 5px 9px -5px;',
'rgba(50, 50, 93, 0.125) 0px 7px 20px -3px,rgba(0, 0, 0, 0.13) 0px 6px 10px -6px;',
'rgba(50, 50, 93, 0.125) 0px 8px 22px -4px,rgba(0, 0, 0, 0.13) 0px 7px 12px -7px;',
'rgba(50, 50, 93, 0.125) 0px 8px 24px -5px,rgba(0, 0, 0, 0.13) 0px 8px 13px -7px;',
'rgba(50, 50, 93, 0.125) 0px 8px 27px -5px,rgba(0, 0, 0, 0.13) 0px 8px 15px -8px;',
'rgba(50, 50, 93, 0.125) 0px 13px 27px -5px,rgba(0, 0, 0, 0.13) 0px 8px 16px -8px;',
'rgba(50, 50, 93, 0.125) 0px 25px 35px -5px,rgba(0, 0, 0, 0.13) 0px 15px 20px -12px;',
'rgba(50, 50, 93, 0.125) 0px 30px 45px -7px,rgba(0, 0, 0, 0.13) 0px 20px 25px -15px;',
'rgba(50, 50, 93, 0.125) 0px 35px 55px -10px,rgba(0, 0, 0, 0.13) 0px 25px 30px -18px;',
'rgba(50, 50, 93, 0.125) 0px 40px 65px -12px,rgba(0, 0, 0, 0.13) 0px 30px 35px -21px;',
'rgba(50, 50, 93, 0.125) 0px 45px 75px -15px,rgba(0, 0, 0, 0.13) 0px 35px 40px -24px;',
'rgba(50, 50, 93, 0.125) 0px 50px 85px -17px,rgba(0, 0, 0, 0.13) 0px 40px 45px -27px;',
'rgba(50, 50, 93, 0.125) 0px 55px 95px -20px,rgba(0, 0, 0, 0.13) 0px 45px 50px -30px;',
'rgba(50, 50, 93, 0.125) 0px 60px 105px -22px,rgba(0, 0, 0, 0.13) 0px 50px 55px -33px;',
'rgba(50, 50, 93, 0.125) 0px 65px 110px -25px,rgba(0, 0, 0, 0.13) 0px 55px 60px -36px;',
'rgba(50, 50, 93, 0.125) 0px 70px 115px -27px,rgba(0, 0, 0, 0.13) 0px 60px 65px -39px;',
'none',
'none',
'none',
'none',
],
});
return (
<ThemeProvider theme={Theme}>
<CssBaseline />
{children}
</ThemeProvider>
);
}

22
tsconfig.json Normal file
View file

@ -0,0 +1,22 @@
{
"compilerOptions": {
"target": "es5",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"noFallthroughCasesInSwitch": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "react-jsx",
"typeRoots": ["./src/@types", "./node_modules/@types"],
"strictPropertyInitialization": false
},
"include": ["src"]
}