guesstimate/src/routes/project/repartition-preview.tsx

49 lines
1.7 KiB
TypeScript

import { FunctionalComponent, h } from "preact";
import { Project } from "../../models/project";
import { useProjectEstimations } from "../../hooks/use-project-estimations";
import { getCurrency, getRoundUpEstimations } from "../../models/params";
import ProjectTimeUnit from "../../components/project-time-unit";
import { getTaskCategoryWeightedMean, getProjectWeightedMean } from "../../util/stat";
export interface RepartitionPreviewProps {
project: Project
}
const RepartitionPreview: FunctionalComponent<RepartitionPreviewProps> = ({ project }) => {
const projectMean = getProjectWeightedMean(project);
return (
<div class="table-container">
<table class="table is-bordered is-striped is-fullwidth">
<thead>
<tr>
<th colSpan={2}>Répartition moyenne pondérée</th>
</tr>
<tr>
<th>Catégorie</th>
<th>Temps</th>
</tr>
</thead>
<tbody>
{
Object.values(project.params.taskCategories).map(tc => {
let mean = getTaskCategoryWeightedMean(tc.id, project);
const percent = ((mean/projectMean) * 100).toFixed(0);
if (getRoundUpEstimations(project)) {
mean = Math.ceil(mean);
}
return (
<tr key={`task-category-${tc.id}`}>
<td>{tc.label}</td>
<td>~ {mean} <ProjectTimeUnit project={project} /> <span class="is-size-7 is-pulled-right">({percent} %)</span></td>
</tr>
);
})
}
</tbody>
</table>
</div>
);
};
export default RepartitionPreview;