-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2817 from ever-co/stage
Release
- Loading branch information
Showing
66 changed files
with
1,952 additions
and
989 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,48 @@ | ||
"use client" | ||
|
||
import { IDailyPlan } from "@app/interfaces"; | ||
import { convertHourToSeconds } from "./date"; | ||
|
||
export const dailyPlanCompareEstimated = (plans: IDailyPlan[]) => { | ||
|
||
const plan = plans.find((plan) => plan.date?.toString()?.startsWith(new Date()?.toISOString().split('T')[0])); | ||
export interface IDailyPlanCompareEstimated { | ||
difference: boolean, | ||
workTimePlanned?: number, | ||
estimated?: boolean[] | undefined, | ||
plan?: IDailyPlan | undefined | ||
} | ||
|
||
const times = plan?.tasks?.map((task) => task?.estimate).filter((time): time is number => typeof time === 'number') ?? []; | ||
const estimated = plan?.tasks?.map((task) => task.estimate! > 0); | ||
export const dailyPlanCompareEstimated = (plans: IDailyPlan[]): IDailyPlanCompareEstimated => { | ||
const plan = plans.find((plan) => plan.date?.toString()?.startsWith(new Date().toISOString().split('T')[0])); | ||
|
||
let estimatedTime = 0; | ||
if (times.length > 0) estimatedTime = times.reduce((acc, cur) => acc + cur, 0) ?? 0; | ||
if (!plan) { | ||
return { | ||
difference: false, | ||
workTimePlanned: 0, | ||
estimated: [], | ||
plan: undefined | ||
}; | ||
} | ||
|
||
const workedTimes = | ||
plan?.tasks?.map((task) => task.totalWorkedTime).filter((time): time is number => typeof time === 'number') ?? | ||
[]; | ||
const workTimePlanned = convertHourToSeconds(plan.workTimePlanned!); | ||
const times = plan.tasks?.map((task) => task.estimate).filter((time): time is number => typeof time === 'number') ?? []; | ||
const estimated = plan.tasks?.map((task) => task.estimate! > 0); | ||
|
||
let totalWorkTime = 0; | ||
if (workedTimes?.length > 0) totalWorkTime = workedTimes.reduce((acc, cur) => acc + cur, 0) ?? 0; | ||
let estimatedTime = 0; | ||
if (times.length > 0) { | ||
estimatedTime = times.reduce((acc, cur) => acc + cur, 0) ?? 0; | ||
} | ||
|
||
const result = estimated?.every(Boolean) ? estimatedTime - totalWorkTime : null; | ||
const difference = dailyPlanSubtraction(estimatedTime, workTimePlanned); | ||
|
||
return { | ||
result, | ||
totalWorkTime, | ||
estimatedTime | ||
} | ||
workTimePlanned, | ||
estimated, | ||
difference, | ||
plan | ||
}; | ||
} | ||
|
||
export function dailyPlanSubtraction( | ||
estimatedTime: number, | ||
workTimePlanned: number | ||
): boolean { | ||
const difference = Math.abs(estimatedTime - workTimePlanned) / (60 * 2); | ||
return difference >= -1 && difference <= 1; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.