-
Notifications
You must be signed in to change notification settings - Fork 0
/
findStations.js
70 lines (52 loc) · 1.19 KB
/
findStations.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
"use strict";
export class Stations {
constructor(raw_data) {
this.stations_obj = {
'data': raw_data,
'stations': undefined,
'min_date': undefined,
'station_ids': undefined,
};
this.findCurrentStations();
this.findStationIds();
this.findMinDate();
}
findCurrentStations(){
let arr = [];
let date = new Date();
let year = date.getUTCFullYear();
let rep = year.toString()+'-\\d{2}-\\d{2}';
let re = new RegExp(rep);
this.stations_obj.data.results.forEach(function(o, i){
if (re.test(o.maxdate)===true){
arr.push(o);
}
});
this.stations_obj.stations = arr;
}
findMinDate(){
let arr = this.stations_obj.stations;
arr.sort(function (a, b) {
let x = a.maxdate;
let y = b.maxdate;
if (x < y ) {
return -1;
}
if (x > y ) {
return 1;
}
return 0;
});
this.stations_obj.min_date = arr[0].maxdate;
}
findStationIds(){
let arr = [];
this.stations_obj.stations.forEach(function (o) {
arr.push(o.id);
});
this.stations_obj.station_ids = arr;
}
print() {
console.log(this.stations_obj);
}
};