Showing 1 changed files with 63 additions and 46 deletions
+63 -46
analyse-votes-AN
... ...
@@ -181,9 +181,9 @@ function write_comparaison () {
181 181
     fi
182 182
     content="/dev/shm/$result/content.xml"
183 183
     id_cols=(Scrutin Date Séance Titre Adoption Dossier)
184
+    declare -A style=(["Pour"]=Good ["Contre"]=Bad ["Abstention"]=Neutral ["oui"]=Good ["non"]=Bad)
184 185
     eval $(sqlite_request 'select printf("typevotes[%i]=%s;", id, nom) from votes')
185
-    nb_cols=$(( ${#id_cols[@]} + ${#typevotes[@]} * ${#groupe[@]} ))
186
-    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')
186
+    nb_cols=$(( ${#id_cols[@]} + ${#groupe[@]} ))
187 187
     colors=($(awk -v n=${#groupe[@]} -v from=${from_color:-2A0636} -v to=${to_color:-D09B8A} '
188 188
         function rgbL (p) {
189 189
             r = rgb_from[1] + p * (rgb_to[1] - rgb_from[1])
... ...
@@ -206,20 +206,30 @@ function write_comparaison () {
206 206
             if (n > 1) rgbL(1)
207 207
         }
208 208
     '))
209
+    function get_colname () {
210
+        awk -v n=$1 '
211
+            BEGIN{
212
+                printf("%c%c", n < 27 ? "" : int(n/26) + 64, (n % 26) + (n % 26 == 0 ? 26 : 0) + 64)
213
+            }' | tr -d '\0'
214
+    }
209 215
     function write_cell () {
216
+        cell='<table:table-cell office:value-type='
210 217
         case $1 in
211 218
             url)
212
-                cell='<table:table-cell office:value-type="string" calcext:value-type="string">'
219
+                cell+='"string" calcext:value-type="string">'
213 220
                 cell+="<text:p><text:a xlink:href=$2 xlink:type=\"simple\">$3</text:a></text:p>"
214 221
                 ;;
215 222
             texte)
216
-                cell='<table:table-cell office:value-type="string" calcext:value-type="string">'
217
-                cell+="<text:p>$2</text:p>"
223
+                cell+='"string" calcext:value-type="string"'${style[${2:- }]:+ table:style-name=\"${style[$2]}\"}'>'
224
+                cell+="<text:p>${2:- }</text:p>"
218 225
                 ;;
219 226
             nombre)
220
-                cell="<table:table-cell office:value-type=\"float\" office:value=\"$2\" calcext:value-type=\"float\">"
227
+                cell+='"float" office:value="'$2'" calcext:value-type="float">'
221 228
                 cell+="<text:p>$2</text:p>"
222 229
                 ;;
230
+            formule)
231
+                cell+='"string" table:formula="of:='"$2"'" calcext:value-type="string"'${3:+ table:style-name=\"${3}\"}'>'
232
+                ;;
223 233
             *)
224 234
                 return 1;;
225 235
         esac
... ...
@@ -272,11 +282,20 @@ EOcontent
272 282
     <style:style style:name="ta1" style:family="table" style:master-page-name="Default">
273 283
     <style:table-properties table:display="true" style:writing-mode="lr-tb"/>
274 284
     </style:style>
285
+    <style:style style:name="T1" style:family="text">
286
+    <style:text-properties fo:font-weight="bold" style:font-weight-asian="bold" style:font-weight-complex="bold" fo:color="#5eb91e"/>
287
+    </style:style>
288
+    <style:style style:name="T2" style:family="text">
289
+    <style:text-properties fo:font-weight="bold" style:font-weight-asian="bold" style:font-weight-complex="bold" fo:color="#c9211e"/>
290
+    </style:style>
291
+    <style:style style:name="T3" style:family="text">
292
+    <style:text-properties fo:font-weight="bold" style:font-weight-asian="bold" style:font-weight-complex="bold" fo:color="#e8a202"/>
293
+    </style:style>
275 294
 EOcontent
276 295
 
277 296
     for i in $(seq ${#groupe[@]}); do
278 297
         cat >> "$content" << EOcontent
279
-        <style:style style:name="ce$i" style:family="table-cell" style:parent-style-name="Default">
298
+        <style:style style:name="groupe$i" style:family="table-cell" style:parent-style-name="Default">
280 299
         <style:table-cell-properties fo:wrap-option="wrap" style:vertical-align="middle" fo:background-color="#${colors[$i]%:*}"/>
281 300
         <style:text-properties fo:hyphenate="false" fo:color="#${colors[$i]}"/>
282 301
         </style:style>
... ...
@@ -293,12 +312,10 @@ EOcontent
293 312
     <table:table-column table:style-name="co1" table:number-columns-repeated="${#id_cols[@]}" table:default-cell-style-name="Default"/>
294 313
 EOcontent
295 314
 
296
-    for i in $(seq ${#typevotes[@]}); do
297
-        for g in $(seq ${#groupe[@]}); do
298
-            cat >> "$content" << EOcontent
299
-            <table:table-column table:style-name="co1" table:default-cell-style-name="ce$g"/>
315
+    for g in $(seq ${#groupe[@]}); do
316
+        cat >> "$content" << EOcontent
317
+        <table:table-column table:style-name="co1" table:default-cell-style-name="ce$g"/>
300 318
 EOcontent
301
-        done
302 319
     done
303 320
     echo '<table:table-row table:style-name="ro1">' >> "$content"
304 321
 
... ...
@@ -307,10 +324,9 @@ EOcontent
307 324
         write_cell texte $colonne
308 325
     done
309 326
 
310
-    for typevote in ${typevotes[@]}; do
311
-        for g in "${groupe[@]}"; do
312
-            write_cell texte "$typevote - $g"
313
-        done
327
+    for (( g=0; g<${#groupe[@]}; g++ )); do
328
+        colname=$(get_colname $(( ${#id_cols[@]} + $g + 1)) )
329
+        write_cell formule "COM.MICROSOFT.CONCAT(&quot;${groupe[$g]} (&quot;; $(($last-$first+1))-COUNTIF([.${colname}2:.${colname}$(($last-$first+2))];&quot; &quot;); &quot;)&quot;)" groupe$(($g+1))
314 330
     done
315 331
 
316 332
     echo '</table:table-row>' >> "$content"
... ...
@@ -342,37 +358,38 @@ EOcontent
342 358
         write_cell url   "${dossier_url/#null/\"\"}" "${dossier_texte/#null}"
343 359
 
344 360
         unset votes
345
-        for typevote in $(seq ${#typevotes[@]}); do
346
-            for (( g = 0; g < ${#groupe[@]}; g++ )); do
347
-                votes[${#votes[@]}]=$(sqlite_request "select
348
-                                            count(député)
349
-                                         from
350
-                                            dépouillements
351
-                                         inner join
352
-                                            députés, groupes
353
-                                         on
354
-                                            députés.groupe = groupes.id and dépouillements.député = députés.id
355
-                                         where
356
-                                            scrutin is $scrutin
357
-                                         and
358
-                                            vote is $typevote
359
-                                         and
360
-                                            ${id_groupe[$g]%:*}.nom = '${groupe[$g]//\'/\'\'}'")
361
-            done
362
-        done
363
-        for ((j = 0; j < ${#groupe[@]}; j++)); do
364
-            presence=1 # `let presence+=0` sort en erreur si variable est unset ou égale à 0
365
-            for ((i = $j; i < ${#votes[@]}; i += ${#groupe[@]})); do
366
-                let presence+=${votes[$i]}
367
-            done
368
-            if test $presence -eq 1; then
369
-                for ((i = $j; i < ${#votes[@]}; i += ${#groupe[@]})); do
370
-                    votes[$i]=-1
371
-                done
372
-            fi
361
+        for (( g = 0; g < ${#groupe[@]}; g++ )); do
362
+            case ${id_groupe[$g]%:*} in
363
+                groupes)
364
+                    unset _vote
365
+                    eval $(sqlite_request "select '_vote[' || vote || ']=' || count(vote) from dépouillements
366
+                                           where scrutin = $scrutin and député in (
367
+                                               select id from députés
368
+                                               where groupe in (${id_groupe[$g]#*:})
369
+                                           )
370
+                                           group by vote")
371
+                    if test ${#_vote[@]} -gt 0; then
372
+                        unset _votes
373
+                        for i in {1..3}; do
374
+                            _votes+="<text:span text:style-name=\"T$i\">${_vote[$i]:-0}</text:span> / "
375
+                        done
376
+                        _votes+="${_vote[4]:-0}"
377
+                        votes[${#votes[@]}]=$_votes
378
+                    else
379
+                        votes[${#votes[@]}]=" "
380
+                    fi
381
+                ;;
382
+                députés)
383
+                    votes[${#votes[@]}]=$(sqlite_request "select nom from votes
384
+                                                          where id in (
385
+                                                              select vote from dépouillements
386
+                                                              where scrutin = $scrutin and député in (${id_groupe[$g]#*:})
387
+                                                          )")
388
+                ;;
389
+            esac
373 390
         done
374 391
         for ((i = 0; i < ${#votes[@]}; i ++)); do
375
-            write_cell nombre ${votes[$i]}
392
+            write_cell texte ${votes[$i]}
376 393
         done
377 394
         echo '</table:table-row>' >> "$content"
378 395
 
... ...
@@ -393,7 +410,7 @@ EOcontent
393 410
     </table:table>
394 411
     <table:named-expressions/>
395 412
     <table:database-ranges>
396
-    <table:database-range table:name="__Anonymous_Sheet_DB__0" table:target-range-address="&apos;$result&apos;.D1:&apos;$result&apos;.$last_col$line" table:display-filter-buttons="true"/>
413
+    <table:database-range table:name="__Anonymous_Sheet_DB__0" table:target-range-address="&apos;$result&apos;.D1:&apos;$result&apos;.$(get_colname $nb_cols)$line" table:display-filter-buttons="true"/>
397 414
     </table:database-ranges>
398 415
     </office:spreadsheet>
399 416
     </office:body>