@tricoteuses/senat 2.22.4 → 2.22.5

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.
Files changed (257) hide show
  1. package/lib/aggregates.d.ts +52 -0
  2. package/lib/aggregates.js +930 -0
  3. package/lib/aggregates.mjs +713 -0
  4. package/lib/aggregates.ts +833 -0
  5. package/lib/config.d.ts +10 -0
  6. package/lib/config.js +16 -0
  7. package/lib/config.mjs +16 -0
  8. package/lib/config.ts +26 -0
  9. package/lib/databases.d.ts +2 -0
  10. package/lib/databases.js +26 -0
  11. package/lib/databases.mjs +57 -0
  12. package/lib/databases.ts +71 -0
  13. package/lib/datasets.d.ts +34 -0
  14. package/lib/datasets.js +233 -0
  15. package/lib/datasets.mjs +78 -0
  16. package/lib/datasets.ts +118 -0
  17. package/lib/fields.d.ts +10 -0
  18. package/lib/fields.js +68 -0
  19. package/lib/fields.mjs +22 -0
  20. package/lib/fields.ts +29 -0
  21. package/lib/git.d.ts +26 -0
  22. package/lib/git.js +167 -0
  23. package/lib/index.d.ts +13 -0
  24. package/lib/index.js +1 -0
  25. package/lib/index.mjs +7 -0
  26. package/lib/index.ts +64 -0
  27. package/lib/inserters.d.ts +98 -0
  28. package/lib/inserters.js +500 -0
  29. package/lib/inserters.mjs +360 -0
  30. package/lib/inserters.ts +521 -0
  31. package/lib/legislatures.json +38 -0
  32. package/lib/loaders.d.ts +58 -0
  33. package/lib/loaders.js +286 -0
  34. package/lib/loaders.mjs +158 -0
  35. package/lib/loaders.ts +271 -0
  36. package/lib/model/agenda.d.ts +6 -0
  37. package/lib/model/agenda.js +148 -0
  38. package/lib/model/ameli.d.ts +51 -0
  39. package/lib/model/ameli.js +149 -0
  40. package/lib/model/ameli.mjs +84 -0
  41. package/lib/model/ameli.ts +100 -0
  42. package/lib/model/commission.d.ts +18 -0
  43. package/lib/model/commission.js +269 -0
  44. package/lib/model/debats.d.ts +67 -0
  45. package/lib/model/debats.js +95 -0
  46. package/lib/model/debats.mjs +43 -0
  47. package/lib/model/debats.ts +68 -0
  48. package/lib/model/documents.d.ts +12 -0
  49. package/lib/model/documents.js +151 -0
  50. package/lib/model/dosleg.d.ts +7 -0
  51. package/lib/model/dosleg.js +326 -0
  52. package/lib/model/dosleg.mjs +196 -0
  53. package/lib/model/dosleg.ts +240 -0
  54. package/lib/model/index.d.ts +7 -0
  55. package/lib/model/index.js +7 -0
  56. package/lib/model/index.mjs +5 -0
  57. package/lib/model/index.ts +15 -0
  58. package/lib/model/questions.d.ts +45 -0
  59. package/lib/model/questions.js +89 -0
  60. package/lib/model/questions.mjs +71 -0
  61. package/lib/model/questions.ts +93 -0
  62. package/lib/model/scrutins.d.ts +13 -0
  63. package/lib/model/scrutins.js +114 -0
  64. package/lib/model/seance.d.ts +3 -0
  65. package/lib/model/seance.js +267 -0
  66. package/lib/model/sens.d.ts +146 -0
  67. package/lib/model/sens.js +454 -0
  68. package/lib/model/sens.mjs +415 -0
  69. package/lib/model/sens.ts +516 -0
  70. package/lib/model/texte.d.ts +7 -0
  71. package/lib/model/texte.js +256 -0
  72. package/lib/model/texte.mjs +208 -0
  73. package/lib/model/texte.ts +229 -0
  74. package/lib/model/util.d.ts +9 -0
  75. package/lib/model/util.js +38 -0
  76. package/lib/model/util.mjs +19 -0
  77. package/lib/model/util.ts +32 -0
  78. package/lib/parsers/texte.d.ts +7 -0
  79. package/lib/parsers/texte.js +228 -0
  80. package/lib/raw_types/ameli.d.ts +914 -0
  81. package/lib/raw_types/ameli.js +5 -0
  82. package/lib/raw_types/ameli.mjs +163 -0
  83. package/lib/raw_types/debats.d.ts +207 -0
  84. package/lib/raw_types/debats.js +5 -0
  85. package/lib/raw_types/debats.mjs +58 -0
  86. package/lib/raw_types/dosleg.d.ts +1619 -0
  87. package/lib/raw_types/dosleg.js +5 -0
  88. package/lib/raw_types/dosleg.mjs +438 -0
  89. package/lib/raw_types/questions.d.ts +419 -0
  90. package/lib/raw_types/questions.js +5 -0
  91. package/lib/raw_types/questions.mjs +11 -0
  92. package/lib/raw_types/senat.d.ts +11368 -0
  93. package/lib/raw_types/senat.js +5 -0
  94. package/lib/raw_types/sens.d.ts +8248 -0
  95. package/lib/raw_types/sens.js +5 -0
  96. package/lib/raw_types/sens.mjs +508 -0
  97. package/lib/raw_types_kysely/ameli.d.ts +915 -0
  98. package/lib/raw_types_kysely/ameli.js +7 -0
  99. package/lib/raw_types_kysely/ameli.mjs +5 -0
  100. package/lib/raw_types_kysely/ameli.ts +951 -0
  101. package/lib/raw_types_kysely/debats.d.ts +207 -0
  102. package/lib/raw_types_kysely/debats.js +7 -0
  103. package/lib/raw_types_kysely/debats.mjs +5 -0
  104. package/lib/raw_types_kysely/debats.ts +222 -0
  105. package/lib/raw_types_kysely/dosleg.d.ts +3532 -0
  106. package/lib/raw_types_kysely/dosleg.js +7 -0
  107. package/lib/raw_types_kysely/dosleg.mjs +5 -0
  108. package/lib/raw_types_kysely/dosleg.ts +3621 -0
  109. package/lib/raw_types_kysely/questions.d.ts +414 -0
  110. package/lib/raw_types_kysely/questions.js +7 -0
  111. package/lib/raw_types_kysely/questions.mjs +5 -0
  112. package/lib/raw_types_kysely/questions.ts +426 -0
  113. package/lib/raw_types_kysely/sens.d.ts +4394 -0
  114. package/lib/raw_types_kysely/sens.js +7 -0
  115. package/lib/raw_types_kysely/sens.mjs +5 -0
  116. package/lib/raw_types_kysely/sens.ts +4499 -0
  117. package/lib/raw_types_schemats/ameli.d.ts +539 -0
  118. package/lib/raw_types_schemats/ameli.js +2 -0
  119. package/lib/raw_types_schemats/ameli.mjs +2 -0
  120. package/lib/raw_types_schemats/ameli.ts +601 -0
  121. package/lib/raw_types_schemats/debats.d.ts +127 -0
  122. package/lib/raw_types_schemats/debats.js +2 -0
  123. package/lib/raw_types_schemats/debats.mjs +2 -0
  124. package/lib/raw_types_schemats/debats.ts +145 -0
  125. package/lib/raw_types_schemats/dosleg.d.ts +977 -0
  126. package/lib/raw_types_schemats/dosleg.js +2 -0
  127. package/lib/raw_types_schemats/dosleg.mjs +2 -0
  128. package/lib/raw_types_schemats/dosleg.ts +2193 -0
  129. package/lib/raw_types_schemats/questions.d.ts +235 -0
  130. package/lib/raw_types_schemats/questions.js +2 -0
  131. package/lib/raw_types_schemats/questions.mjs +2 -0
  132. package/lib/raw_types_schemats/questions.ts +249 -0
  133. package/lib/raw_types_schemats/sens.d.ts +6915 -0
  134. package/lib/raw_types_schemats/sens.js +2 -0
  135. package/lib/raw_types_schemats/sens.mjs +2 -0
  136. package/lib/raw_types_schemats/sens.ts +2907 -0
  137. package/lib/scripts/convert_data.d.ts +1 -0
  138. package/lib/scripts/convert_data.js +354 -0
  139. package/lib/scripts/convert_data.mjs +181 -0
  140. package/lib/scripts/convert_data.ts +243 -0
  141. package/lib/scripts/data-download.d.ts +1 -0
  142. package/lib/scripts/data-download.js +12 -0
  143. package/lib/scripts/datautil.d.ts +8 -0
  144. package/lib/scripts/datautil.js +34 -0
  145. package/lib/scripts/datautil.mjs +16 -0
  146. package/lib/scripts/datautil.ts +19 -0
  147. package/lib/scripts/images/transparent_150x192.jpg +0 -0
  148. package/lib/scripts/images/transparent_155x225.jpg +0 -0
  149. package/lib/scripts/parse_textes.d.ts +1 -0
  150. package/lib/scripts/parse_textes.js +44 -0
  151. package/lib/scripts/parse_textes.mjs +46 -0
  152. package/lib/scripts/parse_textes.ts +65 -0
  153. package/lib/scripts/retrieve_agenda.d.ts +1 -0
  154. package/lib/scripts/retrieve_agenda.js +132 -0
  155. package/lib/scripts/retrieve_cr_commission.d.ts +1 -0
  156. package/lib/scripts/retrieve_cr_commission.js +364 -0
  157. package/lib/scripts/retrieve_cr_seance.d.ts +6 -0
  158. package/lib/scripts/retrieve_cr_seance.js +347 -0
  159. package/lib/scripts/retrieve_documents.d.ts +3 -0
  160. package/lib/scripts/retrieve_documents.js +219 -0
  161. package/lib/scripts/retrieve_documents.mjs +249 -0
  162. package/lib/scripts/retrieve_documents.ts +298 -0
  163. package/lib/scripts/retrieve_open_data.d.ts +1 -0
  164. package/lib/scripts/retrieve_open_data.js +315 -0
  165. package/lib/scripts/retrieve_open_data.mjs +217 -0
  166. package/lib/scripts/retrieve_open_data.ts +268 -0
  167. package/lib/scripts/retrieve_senateurs_photos.d.ts +1 -0
  168. package/lib/scripts/retrieve_senateurs_photos.js +147 -0
  169. package/lib/scripts/retrieve_senateurs_photos.mjs +147 -0
  170. package/lib/scripts/retrieve_senateurs_photos.ts +177 -0
  171. package/lib/scripts/retrieve_videos.d.ts +1 -0
  172. package/lib/scripts/retrieve_videos.js +461 -0
  173. package/lib/scripts/shared/cli_helpers.d.ts +95 -0
  174. package/lib/scripts/shared/cli_helpers.js +91 -0
  175. package/lib/scripts/shared/cli_helpers.ts +36 -0
  176. package/lib/scripts/shared/util.d.ts +4 -0
  177. package/lib/scripts/shared/util.js +35 -0
  178. package/lib/scripts/shared/util.ts +33 -0
  179. package/lib/scripts/test_iter_load.d.ts +1 -0
  180. package/lib/scripts/test_iter_load.js +12 -0
  181. package/lib/src/conversion_textes.js +10 -1
  182. package/lib/src/index.d.ts +1 -1
  183. package/lib/src/index.js +1 -1
  184. package/lib/src/loaders.d.ts +1 -0
  185. package/lib/src/loaders.js +1 -0
  186. package/lib/src/parsers/texte.js +2 -2
  187. package/lib/src/scripts/convert_data.js +11 -10
  188. package/lib/src/scripts/retrieve_documents.d.ts +1 -1
  189. package/lib/src/scripts/retrieve_documents.js +25 -10
  190. package/lib/src/scripts/retrieve_open_data.js +1 -1
  191. package/lib/src/types/sessions.d.ts +5 -4
  192. package/lib/src/types/sessions.js +10 -75
  193. package/lib/src/types/texte.d.ts +2 -0
  194. package/lib/strings.d.ts +1 -0
  195. package/lib/strings.js +18 -0
  196. package/lib/strings.mjs +18 -0
  197. package/lib/strings.ts +26 -0
  198. package/lib/types/agenda.d.ts +44 -0
  199. package/lib/types/agenda.js +1 -0
  200. package/lib/types/ameli.d.ts +5 -0
  201. package/lib/types/ameli.js +1 -0
  202. package/lib/types/ameli.mjs +13 -0
  203. package/lib/types/ameli.ts +21 -0
  204. package/lib/types/compte_rendu.d.ts +83 -0
  205. package/lib/types/compte_rendu.js +1 -0
  206. package/lib/types/debats.d.ts +2 -0
  207. package/lib/types/debats.js +1 -0
  208. package/lib/types/debats.mjs +2 -0
  209. package/lib/types/debats.ts +6 -0
  210. package/lib/types/dosleg.d.ts +70 -0
  211. package/lib/types/dosleg.js +1 -0
  212. package/lib/types/dosleg.mjs +151 -0
  213. package/lib/types/dosleg.ts +284 -0
  214. package/lib/types/questions.d.ts +2 -0
  215. package/lib/types/questions.js +1 -0
  216. package/lib/types/questions.mjs +1 -0
  217. package/lib/types/questions.ts +3 -0
  218. package/lib/types/sens.d.ts +10 -0
  219. package/lib/types/sens.js +1 -0
  220. package/lib/types/sens.mjs +1 -0
  221. package/lib/types/sens.ts +12 -0
  222. package/lib/types/sessions.d.ts +5 -0
  223. package/lib/types/sessions.js +84 -0
  224. package/lib/types/sessions.mjs +43 -0
  225. package/lib/types/sessions.ts +42 -0
  226. package/lib/types/texte.d.ts +74 -0
  227. package/lib/types/texte.js +16 -0
  228. package/lib/types/texte.mjs +16 -0
  229. package/lib/types/texte.ts +76 -0
  230. package/lib/typings/windows-1252.d.js +2 -0
  231. package/lib/typings/windows-1252.d.mjs +2 -0
  232. package/lib/typings/windows-1252.d.ts +11 -0
  233. package/lib/utils/cr_spliting.d.ts +28 -0
  234. package/lib/utils/cr_spliting.js +265 -0
  235. package/lib/utils/date.d.ts +10 -0
  236. package/lib/utils/date.js +100 -0
  237. package/lib/utils/nvs-timecode.d.ts +7 -0
  238. package/lib/utils/nvs-timecode.js +79 -0
  239. package/lib/utils/reunion_grouping.d.ts +9 -0
  240. package/lib/utils/reunion_grouping.js +361 -0
  241. package/lib/utils/reunion_odj_building.d.ts +5 -0
  242. package/lib/utils/reunion_odj_building.js +154 -0
  243. package/lib/utils/reunion_parsing.d.ts +23 -0
  244. package/lib/utils/reunion_parsing.js +209 -0
  245. package/lib/utils/scoring.d.ts +14 -0
  246. package/lib/utils/scoring.js +147 -0
  247. package/lib/utils/string_cleaning.d.ts +7 -0
  248. package/lib/utils/string_cleaning.js +57 -0
  249. package/lib/validators/config.d.ts +9 -0
  250. package/lib/validators/config.js +10 -0
  251. package/lib/validators/config.mjs +54 -0
  252. package/lib/validators/config.ts +79 -0
  253. package/lib/validators/senat.d.ts +0 -0
  254. package/lib/validators/senat.js +28 -0
  255. package/lib/validators/senat.mjs +24 -0
  256. package/lib/validators/senat.ts +26 -0
  257. package/package.json +5 -5
