Add support for penalising overtime to the heatmap
All checks were successful
Build and Publish Docker Container / build (push) Successful in 3m44s

This commit is contained in:
Joshua Coles 2024-02-28 16:43:40 +00:00
parent 65e8899426
commit f350018eb2
5 changed files with 51 additions and 18 deletions

View File

@ -1,5 +1,6 @@
import React from "react"; import React from "react";
import * as dFns from "date-fns"; import * as dFns from "date-fns";
import * as R from 'ramda';
interface DateValue { interface DateValue {
date: Date; date: Date;
@ -12,6 +13,7 @@ interface Props {
data: DateValue[]; data: DateValue[];
className?: string; className?: string;
goal: number; goal: number;
penaliseOvertime?: boolean;
} }
function GitHubCalendarHeatmap({ function GitHubCalendarHeatmap({
@ -19,7 +21,8 @@ function GitHubCalendarHeatmap({
endDate, endDate,
data, data,
className, className,
goal goal,
penaliseOvertime = false,
}: Props) { }: Props) {
const numDays = dFns.differenceInDays(endDate, startDate); const numDays = dFns.differenceInDays(endDate, startDate);
@ -38,22 +41,47 @@ function GitHubCalendarHeatmap({
const weekGoalTime = 5 * dayGoalTime; const weekGoalTime = 5 * dayGoalTime;
const getColorForValue = (value: number, goalTime: number): string => { const getColorForValue = (value: number, goalTime: number): string => {
const values = [ const buckets = [
"#eeeeee", {
"#d6e685", min: -Infinity,
"#8cc665", max: 0,
"#44a340", color: '#eeeeee'
"#1e6823", },
] {
min: 0,
max: 0.40,
color: '#d6e685'
},
{
min: 0.40,
max: 0.50,
color: '#8cc665'
},
{
min: 0.50,
max: 0.90,
color: '#44a340'
},
{
min: 0.90,
// If penalising overtime, the max is 1.125, otherwise it's infinity (ie this is the last bucket)
max: penaliseOvertime ? 1.125 : Infinity,
color: '#1e6823'
},
{
min: 1.125,
max: 1.25,
color: '#f59e0b'
},
{
min: 1.25,
max: Infinity,
color: '#ef4444'
},
];
const linearValue = Math.round((value / goalTime) * 4); const linearValue = value / goalTime;
return R.find(minMax => minMax.min < linearValue && linearValue <= minMax.max, buckets)!.color;
// If we did something, but not enough to reach the first level, return 1
if (linearValue == 0 && value > 0) return values[1];
// Clamp to the granularity
if (linearValue > 4) return values[4];
return values[linearValue];
}; };
const getWeekTotal = (weekIndex: number): number => { const getWeekTotal = (weekIndex: number): number => {

View File

@ -47,6 +47,7 @@ export default function OverviewPage({
<CalendarOverviewCard <CalendarOverviewCard
data={data} data={data}
goal={config.goalHours} goal={config.goalHours}
penaliseOvertime={config.penaliseOvertime}
startTime={config.timePeriod.start} startTime={config.timePeriod.start}
endTime={config.timePeriod.end} endTime={config.timePeriod.end}
/> />

View File

@ -38,11 +38,13 @@ function useCalendarData(data: Data, initialDate: Date, endDate: Date) {
export function CalendarOverviewCard({ export function CalendarOverviewCard({
data, data,
goal, goal,
penaliseOvertime,
startTime, startTime,
endTime, endTime,
}: { }: {
data: Data, data: Data,
goal: number, goal: number,
penaliseOvertime?: boolean,
startTime: string, startTime: string,
endTime: string, endTime: string,
}) { }) {
@ -54,7 +56,7 @@ export function CalendarOverviewCard({
<Tooltip id="calendar-tooltip"/> <Tooltip id="calendar-tooltip"/>
<Title>Semester Overview</Title> <Title>Semester Overview</Title>
<div className="m-2"> <div className="m-2">
<HeatMap startDate={initialDate} endDate={endDate} data={calendarData} goal={goal}/> <HeatMap startDate={initialDate} endDate={endDate} data={calendarData} goal={goal} penaliseOvertime={penaliseOvertime}/>
</div> </div>
</Card> </Card>
} }

View File

@ -30,6 +30,7 @@ export interface OverviewConfig {
}[], }[],
goalHours: number, goalHours: number,
penaliseOvertime?: boolean,
timePeriod: { timePeriod: {
start: string, start: string,

View File

@ -29,7 +29,8 @@ export const semester1Revision: OverviewConfig = {
export const semester2: OverviewConfig = { export const semester2: OverviewConfig = {
title: 'Semester 2', title: 'Semester 2',
periodKey: 'y5-s2', periodKey: 'y5-s2',
goalHours: 7.5, goalHours: 6,
penaliseOvertime: true,
subjects: [ subjects: [
{ {
projectId: 195754611, projectId: 195754611,