diff --git a/src/components/estimation-range.tsx b/src/components/estimation-range.tsx index 7341836..f8f90b0 100644 --- a/src/components/estimation-range.tsx +++ b/src/components/estimation-range.tsx @@ -11,13 +11,18 @@ export interface EstimationRangeProps { export const EstimationRange: FunctionalComponent = ({ project, estimation }) => { const roundUp = getRoundUpEstimations(project); - let e: number|string = roundUp ? Math.ceil(estimation.e) : estimation.e; - let sd: number|string = roundUp ? Math.ceil(estimation.sd) : estimation.sd; - const max = e+sd; - const min = Math.max(e-sd, 0); - if (!roundUp) { - sd = sd.toFixed(2); - e = e.toFixed(2); + let e: number|string = estimation.e; + let sd: number|string = estimation.sd; + let max = e+sd; + let min = Math.max(e-sd, 0); + if (roundUp) { + sd = Math.ceil(sd); + e = Math.ceil(e); + max = Math.ceil(max); + min = Math.ceil(min); + } else { + sd = sd.toFixed(2); + e = e.toFixed(2); } return ( diff --git a/src/routes/project/financial-preview.tsx b/src/routes/project/financial-preview.tsx index 1970411..1d4f8be 100644 --- a/src/routes/project/financial-preview.tsx +++ b/src/routes/project/financial-preview.tsx @@ -1,7 +1,7 @@ import { FunctionalComponent, h } from "preact"; import { Project } from "../../models/project"; import { useProjectEstimations } from "../../hooks/use-project-estimations"; -import { getCurrency, defaults, getTaskCategoryCost } from "../../models/params"; +import { getCurrency, defaults, getTaskCategoryCost, getRoundUpEstimations } from "../../models/params"; import { getMinMaxCosts, Cost } from "../../util/stat"; import * as style from './style.module.css'; import ProjectTimeUnit from "../../components/project-time-unit"; @@ -13,7 +13,7 @@ export interface FinancialPreviewProps { const FinancialPreview: FunctionalComponent = ({ project }) => { const estimations = useProjectEstimations(project); const costs = getMinMaxCosts(project, estimations.p99); - + const roundUp = getRoundUpEstimations(project); return (
@@ -33,13 +33,13 @@ const FinancialPreview: FunctionalComponent = ({ project @@ -51,14 +51,15 @@ const FinancialPreview: FunctionalComponent = ({ project export interface CostDetailsProps { project: Project cost: Cost + roundUp: boolean } -export const CostDetails:FunctionalComponent = ({ project, cost }) => { +export const CostDetails:FunctionalComponent = ({ project, cost, roundUp }) => { return (
≈ {cost.totalCost} {getCurrency(project)} - {cost.totalTime} + { roundUp ? Math.ceil(cost.totalTime) : cost.totalTime.toFixed(2) }
Maximum - +
Minimum - +
@@ -70,7 +71,7 @@ export const CostDetails:FunctionalComponent = ({ project, cos - + ) }) diff --git a/src/util/stat.ts b/src/util/stat.ts index 2ccb287..2113d71 100644 --- a/src/util/stat.ts +++ b/src/util/stat.ts @@ -39,11 +39,14 @@ export interface MeanRepartition { export function getTaskCategoriesMeanRepartition(project: Project): MeanRepartition { let projectMean = getProjectWeightedMean(project); + const repartition: MeanRepartition = {}; + Object.values(project.params.taskCategories).forEach(tc => { repartition[tc.id] = getTaskCategoryWeightedMean(tc.id, project) / projectMean; if (Number.isNaN(repartition[tc.id])) repartition[tc.id] = 0; }); + return repartition; } @@ -67,18 +70,18 @@ export function getMinMaxCosts(project: Project, estimation: Estimation): MinMax Object.values(project.params.taskCategories).forEach(tc => { const cost = getTaskCategoryCost(tc); - const maxTime = Math.ceil((estimation.e + estimation.sd) * repartition[tc.id]); + const maxTime = Math.round((estimation.e + estimation.sd) * repartition[tc.id]); max.details[tc.id] = { time: maxTime, - cost: maxTime * cost, + cost: Math.ceil(maxTime) * cost, }; max.totalTime += max.details[tc.id].time; max.totalCost += max.details[tc.id].cost; - const minTime = Math.ceil((estimation.e - estimation.sd) * repartition[tc.id]); + const minTime = Math.round((estimation.e - estimation.sd) * repartition[tc.id]); min.details[tc.id] = { time: minTime, - cost: minTime * cost, + cost: Math.ceil(minTime) * cost, }; min.totalTime += min.details[tc.id].time; min.totalCost += min.details[tc.id].cost;
{taskCategory.label} {details.cost} {getCurrency(project)}{details.time} × {getTaskCategoryCost(taskCategory)} {getCurrency(project)}{ roundUp ? Math.ceil(details.time) : details.time.toFixed(2) } × {getTaskCategoryCost(taskCategory)} {getCurrency(project)}