diff --git a/Modules/database.ts b/Modules/database.ts index 1e12d84a..54780552 100644 --- a/Modules/database.ts +++ b/Modules/database.ts @@ -235,6 +235,7 @@ export interface historicalPlayers { pictureUrl: string; value: number; position: position; + forecast: forecast; total_points: number; average_points: number; last_match: number; diff --git a/components/Player.js b/components/Player.js index dbf42a23..1737d24f 100644 --- a/components/Player.js +++ b/components/Player.js @@ -91,7 +91,6 @@ function InternalPlayer({ data, children, starred, extraText, condensed }) { alt="" onError={() => { // If the picture does not exist a fallback picture is used - console.log(1); setPictureUrl(fallbackImg); }} src={pictureUrl} diff --git a/package-lock.json b/package-lock.json index 1e7a4f90..e2a7aea1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "fantasy-manager", - "version": "1.9.0", + "version": "1.9.1", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "fantasy-manager", - "version": "1.9.0", + "version": "1.9.1", "dependencies": { "@emotion/react": "11.10.5", "@emotion/styled": "11.10.5", diff --git a/package.json b/package.json index d6d16673..92bdd6f7 100644 --- a/package.json +++ b/package.json @@ -1,9 +1,9 @@ { "name": "fantasy-manager", - "version": "1.9.0", + "version": "1.9.1", "private": true, "scripts": { - "dev": "export NODE_ENV=development APP_ENV=development; npm install; npm run build:ts; node scripts/entrypoint.js & next dev", + "dev": "export NODE_ENV=development APP_ENV=development; npm run build:ts; node scripts/entrypoint.js & next dev", "build": "npm ci; npm run build:ts; next build;", "start": "export NODE_ENV=production APP_ENV=production; npm run start2", "test": "npm run cypress & npm run start:test", diff --git a/pages/api/player/[leagueType]/[uid].ts b/pages/api/player/[leagueType]/[uid].ts index 9a17bcf7..e852aad8 100644 --- a/pages/api/player/[leagueType]/[uid].ts +++ b/pages/api/player/[leagueType]/[uid].ts @@ -9,7 +9,7 @@ import { checkUpdate } from "../../../../scripts/checkUpdate"; // Used to return a dictionary on the data for a player export default async function handler( req: NextApiRequest, - res: NextApiResponse + res: NextApiResponse ) { if (req.method == "GET") { const connection = await connect(); @@ -40,7 +40,6 @@ export default async function handler( ); returnValue.push({ ...answer[0], - forecast: "a", updateRunning: true, game, }); diff --git a/pages/player/[league]/[uid].tsx b/pages/player/[league]/[uid].tsx index 29a82b29..570c0baa 100644 --- a/pages/player/[league]/[uid].tsx +++ b/pages/player/[league]/[uid].tsx @@ -3,7 +3,11 @@ import Link from "../../../components/Link"; import Dialog from "../../../components/Dialog"; import { GetServerSideProps } from "next"; import Head from "next/head.js"; -import connect, { historicalPlayers, players } from "../../../Modules/database"; +import connect, { + forecast, + historicalPlayers, + players, +} from "../../../Modules/database"; import Image from "next/image"; import { useEffect, useState } from "react"; import { @@ -92,6 +96,7 @@ interface Data { opponent: string; position: string; exists: boolean; + forecast: forecast; loading: false; } export default function Home({ @@ -127,6 +132,7 @@ export default function Home({ club: player.club, position: player.position, exists: player.exists, + forecast: player.forecast, loading: false, }, }); @@ -158,6 +164,7 @@ export default function Home({ opponent: data.game ? data.game.opponent : "", position: data.position, exists: data.exists, + forecast: data.forecast, loading: false, }; return newRows; @@ -269,7 +276,10 @@ export default function Home({

Historical Data Table

All the ones with a purple background mean the player was not in the - league during these matchdays. + league during these matchdays. Red background means that they were + missing and yellow that attendence was unknown(This data is what was + known just before the game started). Note: That that historical forecast + and historical opponents only exist since version 1.9.1.

@@ -286,7 +296,7 @@ export default function Home({ .sort((e) => e.time) .slice(page * rowsPerPage, page * rowsPerPage + rowsPerPage) .map((row) => { - if (row.loading) + if (row.loading) { return ( ); + } + // Gets the background color based on the status of the player + let background; + if (row.forecast == "u") { + background = dark ? "rgb(50, 50, 0)" : "rgb(255, 255, 220)"; + } else if (row.forecast == "m") { + background = dark ? "rgb(50, 0, 0)" : "rgb(255, 200, 200)"; + } + // Checks if the player exists + if (!row.exists) { + background = dark ? "rgb(50, 0, 50)" : "rgb(255, 235, 255)"; + } return ( { }); return result; }); - console.log(player); connection.end(); return { props: { diff --git a/scripts/entrypoint.ts b/scripts/entrypoint.ts index 1ceaf0f4..e4b59760 100644 --- a/scripts/entrypoint.ts +++ b/scripts/entrypoint.ts @@ -11,7 +11,7 @@ if (process.env.APP_ENV !== "test") { } const analyticsDomain = "https://fantasy.lschaefer.xyz"; // Used to tell the program what version of the database to use -const currentVersion = "1.9.0"; +const currentVersion = "1.9.1"; const date = new Date(); let day = date.getDay(); @@ -72,7 +72,7 @@ async function startUp() { ), // Used to store historical player data connection.query( - "CREATE TABLE IF NOT EXISTS historicalPlayers (time int, uid varchar(25), name varchar(255), nameAscii varchar(255), club varchar(3), pictureUrl varchar(255), value int, position varchar(3), total_points int, average_points int, last_match int, `exists` bool, league varchar(25))" + "CREATE TABLE IF NOT EXISTS historicalPlayers (time int, uid varchar(25), name varchar(255), nameAscii varchar(255), club varchar(3), pictureUrl varchar(255), value int, position varchar(3), forecast varchar(1), total_points int, average_points int, last_match int, `exists` bool, league varchar(25))" ), // Used to store historical transfer data connection.query( @@ -365,6 +365,23 @@ async function startUp() { await connection.query("DROP TABLE leagueSettingsTemp"); oldVersion = "1.9.0"; } + if (oldVersion === "1.9.0") { + console.log("Updating database to version 1.9.1"); + // Checks if the forecast column actually exists because it was removed a long time ago but not actually dropped + const forecastExists = await connection + .query( + "SELECT COUNT(*) AS CNT FROM pragma_table_info('historicalPlayers') WHERE name='forecast'" + ) + .then((e) => e[0].CNT === 1); + if (!forecastExists) { + await connection.query( + "ALTER TABLE historicalPlayers ADD forecast varchar(1)" + ); + } + // Sets all the forecasts for the historical players to attending because they were unknown. + await connection.query("UPDATE historicalPlayers SET forecast='a'"); + oldVersion = "1.9.1"; + } // HERE IS WHERE THE CODE GOES TO UPDATE THE DATABASE FROM ONE VERSION TO THE NEXT // Makes sure that the database is up to date if (oldVersion !== currentVersion) { diff --git a/scripts/update.ts b/scripts/update.ts index 83a10a45..d2a192cb 100644 --- a/scripts/update.ts +++ b/scripts/update.ts @@ -92,6 +92,7 @@ export async function updateData( let index = 0; let club = ""; let clubDone = false; + let gameStarted = false; const getClub = (club: string): clubs => { const result = clubs.filter((e) => e.club == club); if (result.length == 0) { @@ -178,9 +179,11 @@ export async function updateData( .then((res) => res.length > 0 ? clubData.opponent !== res[0].opponent : false ); - // Checks if the club has not changed during the transfer period + gameStarted = clubData.gameStart <= currentTime; + // Checks if the club has not changed during the matchday if (!clubDone) { - if (clubData.gameStart > currentTime) { + // Checks if the game is supposed to have already started + if (!gameStarted) { await connection.query( "INSERT INTO clubs (club, gameStart, opponent, league) VALUES (?, ?, ?, ?) ON DUPLICATE KEY UPDATE gameStart=?, opponent=?", [ @@ -232,20 +235,37 @@ export async function updateData( ); // Makes sure that the club is not done for the matchday } else if (!clubDone) { - await connection.query( - "UPDATE players SET value=?, forecast=?, total_points=?, average_points=?, last_match=?, locked=?, `exists`=1 WHERE uid=?", - [ - val.value, - val.forecast, - val.total_points, - val.average_points, - playerExists[0].last_match + - val.total_points - - playerExists[0].total_points, - val.locked, - val.uid, - ] - ); + // Only updates the forecast if the game has not already started + if (gameStarted) { + await connection.query( + "UPDATE players SET value=?, total_points=?, average_points=?, last_match=?, locked=?, `exists`=1 WHERE uid=?", + [ + val.value, + val.total_points, + val.average_points, + playerExists[0].last_match + + val.total_points - + playerExists[0].total_points, + val.locked, + val.uid, + ] + ); + } else { + await connection.query( + "UPDATE players SET value=?, forecast=?, total_points=?, average_points=?, last_match=?, locked=?, `exists`=1 WHERE uid=?", + [ + val.value, + val.forecast, + val.total_points, + val.average_points, + playerExists[0].last_match + + val.total_points - + playerExists[0].total_points, + val.locked, + val.uid, + ] + ); + } } else { await connection.query("UPDATE players SET `exists`=1 WHERE uid=?", [ val.uid, @@ -375,7 +395,7 @@ async function endMatchday(league: string) { console.log(`Archiving player data for ${league}`); // Copies all the player data to the historical player data await connection.query( - "INSERT INTO historicalPlayers (time, uid, name, nameAscii, club, pictureUrl, value, position, total_points, average_points, last_match, `exists`, league) SELECT ? as time, uid, name, nameAscii, club, pictureUrl, value, position, total_points, average_points, last_match, `exists`, league FROM players WHERE league=?", + "INSERT INTO historicalPlayers (time, uid, name, nameAscii, club, pictureUrl, value, position, forecast, total_points, average_points, last_match, `exists`, league) SELECT ? as time, uid, name, nameAscii, club, pictureUrl, value, position, forecast, total_points, average_points, last_match, `exists`, league FROM players WHERE league=?", [time, league] ); console.log(`Archiving matchday data for ${league}`);