@tricoteuses/senat 2.16.0 → 2.16.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/datasets.js +1 -0
- package/lib/model/scrutins.js +56 -4
- package/package.json +1 -1
package/lib/datasets.js
CHANGED
|
@@ -220,6 +220,7 @@ export const datasets = {
|
|
|
220
220
|
],
|
|
221
221
|
votsen: [
|
|
222
222
|
{ name: "idx_scrnum", columns: ["scrnum"] },
|
|
223
|
+
{ name: "idx_sesann", columns: ["sesann"] },
|
|
223
224
|
{ name: "idx_titsencod", columns: ["titsencod"] },
|
|
224
225
|
{ name: "idx_stavotidt", columns: ["stavotidt"] },
|
|
225
226
|
{ name: "idx_posvotcod", columns: ["posvotcod"] },
|
package/lib/model/scrutins.js
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import { jsonArrayFrom } from "kysely/helpers/postgres";
|
|
2
2
|
import { dbSenat } from "../databases";
|
|
3
3
|
import { rtrim, toDateString } from "./util";
|
|
4
|
-
function votes(scrutinNum, scrutinDate) {
|
|
4
|
+
function votes(scrutinNum, scrutinSession, scrutinDate) {
|
|
5
5
|
return jsonArrayFrom(dbSenat
|
|
6
6
|
.selectFrom("dosleg.votsen")
|
|
7
7
|
.leftJoin("dosleg.titsen", "dosleg.titsen.titsencod", "dosleg.votsen.titsencod")
|
|
8
8
|
.leftJoin("dosleg.stavot", "dosleg.stavot.stavotidt", "dosleg.votsen.stavotidt")
|
|
9
9
|
.leftJoin("dosleg.posvot", "dosleg.posvot.posvotcod", "dosleg.votsen.posvotcod")
|
|
10
|
-
.leftJoin("sens.sen", "dosleg.votsen.senmat", "sens.sen.senmat")
|
|
11
10
|
.leftJoin("sens.memgrppol", (join) => join
|
|
12
11
|
.onRef("sens.memgrppol.senmat", "=", "dosleg.votsen.senmat")
|
|
13
12
|
.onRef("sens.memgrppol.memgrppoldatdeb", "<=", scrutinDate)
|
|
@@ -16,7 +15,8 @@ function votes(scrutinNum, scrutinDate) {
|
|
|
16
15
|
eb("sens.memgrppol.memgrppoldatfin", "is", null)
|
|
17
16
|
])))
|
|
18
17
|
.where("dosleg.votsen.scrnum", "=", scrutinNum)
|
|
19
|
-
.where("
|
|
18
|
+
.where("dosleg.votsen.sesann", "=", scrutinSession)
|
|
19
|
+
.orderBy("sens.memgrppol.memgrppoldatdeb", "desc")
|
|
20
20
|
.select([
|
|
21
21
|
"dosleg.votsen.senmat as matricule_votant",
|
|
22
22
|
"dosleg.votsen.senmatdel as matricule_delegant",
|
|
@@ -27,6 +27,57 @@ function votes(scrutinNum, scrutinDate) {
|
|
|
27
27
|
"sens.memgrppol.grppolcod as groupe_politique_code",
|
|
28
28
|
]));
|
|
29
29
|
}
|
|
30
|
+
function groupesVotants(scrutinNum, scrutinSession, scrutinDate) {
|
|
31
|
+
return jsonArrayFrom(dbSenat
|
|
32
|
+
.selectFrom((eb) => eb
|
|
33
|
+
.selectFrom("dosleg.votsen")
|
|
34
|
+
.leftJoin("dosleg.posvot", "dosleg.posvot.posvotcod", "dosleg.votsen.posvotcod")
|
|
35
|
+
.leftJoin("dosleg.stavot", "dosleg.stavot.stavotidt", "dosleg.votsen.stavotidt")
|
|
36
|
+
.leftJoin("sens.memgrppol", (join) => join
|
|
37
|
+
.onRef("sens.memgrppol.senmat", "=", "dosleg.votsen.senmat")
|
|
38
|
+
.onRef("sens.memgrppol.memgrppoldatdeb", "<=", scrutinDate)
|
|
39
|
+
.on((eb) => eb.or([
|
|
40
|
+
eb("sens.memgrppol.memgrppoldatfin", ">=", scrutinDate),
|
|
41
|
+
eb("sens.memgrppol.memgrppoldatfin", "is", null)
|
|
42
|
+
])))
|
|
43
|
+
.where("dosleg.votsen.scrnum", "=", scrutinNum)
|
|
44
|
+
.where("dosleg.votsen.sesann", "=", scrutinSession)
|
|
45
|
+
.orderBy("sens.memgrppol.memgrppoldatdeb", "desc")
|
|
46
|
+
.select([
|
|
47
|
+
"dosleg.votsen.senmat",
|
|
48
|
+
"dosleg.posvot.posvotlib",
|
|
49
|
+
"dosleg.stavot.stavotlib",
|
|
50
|
+
"sens.memgrppol.grppolcod",
|
|
51
|
+
])
|
|
52
|
+
.as("unique_votes"))
|
|
53
|
+
.groupBy([
|
|
54
|
+
"unique_votes.grppolcod",
|
|
55
|
+
])
|
|
56
|
+
.select(({ fn, eb }) => [
|
|
57
|
+
"unique_votes.grppolcod as groupe_politique_code",
|
|
58
|
+
fn.sum(eb.case()
|
|
59
|
+
.when("unique_votes.posvotlib", "=", "pour")
|
|
60
|
+
.then(1)
|
|
61
|
+
.else(0)
|
|
62
|
+
.end()).as("nombre_pour"),
|
|
63
|
+
fn.sum(eb.case()
|
|
64
|
+
.when("unique_votes.posvotlib", "=", "contre")
|
|
65
|
+
.then(1)
|
|
66
|
+
.else(0)
|
|
67
|
+
.end()).as("nombre_contre"),
|
|
68
|
+
fn.sum(eb.case()
|
|
69
|
+
.when("unique_votes.posvotlib", "=", "abstention")
|
|
70
|
+
.then(1)
|
|
71
|
+
.else(0)
|
|
72
|
+
.end()).as("nombre_abstentions"),
|
|
73
|
+
fn.sum(eb.case()
|
|
74
|
+
.when("unique_votes.posvotlib", "=", "non-votant")
|
|
75
|
+
.then(1)
|
|
76
|
+
.else(0)
|
|
77
|
+
.end()).as("nombre_non_votants"),
|
|
78
|
+
fn.count("unique_votes.senmat").as("nombre_votants"),
|
|
79
|
+
]));
|
|
80
|
+
}
|
|
30
81
|
function misesAuPoint(scrutinNum) {
|
|
31
82
|
return jsonArrayFrom(dbSenat
|
|
32
83
|
.withSchema("dosleg")
|
|
@@ -65,7 +116,8 @@ const findAllScrutinsQuery = dbSenat
|
|
|
65
116
|
"scr.scrconsea as nombre_contre_seance",
|
|
66
117
|
"scr.scrpou as nombre_pour",
|
|
67
118
|
"scr.scrpousea as nombre_pour_seance",
|
|
68
|
-
votes(ref("scr.scrnum"), ref("scr.scrdat")).as("votes"),
|
|
119
|
+
votes(ref("scr.scrnum"), ref("scr.sesann"), ref("scr.scrdat")).as("votes"),
|
|
120
|
+
groupesVotants(ref("scr.scrnum"), ref("scr.sesann"), ref("scr.scrdat")).as("groupes_votants"),
|
|
69
121
|
misesAuPoint(ref("scr.scrnum")).as("mises_au_point"),
|
|
70
122
|
])
|
|
71
123
|
.$narrowType();
|