Repository navigation
Expand file tree
/
Copy pathconvertJsonToCsv.html
More file actions
68 lines (58 loc) · 2.29 KB
/
Copy pathconvertJsonToCsv.html
File metadata and controls
68 lines (58 loc) · 2.29 KB
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
<!-- Run a simple python server with root set to ~/Desktop:
$ cd Desktop
$ python -m SimpleHTTPServer 8083
-->
<html>
<head>
<script src="https://cdn.jsdelivr.net/npm/json2csv"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
</head>
<body>
<script>
$.getJSON("http://localhost:8083/production-223120-DriverLogs-export.json", (data) => {
console.log(data);
let entries = [];
for (let [jankDate, entry] of Object.entries(data)) {
let [month, day, year] = jankDate.split(' ');
let date = `${year}-${month}-${day}`;
let parseForPhone = (phoneType, userObj) => {
for (let [userId, requestObj] of Object.entries(userObj)) {
for (let [requestType, requestItem] of Object.entries(requestObj)) {
for (let [requestId, requestContents] of Object.entries(requestItem)) {
let action = '';
let body = requestContents.body;
if (body) {
// For android the body is just the route, e.g. "https://rynlyproduction.azurewebsites.net/api/job/route"
// For iOS it's a multi-line string with the request body, too.
let pathFragments = body.split('\n')[0].split('/');
action = pathFragments[pathFragments.length - 1];
if (phoneType === 'iOS' && requestType === 'Request') {
action = action.substring(0, action.length - 2);
}
}
delete requestContents.TimeStamp;
delete requestContents.body;
requestContents.action = action;
requestContents.requestType = requestType;
requestContents.date = date;
requestContents.phoneType = phoneType;
entries.push(requestContents);
}
}
}
};
parseForPhone('android', entry.Android ?? {});
parseForPhone('iOS', entry.iOS ?? {});
}
console.log('Number of rows: ' + entries.length);
let parser = new json2csv.Parser({});
let csv = parser.parse(entries);
let blob = new Blob([csv], { type: 'text/csv' });
let a = document.createElement('a');
a.href = window.URL.createObjectURL(blob);
a.download = 'test.csv';
a.click();
});
</script>
</body>
</html>