Skip to content

Commit

Permalink
feat: petit message d'info concernant la force du café
Browse files Browse the repository at this point in the history
  • Loading branch information
bachrc committed Oct 26, 2024
1 parent 6804540 commit 6def703
Show file tree
Hide file tree
Showing 7 changed files with 173 additions and 124 deletions.
76 changes: 7 additions & 69 deletions deno.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/components/ChampEditable.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
<div class="flex flex-col">
{#if titre}
<div class="flex flex-row items-center gap-2">
<span class="text-sm font-bold">{titre}</span>
<span class="font-bold">{titre}</span>
{@render boutonsEdition()}
</div>
{/if}
Expand Down
10 changes: 6 additions & 4 deletions src/components/TdsChart.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,23 @@
annotationPlugin
);
let {
extraction = $bindable()
extraction
}: {
extraction: Extraction;
} = $props();
let ctx: CanvasRenderingContext2D;
let chartCanvas: HTMLCanvasElement;
let chart: Chart | null;
let chart: Chart;
$effect(() => {
chart?.destroy();
ctx = chartCanvas.getContext('2d')!;
chart = setupChart(ctx, extraction);
return () => {
chart.destroy();
};
});
</script>

Expand Down
37 changes: 37 additions & 0 deletions src/components/Verdict.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<script lang="ts">
import type { Extraction } from '$lib/extractions';
import { renduDeVerdict, serialisationDeVerdict } from '$lib/verdict';
let props: {
extraction: Extraction;
} = $props();
let verdictFinal = $state('');
let mauvaisPoints = $state(0);
$effect(() => {
const verdict = renduDeVerdict(props.extraction);
let compteurMauvaisPoints = 0;
if (verdict.force !== 'optimale') {
compteurMauvaisPoints++;
}
if (verdict.intensiteExtraction !== 'bien extrait') {
compteurMauvaisPoints++;
}
mauvaisPoints = compteurMauvaisPoints;
verdictFinal = serialisationDeVerdict(verdict);
});
const couleursDeReussite: { [mauvaisPoint: number]: string } = {
0: 'bg-green-100',
1: 'bg-orange-100',
2: 'bg-red-100'
};
</script>

<span class="w-full px-2 py-4 {couleursDeReussite[mauvaisPoints]}">
{verdictFinal}
</span>
58 changes: 32 additions & 26 deletions src/lib/chart_config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import { calculYield, tdsMoyen, yieldMoyen, type Extraction } from './extractions.ts';
import annotationPlugin from 'chartjs-plugin-annotation';
import { Chart, type ChartItem, type ChartConfiguration } from 'chart.js';
import {
LIMITE_TDS_FAIBLESSE,
LIMITE_TDS_FORCE,
LIMITE_YIELD_SOUS_EXTRACTION,
LIMITE_YIELD_SUR_EXTRACTION
} from './verdict.ts';

export function setupChart(node: ChartItem, extraction: Extraction): Chart {
const config: ChartConfiguration = {
Expand All @@ -14,72 +20,72 @@ export function setupChart(node: ChartItem, extraction: Extraction): Chart {
weak_and_underextracted: {
type: 'box',
xMin: 0,
xMax: 18,
xMax: LIMITE_YIELD_SOUS_EXTRACTION,
yMin: 0,
yMax: 1.15,
yMax: LIMITE_TDS_FAIBLESSE,
backgroundColor: 'rgba(0, 125, 200, 0.20)'
},
underextracted: {
type: 'box',
xMin: 0,
xMax: 18,
yMin: 1.15,
yMax: 1.45,
xMax: LIMITE_YIELD_SOUS_EXTRACTION,
yMin: LIMITE_TDS_FAIBLESSE,
yMax: LIMITE_TDS_FORCE,
backgroundColor: 'rgba(0, 125, 200, 0.40)'
},
strong_and_underextracted: {
type: 'box',
xMin: 0,
xMax: 18,
yMin: 1.45,
xMax: LIMITE_YIELD_SOUS_EXTRACTION,
yMin: LIMITE_TDS_FORCE,
yMax: 2,
backgroundColor: 'rgba(0, 125, 200, 0.60)'
},
weak: {
type: 'box',
xMin: 18,
xMax: 22,
xMin: LIMITE_YIELD_SOUS_EXTRACTION,
xMax: LIMITE_YIELD_SUR_EXTRACTION,
yMin: 0,
yMax: 1.15,
yMax: LIMITE_TDS_FAIBLESSE,
backgroundColor: 'rgba(39, 212, 82, 0.2)'
},
ideal: {
type: 'box',
xMin: 18,
xMax: 22,
yMin: 1.15,
yMax: 1.45,
xMin: LIMITE_YIELD_SOUS_EXTRACTION,
xMax: LIMITE_YIELD_SUR_EXTRACTION,
yMin: LIMITE_TDS_FAIBLESSE,
yMax: LIMITE_TDS_FORCE,
backgroundColor: 'rgba(39, 212, 82, 0.4)'
},
strong: {
type: 'box',
xMin: 18,
xMax: 22,
yMin: 1.45,
xMin: LIMITE_YIELD_SOUS_EXTRACTION,
xMax: LIMITE_YIELD_SUR_EXTRACTION,
yMin: LIMITE_TDS_FORCE,
yMax: 2,
backgroundColor: 'rgba(39, 212, 82, 0.6)'
},
weak_and_overextracted: {
type: 'box',
xMin: 22,
xMin: LIMITE_YIELD_SUR_EXTRACTION,
xMax: 30,
yMin: 0,
yMax: 1.15,
yMax: LIMITE_TDS_FAIBLESSE,
backgroundColor: 'rgba(200, 75, 0, 0.2)'
},
overextracted: {
type: 'box',
xMin: 22,
xMin: LIMITE_YIELD_SUR_EXTRACTION,
xMax: 30,
yMin: 1.15,
yMax: 1.45,
yMin: LIMITE_TDS_FAIBLESSE,
yMax: LIMITE_TDS_FORCE,
backgroundColor: 'rgba(200, 75, 0, 0.4)'
},
strong_and_overextracted: {
type: 'box',
xMin: 22,
xMin: LIMITE_YIELD_SUR_EXTRACTION,
xMax: 30,
yMin: 1.45,
yMin: LIMITE_TDS_FORCE,
yMax: 2,
backgroundColor: 'rgba(200, 75, 0, 0.6)'
}
Expand Down Expand Up @@ -128,12 +134,12 @@ export function setupChart(node: ChartItem, extraction: Extraction): Chart {
label: 'TDS Moyen',
backgroundColor: 'rgba(254, 70, 255, 1)',
borderColor: 'rgba(254, 70, 255, 1)',
data: [{ x: tdsMoyen(extraction), y: yieldMoyen(extraction) }],
data: [{ x: yieldMoyen(extraction), y: tdsMoyen(extraction) }],
radius: 6
}
]
}
};
console.log(config);

return new Chart(node, config);
}
Loading

0 comments on commit 6def703

Please sign in to comment.