This repository has been archived by the owner on Feb 26, 2020. It is now read-only.
forked from seykron/ogov-data
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathto-popolo.js
150 lines (117 loc) · 4.42 KB
/
to-popolo.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
var file =require("file");
var fs = require('fs');
var walki=0;
var folderBills = [];
file.walk("bills", billsindir);
var fileName = "pbills/mongo"+walki+".json";
console.log(fileName);
fs.writeFileSync(fileName, JSON.stringify(folderBills).replace("}","}\n"));
function billsindir(nothing,dirPath,dirs,files) {
for (f in files) {
json = JSON.parse(fs.readFileSync(files[f],"utf8"));
folderBills.push(toPopolo(json));
}
//console.log(dirPath,fileName);
if (folderBills.length > 1000) {
var fileName = "pbills/mongo"+walki+".json";
fs.writeFileSync(fileName, JSON.stringify(folderBills).replace("}","}\n"));
walki++;
folderBills = []
}
}
var toPopolo = function(ogovBill) {
var billitAuthors = [];
for (s in ogovBill.subscribers) {
billitAuthors.push(ogovBill.subscribers[s].name);
}
var billitPaperworks = [];
for (d in ogovBill.dictums) {
var dictum = ogovBill.dictums[d];
var billitPaperwork = {}
billitPaperwork.session = dictum["orderPaper"]
billitPaperwork.date = { "$date": new Date(dictum["date"]).getTime() }
billitPaperwork.description = dictum["result"]
billitPaperwork.stage = "Con dictámen"
billitPaperwork.chamber = dictum["source"]
billitPaperwork.bill_uid = ogovBill.file
billitPaperwork.timeline_status = "Indicaciones"
billitPaperworks.push(billitPaperwork);
}
var billitDirectives = [];
for (p in ogovBill.procedures) {
var procedure = [p];
var billitDirective = {};
billitDirective.date = { "$date": new Date(procedure["date"]).getTime() };
billitDirective.step = procedure["topic"];
billitDirective.stage = procedure["result"];
billitDirective.link = "";
billitDirective.bill_uid = procedure["file"]
billitDirective.source = procedure["source"]
billitDirectives.push(billitDirective);
}
var billitBill = {
"uid": ogovBill.file,
"short_uid": ogovBill.file.split("-")[0],
"title": ogovBill.summary,
"creation_date": { "$date": new Date(ogovBill.creationTime).getTime() },
"source": ogovBill.source,
"initial_chamber": ogovBill.source, //This we have to find out more, becase it cannot be "PE"
"bill_draft_link": ogovBill.textUrl,
"subject_areas": ogovBill.committees,
"authors": billitAuthors,
"paperworks": billitPaperworks,
"directives": billitDirectives,
"lawNumber": ogovBill.lawNumber,
"stage": "Ingresado",
"project_type": ogovBill.type.replace("PROYECTO DE ",""),
"current_priority": "Normal",
//We don't have any of these
"priorities":[],
"reports":[],
"documents":[],
"remarks":[],
"revisions":[],
}
// Si existe, se considera "Ingresado"
//Si tiene un dictámen, considero que el estado es "Con dictámen en Cámara de Orígen"
if (billitBill.paperworks.length > 0) {
billitBill.stage = "Con dictámen en Cámara de Orígen";
//Si tiene dos dictámenes, considero que el estado es "Con dictámen en Cámara Revisora"
//Todavía no encontré un ejemplo en el que esto no sea cierto, pero creo que debe haber y que esto está mal.
if (billitBill.paperworks.length > 1) {
billitBill.stage = "Con dictámen en Cámara Revisora";
}
}
//Si tiene un trámite cuyo estado es APROBADO, entonces lo considero "Con media sanción"
//si es una ley, o Aprobado si es un proyecto de declaración, resolución o mensaje.
if (billitBill.directives.length > 0) {
if (billitBill.directives[0].stage == "APROBADO") {
if (billitBill.project_type == "LEY") {
billitBill.stage = "Con media sanción";
}
else {
billitBill.stage = "Aprobado o sancionado";
}
}
// Si en el primer trámite, el estado NO ES APROBADO, entonces lo considero "Rechazado"
else {
console.log(billitBill.project_type,ogovBill.procedures);
billitBill.stage = "Rechazado";
}
//Si tiene más de un trámite y el resultado del segundo trámite es SANCIONADO, lo considero Sancionado.
if (billitBill.directives.length > 1) {
if (billitBill.directives[1].result == "SANCIONADO") {
billitBill.stage = "Aprobado o sancionado";
}
//Si el resultado del segundo trámite NO ES SANCIONADO lo considero "Rechazado".
else {
billitBill.stage = "Rechazado";
}
}
}
// Si tiene número de ley es porque está aprobada
if (billitBill.lawNumber) {
billitBill.stage = "Aprobado o sancionado";
}
return billitBill;
}