-
Notifications
You must be signed in to change notification settings - Fork 61
/
Copy pathtransform-csv-rides.ts
68 lines (66 loc) · 2.41 KB
/
transform-csv-rides.ts
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
import { IDerivation, Document, SourceFromCsvRides } from 'flow/examples/citi-bike/rides.ts';
// Implementation for derivation examples/citi-bike/rides.
export class Derivation extends IDerivation {
fromCsvRides(read: { doc: SourceFromCsvRides }): Document[] {
const source = read.doc;
let birth_year: number | null = null;
if (source['Birth Year']) {
birth_year = parseInt(source['Birth Year']);
}
let gender: 0 | 1 | 2 = 0;
if (source['Gender']) {
switch (parseInt(source['Gender'])) {
case 1:
gender = 1;
break;
case 2:
gender = 2;
break;
default:
gender = 0;
}
}
let user_type: null | 'Customer' | 'Subscriber' = null;
switch (source['User Type']) {
case 'Customer':
user_type = 'Customer';
break;
case 'Subscriber':
user_type = 'Subscriber';
break;
default:
user_type = null;
}
return [
{
bike_id: parseInt(source['Bike ID']),
birth_year: birth_year,
duration_seconds: parseFloat(source['Trip Duration']),
gender: gender,
user_type: user_type,
begin: {
station: {
geo: {
latitude: parseFloat(source['Start Station Latitude']),
longitude: parseFloat(source['Start Station Longitude']),
},
id: parseInt(source['Start Station ID']),
name: source['Start Station Name'],
},
timestamp: source['Start Time'],
},
end: {
station: {
geo: {
latitude: parseFloat(source['End Station Latitude']),
longitude: parseFloat(source['End Station Longitude']),
},
id: parseInt(source['End Station ID']),
name: source['End Station Name'],
},
timestamp: source['Stop Time'],
},
},
];
}
}