Skip to content

Commit

Permalink
Merge branch 'master' of github.com:radeksoft/gjpcup2
Browse files Browse the repository at this point in the history
  • Loading branch information
chamik committed Aug 15, 2023
2 parents 16a52ee + 16c4312 commit cc435ac
Show file tree
Hide file tree
Showing 10 changed files with 96 additions and 24 deletions.
36 changes: 36 additions & 0 deletions rozpis
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
Septima : 1.B
Kvinta : NG
Druháci : Třeťáci
4.B : 1.A
Sexta : Kvinta
Třeťáci : Septima
NG : 4.B
1.A : Druháci
1.B : Třeťáci
4.B : Sexta
Septima : 1.A
Druháci : NG
Kvinta : 4.B
1.A : 1.B
Sexta : Druháci
NG : Septima
Třeťáci : 1.A
Druháci : Kvinta
1.B : NG
Septima : Sexta
4.B : Druháci
NG : Třeťáci
Kvinta : Septima
Sexta : 1.B
1.A : NG
Septima : 4.B
Třeťáci : Sexta
1.B : Kvinta
Druháci : Septima
Sexta : 1.A
4.B : 1.B
Kvinta : Třeťáci
NG : Sexta
1.B : Druháci
1.A : Kvinta
Třeťáci : 4.B
7 changes: 6 additions & 1 deletion scripts/filldb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ if (!await confirm())
const csv = fs.readFileSync('./tymy.csv', 'utf8');
const teams = parseTeamsPlayers(csv);

const rozpisyStr = fs.readFileSync('./rozpis', 'utf8');
const rozpisy = rozpisyStr.split('\n');
console.log({rozpisy});
// process.exit(1);

const pb = new PocketBase(POCKETBASE_ENDPOINT);
await pb.admins.authWithPassword(POCKETBASE_ADMIN_EMAIL, POCKETBASE_ADMIN_PASSWORD);

Expand All @@ -37,7 +42,7 @@ await addMembersToTeams(updatedTeams, pb);

const studentTeams = emptyTeams.filter(t => !t.teachers);

const nextNo = await createGames(studentTeams, pb);
const nextNo = await createGames(studentTeams, rozpisy, pb);

