Skip to content
Snippets Groups Projects
Commit 71388263 authored by Emmanuel Raviart's avatar Emmanuel Raviart
Browse files

Merge law, bill & amendment waterfalls.

parent 92da2146
No related branches found
No related tags found
No related merge requests found
......@@ -11,6 +11,7 @@
DecompositionByName,
EvaluationByName,
VisibleDecomposition,
VisibleEvaluationByCalculationName,
} from "$lib/decompositions"
import { buildVisibleDecompositions } from "$lib/decompositions"
import type { EditionMode } from "$lib/editions"
......@@ -171,7 +172,9 @@
<div class="flex justify-between">
<!-- Navigation dispositifs-->
<div class="flex-auto pt-2 w-3/5">
{#each visibleDecompositions as { decomposition, depth, trunk, variable, visibleChildren }, index}
{#each visibleDecompositions as { decomposition, depth, rows, trunk, visibleChildren }, index}
{#each rows as { calculationName }}
{#if calculationName === "law"}
<div class="flex items-center h-8 whitespace-nowrap">
{#if trunk}
<div
......@@ -227,7 +230,9 @@
</title>
<path
d="M0.124322 18.4377C-0.240619 19.1041 0.241623 19.918 1.00142 19.918H20.6259C21.3857 19.918 21.868 19.1041 21.503 18.4377L11.6908 0.519686C11.3113 -0.173228 10.316 -0.173229 9.93658 0.519685L0.124322 18.4377ZM11.8591 16.8375C11.8591 17.3898 11.4114 17.8375 10.8591 17.8375H10.7682C10.2159 17.8375 9.76822 17.3898 9.76822 16.8375V16.627C9.76822 16.0747 10.2159 15.627 10.7682 15.627H10.8591C11.4114 15.627 11.8591 16.0747 11.8591 16.627V16.8375ZM11.8591 12.7416C11.8591 13.2938 11.4114 13.7416 10.8591 13.7416H10.7682C10.2159 13.7416 9.76822 13.2938 9.76822 12.7416V7.3298C9.76822 6.77751 10.2159 6.3298 10.7682 6.3298H10.8591C11.4114 6.3298 11.8591 6.77751 11.8591 7.3298V12.7416Z"
fill={decomposition.obsolete ? "#FF4133" : "#FFAC33"}
fill={decomposition.obsolete
? "#FF4133"
: "#FFAC33"}
/>
<path
d="M10.7686 17.8378H10.8595C11.4117 17.8378 11.8595 17.3901 11.8595 16.8378V16.6273C11.8595 16.075 11.4117 15.6273 10.8595 15.6273H10.7686C10.2163 15.6273 9.76855 16.075 9.76855 16.6273V16.8378C9.76855 17.3901 10.2163 17.8378 10.7686 17.8378Z"
......@@ -364,55 +369,108 @@
{/if}
{/if}
</div>
{:else if !decomposition.open || trunk}
<div class="flex items-center h-8 whitespace-nowrap">
{#if !trunk}
{#each [...iterToDepth(depth)] as _level}
<div class="border-l border-le-gris-dispositif h-8 ml-2">
&nbsp;
</div>
{/each}
{/if}
<div class="h-8" />
</div>
{/if}
{/each}
{/each}
</div>
<!-- ticket de caisse-->
<div class="flex flex-none pt-2 px-2">
<div class="flex-col ">
{#each visibleDecompositions as { decomposition, evaluationByCalculationName, trunk, visibleChildren }, index}
{#each Object.entries(evaluationByCalculationName) as [calculationNames, { deltaAtVectorIndex }]}
{#each visibleDecompositions as { decomposition, rows, trunk, visibleChildren }, index}
{#each rows as { calculationName, deltaAtVectorIndex }}
{#if !decomposition.open || trunk || calculationName === "law"}
<div
class="{decomposition.open &&
class="border-t h-7 my-1 px-1 text-sm {decomposition.open &&
trunk &&
visibleChildren.length > 1
visibleChildren.length > 1 &&
calculationName === 'law'
? 'border-gray-400'
: 'border-transparent'} border-t h-7 my-1 px-1 text-sm"
: 'border-transparent'}"
>
{#if decomposition.open}{#if trunk}<span
class="text-gray-500 align-middle">=</span
>{/if}{:else if index > 0}{#if deltaAtVectorIndex < 0}<span
class="text-red-600 font-bold align-middle">-</span
class="align-middle font-bold">-</span
>{:else if deltaAtVectorIndex > 0}<span
class="text-green-600 font-bold align-middle">+</span
class="align-middle font-bold">+</span
>{/if}{/if}
</div>
{/if}
{/each}
{/each}
</div>
<div class="flex-col">
{#each visibleDecompositions as { decomposition, evaluationByCalculationName, trunk, visibleChildren }, index}
{#each Object.entries(evaluationByCalculationName) as [calculationNames, { deltaAtVectorIndex }]}
{#each visibleDecompositions as { decomposition, rows, trunk, visibleChildren }, index}
{#each rows as { calculationName, deltaAtVectorIndex }}
{#if !decomposition.open || trunk || calculationName === "law"}
<div
class="{decomposition.open &&
trunk &&
visibleChildren.length > 1
visibleChildren.length > 1 &&
calculationName === 'law'
? 'border-gray-400'
: 'border-transparent'} border-t h-7 my-1 text-right text-sm"
>
{#if decomposition.open || index === 0}
{#if trunk || index === 0}
<span class="text-gray-500 text-sm align-middle"
<span
class="align-middle text-sm {calculationName === 'law'
? rows.find(
(row) => row.calculationName === 'bill',
) === undefined
? rows.find(
(row) => row.calculationName === 'amendment',
) === undefined
? 'text-gray-500'
: 'line-through-amendment text-gray-500'
: 'line-through-bill text-gray-500'
: calculationName === 'bill'
? rows.find(
(row) => row.calculationName === 'amendment',
) === undefined
? 'text-le-rouge-bill'
: 'line-through-amendment text-le-rouge-bill'
: 'bg-le-jaune'}"
>{firstDeltaFormatter.format(
deltaAtVectorIndex ?? 0,
)}</span
>
{/if}
{:else}<span class="font-bold text-base"
{:else}<span
class="font-bold text-base {calculationName === 'law'
? rows.find(
(row) => row.calculationName === 'bill',
) === undefined
? rows.find(
(row) => row.calculationName === 'amendment',
) === undefined
? ''
: 'line-through-amendment'
: 'line-through-bill'
: calculationName === 'bill'
? rows.find(
(row) => row.calculationName === 'amendment',
) === undefined
? 'text-le-rouge-bill'
: 'line-through-amendment text-le-rouge-bill'
: 'bg-le-jaune'}"
>{deltaFormatter.format(deltaAtVectorIndex ?? 0)}</span
>
{/if}
</div>
{/if}
{/each}
{/each}
</div>
......@@ -436,8 +494,9 @@
<!-- Waterfall-->
<div class="flex flex-col pt-2 w-1/5" bind:offsetWidth={waterfallWidth}>
{#each visibleDecompositions as { decomposition, trunk, evaluationByCalculationName }, index}
{#each Object.entries(evaluationByCalculationName) as [calculationNames, { valuesAtVectorIndex }]}
{#each visibleDecompositions as { decomposition, trunk, rows }, index}
{#each rows as { calculationName, valuesAtVectorIndex }}
{#if !decomposition.open || trunk || calculationName === "law"}
<div
class="{decomposition.open || index === 0
? trunk || index === 0
......@@ -458,6 +517,7 @@
>
&nbsp;
</div>
{/if}
{/each}
{/each}
</div>
......
......@@ -52,6 +52,7 @@ export interface VisibleDecomposition {
decomposition: Decomposition
depth: number
evaluationByCalculationName: VisibleEvaluationByCalculationName
rows: VisibleRow[]
trunk: boolean
variable?: Variable
/// These children are not always the same as the one from the decomposition,
......@@ -68,6 +69,12 @@ export interface VisibleEvaluation {
valuesAtVectorIndex: [number, number]
}
export interface VisibleRow {
calculationName: CalculationName
deltaAtVectorIndex: number
valuesAtVectorIndex: [number, number]
}
export type VisibleEvaluationByCalculationName = Partial<{
[name in CalculationName]: VisibleEvaluation
}>
......@@ -274,7 +281,7 @@ function buildVisibleDecompositions1(
deltaEvaluation.delta.some((deltaItem) => deltaItem !== 0),
)
if (showNode) {
const visibleDecomposition: VisibleDecomposition = {
const visibleDecomposition = {
decomposition,
evaluationByCalculationName: Object.fromEntries(
Object.entries(evaluation.deltaEvaluationByCalculationName).map(
......@@ -287,7 +294,7 @@ function buildVisibleDecompositions1(
calculationName,
{
delta,
deltaAtVectorIndex,
deltaAtVectorIndex: deltaAtVectorIndex,
} as VisibleEvaluation,
]
},
......@@ -295,7 +302,7 @@ function buildVisibleDecompositions1(
),
depth,
trunk,
}
} as VisibleDecomposition
let visibleChildren = decomposition.children
for (const options of decomposition.options ?? []) {
......@@ -390,6 +397,74 @@ function buildVisibleDecompositions1(
if (variable !== undefined) {
visibleDecomposition.variable = variable
}
const evaluationByCalculationName =
visibleDecomposition.evaluationByCalculationName
const rows = (visibleDecomposition.rows = [])
const lawVisibleEvaluation = evaluationByCalculationName.law
if (lawVisibleEvaluation !== undefined) {
const lawRow: VisibleRow = {
calculationName: "law",
deltaAtVectorIndex: lawVisibleEvaluation.deltaAtVectorIndex,
valuesAtVectorIndex: lawVisibleEvaluation.valuesAtVectorIndex,
}
rows.push(lawRow)
const billVisibleEvaluation = evaluationByCalculationName.bill
let previousRow: VisibleRow
let previousVisibleEvaluation: VisibleEvaluation
if (billVisibleEvaluation === undefined) {
previousVisibleEvaluation = lawVisibleEvaluation
} else {
if (
billVisibleEvaluation.deltaAtVectorIndex ===
lawVisibleEvaluation.deltaAtVectorIndex
) {
lawRow.valuesAtVectorIndex = billVisibleEvaluation.valuesAtVectorIndex
previousRow = lawRow
} else {
lawRow.valuesAtVectorIndex = [
billVisibleEvaluation.valuesAtVectorIndex[0],
billVisibleEvaluation.valuesAtVectorIndex[0] +
lawVisibleEvaluation.deltaAtVectorIndex,
]
const billRow: VisibleRow = {
calculationName: "bill",
deltaAtVectorIndex: billVisibleEvaluation.deltaAtVectorIndex,
valuesAtVectorIndex: billVisibleEvaluation.valuesAtVectorIndex,
}
rows.push(billRow)
previousRow = billRow
}
previousVisibleEvaluation = billVisibleEvaluation
}
const amendmentVisibleEvaluation = evaluationByCalculationName.amendment
if (amendmentVisibleEvaluation !== undefined) {
// Law + bill + amendement
if (
amendmentVisibleEvaluation.deltaAtVectorIndex ===
previousVisibleEvaluation.deltaAtVectorIndex
) {
previousRow.valuesAtVectorIndex =
amendmentVisibleEvaluation.valuesAtVectorIndex
} else {
previousRow.valuesAtVectorIndex = [
amendmentVisibleEvaluation.valuesAtVectorIndex[0],
amendmentVisibleEvaluation.valuesAtVectorIndex[0] +
previousVisibleEvaluation.deltaAtVectorIndex,
]
const amendmentRow: VisibleRow = {
calculationName: "amendment",
deltaAtVectorIndex: amendmentVisibleEvaluation.deltaAtVectorIndex,
valuesAtVectorIndex: amendmentVisibleEvaluation.valuesAtVectorIndex,
}
rows.push(amendmentRow)
}
}
}
}
return visibleDecompositionIndex
......@@ -448,18 +523,6 @@ function extractNonVirtualDecompositionsName(
// }
// }
export function labelFromCalculationName(
calculationName: CalculationName | string,
): string {
return (
{
amendment: "Amendement",
bill: "Projet de loi",
law: "Législation actuelle",
}[calculationName] ?? calculationName
)
}
function patchDecompositionCoreByName(
decompositionCoreByName: DecompositionCoreByName,
patch: { [name: string]: DecompositionCore | null },
......@@ -526,22 +589,11 @@ function updateEvaluations1(
// because those children are used for rendering, not to calculate
// from OpenFisca variables.
const children = decomposition.children
const evaluation = evaluationByName[name]
const newDeltaEvaluationByCalculationName: Partial<{
[calculationName in CalculationName]: Partial<DeltaEvaluation>
}> = {}
const evaluation = evaluationByName[name]
if (evaluation !== undefined && evaluation.fromOpenFisca) {
for (const [calculationName, deltaEvaluation] of Object.entries(
evaluation.deltaEvaluationByCalculationName,
)) {
newDeltaEvaluationByCalculationName[calculationName] = {
delta:
deltaEvaluation.delta.length === vectorLength
? deltaEvaluation.delta
: new Array(vectorLength).fill(deltaEvaluation.deltaAtVectorIndex),
}
}
} else if (children !== undefined) {
if (children !== undefined) {
for (const childReference of children) {
const childEvaluation = updateEvaluations1(
decompositionByName,
......@@ -552,7 +604,9 @@ function updateEvaluations1(
vectorIndex,
vectorLength,
)
if (childEvaluation !== undefined) {
// When variable is not (yet?) computed by OpenFisca, compute its delta
// from the delta of its children.
if (!evaluation?.fromOpenFisca && childEvaluation !== undefined) {
for (const [calculationName, childDeltaEvaluation] of Object.entries(
childEvaluation.deltaEvaluationByCalculationName,
)) {
......@@ -582,6 +636,22 @@ function updateEvaluations1(
}
}
// If variable is computed by OpenFisca, recopy (and rescale if needed) its
// computed delta
if (evaluation?.fromOpenFisca) {
for (const [calculationName, deltaEvaluation] of Object.entries(
evaluation.deltaEvaluationByCalculationName,
)) {
newDeltaEvaluationByCalculationName[calculationName] = {
delta:
deltaEvaluation.delta.length === vectorLength
? deltaEvaluation.delta
: new Array(vectorLength).fill(deltaEvaluation.deltaAtVectorIndex),
}
}
}
// Extract deltaAtIndex from delta.
for (const [calculationName, newDeltaEvaluation] of Object.entries(
newDeltaEvaluationByCalculationName,
)) {
......
......@@ -44,9 +44,6 @@
const billName: Writable<string | undefined> = writable(currentBillName)
setContext("billName", billName)
const calculationName: Writable<CalculationName> = writable("law")
setContext("calculationName", calculationName)
const calculationRunningByName: Writable<{
[name in CalculationName]?: boolean
}> = writable({})
......@@ -363,15 +360,15 @@
}
const evaluation = evaluationByName[result.name]
const deltaEvaluationByCalculationName =
evaluation?.deltaEvaluationByCalculationName
evaluation?.deltaEvaluationByCalculationName ?? {}
return {
...evaluationByName,
[result.name]: {
...(evaluation ?? {}),
deltaEvaluationByCalculationName: {
...(deltaEvaluationByCalculationName ?? {}),
...deltaEvaluationByCalculationName,
[calculationName]: {
...((deltaEvaluationByCalculationName ?? {})[
...(deltaEvaluationByCalculationName[
calculationName
] ?? {}),
delta: sum,
......
......@@ -25,7 +25,6 @@
} from "$lib/decompositions"
import {
calculationNames,
labelFromCalculationName,
nonVirtualDecompositionsName,
nonVirtualDecompositionsNameByReformName,
updateEvaluations,
......@@ -67,9 +66,6 @@
setContext("adaptAmountsScale", adaptAmountsScale)
let axes: Axis[][] = []
const billName = getContext("billName") as Writable<string | undefined>
const calculationName = getContext(
"calculationName",
) as Writable<CalculationName>
const calculationRunningByName = getContext(
"calculationRunningByName",
) as Writable<{ [name in CalculationName]?: boolean }>
......@@ -832,7 +828,7 @@
Note: When you change the height below (h-...), don't forget to adjust
the height of the div enclosing the TestCasesPane below.
-->
<div class="flex lg:h-8 justify-between">
<div class="flex lg:h-8 justify-end">
<!-- <label
><input bind:checked={$adaptAmountsScale} type="checkbox" />
<span class="hidden text-xs lg:inline text-gray-600">
......@@ -854,16 +850,6 @@
{/each}
</select> -->
<select
class=" rounded border-1 text-xs "
required
bind:value={$calculationName}
>
{#each calculationNames as name}
<option value={name}>{labelFromCalculationName(name)}</option>
{/each}
</select>
<div class="flex items-center">
<button
class="bg-gray-200 flex justify-center text-gray-900 shadow-md hover:bg-gray-400 px-5 mr-2 rounded p-2 uppercase text-sm"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment