From 9ce1a9bc0421cccf27033f335ecefeeeb92bd281 Mon Sep 17 00:00:00 2001 From: Orfeas Stefanos Thyfronitis Litos Date: Sun, 2 Jul 2023 22:59:56 +0100 Subject: [PATCH 1/9] Change site as a test --- components/leaderboard.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/components/leaderboard.tsx b/components/leaderboard.tsx index 925564f..0ff6c4b 100644 --- a/components/leaderboard.tsx +++ b/components/leaderboard.tsx @@ -77,7 +77,7 @@ export default ({year, month, contractorHours, monthProjections}: {

- High Scores + Test! @@ -95,7 +95,7 @@ export default ({year, month, contractorHours, monthProjections}: { contractors.length == 0 || year < 2000 || year > 2100 || month < 1 || month > 12? ( -

No data yet for this month.

+

Test...

) : ( From 16a12ad70c12ace730cbc35112aea9508705c94f Mon Sep 17 00:00:00 2001 From: Orfeas Stefanos Thyfronitis Litos Date: Mon, 10 Jul 2023 20:28:56 +0100 Subject: [PATCH 2/9] =?UTF-8?q?Revert=20"Remove=20=F0=9F=92=A9"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit e8f46443557d98477f8ea594103f122c496e5745. --- components/leaderboard.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/components/leaderboard.tsx b/components/leaderboard.tsx index 0ff6c4b..2bc0af8 100644 --- a/components/leaderboard.tsx +++ b/components/leaderboard.tsx @@ -114,7 +114,8 @@ export default ({year, month, contractorHours, monthProjections}: { const emoji = i == 0? '🥇': i == 1? '🥈': - i == 2? '🥉': '' + i == 2? '🥉': + i == contractors.length - 1? '💩': '' return Date: Mon, 10 Jul 2023 20:31:49 +0100 Subject: [PATCH 3/9] =?UTF-8?q?Revert=20"Revert=20"Remove=20=F0=9F=92=A9""?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 16a12ad70c12ace730cbc35112aea9508705c94f. --- components/leaderboard.tsx | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/components/leaderboard.tsx b/components/leaderboard.tsx index 2bc0af8..0ff6c4b 100644 --- a/components/leaderboard.tsx +++ b/components/leaderboard.tsx @@ -114,8 +114,7 @@ export default ({year, month, contractorHours, monthProjections}: { const emoji = i == 0? '🥇': i == 1? '🥈': - i == 2? '🥉': - i == contractors.length - 1? '💩': '' + i == 2? '🥉': '' return Date: Mon, 10 Jul 2023 20:31:53 +0100 Subject: [PATCH 4/9] Revert "Change site as a test" This reverts commit 9ce1a9bc0421cccf27033f335ecefeeeb92bd281. --- components/leaderboard.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/components/leaderboard.tsx b/components/leaderboard.tsx index 0ff6c4b..925564f 100644 --- a/components/leaderboard.tsx +++ b/components/leaderboard.tsx @@ -77,7 +77,7 @@ export default ({year, month, contractorHours, monthProjections}: {

- Test! + High Scores @@ -95,7 +95,7 @@ export default ({year, month, contractorHours, monthProjections}: { contractors.length == 0 || year < 2000 || year > 2100 || month < 1 || month > 12? ( -

Test...

+

No data yet for this month.

) : ( From f28be9940e44716767bf7cb91cd85938a0811b84 Mon Sep 17 00:00:00 2001 From: Orfeas Stefanos Thyfronitis Litos Date: Mon, 10 Jul 2023 20:31:54 +0100 Subject: [PATCH 5/9] Revert "Begin work on profile page" This reverts commit b89c7ef8f4ae3b38876077fe32d2ccbbb1270d94. --- lib/spreadsheet.ts | 45 ++--------------------- pages/index.tsx | 4 +- pages/leaderboard/[...date].tsx | 4 +- pages/profile/[username].tsx | 65 ++------------------------------- styles/Home.module.css | 23 ------------ test.html | 48 ------------------------ 6 files changed, 11 insertions(+), 178 deletions(-) delete mode 100644 test.html diff --git a/lib/spreadsheet.ts b/lib/spreadsheet.ts index 2147f57..5b43768 100644 --- a/lib/spreadsheet.ts +++ b/lib/spreadsheet.ts @@ -106,12 +106,12 @@ function parseDate(dateString: string) { year = parseInt(year) month = parseInt(month) - return { month, year } + return {month, year} } function filterLogByDate(desiredYear: number, desiredMonth: number) { return (entry: LogEntry): boolean => { - const { month, year } = parseDate(entry.date) + const {month, year} = parseDate(entry.date) return year == desiredYear && month == desiredMonth } @@ -121,7 +121,7 @@ function filterLogByContractor(desiredContractor: string) { return (entry: LogEntry) => entry.contractor == desiredContractor } -export async function getMonthHoursByContractor(year: number, month: number): Promise<{ [index: string]: number }> { +export async function getMonthHours(year: number, month: number): Promise<{ [index: string]: number }> { let log = await getLog() const contractors: {[index: string]: number} = {} @@ -138,42 +138,3 @@ export async function getMonthHoursByContractor(year: number, month: number): Pr return contractors } - -export async function getContractorHoursByMonth(contractor: string): - Promise<[number, number, number][]> { - let log = await getLog() - let ret: [number, number, number][] = [] - - log = log.filter(filterLogByContractor(contractor)) - - const dict: { [year: string]: { [month: string]: number } } = {} - - for (const { date, hours } of log) { - const { month, year } = parseDate(date) - - if (dict[year] === undefined) { - dict[year] = {} - } - if (dict[year][month] === undefined) { - dict[year][month] = 0 - } - dict[year][month] += parseFloat(hours) - } - - for (const year in dict) { - for (const month in dict[year]) { - ret.push([parseInt(year), parseInt(month), dict[year][month]]) - } - } - - ret = ret.sort(([year1, month1], [year2, month2]) => { - if (year1 == year2) { - return month1 - month2 - } - return year1 - year2 - }) - - console.log({ ret }) - - return ret -} diff --git a/pages/index.tsx b/pages/index.tsx index 0c3ee2f..df25a2a 100644 --- a/pages/index.tsx +++ b/pages/index.tsx @@ -1,4 +1,4 @@ -import { getMonthHoursByContractor, getMonthProjections } from '../lib/spreadsheet' +import { getMonthHours, getMonthProjections } from '../lib/spreadsheet' import Leaderboard from '../components/leaderboard' function getCurrentDate() { @@ -14,7 +14,7 @@ export async function getServerSideProps() { const { year, month } = getCurrentDate() const contractorHours: { [index: string]: number - } = await getMonthHoursByContractor(year, month) + } = await getMonthHours(year, month) const monthProjections = await getMonthProjections(year, month) return { diff --git a/pages/leaderboard/[...date].tsx b/pages/leaderboard/[...date].tsx index d5ec219..06482a6 100644 --- a/pages/leaderboard/[...date].tsx +++ b/pages/leaderboard/[...date].tsx @@ -1,4 +1,4 @@ -import { getMonthHoursByContractor, getMonthProjections } from '../../lib/spreadsheet' +import { getMonthHours, getMonthProjections } from '../../lib/spreadsheet' import Leaderboard from '../../components/leaderboard' function getCurrentDate() { @@ -17,7 +17,7 @@ export async function getServerSideProps(context: any) { const contractorHours: { [index: string]: number - } = await getMonthHoursByContractor(year, month) + } = await getMonthHours(year, month) const monthProjections:{ [index: string]: number diff --git a/pages/profile/[username].tsx b/pages/profile/[username].tsx index c81bb16..f412355 100644 --- a/pages/profile/[username].tsx +++ b/pages/profile/[username].tsx @@ -1,84 +1,27 @@ import styles from '../../styles/Home.module.css' import Head from 'next/head' -import { getContractorHoursByMonth } from '../../lib/spreadsheet' -function UserProfile(data: - { error?: string, - username: string, - log?: [number, number, number][], - maxHours?: number }) { - const { username } = data - let body - - if (data.error) { - body = data.error - } - else { - let maxHours = data.maxHours! - body =
- { - data.log!.map(([year, month, hours], index) => -
-
-
{ Math.round(hours) }
-
- ) - } -
- } +function UserProfile({ username }: { username: string }) { + console.log({ username }) return
- { `${username} - Common Prefix Leaderboard` } + Common Prefix Leaderboard

{ username }

- - { body }
} export async function getServerSideProps(context: any) { const username = context.params.username - let log - - return { - props: { - username: 'dionyziz', - maxHours: 70, - log: [ - [2023, 1, 30], - [2023, 2, 70], - [2023, 3, 17.5] - ] - } - } - - try { - log = await getContractorHoursByMonth(username) - } - catch { - return { - props: { - username, - error: 'Failed to fetch data' - } - } - } - log = log.slice(-20) - - let maxHours = 1 - - for (const [year, month, hours] of log) { - maxHours = Math.max(hours, maxHours) - } return { - props: { username, log, maxHours } + props: { username } } } diff --git a/styles/Home.module.css b/styles/Home.module.css index d039a5b..277994f 100644 --- a/styles/Home.module.css +++ b/styles/Home.module.css @@ -110,29 +110,6 @@ margin: 0; } -.histogram { - display: flex; - flex-direction: row; -} - -.histogram div { - padding: 5px; - margin: 5px; -} - -.histogram>div { - display: flex; - flex-direction: column; - justify-content: flex-end; - height: 500px; - width: 65px; - text-align: center; -} - -.histogram div.histobar { - background-color: green; -} - @media (max-width: 800px) { .table, .table tbody, .table thead, .table tr, .table th, .table td { display: block; diff --git a/test.html b/test.html deleted file mode 100644 index a444563..0000000 --- a/test.html +++ /dev/null @@ -1,48 +0,0 @@ - - - - -Test - - - -
-
-
-
5
-
-
-
-
7
-
-
-
x
-
35
-
-
-
-
12
-
-
- - From 44c4bf1dde56b37c63db6c416a9854157744e35e Mon Sep 17 00:00:00 2001 From: Orfeas Stefanos Thyfronitis Litos Date: Mon, 10 Jul 2023 20:43:53 +0100 Subject: [PATCH 6/9] Remove extra character space --- components/leaderboard.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/components/leaderboard.tsx b/components/leaderboard.tsx index 925564f..c366b48 100644 --- a/components/leaderboard.tsx +++ b/components/leaderboard.tsx @@ -127,14 +127,14 @@ export default ({year, month, contractorHours, monthProjections}: {
{Math.round(100 * contractor.hours) / 100}
{ contractor.hoursProjection && contractor.percentageProjection?
Date: Mon, 10 Jul 2023 21:04:57 +0100 Subject: [PATCH 7/9] Replace div with canvas --- components/leaderboard.tsx | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/components/leaderboard.tsx b/components/leaderboard.tsx index c366b48..f1f1a66 100644 --- a/components/leaderboard.tsx +++ b/components/leaderboard.tsx @@ -124,13 +124,8 @@ export default ({year, month, contractorHours, monthProjections}: { {contractor.name}
-
- {Math.round(100 * contractor.hours) / 100} -
+ + { contractor.hoursProjection && contractor.percentageProjection?
Date: Mon, 17 Jul 2023 17:55:19 +0100 Subject: [PATCH 8/9] Make canvas handleable --- components/leaderboard.tsx | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/components/leaderboard.tsx b/components/leaderboard.tsx index f1f1a66..6dcf5db 100644 --- a/components/leaderboard.tsx +++ b/components/leaderboard.tsx @@ -69,7 +69,7 @@ export default ({year, month, contractorHours, monthProjections}: { const prevLink = prevMonth(year, month) const nextLink = nextMonth(year, month) - return ( + const html = (
Common Prefix Leaderboard @@ -124,8 +124,9 @@ export default ({year, month, contractorHours, monthProjections}: { {contractor.name}
- - +
+ +
{ contractor.hoursProjection && contractor.percentageProjection?
) + console.log("adsf") + const canvas = document.getElementById("lalaOrfeas") + //console.log("lkjh") + //const ctx = canvas.getContext("2d") + //ctx.fillText("a", 10, 10) + + return html } From 8cd50a8ffcc88d7ed25dd77e6df8a5a9ee168df2 Mon Sep 17 00:00:00 2001 From: Orfeas Stefanos Thyfronitis Litos Date: Mon, 17 Jul 2023 18:23:53 +0100 Subject: [PATCH 9/9] Paint canvas repeatedly from external script --- components/leaderboard.tsx | 18 +++++++++--------- public/assets/colorHours.js | 4 ++++ 2 files changed, 13 insertions(+), 9 deletions(-) create mode 100644 public/assets/colorHours.js diff --git a/components/leaderboard.tsx b/components/leaderboard.tsx index 6dcf5db..e1da226 100644 --- a/components/leaderboard.tsx +++ b/components/leaderboard.tsx @@ -1,6 +1,7 @@ import type { NextPage } from 'next' import Head from 'next/head' import styles from '../styles/Home.module.css' +import Script from 'next/script' import { createHash } from 'crypto' import { invertColor } from '../lib/color.js' import Link from 'next/link' @@ -69,12 +70,13 @@ export default ({year, month, contractorHours, monthProjections}: { const prevLink = prevMonth(year, month) const nextLink = nextMonth(year, month) - const html = ( + return (
Common Prefix Leaderboard +
{ contractor.hoursProjection && contractor.percentageProjection? @@ -152,11 +159,4 @@ export default ({year, month, contractorHours, monthProjections}: {

) - console.log("adsf") - const canvas = document.getElementById("lalaOrfeas") - //console.log("lkjh") - //const ctx = canvas.getContext("2d") - //ctx.fillText("a", 10, 10) - - return html } diff --git a/public/assets/colorHours.js b/public/assets/colorHours.js new file mode 100644 index 0000000..d5fb8ec --- /dev/null +++ b/public/assets/colorHours.js @@ -0,0 +1,4 @@ +window.colorHours = (canvas) => { + const ctx = canvas.getContext("2d") + ctx.fillText("a", 10, 10) +}