améliore le fichier de sortie + adaptation nouveau...
...schéma de base de données
... | ... |
@@ -171,18 +171,18 @@ function update_database () { |
171 | 171 |
} |
172 | 172 |
|
173 | 173 |
function write_comparaison () { |
174 |
- |
|
175 | 174 |
result="comparaisons ${groupe[0]} avec ${groupe_ref:-GDR}${dossier:+ - ${dossier}}" |
176 | 175 |
content="/dev/shm/$result/content.xml" |
177 |
- id_cols="Scrutin Date Titre Adoption Panurgisme${nom:+ Participation Loyauté}" |
|
178 |
- typevotes=$(sqlite_request "select nom from votes") |
|
179 |
- nb_cols=$(( $(wc -w <<< $id_cols) + $(wc -w <<< $typevotes) * ${#groupe[@]} )) |
|
176 |
+ id_cols=(Scrutin Date Scéance Titre Adoption Panurgisme${nom:+ Participation Loyauté} Dossier) |
|
177 |
+ eval $(sqlite_request 'select printf("typevotes[%i]=%s;", id, nom) from votes') |
|
178 |
+ nb_cols=$(( ${#id_cols[@]} + ${#typevotes[@]} * ${#groupe[@]} )) |
|
180 | 179 |
last_col=$(awk -v n=$nb_cols 'BEGIN{printf("%c%c", n < 27 ? "" : int(n/26) + 64, (n % 26) + (n % 26 == 0 ? 26 : 0) + 64)}' | tr -d '\0') |
181 | 180 |
function write_cell () { |
182 | 181 |
case $1 in |
183 | 182 |
url) |
184 | 183 |
cell='<table:table-cell office:value-type="string" calcext:value-type="string">' |
185 |
- cell+="<text:p><text:a xlink:href=\"$2\" xlink:type=\"simple\">$3</text:a></text:p>";; |
|
184 |
+ cell+="<text:p><text:a xlink:href=$2 xlink:type=\"simple\">$3</text:a></text:p>" |
|
185 |
+ ;; |
|
186 | 186 |
texte) |
187 | 187 |
cell='<table:table-cell office:value-type="string" calcext:value-type="string">' |
188 | 188 |
cell+="<text:p>$2</text:p>" |
... | ... |
@@ -250,10 +250,10 @@ EOcontent |
250 | 250 |
<table:calculation-settings table:automatic-find-labels="false"/> |
251 | 251 |
<table:table table:name="$result" table:style-name="ta1"> |
252 | 252 |
<office:forms form:automatic-focus="false" form:apply-design-mode="false"/> |
253 |
- <table:table-column table:style-name="co1" table:number-columns-repeated="$(wc -w <<< $id_cols)" table:default-cell-style-name="Default"/> |
|
253 |
+ <table:table-column table:style-name="co1" table:number-columns-repeated="${#id_cols[@]}" table:default-cell-style-name="Default"/> |
|
254 | 254 |
EOcontent |
255 | 255 |
|
256 |
- for i in $(seq $(wc -w <<< $typevotes)); do |
|
256 |
+ for i in $(seq ${#typevotes[@]}); do |
|
257 | 257 |
cat >> "$content" << EOcontent |
258 | 258 |
<table:table-column table:style-name="co1" table:default-cell-style-name="ce1"/> |
259 | 259 |
EOcontent |
... | ... |
@@ -266,11 +266,11 @@ EOcontent |
266 | 266 |
echo '<table:table-row table:style-name="ro1">' >> "$content" |
267 | 267 |
|
268 | 268 |
IFS=$IFS_ |
269 |
- for colonne in $id_cols; do |
|
269 |
+ for colonne in ${id_cols[@]}; do |
|
270 | 270 |
write_cell texte $colonne |
271 | 271 |
done |
272 | 272 |
|
273 |
- for typevote in $typevotes; do |
|
273 |
+ for typevote in ${typevotes[@]}; do |
|
274 | 274 |
for g in "${groupe[@]}"; do |
275 | 275 |
write_cell texte "$typevote - $g" |
276 | 276 |
done |
... | ... |
@@ -283,82 +283,96 @@ EOcontent |
283 | 283 |
line=1 |
284 | 284 |
test -z "$seq" && qty=$(( $last - $first )) |
285 | 285 |
IFS=$'\n' |
286 |
+ scrutin_base_url="https://www2.assemblee-nationale.fr/scrutins/detail/(legislature)/$mandature/(num)/" |
|
286 | 287 |
for scrutin in $(eval ${seq:-seq $first $last}); do |
287 | 288 |
|
288 |
- data=$(sqlite_request "select date,intitulé,adoption,url.url from scrutins inner join url on scrutins.url = url.id where num is $scrutin") |
|
289 |
- date=$(cut -d'|' -sf 1 <<< $data) |
|
290 |
- title=$(cut -d'|' -sf 2 <<< $data) |
|
291 |
- adoption=$(cut -d'|' -sf 3 <<< $data) |
|
292 |
- url=$(cut -d'|' -sf 4 <<< $data) |
|
289 |
+ data=$(sqlite_request "select date,séance,intitulé,adoption,dossiers.url,dossiers.titre from scrutins left join dossiers on scrutins.dossier = dossiers.id where num is $scrutin" json) |
|
290 |
+ date=$(jq -r '.[].date' <<< $data) |
|
291 |
+ seance=$(jq -r '.[]."séance"' <<< $data) |
|
292 |
+ title=$(jq -r '.[]."intitulé" | @html' <<< $data) |
|
293 |
+ adoption=$(jq '.[].adoption' <<< $data) |
|
294 |
+ dossier_url=$(jq '.[].url' <<< $data) |
|
295 |
+ dossier_texte=$(jq -r '.[].titre | @html' <<< $data) |
|
293 | 296 |
test $adoption -eq 1 && adoption='oui' || adoption='non' |
294 | 297 |
|
295 | 298 |
echo '<table:table-row table:style-name="ro1">' >> "$content" |
296 | 299 |
|
297 |
- if test -n "$url"; then |
|
298 |
- write_cell url "$url" $scrutin |
|
299 |
- else |
|
300 |
- write_cell nombre $scrutin |
|
301 |
- fi |
|
300 |
+ write_cell url "\"$scrutin_base_url$scrutin\"" $scrutin |
|
302 | 301 |
write_cell texte "$date" |
303 |
- write_cell texte "${title//\'/'}" |
|
302 |
+ write_cell texte "$seance" |
|
303 |
+ write_cell texte "$title" |
|
304 | 304 |
write_cell texte "$adoption" |
305 | 305 |
|
306 |
- for typevote in $(seq 0 $(( $(wc -w <<< $typevotes) - 1 ))); do |
|
306 |
+ for typevote in $(seq ${#typevotes[@]}); do |
|
307 | 307 |
vote_cible[$typevote]=$(sqlite_request "select |
308 | 308 |
count(député) |
309 | 309 |
from |
310 |
- dépouillement |
|
310 |
+ dépouillements |
|
311 |
+ inner join |
|
312 |
+ députés, groupes |
|
313 |
+ on |
|
314 |
+ députés.groupe = groupes.id and dépouillements.député = députés.id |
|
311 | 315 |
where |
312 | 316 |
scrutin is $scrutin |
313 | 317 |
and |
314 | 318 |
vote is $typevote |
315 | 319 |
and |
316 |
- groupe is ${groupe_id[0]} ${nom:+ and député is ${nom%|*}}") |
|
320 |
+ groupes.id = ${groupe_id[0]} ${nom:+ and députés.nom is \"${nom}\"}") |
|
317 | 321 |
done |
318 |
- if test \( ${vote_cible[0]} -gt ${vote_cible[1]} -a $adoption = oui \) \ |
|
319 |
- -o \( ${vote_cible[1]} -gt ${vote_cible[0]} -a $adoption = non \); then |
|
320 |
- panurge=1 |
|
322 |
+ if test \( ${vote_cible[1]} -gt ${vote_cible[2]} -a $adoption = oui \) \ |
|
323 |
+ -o \( ${vote_cible[2]} -gt ${vote_cible[1]} -a $adoption = non \); then |
|
324 |
+ panurge=oui |
|
321 | 325 |
else |
322 |
- panurge=0 |
|
326 |
+ panurge=non |
|
323 | 327 |
fi |
324 |
- write_cell nombre $panurge |
|
328 |
+ write_cell texte $panurge |
|
325 | 329 |
|
326 | 330 |
if test -n "$nom"; then |
327 |
- for typevote in 0 1; do |
|
331 |
+ for typevote in 1 2; do |
|
328 | 332 |
votes_g0[$typevote]=$(sqlite_request "select |
329 | 333 |
count(député) |
330 | 334 |
from |
331 |
- dépouillement |
|
335 |
+ dépouillements |
|
336 |
+ inner join |
|
337 |
+ députés, groupes |
|
338 |
+ on |
|
339 |
+ députés.groupe = groupes.id and dépouillements.député = députés.id |
|
332 | 340 |
where |
333 | 341 |
scrutin is $scrutin |
334 | 342 |
and |
335 | 343 |
vote is $typevote |
336 | 344 |
and |
337 |
- groupe is ${groupe_id[0]}") |
|
345 |
+ groupes.id is ${groupe_id[0]}") |
|
338 | 346 |
done |
339 |
- participation=$(( vote_cible[0] + vote_cible[1] + vote_cible[2] + vote_cible[3] )) |
|
340 |
- if test $(( (${votes_g0[0]} - ${votes_g0[1]}) * (${vote_cible[0]} - ${vote_cible[1]}) )) -gt 0; then |
|
341 |
- loyaute=1 |
|
347 |
+ participation=$(( vote_cible[1] + vote_cible[2] + vote_cible[3] + vote_cible[4] )) |
|
348 |
+ if test $(( (${votes_g0[1]} - ${votes_g0[2]}) * (${vote_cible[1]} - ${vote_cible[2]}) )) -gt 0; then |
|
349 |
+ loyaute=oui |
|
342 | 350 |
else |
343 |
- loyaute=0 |
|
351 |
+ loyaute=non |
|
344 | 352 |
fi |
345 | 353 |
write_cell nombre $participation |
346 |
- write_cell nombre $loyaute |
|
354 |
+ write_cell texte $loyaute |
|
347 | 355 |
fi |
348 | 356 |
|
349 |
- for typevote in $(seq 0 $(( $(wc -w <<< $typevotes) - 1 ))); do |
|
357 |
+ write_cell url "${dossier_url/#null/\"\"}" "${dossier_texte/#null}" |
|
358 |
+ |
|
359 |
+ for typevote in $(seq ${#typevotes[@]}); do |
|
350 | 360 |
write_cell nombre ${vote_cible[$typevote]} |
351 | 361 |
for (( g = 1; g < ${#groupe_id[@]}; g++ )); do |
352 | 362 |
votes=$(sqlite_request "select |
353 | 363 |
count(député) |
354 | 364 |
from |
355 |
- dépouillement |
|
365 |
+ dépouillements |
|
366 |
+ inner join |
|
367 |
+ députés, groupes |
|
368 |
+ on |
|
369 |
+ députés.groupe = groupes.id and dépouillements.député = députés.id |
|
356 | 370 |
where |
357 | 371 |
scrutin is $scrutin |
358 | 372 |
and |
359 | 373 |
vote is $typevote |
360 | 374 |
and |
361 |
- groupe is ${groupe_id[$g]}") |
|
375 |
+ groupes.id is ${groupe_id[$g]}") |
|
362 | 376 |
write_cell nombre $votes |
363 | 377 |
done |
364 | 378 |
done |