const teachersTeam = emptyTeams.find(t => t.teachers);
assert(teachersTeam);
Expand Down
26 changes: 20 additions & 6 deletions scripts/filldb/games.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,39 @@ import { TeamWithRef } from './teams';
/**
* @returns the next games.no to be used for createTeachersGame
*/
export const createGames = async (studentTeams: TeamWithRef[], pb: PocketBase) => {
export const createGames = async (studentTeams: TeamWithRef[], rozpisy: string[], pb: PocketBase) => {
const gamesColl = pb.collection('games');
let no = 0;

for (let i = 0; i < studentTeams.length; i++) {
const team1 = studentTeams[i];
for (let j = i+1; j < studentTeams.length; j++) {
const team2 = studentTeams[j];
const no = rozpisy.findIndex(match => match === `${team1.name} : ${team2.name}` || match === `${team2.name} : ${team1.name}`)
const match = rozpisy[no];

let currentTeam1: TeamWithRef;
let currentTeam2: TeamWithRef;

if (match === `${team1.name} : ${team2.name}`) {
// correct order
currentTeam1 = team1;
currentTeam2 = team2;
} else {
currentTeam1 = team2;
currentTeam2 = team1;
}

console.log(team1.name, team2.name, no);
await gamesColl.create({
team1: team1.dbRef,
team2: team2.dbRef,
team1: currentTeam1.dbRef,
team2: currentTeam2.dbRef,
no,
finished: false,
});
no++;
}
}

return no;
return studentTeams.length * (studentTeams.length-1) / 2;
};

export const createTeachersGame = async (teachersTeam: TeamWithRef, no: number, pb: PocketBase) => {
Expand Down
4 changes: 2 additions & 2 deletions scripts/resetdb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ console.log('Confirm with y<Enter>')
if (!await confirm())
process.exit(1);

const TEACHERS_TEAM_ID = 'pg7a6r910fvfhlq';
const TEACHERS_TEAM_ID = '2578hwt3ngdwr3b';

const pb = new PocketBase(POCKETBASE_ENDPOINT);
await pb.admins.authWithPassword(POCKETBASE_ADMIN_EMAIL, POCKETBASE_ADMIN_PASSWORD);
Expand Down Expand Up @@ -66,7 +66,7 @@ console.log('resetting gameState');
await miscColl.update(gameState.id!, {
currentGameNo: 0,
matchStarted: false,
gameDuration: 6.5,
gameDuration: 8,
currentGameStart: null,
revealTeachers: false,
});
Expand Down
2 changes: 2 additions & 0 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import './style.css';

import { useAppContent } from 'pocketbase-react/src';
import type { Game, GameState, Goal, News, Player, Team } from './types';
import { AppFooter } from './components/app-footer';

const serverURL = import.meta.env.VITE_POCKETBASE_ENDPOINT;
// these get automatically prefetched & subscribed to updates
Expand All @@ -29,6 +30,7 @@ export const App: React.FC = () => {
<PocketbaseDataLoader>
<Router />
</PocketbaseDataLoader>
<AppFooter />
</div>
</PocketbaseProvider>
);
Expand Down
12 changes: 12 additions & 0 deletions src/components/app-footer.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import React from 'react';
import Container from 'react-bootstrap/Container';

export const AppFooter: React.FC = () => {
return (
<footer className=''>
<Container className='text-center p-3'>
<span>Vytvořil <a href='https://radeksoft.cz/'>Radeksoft</a>.</span>
</Container>
</footer>
);
};
3 changes: 2 additions & 1 deletion src/components/finished-matches.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ export const FinishedMatches: React.FC = () => {

const finishedGames = useMemo(() => {
const filtered = games.filter(g => g.no < gameState.currentGameNo)
return filtered;
const sorted = filtered.sort((a, b) => a.no - b.no);
return sorted;
}, [games, gameState]);

if (!finishedGames || !finishedGames.length)
Expand Down
6 changes: 3 additions & 3 deletions src/components/future-matches.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ export const FutureMatches: React.FC<FutureMatchesProps> = props => {
const offset = gameState.matchStarted ? 0 : 1;

if (limit) {
return gamesToShow.filter(g => g.no+offset > gameState.currentGameNo).slice(0, limit);
return gamesToShow.filter(g => g.no+offset > gameState.currentGameNo).sort((a, b) => a.no - b.no).slice(0, limit);
} else {
return gamesToShow.filter(g => g.no+offset > gameState.currentGameNo);
return gamesToShow.filter(g => g.no+offset > gameState.currentGameNo).sort((a, b) => a.no - b.no);
}
}, [games, gameState, limit]);

Expand Down Expand Up @@ -74,7 +74,7 @@ const FutureMatch: React.FC<FutureMatchProps> = props => {
}, [game, getTeamsByGame]);

const gameStartFormatted = useMemo(() => {
const diff = game.no - gameState.currentGameNo;
const diff = game.no - gameState.currentGameNo - 1;
const cloned = new Date(nextGameStart);
cloned.setMinutes(cloned.getMinutes() + diff * gameState.gameDuration);
const formatted = cloned.toLocaleTimeString('cs-cz', { hour: 'numeric', minute: '2-digit' });
Expand Down
2 changes: 2 additions & 0 deletions src/pages/admin/home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { GoalRow } from '../../components/goal-row';
import { useGameLogic, PAGE_STYLE } from '../../logic';
import { useAdminLogic } from '../../admin-logic';
import { AdminGoalInput } from '../../components/admin/goal-input';
import { FutureMatches } from '../../components/future-matches';

const vsInlineStyle: React.CSSProperties = {
marginTop: 'auto',
Expand Down Expand Up @@ -155,6 +156,7 @@ export const AdminHomePage: React.FC = () => {
</Table>
</Card>
)}
<FutureMatches limit={6} />
<Button variant="danger" onClick={() => actions.signOut()}>log out</Button>
</div>
);
Expand Down
22 changes: 11 additions & 11 deletions src/pages/bufet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@ export const BufetPage: React.FC = () => {
<Card.Header>Bufet</Card.Header>

<Card.Body style={{fontSize: 18}}>
<p className="pb-4">Bufet je otevřený! V nabídce najdete:</p>
<p className="pb-4">Bufet je otevřený!</p>

<p>Whey protein - 30 Kč</p>
<p>Párek v rohlíku - 20 Kč</p>
<p>Párek na tácku - 10 Kč</p>
<p>Toust - 20 Kč</p>
<p>Voda citrón máta - 5 Kč</p>
<p>Kreatin 10g - 30 Kč</p>
<p>Kofein 200mg - 40 Kč</p>
<p>Sušené mléko - 15 Kč</p>
<p>Muffin od Bobisovy babičky - 10 Kč</p>
<p>Párek v rohlíku – 25 Kč</p>
<p>Pomelo grep 0.3 – 27 Kč</p>
<p>Pomelo grep 0.5 – 35 Kč</p>
<p>Oreo zmrzlina – 20 Kč/kopeček</p>
<p>Voda citron led 0.5 – 10 Kč</p>
<p>Toust – 25 Kč</p>

<p className="mt-4">Dejte si do nosu :)</p>

<p className="mt-4"><b>Prosíme, nenoste jídlo do haly!</b></p>

<p className="pt-2">Dejte si do nosu ;)</p>
</Card.Body>
</Card>
</div>
Expand Down

0 comments on commit cc435ac

Please sign in to comment.