@@ -0,0 +1,71 @@
1
+ import { jsonArrayFrom } from "kysely/helpers/postgres";
2
+ import { dbQuestions } from "../databases";
3
+ import { expandToRows, rtrim, toDateString } from "./util";
4
+ function reponses(questionId) {
5
+ return jsonArrayFrom(dbQuestions.selectFrom("tam_reponses")
6
+ .where("tam_reponses.idque", "=", questionId)
7
+ .select(({ ref }) => [
8
+ toDateString(ref("tam_reponses.datejorep")).as("date_reponse_JO"),
9
+ "tam_reponses.minreplib as ministere_reponse",
10
+ "tam_reponses.txtrep as texte",
11
+ "tam_reponses.txterrrep as texte_erratum",
12
+ ])
13
+ .orderBy("tam_reponses.datejorep asc"));
14
+ }
15
+ function themes(questionId) {
16
+ return jsonArrayFrom(dbQuestions.with("question_theme", (db) => db
17
+ .selectFrom("tam_questions")
18
+ .select(({ eb, ref, val }) => [
19
+ "id as question_id",
20
+ eb.cast(expandToRows(ref("tam_questions.themes"), val("#(\\d+)")), "smallint").as("theme_id"),
21
+ ]))
22
+ .selectFrom("the")
23
+ .leftJoin("question_theme", "the.thenouidt", "question_theme.theme_id")
24
+ .where("question_theme.question_id", "=", questionId)
25
+ .select("the.thelib as libelle")
26
+ .orderBy("the.thenouidt asc"));
27
+ }
28
+ const findAllQuery = dbQuestions
29
+ .selectFrom("tam_questions")
30
+ .leftJoin("tam_ministeres", "tam_questions.mindepotid", "tam_ministeres.minid")
31
+ .leftJoin("sortquestion", (join) => join
32
+ .onRef("tam_questions.sorquecod", "=", eb => eb.cast("sortquestion.sorquecod", "bigint")))
33
+ .leftJoin("naturequestion", "tam_questions.natquecod", "naturequestion.natquecod")
34
+ .leftJoin("etatquestion", (join) => join
35
+ .onRef("tam_questions.etaquecod", "=", eb => eb.cast("etatquestion.etaquecod", "bigint")))
36
+ .select(({ ref }) => [
37
+ "tam_questions.repub as republique",
38
+ "tam_questions.legislature as legislature",
39
+ "sortquestion.sorquelib as sort",
40
+ "tam_questions.natquecod as nature",
41
+ "tam_questions.numero as numero",
42
+ "tam_questions.reference as reference",
43
+ "tam_questions.titre as titre",
44
+ "tam_questions.nom as nom",
45
+ "tam_questions.prenom as prenom",
46
+ "tam_questions.codequalite as civilite",
47
+ "tam_questions.matricule as matricule",
48
+ "tam_questions.circonscription as circonscription",
49
+ "tam_questions.groupe as groupe",
50
+ "tam_questions.ratgrp as type_appartenance",
51
+ toDateString(ref("tam_questions.datejodepot")).as("date_publication_JO"),
52
+ rtrim(ref("tam_questions.mindepotlib")).as("ministere_depot"),
53
+ toDateString(ref("tam_ministeres.datedebut")).as("ministere_depot_date_debut"),
54
+ toDateString(ref("tam_questions.datejotran")).as("date_transmission"),
55
+ "tam_questions.mintranlib as ministere_transmission",
56
+ toDateString(ref("tam_questions.datejorep1")).as("date_reponse_JO"),
57
+ "tam_questions.minreplib1 as ministere_reponse",
58
+ toDateString(ref("tam_questions.datecloture")).as("date_cloture"),
59
+ "tam_questions.refquerappelee as reference_question_rappelee",
60
+ //"tam_questions.url as url", // TODO ?
61
+ "tam_questions.txtque as texte",
62
+ "tam_questions.txtque as texte_erratum",
63
+ "tam_questions.rubrique as rubrique",
64
+ ])
65
+ .select(({ ref }) => [
66
+ themes(ref("tam_questions.id")).as("themes"),
67
+ reponses(ref("tam_questions.id")).as("reponses"),
68
+ ]);
69
+ export function findAll() {
70
+ return findAllQuery.stream();
71
+ }
@@ -0,0 +1,93 @@
1
+ import { Expression, InferResult } from "kysely"
2
+ import { jsonArrayFrom } from "kysely/helpers/postgres"
3
+ import { dbQuestions } from "../databases"
4
+ import { expandToRows, rtrim, toDateString } from "./util"
5
+
6
+ function reponses (questionId: Expression<string>) {
7
+ return jsonArrayFrom(
8
+ dbQuestions.selectFrom("tam_reponses")
9
+ .where("tam_reponses.idque", "=", questionId)
10
+ .select(({ ref }) => [
11
+ toDateString(ref("tam_reponses.datejorep")).as("date_reponse_JO"),
12
+ "tam_reponses.minreplib as ministere_reponse",
13
+ "tam_reponses.txtrep as texte",
14
+ "tam_reponses.txterrrep as texte_erratum",
15
+ ])
16
+ .orderBy("tam_reponses.datejorep asc"),
17
+ )
18
+ }
19
+
20
+ function themes (questionId: Expression<string>) {
21
+ return jsonArrayFrom(
22
+ dbQuestions.with("question_theme", (db) => db
23
+ .selectFrom("tam_questions")
24
+ .select(({ eb, ref, val }) => [
25
+ "id as question_id",
26
+ eb.cast<number>(expandToRows(ref("tam_questions.themes"), val("#(\\d+)")), "smallint").as("theme_id"),
27
+ ]),
28
+ )
29
+ .selectFrom("the")
30
+ .leftJoin("question_theme", "the.thenouidt", "question_theme.theme_id")
31
+ .where("question_theme.question_id", "=", questionId)
32
+ .select("the.thelib as libelle")
33
+ .orderBy("the.thenouidt asc"),
34
+ )
35
+ }
36
+
37
+ const findAllQuery = dbQuestions
38
+ .selectFrom("tam_questions")
39
+ .leftJoin("tam_ministeres", "tam_questions.mindepotid", "tam_ministeres.minid")
40
+ .leftJoin("sortquestion", (join) => join
41
+ .onRef(
42
+ "tam_questions.sorquecod",
43
+ "=",
44
+ eb => eb.cast<number>("sortquestion.sorquecod", "bigint"),
45
+ ),
46
+ )
47
+ .leftJoin("naturequestion", "tam_questions.natquecod", "naturequestion.natquecod")
48
+ .leftJoin("etatquestion", (join) => join
49
+ .onRef(
50
+ "tam_questions.etaquecod",
51
+ "=",
52
+ eb => eb.cast<number>("etatquestion.etaquecod", "bigint"),
53
+ ),
54
+ )
55
+ .select(({ ref }) => [
56
+ "tam_questions.repub as republique",
57
+ "tam_questions.legislature as legislature",
58
+ "sortquestion.sorquelib as sort",
59
+ "tam_questions.natquecod as nature",
60
+ "tam_questions.numero as numero",
61
+ "tam_questions.reference as reference",
62
+ "tam_questions.titre as titre",
63
+ "tam_questions.nom as nom",
64
+ "tam_questions.prenom as prenom",
65
+ "tam_questions.codequalite as civilite",
66
+ "tam_questions.matricule as matricule",
67
+ "tam_questions.circonscription as circonscription",
68
+ "tam_questions.groupe as groupe",
69
+ "tam_questions.ratgrp as type_appartenance",
70
+ toDateString(ref("tam_questions.datejodepot")).as("date_publication_JO"),
71
+ rtrim(ref("tam_questions.mindepotlib")).as("ministere_depot"),
72
+ toDateString(ref("tam_ministeres.datedebut")).as("ministere_depot_date_debut"),
73
+ toDateString(ref("tam_questions.datejotran")).as("date_transmission"),
74
+ "tam_questions.mintranlib as ministere_transmission",
75
+ toDateString(ref("tam_questions.datejorep1")).as("date_reponse_JO"),
76
+ "tam_questions.minreplib1 as ministere_reponse",
77
+ toDateString(ref("tam_questions.datecloture")).as("date_cloture"),
78
+ "tam_questions.refquerappelee as reference_question_rappelee",
79
+ //"tam_questions.url as url", // TODO ?
80
+ "tam_questions.txtque as texte",
81
+ "tam_questions.txtque as texte_erratum",
82
+ "tam_questions.rubrique as rubrique",
83
+ ])
84
+ .select(({ ref }) => [
85
+ themes(ref("tam_questions.id")).as("themes"),
86
+ reponses(ref("tam_questions.id")).as("reponses"),
87
+ ])
88
+
89
+ export type QuestionResult = InferResult<typeof findAllQuery>[0]
90
+
91
+ export function findAll () {
92
+ return findAllQuery.stream()
93
+ }
@@ -0,0 +1,13 @@
1
+ import { InferResult } from "kysely";
2
+ export type ScrutinResult = InferResult<typeof findAllScrutinsQuery>[0];
3
+ declare const findAllScrutinsQuery: import("kysely").SelectQueryBuilder<{
4
+ [x: string]: any;
5
+ [x: number]: any;
6
+ [x: symbol]: any;
7
+ }, "date_seance" | "lecass" | "lecture" | "loi" | "scr" | "typlec", {
8
+ [x: string]: any;
9
+ }>;
10
+ export declare function findAllScrutins(fromSession?: number): AsyncIterableIterator<{
11
+ [x: string]: any;
12
+ }>;
13
+ export {};
@@ -0,0 +1,114 @@
1
+ import { sql } from "kysely";
2
+ import { jsonArrayFrom } from "kysely/helpers/postgres";
3
+ import { dbSenat } from "../databases";
4
+ import { rtrim, toDateString } from "./util";
5
+ function votes(scrutinNum, scrutinSession, scrutinDate) {
6
+ return jsonArrayFrom(dbSenat
7
+ .selectFrom("dosleg.votsen")
8
+ .leftJoin("dosleg.titsen", "dosleg.titsen.titsencod", "dosleg.votsen.titsencod")
9
+ .leftJoin("dosleg.stavot", "dosleg.stavot.stavotidt", "dosleg.votsen.stavotidt")
10
+ .leftJoin("dosleg.posvot", "dosleg.posvot.posvotcod", "dosleg.votsen.posvotcod")
11
+ .leftJoin("sens.memgrppol", (join) => join
12
+ .onRef("sens.memgrppol.senmat", "=", "dosleg.votsen.senmat")
13
+ .onRef("sens.memgrppol.memgrppoldatdeb", "<=", scrutinDate)
14
+ .on((eb) => eb.or([
15
+ eb("sens.memgrppol.memgrppoldatfin", ">=", scrutinDate),
16
+ eb("sens.memgrppol.memgrppoldatfin", "is", null),
17
+ ])))
18
+ .where("dosleg.votsen.scrnum", "=", scrutinNum)
19
+ .where("dosleg.votsen.sesann", "=", scrutinSession)
20
+ .orderBy("sens.memgrppol.memgrppoldatdeb", "desc")
21
+ .select([
22
+ "dosleg.votsen.senmat as matricule_votant",
23
+ "dosleg.votsen.senmatdel as matricule_delegant",
24
+ "dosleg.posvot.posvotlib as position",
25
+ "dosleg.stavot.stavotlib as statut_votant",
26
+ "dosleg.titsen.titsenlib as titre_votant",
27
+ "sens.memgrppol.memgrppolid as groupe_politique_id",
28
+ "sens.memgrppol.grppolcod as groupe_politique_code",
29
+ ]));
30
+ }
31
+ function groupesVotants(scrutinNum, scrutinSession, scrutinDate) {
32
+ return jsonArrayFrom(dbSenat
33
+ .selectFrom((eb) => eb
34
+ .selectFrom("dosleg.votsen")
35
+ .leftJoin("dosleg.posvot", "dosleg.posvot.posvotcod", "dosleg.votsen.posvotcod")
36
+ .leftJoin("dosleg.stavot", "dosleg.stavot.stavotidt", "dosleg.votsen.stavotidt")
37
+ .leftJoin("sens.memgrppol", (join) => join
38
+ .onRef("sens.memgrppol.senmat", "=", "dosleg.votsen.senmat")
39
+ .onRef("sens.memgrppol.memgrppoldatdeb", "<=", scrutinDate)
40
+ .on((eb) => eb.or([
41
+ eb("sens.memgrppol.memgrppoldatfin", ">=", scrutinDate),
42
+ eb("sens.memgrppol.memgrppoldatfin", "is", null),
43
+ ])))
44
+ .where("dosleg.votsen.scrnum", "=", scrutinNum)
45
+ .where("dosleg.votsen.sesann", "=", scrutinSession)
46
+ .orderBy("sens.memgrppol.memgrppoldatdeb", "desc")
47
+ .select([
48
+ "dosleg.votsen.senmat",
49
+ "dosleg.posvot.posvotlib",
50
+ "dosleg.stavot.stavotlib",
51
+ "sens.memgrppol.grppolcod",
52
+ ])
53
+ .as("unique_votes"))
54
+ .groupBy(["unique_votes.grppolcod"])
55
+ .select(({ fn, eb }) => [
56
+ "unique_votes.grppolcod as groupe_politique_code",
57
+ fn.sum(eb.case().when("unique_votes.posvotlib", "=", "pour").then(1).else(0).end()).as("nombre_pour"),
58
+ fn.sum(eb.case().when("unique_votes.posvotlib", "=", "contre").then(1).else(0).end()).as("nombre_contre"),
59
+ fn
60
+ .sum(eb.case().when("unique_votes.posvotlib", "=", "abstention").then(1).else(0).end())
61
+ .as("nombre_abstentions"),
62
+ fn
63
+ .sum(eb.case().when("unique_votes.posvotlib", "=", "non-votant").then(1).else(0).end())
64
+ .as("nombre_non_votants"),
65
+ fn.count("unique_votes.senmat").as("nombre_votants"),
66
+ ]));
67
+ }
68
+ function misesAuPoint(scrutinNum) {
69
+ return jsonArrayFrom(dbSenat
70
+ .withSchema("dosleg")
71
+ .selectFrom("corscr")
72
+ .where("corscr.scrnum", "=", scrutinNum)
73
+ .select(["corscr.corscrtxt as texte", "corscr.corscrord as ordre", "corscr.corscrurl as url"]));
74
+ }
75
+ const findAllScrutinsQuery = dbSenat
76
+ .withSchema("dosleg")
77
+ .selectFrom("scr")
78
+ .leftJoin("date_seance", "scr.code", "date_seance.code")
79
+ .leftJoin("lecass", "date_seance.lecidt", "lecass.lecassidt")
80
+ .leftJoin("lecture", "lecture.lecidt", "lecass.lecidt")
81
+ .leftJoin("loi", "loi.loicod", "lecture.loicod")
82
+ .leftJoin("typlec", "typlec.typleccod", "lecture.typleccod")
83
+ .select(({ eb, ref, val }) => [
84
+ "scr.sesann as session",
85
+ "scr.scrnum as numero",
86
+ rtrim(ref("date_seance.lecidt")).as("lecture_id"),
87
+ rtrim(ref("lecture.leccom")).as("lecture_libelle"),
88
+ "loi.signet as signet_dossier",
89
+ rtrim(ref("typlec.typleclib")).as("type_lecture"),
90
+ toDateString(ref("scr.scrdat")).as("date_scrutin"),
91
+ toDateString(ref("scr.scrdateff")).as("date_scrutin_effective"),
92
+ sql `REPLACE(scr.scrint, E'\\u0092', '''')`.as("intitule"),
93
+ "scr.scrbaspag as note",
94
+ "scr.scrmaj as nombre_majorite",
95
+ "scr.scrmajsea as nombre_majorite_seance",
96
+ "scr.scrvot as nombre_votants",
97
+ "scr.scrvotsea as nombre_votants_seance",
98
+ "scr.scrsuf as nombre_suffrages",
99
+ "scr.scrsufsea as nombre_suffrages_seance",
100
+ "scr.scrcon as nombre_contre",
101
+ "scr.scrconsea as nombre_contre_seance",
102
+ "scr.scrpou as nombre_pour",
103
+ "scr.scrpousea as nombre_pour_seance",
104
+ votes(ref("scr.scrnum"), ref("scr.sesann"), ref("scr.scrdat")).as("votes"),
105
+ groupesVotants(ref("scr.scrnum"), ref("scr.sesann"), ref("scr.scrdat")).as("groupes_votants"),
106
+ misesAuPoint(ref("scr.scrnum")).as("mises_au_point"),
107
+ ])
108
+ .$narrowType();
109
+ export function findAllScrutins(fromSession) {
110
+ if (fromSession !== undefined) {
111
+ return findAllScrutinsQuery.where("scr.sesann", ">=", fromSession).stream();
112
+ }
113
+ return findAllScrutinsQuery.stream();
114
+ }
@@ -0,0 +1,3 @@
1
+ import { CompteRendu } from "../types/compte_rendu";
2
+ export declare function parseCompteRenduIntervalFromFile(xmlFilePath: string, startIndex: number, endIndex: number, agendaEventId: string): Promise<CompteRendu | null>;
3
+ export declare function sessionStartYearFromDate(d: Date): number;
@@ -0,0 +1,267 @@
1
+ import fs from "fs";
2
+ import * as cheerio from "cheerio";
3
+ import { toCRDate } from "./util";
4
+ import { makeReunionUid } from "../utils/reunion_parsing";
5
+ import { yyyymmddFromPath } from "../utils/date";
6
+ import { decodeHtmlEntities, dedupeSpeaker, fixApostrophes, norm } from "../utils/string_cleaning";
7
+ export async function parseCompteRenduIntervalFromFile(xmlFilePath, startIndex, endIndex, agendaEventId) {
8
+ try {
9
+ const raw = fs.readFileSync(xmlFilePath, "utf8");
10
+ const $ = cheerio.load(raw, { xml: false });
11
+ const metadonnees = extractMetadonnees($, xmlFilePath);
12
+ const order = $("body *").toArray();
13
+ const idx = new Map(order.map((el, i) => [el, i]));
14
+ const totalNodes = order.length;
15
+ const clampedStart = Math.max(0, Math.min(startIndex, totalNodes - 1));
16
+ const clampedEnd = Math.max(0, Math.min(endIndex, totalNodes - 1));
17
+ const intervals = [
18
+ {
19
+ start: clampedStart,
20
+ end: clampedEnd,
21
+ },
22
+ ];
23
+ metadonnees.sommaire = extractSommaireForIntervals($, idx, intervals);
24
+ const points = [];
25
+ let ordre = 0;
26
+ const addPoint = (p) => points.push({ ...p, ordre_absolu_seance: String(++ordre) });
27
+ // Interventions
28
+ $("div.intervenant").each((_, block) => {
29
+ if (!elementInAnyInterval(block, idx, intervals))
30
+ return;
31
+ const $block = $(block);
32
+ $block
33
+ .find([
34
+ "p[class^='titre_S']",
35
+ "p.mention_titre",
36
+ "p.intitule_titre",
37
+ "p.mention_chapitre",
38
+ "p.intitule_chapitre",
39
+ "p.mention_article",
40
+ "p.intitule_article",
41
+ "p.mention_section",
42
+ "p.intitule_section",
43
+ ].join(","))
44
+ .remove();
45
+ const firstP = $block.find("p").first();
46
+ if (!firstP || firstP.length === 0)
47
+ return;
48
+ const speakerLabelRaw = firstP.find(".orateur_nom").text() || firstP.find("a.lien_senfic").text() || "";
49
+ const speakerLabel = dedupeSpeaker(speakerLabelRaw);
50
+ const { mat, nom: nomCRI, qua: quaCRI } = readIntervenantMeta($block);
51
+ const qualFromSpans = extractAndRemoveLeadingQualite($, $block);
52
+ const qualite = norm(decodeHtmlEntities(quaCRI || "")) || qualFromSpans;
53
+ const canonicalName = dedupeSpeaker(nomCRI || speakerLabel);
54
+ const role = roleForSpeaker(speakerLabel) || roleForSpeaker(qualite) || roleForSpeaker(quaCRI || "");
55
+ const speechHtml = sanitizeInterventionHtml($, $block);
56
+ const speechText = norm(cheerio.load(speechHtml).text() || "");
57
+ if (!speechText)
58
+ return;
59
+ addPoint({
60
+ code_grammaire: "PAROLE_GENERIQUE",
61
+ roledebat: role,
62
+ orateurs: { orateur: { nom: canonicalName, id: mat || "", qualite } },
63
+ texte: { _: speechHtml },
64
+ });
65
+ });
66
+ const contenu = {
67
+ quantiemes: {
68
+ journee: metadonnees.dateSeance,
69
+ session: metadonnees.session,
70
+ },
71
+ point: points,
72
+ };
73
+ const yyyymmdd = yyyymmddFromPath(xmlFilePath);
74
+ const dateISO = `${yyyymmdd.slice(0, 4)}-${yyyymmdd.slice(4, 6)}-${yyyymmdd.slice(6, 8)}`;
75
+ const seanceRef = makeReunionUid(dateISO, "SP", agendaEventId, null);
76
+ return {
77
+ uid: `CRSSN${yyyymmdd}E${agendaEventId}`,
78
+ seanceRef,
79
+ sessionRef: metadonnees.session,
80
+ metadonnees,
81
+ contenu,
82
+ };
83
+ }
84
+ catch (e) {
85
+ console.error(`[CRI] parseInterval error file=${xmlFilePath} interval=[${startIndex}..${endIndex}] event=${agendaEventId}:`, e);
86
+ return null;
87
+ }
88
+ }
89
+ export function sessionStartYearFromDate(d) {
90
+ // Session (1th oct N → 30 sept N+1)
91
+ const m = d.getMonth();
92
+ const y = d.getFullYear();
93
+ return m >= 9 ? y : y - 1;
94
+ }
95
+ function roleForSpeaker(labelOrQualite) {
96
+ const s = (labelOrQualite || "").toLowerCase();
97
+ if (/^(m\.|mme)?\s*(le|la)\s+pr[ée]sident(e)?\b/.test(s) || /\bpr[ée]sident[e]?\s+de\s+séance\b/.test(s))
98
+ return "président";
99
+ return "";
100
+ }
101
+ function readIntervenantMeta($block) {
102
+ const int = $block.find("cri\\:intervenant").first();
103
+ if (int.length)
104
+ return { mat: int.attr("mat") || undefined, nom: int.attr("nom") || undefined, qua: int.attr("qua") || undefined };
105
+ const html = $block.html() || "";
106
+ const m = html.match(/<!--\s*cri:intervenant\b([^>]+)-->/i);
107
+ if (!m)
108
+ return {};
109
+ const out = {};
110
+ const re = /(\w+)="([^"]*)"/g;
111
+ let a;
112
+ while ((a = re.exec(m[1])))
113
+ out[a[1]] = decodeHtmlEntities(a[2]);
114
+ return { mat: out["mat"], nom: out["nom"], qua: out["qua"] };
115
+ }
116
+ function extractAndRemoveLeadingQualite($, $block) {
117
+ const firstP = $block.find("p").first();
118
+ if (firstP.length === 0)
119
+ return "";
120
+ const parts = [];
121
+ let stop = false;
122
+ firstP.contents().each((_, node) => {
123
+ if (stop)
124
+ return;
125
+ if (node.type === "tag") {
126
+ const $node = $(node);
127
+ if ($node.hasClass("orateur_nom")) {
128
+ $node.remove();
129
+ return;
130
+ }
131
+ if ($node.hasClass("orateur_qualite")) {
132
+ parts.push($node.text() || "");
133
+ $node.remove();
134
+ return;
135
+ }
136
+ const t = norm($node.text() || "");
137
+ if (t)
138
+ stop = true;
139
+ else
140
+ $node.remove();
141
+ }
142
+ else if (node.type === "text") {
143
+ const t = norm(node.data || "");
144
+ if (!t || /^[:.,;–—-]+$/.test(t)) {
145
+ ;
146
+ node.data = "";
147
+ return;
148
+ }
149
+ stop = true;
150
+ }
151
+ });
152
+ return fixApostrophes(norm(parts.join(" ")));
153
+ }
154
+ function sanitizeInterventionHtml($, $block) {
155
+ const ps = $block.find("p").toArray();
156
+ const cleaned = ps
157
+ .map((p) => {
158
+ const $p = $(p).clone();
159
+ $p.find(".orateur_nom, .orateur_qualite").remove();
160
+ $p.find("a").each((_, a) => {
161
+ const $a = $(a);
162
+ $a.replaceWith($a.text());
163
+ });
164
+ $p.find(".info_entre_parentheses").each((_, el) => {
165
+ const txt = $(el).text();
166
+ $(el).replaceWith($("<em/>").text(txt));
167
+ });
168
+ $p.find("span").each((_, span) => {
169
+ const $s = $(span);
170
+ if (!$s.text().trim())
171
+ $s.remove();
172
+ });
173
+ const inner = ($p.html() || "").trim();
174
+ if (!inner)
175
+ return null;
176
+ return `<p>${inner}</p>`;
177
+ })
178
+ .filter(Boolean);
179
+ return cleaned.join("<br/>");
180
+ }
181
+ function extractSommaireForIntervals($, idx, intervals) {
182
+ const inIv = (el) => elementInAnyInterval(el, idx, intervals);
183
+ const root = $("body");
184
+ const sommaire = { presidentSeance: { _: "" }, sommaire1: [] };
185
+ // (1) Présidence (tm2) — première ligne dans l’intervalle
186
+ const pres = root
187
+ .find("p.tm2")
188
+ .filter((_, el) => inIv(el))
189
+ .first();
190
+ if (pres.length)
191
+ sommaire.presidentSeance = { _: norm(pres.text()) };
192
+ // (2) Paras tm5 présents dans l’intervalle
193
+ const paras = [];
194
+ root.find("p.tm5").each((_, el) => {
195
+ if (!inIv(el))
196
+ return;
197
+ const t = norm($(el).text());
198
+ if (t)
199
+ paras.push({ _: t });
200
+ });
201
+ if (paras.length)
202
+ sommaire.para = paras.length === 1 ? paras[0] : paras;
203
+ // (3) Items de 1er niveau (tm3) présents dans l’intervalle
204
+ const items = [];
205
+ root.find("p.tm3").each((_, el) => {
206
+ if (!inIv(el))
207
+ return;
208
+ const $p = $(el);
209
+ const full = norm($p.text() || "");
210
+ if (!full)
211
+ return;
212
+ const numMatch = full.match(/^(\d+)\s*[.\-–—]\s*/);
213
+ const valeur = numMatch ? numMatch[1] : undefined;
214
+ // prefere intitule in ancre <a> if present
215
+ const a = $p.find("a").first();
216
+ const intituleRaw = a.length ? a.text() : full.replace(/^(\d+)\s*[.\-–—]\s*/, "");
217
+ const intitule = norm(intituleRaw);
218
+ // id_syceron from href="#Niv1_SOMx"
219
+ const href = (a.attr("href") || "").trim();
220
+ const idSyceron = href.startsWith("#") ? href.slice(1) : href;
221
+ const titreStruct = { id_syceron: idSyceron || "", intitule };
222
+ items.push({ valeur_pts_odj: valeur, titreStruct });
223
+ });
224
+ if (items.length)
225
+ sommaire.sommaire1 = items;
226
+ return sommaire;
227
+ }
228
+ function extractMetadonnees($, filePath) {
229
+ let dateText = norm($("h1, h2, .page-title").first().text() || "");
230
+ if (!dateText)
231
+ dateText = norm($("p").first().text() || "");
232
+ const dateMatch = dateText.match(/\b(\d{1,2}\s+\w+\s+\d{4})\b/i);
233
+ const allText = norm($("body").text() || "");
234
+ const sessionMatch = allText.match(/\bsession\s+(\d{4}-\d{4})\b/i);
235
+ let dateSeance = dateMatch?.[1] || "";
236
+ if (!dateSeance) {
237
+ const m = filePath.match(/d(\d{4})(\d{2})(\d{2})\.xml$/i);
238
+ if (m)
239
+ dateSeance = `${m[1]}-${m[2]}-${m[3]}`;
240
+ }
241
+ dateSeance = toCRDate(dateSeance, null);
242
+ return {
243
+ dateSeance,
244
+ dateSeanceJour: dateSeance,
245
+ numSeanceJour: "",
246
+ numSeance: "",
247
+ typeAssemblee: "SN",
248
+ legislature: "",
249
+ session: sessionMatch?.[1] || "",
250
+ nomFichierJo: "",
251
+ validite: "",
252
+ etat: "",
253
+ diffusion: "",
254
+ version: "1.0",
255
+ environnement: "",
256
+ heureGeneration: new Date(),
257
+ };
258
+ }
259
+ function elementInAnyInterval(el, idx, intervals) {
260
+ const p = idx.get(el);
261
+ if (p == null)
262
+ return false;
263
+ for (const iv of intervals)
264
+ if (p >= iv.start && p < iv.end)
265
+ return true;
266
+ return false;
267
+ }