Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
L
leximpact-socio-fiscal-ui
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
leximpact
Simulateur socio-fiscal
leximpact-socio-fiscal-ui
Commits
1547461d
Commit
1547461d
authored
Apr 1, 2021
by
Emmanuel Raviart
Browse files
Options
Downloads
Patches
Plain Diff
Add editable test case.
parent
97ef0b40
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/lib/TestCaseEdit.svelte
+171
-0
171 additions, 0 deletions
src/lib/TestCaseEdit.svelte
src/routes/calculations/index.svelte
+30
-149
30 additions, 149 deletions
src/routes/calculations/index.svelte
with
201 additions
and
149 deletions
src/lib/TestCaseEdit.svelte
0 → 100644
+
171
−
0
View file @
1547461d
<script
lang=
"ts"
>
import
{
createEventDispatcher
,
tick
}
from
"
svelte
"
import
type
{
Situation
}
from
"
$lib/situations
"
export
let
enfants
=
[]
export
let
individus
=
[
{
salaire_de_base
:
18655
,
},
]
export
let
year
=
2021
const
dispatch
=
createEventDispatcher
()
let
inited
=
false
$
:
updateSituation
(
year
,
individus
,
enfants
)
function
changeEnfantsCount
(
count
:
string
):
void
{
const
enfantsCount
=
parseInt
(
count
)
if
(
enfantsCount
===
enfants
.
length
)
{
return
}
enfants
=
enfants
.
slice
(
0
,
Math
.
min
(
enfants
.
length
,
enfantsCount
))
while
(
enfants
.
length
<
enfantsCount
)
{
enfants
.
push
({
age
:
1
,
})
}
}
function
changeEnfantVariable
(
index
:
number
,
key
:
"
age
"
,
value
:
string
)
{
enfants
=
[...
enfants
]
enfants
[
index
]
=
{
...
enfants
[
index
],
[
key
]:
parseInt
(
value
)
}
}
function
changeIndividusCount
(
count
:
string
):
void
{
const
individusCount
=
parseInt
(
count
)
if
(
individusCount
===
individus
.
length
)
{
return
}
individus
=
individus
.
slice
(
0
,
Math
.
min
(
individus
.
length
,
individusCount
))
while
(
individus
.
length
<
individusCount
)
{
individus
.
push
({
salaire_de_base
:
0
,
})
}
}
function
changeIndividuVariable
(
index
:
number
,
key
:
"
salaire_de_base
"
,
value
:
string
,
)
{
individus
=
[...
individus
]
individus
[
index
]
=
{
...
individus
[
index
],
[
key
]:
parseInt
(
value
)
}
}
function
updateSituation
(
year
,
individus
,
enfants
)
{
const
situation
:
Situation
=
{
individus
:
Object
.
fromEntries
([
...
individus
.
map
((
individu
,
index
)
=>
[
`Individu
${
index
+
1
}
`
,
{
salaire_de_base
:
{
[
year
]:
individu
.
salaire_de_base
},
},
]),
...
enfants
.
map
((
enfant
,
index
)
=>
[
`Enfant
${
index
+
1
}
`
,
{
age
:
{
[
`
${
year
}
-01`
]:
enfant
.
age
},
},
]),
]),
menages
:
{
"
Ménage 1
"
:
{
personne_de_reference
:
[
"
Individu 1
"
],
conjoint
:
individus
.
slice
(
1
)
.
map
((
_individu
,
index
)
=>
`Individu
${
index
+
2
}
`
),
enfants
:
enfants
.
map
((
enfants
,
index
)
=>
`Enfant
${
index
+
1
}
`
),
},
},
familles
:
{
"
Famille 1
"
:
{
parents
:
individus
.
map
((
_individu
,
index
)
=>
`Individu
${
index
+
1
}
`
),
enfants
:
enfants
.
map
((
enfants
,
index
)
=>
`Enfant
${
index
+
1
}
`
),
},
},
foyers_fiscaux
:
{
foyer_fiscal_1
:
{
declarants
:
individus
.
map
(
(
_individu
,
index
)
=>
`Individu
${
index
+
1
}
`
,
),
personnes_a_charge
:
enfants
.
map
(
(
enfants
,
index
)
=>
`Enfant
${
index
+
1
}
`
,
),
},
},
}
if
(
inited
)
{
dispatch
(
"
change
"
,
situation
)
}
else
{
inited
=
true
tick
()
.
then
(()
=>
dispatch
(
"
change
"
,
situation
))
.
catch
((
err
)
=>
console
.
error
(
err
))
}
}
</script>
<label>
Nombre d'individus
<input
max=
{
2
}
min=
{
1
}
on:change=
{
({
target
})
=>
changeIndividusCount
(
target
.
value
)
}
step=
"1"
type=
"number"
value=
{
individus
.
length
}
/>
</label>
<ul>
{
#each
individus
as
individu
,
index
}
<li>
<label>
Salaire annuel de base
<input
min=
{
0
}
on:change=
{
({
target
})
=>
changeIndividuVariable
(
index
,
"
salaire_de_base
"
,
target
.
value
)
}
step=
"1"
type=
"number"
value=
{
individu
.
salaire_de_base
}
/>
</label>
</li>
{
/each
}
</ul>
<label>
Nombre d'enfants
<input
max=
{
20
}
min=
{
0
}
on:change=
{
({
target
})
=>
changeEnfantsCount
(
target
.
value
)
}
step=
"1"
type=
"number"
value=
{
enfants
.
length
}
/>
</label>
<ul>
{
#each
enfants
as
enfant
,
index
}
<li>
<label>
Âge
<input
max=
{
150
}
min=
{
-
1
}
on:change=
{
({
target
})
=>
changeEnfantVariable
(
index
,
"
age
"
,
target
.
value
)
}
step=
"1"
type=
"number"
value=
{
enfant
.
age
}
/>
</label>
</li>
{
/each
}
</ul>
This diff is collapsed.
Click to expand it.
src/routes/calculations/index.svelte
+
30
−
149
View file @
1547461d
<script
context=
"module"
lang=
"ts"
>
// import type { LoadInput, LoadOutput } from "@sveltejs/kit/types.internal"
// import { decomposition, walkDecomposition } from "$lib/decompositions"
// import type { Situation } from "$lib/situations"
// // See https://github.com/cbenz/openfisca-interactive/blob/master/waterfall.ipynb
// const year = 2017
// const variablesDecomposition = Object.fromEntries(
// [...walkDecomposition(decomposition)]
// .filter(
// (node) =>
// ![
// "aide_embauche_pme",
// "aide_premier_salarie",
// "allegement_fillon",
// "cotisations_employeur",
// "cotisations_salariales",
// "cout_du_travail",
// "crds_salaire",
// "credit_impot_competitivite_emploi",
// "csg_deductible_salaire",
// "csg_imposable_salaire",
// "irpp",
// "minima_sociaux",
// "ppa",
// "ppe",
// "prestations_sociales",
// "revenus_nets_du_travail",
// "rsa",
// "salaire_de_base",
// "salaire_imposable",
// "salaire_net",
// "salaire_super_brut",
// "salaire_super_brut_hors_allegements",
// "tehr",
// ].includes(node.code),
// )
// .map((node) => [node.code, { [year]: null }]),
// )
// const situation: Situation = {
// individus: {
// Claude: {
// salaire_de_base: {
// [year]: 20000,
// },
// },
// Dominique: {
// salaire_de_base: {
// [year]: 30000,
// },
// },
// Camille: {},
// },
// menages: {
// menage_1: {
// personne_de_reference: ["Claude"],
// conjoint: ["Dominique"],
// enfants: ["Camille"],
// ...variablesDecomposition,
// },
// },
// familles: {
// famille_1: {
// parents: ["Claude", "Dominique"],
// enfants: ["Camille"],
// },
// },
// foyers_fiscaux: {
// foyer_fiscal_1: {
// declarants: ["Claude", "Dominique"],
// personnes_a_charge: ["Camille"],
// },
// },
// }
// export async function load({ fetch }: LoadInput): Promise
<
LoadOutput
>
{
// const url = "https://fr.openfisca.org/api/latest/calculate"
// const res = await fetch(url, {
// body: JSON.stringify(situation, null, 2),
// headers: {
// "Content-Type": "application/json",
// },
// method: "POST",
// })
// if (!res.ok) {
// console.error(
// `Error ${res.status} while calculating at ${url}\n${JSON.stringify(
// situation,
// null,
// 2,
// )}\n\n${await res.text()}`,
// )
// return {
// status: res.status,
// error: new Error(`Could not load ${url}`),
// }
// }
// return {
// props: {
// simulation: await res.json(),
// },
// }
// }
</script>
<script
lang=
"ts"
>
<script
lang=
"ts"
>
import
Sockette
from
"
sockette
"
import
Sockette
from
"
sockette
"
...
@@ -112,59 +5,31 @@
...
@@ -112,59 +5,31 @@
import
{
session
}
from
"
$app/stores
"
import
{
session
}
from
"
$app/stores
"
import
type
{
Decomposition
}
from
"
$lib/decompositions
"
import
type
{
Decomposition
}
from
"
$lib/decompositions
"
import
{
decomposition
as
decompositionWithoutValue
}
from
"
$lib/decompositions
"
import
{
decomposition
as
decompositionWithoutValue
}
from
"
$lib/decompositions
"
// import type { Simulation } from "$lib/simulations"
import
type
{
Situation
}
from
"
$lib/situations
"
import
type
{
Situation
}
from
"
$lib/situations
"
import
TestCaseEdit
from
"
$lib/TestCaseEdit.svelte
"
import
Waterfall
from
"
$lib/Waterfall
"
import
Waterfall
from
"
$lib/Waterfall
"
// export let simulation: Simulation
let
deltaByCode
:
{
[
code
:
string
]:
number
}
=
{}
let
deltaByCode
:
{
[
code
:
string
]:
number
}
=
{}
let
decomposition
=
updateDecompositionValues
(
let
decomposition
=
updateDecompositionValues
(
decompositionWithoutValue
as
Decomposition
,
decompositionWithoutValue
as
Decomposition
,
deltaByCode
,
deltaByCode
,
)
)
const
year
=
2017
let
situation
:
Situation
|
undefined
=
undefined
const
situation
:
Situation
=
{
individus
:
{
Claude
:
{
salaire_de_base
:
{
[
year
]:
20000
,
},
},
Dominique
:
{
salaire_de_base
:
{
[
year
]:
30000
,
},
},
Camille
:
{},
},
menages
:
{
menage_1
:
{
personne_de_reference
:
[
"
Claude
"
],
conjoint
:
[
"
Dominique
"
],
enfants
:
[
"
Camille
"
],
},
},
familles
:
{
famille_1
:
{
parents
:
[
"
Claude
"
,
"
Dominique
"
],
enfants
:
[
"
Camille
"
],
},
},
foyers_fiscaux
:
{
foyer_fiscal_1
:
{
declarants
:
[
"
Claude
"
,
"
Dominique
"
],
personnes_a_charge
:
[
"
Camille
"
],
},
},
}
let
webSocket
:
Sockette
|
undefined
=
undefined
let
webSocket
:
Sockette
|
undefined
=
undefined
let
webSocketOpen
=
false
let
year
=
2021
$
:
if
(
browser
)
{
$
:
if
(
browser
)
{
openWebSocket
()
openWebSocket
()
}
}
function
changeSituation
({
detail
})
{
situation
=
detail
if
(
webSocketOpen
)
{
submit
()
}
}
function
openWebSocket
()
{
function
openWebSocket
()
{
webSocket
=
new
Sockette
(
webSocket
=
new
Sockette
(
new
URL
(
"
ws
"
,
$session
.
apiWebSocketBaseUrl
).
toString
(),
new
URL
(
"
ws
"
,
$session
.
apiWebSocketBaseUrl
).
toString
(),
...
@@ -189,7 +54,12 @@
...
@@ -189,7 +54,12 @@
}
}
},
},
// onopen: (event) => console.log("[WebSocket] Connected!", event),
// onopen: (event) => console.log("[WebSocket] Connected!", event),
onopen
:
()
=>
submit
(),
onopen
:
()
=>
{
webSocketOpen
=
true
if
(
situation
!==
undefined
)
{
submit
()
}
},
// onreconnect: (event) =>
// onreconnect: (event) =>
// console.log("[WebSocket] Reconnecting...", event),
// console.log("[WebSocket] Reconnecting...", event),
// onmaximum: (event) =>
// onmaximum: (event) =>
...
@@ -202,11 +72,15 @@
...
@@ -202,11 +72,15 @@
}
}
function
submit
()
{
function
submit
()
{
if
(
situation
===
undefined
)
{
return
}
deltaByCode
=
{}
deltaByCode
=
{}
webSocket
.
send
(
webSocket
.
send
(
JSON
.
stringify
({
JSON
.
stringify
({
decomposition
,
decomposition
,
situation
,
situation
,
period
:
year
.
toString
(),
}),
}),
)
)
webSocket
.
send
(
webSocket
.
send
(
...
@@ -252,9 +126,16 @@
...
@@ -252,9 +126,16 @@
}
}
</script>
</script>
<pre>
{
JSON
.
stringify
(
situation
)
}
</pre>
<label
class=
"block"
>
Année
<input
max=
{
2021
}
min=
{
2013
}
step=
"1"
type=
"number"
bind:value=
{
year
}
/>
</label>
<TestCaseEdit
on:change=
{
changeSituation
}
{
year
}
/>
<div>
<button
on:click=
{
submit
}
>
Simuler
</button>
<button
on:click=
{
submit
}
>
Simuler
</button>
</div>
<Waterfall
{
decomposition
}
/>
<Waterfall
{
decomposition
}
/>
<!-- <pre>{JSON.stringify(simulation, null, 2)}</pre> -->
<!-- <pre>{JSON.stringify(simulation, null, 2)}</pre> -->
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment