Skip to content

Commit e35405f

Browse files
authored
Merge pull request #16 from daniel-fernandez-edosoft/master
Convert all date fields to year/month/day and add granularity column
2 parents e858f99 + 9fef98d commit e35405f

File tree

5 files changed

+132
-132
lines changed

5 files changed

+132
-132
lines changed

src/CacheHelper.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const cacheVersion = "20200413_1137";
1+
const cacheVersion = "20220510_1058";
22

33
/**
44
* Builds the Cache Helper object.

src/Connector.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,26 +26,26 @@ function Connector(services) {
2626
string: types.TEXT,
2727
float: types.NUMBER,
2828
date: types.YEAR_MONTH_DAY,
29-
date_YEARLY: types.YEAR,
30-
date_BIYEARLY: types.YEAR_MONTH,
31-
date_FOUR_MONTHLY: types.YEAR_MONTH,
32-
date_MONTHLY: types.YEAR_MONTH,
33-
date_QUARTERLY: types.YEAR_QUARTER,
34-
date_DAILY: types.YEAR_MONTH_DAY,
35-
date_WEEKLY: types.YEAR_WEEK
29+
// date_YEARLY: types.YEAR,
30+
// date_BIYEARLY: types.YEAR_MONTH,
31+
// date_FOUR_MONTHLY: types.YEAR_MONTH,
32+
// date_MONTHLY: types.YEAR_MONTH,
33+
// date_QUARTERLY: types.YEAR_QUARTER,
34+
// date_DAILY: types.YEAR_MONTH_DAY,
35+
// date_WEEKLY: types.YEAR_WEEK
3636
};
3737

3838
// sufijo añadido al id de columna para que al actualizar una URL
3939
// editando la conexion se actualice el tipo de fecha (si no, no se actualiza)
4040
const idsTranslator = {
4141
date: "_date_YEAR_MONTH_DAY",
42-
date_YEARLY: "_date_YEAR",
43-
date_BIYEARLY: "_date_YEAR_MONTH",
44-
date_FOUR_MONTHLY: "_date_YEAR_MONTH",
45-
date_MONTHLY: "_date_YEAR_MONTH",
46-
date_QUARTERLY: "_date_YEAR_QUARTER",
47-
date_DAILY: "_date_YEAR_MONTH_DAY",
48-
date_WEEKLY: "_date_YEAR_WEEK"
42+
// date_YEARLY: "_date_YEAR",
43+
// date_BIYEARLY: "_date_YEAR_MONTH",
44+
// date_FOUR_MONTHLY: "_date_YEAR_MONTH",
45+
// date_MONTHLY: "_date_YEAR_MONTH",
46+
// date_QUARTERLY: "_date_YEAR_QUARTER",
47+
// date_DAILY: "_date_YEAR_MONTH_DAY",
48+
// date_WEEKLY: "_date_YEAR_WEEK"
4949
};
5050

5151
for(let column of columns) {

src/DataHelper.js

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -183,38 +183,38 @@ function DataHelper(services) {
183183

184184
const col = utils.getColNameAndId(indicatorsResponse, configParams);
185185

186-
const granularityOrder = {
187-
'YEARLY': 1,
188-
'BIYEARLY': 2,
189-
'QUARTERLY': 3,
190-
'MONTHLY': 4,
191-
'WEEKLY': 5,
192-
'DAILY': 6
193-
};
186+
// const granularityOrder = {
187+
// 'YEARLY': 1,
188+
// 'BIYEARLY': 2,
189+
// 'QUARTERLY': 3,
190+
// 'MONTHLY': 4,
191+
// 'WEEKLY': 5,
192+
// 'DAILY': 6
193+
// };
194194

195-
let desiredGranularity = null;
195+
// let desiredGranularity = null;
196196

197-
if(configParams.recodeDates) {
198-
const granularitySet = new Set();
197+
// if(configParams.recodeDates) {
198+
// const granularitySet = new Set();
199199

200-
if(indicatorsResponse.dimension.TIME && indicatorsResponse.dimension.TIME.representation) {
201-
for(let timeRepresentation of indicatorsResponse.dimension.TIME.representation) {
202-
if(timeRepresentation.granularityCode) {
203-
granularitySet.add(timeRepresentation.granularityCode);
204-
}
205-
}
206-
}
200+
// if(indicatorsResponse.dimension.TIME && indicatorsResponse.dimension.TIME.representation) {
201+
// for(let timeRepresentation of indicatorsResponse.dimension.TIME.representation) {
202+
// if(timeRepresentation.granularityCode) {
203+
// granularitySet.add(timeRepresentation.granularityCode);
204+
// }
205+
// }
206+
// }
207207

208-
let minimumGranularityIndex = 0;
208+
// let minimumGranularityIndex = 0;
209209

210-
// TODO: comprobar valores posibles
211-
for(let temporalGranularity of granularitySet) {
212-
if(granularityOrder[temporalGranularity] && granularityOrder[temporalGranularity] > minimumGranularityIndex) {
213-
minimumGranularityIndex = granularityOrder[temporalGranularity];
214-
desiredGranularity = temporalGranularity;
215-
}
216-
}
217-
}
210+
// // TODO: comprobar valores posibles
211+
// for(let temporalGranularity of granularitySet) {
212+
// if(granularityOrder[temporalGranularity] && granularityOrder[temporalGranularity] > minimumGranularityIndex) {
213+
// minimumGranularityIndex = granularityOrder[temporalGranularity];
214+
// desiredGranularity = temporalGranularity;
215+
// }
216+
// }
217+
// }
218218

219219
const lengthGeographical = indicatorsDataResponse.dimension.GEOGRAPHICAL.representation.size;
220220
for (var i = 0; i < lengthGeographical; i++) {
@@ -231,9 +231,9 @@ function DataHelper(services) {
231231

232232
if(configParams.recodeDates) {
233233
const granularity = indexedTimeRepresentations[codigoTemporal].granularityCode;
234-
if(desiredGranularity && granularity != desiredGranularity) {
235-
continue;
236-
}
234+
// if(desiredGranularity && granularity != desiredGranularity) {
235+
// continue;
236+
// }
237237
const date = codigoTemporal;
238238
row.Fecha = recodeDatesHelper.converDate(date, granularity);
239239
}
@@ -281,9 +281,9 @@ function DataHelper(services) {
281281

282282
if(configParams.recodeDates) {
283283
const granularity = indexedTimeRepresentations[codigoTemporal].granularityCode;
284-
if(desiredGranularity && granularity != desiredGranularity) {
285-
continue;
286-
}
284+
// if(desiredGranularity && granularity != desiredGranularity) {
285+
// continue;
286+
// }
287287
const date = codigoTemporal;
288288
row.Fecha = recodeDatesHelper.converDate(date, granularity);
289289
}

src/RecodeDatesHelper.js

Lines changed: 58 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ function RecodeDatesHelper() {
125125
date = date.split("T")[0];
126126
}
127127
date = date.split("-");
128-
return date[0] + "-" + date[1] + "-" + date[2];
128+
return strPad(date[0], 4, "0") + strPad(date[1], 2, "0") + strPad(date[2], 2, "0");
129129
}
130130

131131
// REPORTING TIME PERIOD
@@ -138,39 +138,39 @@ function RecodeDatesHelper() {
138138
// 2000-D353
139139
const _calculateReportingPeriod = function (time) {
140140
if (time.match(new RegExp(PATTERN_REPORTING_YEAR_TYPE))) {
141-
//return time.match(new RegExp(PATTERN_REPORTING_YEAR_TYPE))[1] + "0101";
142-
return time.match(new RegExp(PATTERN_REPORTING_YEAR_TYPE))[1];
141+
return time.match(new RegExp(PATTERN_REPORTING_YEAR_TYPE))[1] + "0101";
142+
//return time.match(new RegExp(PATTERN_REPORTING_YEAR_TYPE))[1];
143143
}
144144
if (time.match(new RegExp(PATTERN_REPORTING_SEMESTER_TYPE))) {
145145
const year = time.match(new RegExp(PATTERN_REPORTING_SEMESTER_TYPE))[1];
146146
const month = (time.match(new RegExp(PATTERN_REPORTING_SEMESTER_TYPE))[3] - 1) * 6;
147-
return year + (month + 1);
147+
return year + strPad("" + (month + 1), 2, "0") + "01";
148148
}
149149
if (time.match(new RegExp(PATTERN_REPORTING_TRIMESTER_TYPE))) {
150150
const year = time.match(new RegExp(PATTERN_REPORTING_TRIMESTER_TYPE))[1];
151151
const month = (time.match(new RegExp(PATTERN_REPORTING_TRIMESTER_TYPE))[3] - 1) * 4;
152-
return year + (month + 1);
152+
return year + strPad("" + (month + 1), 2, "0") + "01";
153153
}
154154
if (time.match(new RegExp(PATTERN_REPORTING_QUARTER_TYPE))) {
155155
const year = time.match(new RegExp(PATTERN_REPORTING_QUARTER_TYPE))[1];
156-
//const month = (time.match(new RegExp(PATTERN_REPORTING_QUARTER_TYPE))[3] - 1) * 3;
157-
//return year + (month + 1) + "01";
158-
const quarter = time.match(new RegExp(PATTERN_REPORTING_QUARTER_TYPE))[3];
159-
return year + quarter;
156+
const month = (time.match(new RegExp(PATTERN_REPORTING_QUARTER_TYPE))[3] - 1) * 3;
157+
return year + strPad("" + (month + 1), 2, "0") + "01";
158+
// const quarter = time.match(new RegExp(PATTERN_REPORTING_QUARTER_TYPE))[3];
159+
// return year + quarter;
160160
}
161161
if (time.match(new RegExp(PATTERN_REPORTING_MONTH_TYPE))) {
162162
const year = time.match(new RegExp(PATTERN_REPORTING_MONTH_TYPE))[1];
163163
const month = parseInt(time.match(new RegExp(PATTERN_REPORTING_MONTH_TYPE))[3]);
164-
return year + strPad("" + month, 2, "0");
164+
return year + strPad("" + month, 2, "0") + "01";
165165
//return year + month + "01";
166166
}
167167
if (time.match(new RegExp(PATTERN_REPORTING_WEEK_TYPE))) {
168168
const year = time.match(new RegExp(PATTERN_REPORTING_WEEK_TYPE))[1];
169-
//const day = (time.match(new RegExp(PATTERN_REPORTING_WEEK_TYPE))[3] - 1) * 7;
170-
//const date = new Date(year, "", day + 1);
171-
//return year + (date.getMonth() + 1) + date.getDate();
172-
const week = parseInt(time.match(new RegExp(PATTERN_REPORTING_WEEK_TYPE))[3]);
173-
return year + strPad("" + week, 2, "0");
169+
const day = (time.match(new RegExp(PATTERN_REPORTING_WEEK_TYPE))[3] - 1) * 7;
170+
const date = new Date(year, "", day + 1);
171+
return year + strPad("" + (date.getMonth() + 1), 2, "0") + strPad("" + date.getDate(), 2, "0");
172+
// const week = parseInt(time.match(new RegExp(PATTERN_REPORTING_WEEK_TYPE))[3]);
173+
// return year + strPad("" + week, 2, "0");
174174
}
175175
if (time.match(new RegExp(PATTERN_REPORTING_DAY_TYPE))) {
176176
const year = time.match(new RegExp(PATTERN_REPORTING_DAY_TYPE))[1];
@@ -209,42 +209,42 @@ function RecodeDatesHelper() {
209209
const _calculateGpeReportingPeriod = function (time) {
210210
if (time.match(new RegExp(START + GPE_YEARLY_PATTERN + END))) {
211211
//return date + "0101";
212-
return time;
212+
return time + "0101";
213213
}
214214
if (time.match(new RegExp(START + GPE_BIYEARLY_PATTERN + END))) {
215215
const year = time.match(new RegExp(START + GPE_BIYEARLY_PATTERN + END))[1];
216216
const month = (time.match(new RegExp(START + GPE_BIYEARLY_PATTERN + END))[2] - 1) * 6;
217217
//return year + strPad("" + (month + 1), 2, "0") + "01";
218-
return year + strPad("" + (month + 1), 2, "0");
218+
return year + strPad("" + (month + 1), 2, "0") + "01";
219219
}
220220
if (time.match(new RegExp(START + GPE_QUARTERLY_PATTERN + END))) {
221221
const year = time.match(new RegExp(START + GPE_QUARTERLY_PATTERN + END))[1];
222-
// const month = (date.match(new RegExp(START + GPE_QUARTERLY_PATTERN + END))[2] - 1) * 3;
223-
// return year + strPad("" + (month + 1), 2, "0") + "01";
224-
const quarter = time.match(new RegExp(START + GPE_QUARTERLY_PATTERN + END))[2];
225-
return year + quarter;
222+
const month = (time.match(new RegExp(START + GPE_QUARTERLY_PATTERN + END))[2] - 1) * 3;
223+
return year + strPad("" + (month + 1), 2, "0") + "01";
224+
// const quarter = time.match(new RegExp(START + GPE_QUARTERLY_PATTERN + END))[2];
225+
// return year + quarter;
226226
}
227227
if (time.match(new RegExp(START + GPE_MONTHLY_PATTERN + END))) {
228228
const year = time.match(new RegExp(START + GPE_MONTHLY_PATTERN + END))[1];
229229
const month = parseInt(time.match(new RegExp(START + GPE_MONTHLY_PATTERN + END))[2]);
230-
//return year + strPad("" + (month), 2, "0") + "01";
231-
return year + strPad("" + month, 2, "0");
230+
return year + strPad("" + (month), 2, "0") + "01";
231+
//return year + strPad("" + month, 2, "0");
232232
}
233233
if (time.match(new RegExp(START + GPE_MONTHLY_PATTERN_WITHOUT_CHARACTER + END))) {
234234
const year = time.match(new RegExp(START + GPE_MONTHLY_PATTERN_WITHOUT_CHARACTER + END))[1];
235235
const month = parseInt(time.match(new RegExp(START + GPE_MONTHLY_PATTERN_WITHOUT_CHARACTER + END))[2]);
236-
//return year + strPad("" + (month), 2, "0") + "01";
237-
return year + strPad("" + month, 2, "0");
236+
return year + strPad("" + (month), 2, "0") + "01";
237+
//return year + strPad("" + month, 2, "0");
238238
}
239239
if (time.match(new RegExp(START + GPE_WEEKLY_PATTERN + END))) {
240-
// const year = date.match(new RegExp(START + GPE_WEEKLY_PATTERN + END))[1];
241-
// const day =
242-
// (date.match(new RegExp(START + GPE_WEEKLY_PATTERN + END))[2] - 1) * 7;
243-
// date = new Date(year, "", day + 1);
244-
// return year + strPad("" + (date.getMonth()), 2, "0") + date.getDate();
245240
const year = time.match(new RegExp(START + GPE_WEEKLY_PATTERN + END))[1];
246-
const week = parseInt(time.match(new RegExp(START + GPE_WEEKLY_PATTERN + END))[2]);
247-
return year + strPad("" + week, 2, "0");
241+
const day =
242+
(time.match(new RegExp(START + GPE_WEEKLY_PATTERN + END))[2] - 1) * 7;
243+
const date = new Date(year, "", day + 1);
244+
return year + strPad("" + (date.getMonth()), 2, "0") + strPad("" + date.getDate(), 2, "0");
245+
// const year = time.match(new RegExp(START + GPE_WEEKLY_PATTERN + END))[1];
246+
// const week = parseInt(time.match(new RegExp(START + GPE_WEEKLY_PATTERN + END))[2]);
247+
// return year + strPad("" + week, 2, "0");
248248
}
249249
if (time.match(new RegExp(START + GPE_DAILY_PATTERN + END))) {
250250
const year = time.match(new RegExp(START + GPE_DAILY_PATTERN + END))[1];
@@ -288,22 +288,22 @@ function RecodeDatesHelper() {
288288
time = time.split("T")[0];
289289
}
290290
const date = time.split("-");
291-
return date[0] + date[1] + date[2];
291+
return strPad(date[0], 4, "0") + strPad(date[1], 2, "0") + strPad(date[2], 2, "0");
292292
}
293293

294294
// GREGORIAN TIME
295295
// 2000
296-
// 2000-01
297-
// 2000-01-31
296+
// 200001
297+
// 200001-31
298298
const _calculateGregorianTimePeriod = function (time) {
299299
time = time.split("-");
300300
switch (time.length) {
301301
case 1:
302-
return time[0] + "0101";
302+
return strPad(time[0], 4, "0") + "0101";
303303
case 2:
304-
return time[0] + time[1] + "01";
304+
return strPad(time[0], 4, "0") + strPad(time[1], 2, "0") + "01";
305305
case 3:
306-
return time[0] + time[1] + time[2];
306+
return strPad(time[0], 4, "0") + strPad(time[1], 2, "0") + strPad(time[2], 2, "0");
307307
}
308308
}
309309

@@ -345,7 +345,7 @@ function RecodeDatesHelper() {
345345
case "YEARLY": {
346346
if (date.match(new RegExp(START + GPE_YEARLY_PATTERN + END))) {
347347
//return date + "0101";
348-
return date;
348+
return date + "0101";
349349
}
350350
break;
351351
}
@@ -355,19 +355,19 @@ function RecodeDatesHelper() {
355355
if (date.match(new RegExp(START + GPE_BIYEARLY_PATTERN + END))) {
356356
const year = date.match(new RegExp(START + GPE_BIYEARLY_PATTERN + END))[1];
357357
const month = (date.match(new RegExp(START + GPE_BIYEARLY_PATTERN + END))[2] - 1) * 6;
358-
//return year + strPad("" + (month + 1), 2, "0") + "01";
359-
return year + strPad("" + (month + 1), 2, "0");
358+
return year + strPad("" + (month + 1), 2, "0") + "01";
359+
//return year + strPad("" + (month + 1), 2, "0");
360360
}
361361
break;
362362
}
363363
// trimestral
364364
case "QUARTERLY": {
365365
if (date.match(new RegExp(START + GPE_QUARTERLY_PATTERN + END))) {
366366
const year = date.match(new RegExp(START + GPE_QUARTERLY_PATTERN + END))[1];
367-
// const month = (date.match(new RegExp(START + GPE_QUARTERLY_PATTERN + END))[2] - 1) * 3;
368-
// return year + strPad("" + (month + 1), 2, "0") + "01";
369-
const quarter = date.match(new RegExp(START + GPE_QUARTERLY_PATTERN + END))[2];
370-
return year + quarter;
367+
const month = (date.match(new RegExp(START + GPE_QUARTERLY_PATTERN + END))[2] - 1) * 3;
368+
return year + strPad("" + (month + 1), 2, "0") + "01";
369+
// const quarter = date.match(new RegExp(START + GPE_QUARTERLY_PATTERN + END))[2];
370+
// return year + quarter;
371371
}
372372
break;
373373
}
@@ -377,8 +377,8 @@ function RecodeDatesHelper() {
377377
if (date.match(new RegExp(START + GPE_BIYEARLY_PATTERN + END))) {
378378
const year = date.match(new RegExp(START + GPE_BIYEARLY_PATTERN + END))[1];
379379
const month = (date.match(new RegExp(START + GPE_BIYEARLY_PATTERN + END))[2] - 1) * 3;
380-
//return year + strPad("" + (month + 1), 2, "0") + "01";
381-
return year + strPad("" + (month + 1), 2, "0");
380+
return year + strPad("" + (month + 1), 2, "0") + "01";
381+
//return year + strPad("" + (month + 1), 2, "0");
382382
}
383383
break;
384384
}
@@ -387,28 +387,28 @@ function RecodeDatesHelper() {
387387
if (date.match(new RegExp(START + GPE_MONTHLY_PATTERN + END))) {
388388
const year = date.match(new RegExp(START + GPE_MONTHLY_PATTERN + END))[1];
389389
const month = parseInt(date.match(new RegExp(START + GPE_MONTHLY_PATTERN + END))[2]);
390-
//return year + strPad("" + (month), 2, "0") + "01";
391-
return year + strPad("" + month, 2, "0");
390+
return year + strPad("" + (month), 2, "0") + "01";
391+
//return year + strPad("" + month, 2, "0");
392392
} else if(date.match(new RegExp(START + GPE_MONTHLY_PATTERN_WITHOUT_CHARACTER + END))) {
393393
const year = date.match(new RegExp(START + GPE_MONTHLY_PATTERN_WITHOUT_CHARACTER + END))[1];
394394
const month = parseInt(date.match(new RegExp(START + GPE_MONTHLY_PATTERN_WITHOUT_CHARACTER + END))[2]);
395-
//return year + strPad("" + (month), 2, "0") + "01";
396-
return year + strPad("" + month, 2, "0");
395+
return year + strPad("" + (month), 2, "0") + "01";
396+
//return year + strPad("" + month, 2, "0");
397397
}
398398

399399
break;
400400
}
401401
// semanal
402402
case "WEEKLY": {
403403
if (date.match(new RegExp(START + GPE_WEEKLY_PATTERN + END))) {
404-
// const year = date.match(new RegExp(START + GPE_WEEKLY_PATTERN + END))[1];
405-
// const day =
406-
// (date.match(new RegExp(START + GPE_WEEKLY_PATTERN + END))[2] - 1) * 7;
407-
// date = new Date(year, "", day + 1);
408-
// return year + strPad("" + (date.getMonth()), 2, "0") + date.getDate();
409404
const year = date.match(new RegExp(START + GPE_WEEKLY_PATTERN + END))[1];
410-
const week = parseInt(date.match(new RegExp(START + GPE_WEEKLY_PATTERN + END))[2]);
411-
return year + strPad("" + week, 2, "0");
405+
const day =
406+
(date.match(new RegExp(START + GPE_WEEKLY_PATTERN + END))[2] - 1) * 7;
407+
date = new Date(year, "", day + 1);
408+
return year + strPad("" + (date.getMonth()), 2, "0") + strPad(""+date.getDate(), 2, "0");
409+
// const year = date.match(new RegExp(START + GPE_WEEKLY_PATTERN + END))[1];
410+
// const week = parseInt(date.match(new RegExp(START + GPE_WEEKLY_PATTERN + END))[2]);
411+
// return year + strPad("" + week, 2, "0");
412412
}
413413
break;
414414
}

0 commit comments

Comments
 (0)