-
Notifications
You must be signed in to change notification settings - Fork 0
/
render_stats.js
116 lines (93 loc) · 2.93 KB
/
render_stats.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
var graph = d3.select("#graph");
var data;
var width = 800;
var height = 600;
var date_parser = d3.timeParse("%Y-%m-%d");
function renderGraph(datapoints, study) {
let x = d3.scaleTime()
.range([0, width-100]);
let y = d3.scaleLinear()
.range([height-100, 0]);
//parse the date of each entry
datapoints[study].forEach(function(d) {
d.date = date_parser(d.date);
});
//sort by date
datapoints[study].sort(function(a, b) {
if (a.date < b.date) {
return -1;
}
if (a.date > b.date) {
return 1;
}
return 0;
});
let val_line = d3.line()
.x(function(d) { console.log(d.date); return x(d.date); })
.y(function(d) { console.log(d.mean); return y(d.mean); });
x.domain(d3.extent(datapoints[study], function(d) { return d.date; }));
//y.domain([3000, d3.max(datapoints[study], function(d) { return d.mean; })]);
//set a max y val of the max value of the means or 5000 (whichever is
//larger)
//avoids issues with very small changes looking significant on the graph
y.domain([3000, Math.max(5000, d3.max(datapoints[study], function(d) { return d.mean; }))]);
//console.log(x.domain());
//console.log(y.domain());
let svg = graph.append("svg")
.attr("width", width)
.attr("height", height)
.append("g")
.attr("transform", "translate(50, 50)");
//add the path for the values
let line_string = val_line(datapoints[study]);
//console.log(line_string);
svg.append("path")
.data([datapoints[study]])
.attr("d", val_line)
.attr("class", "line");
//console.log(svg);
//console.log(graph);
//add the axes
svg.append("g")
.attr("transform", "translate(0, "+(height-100)+")")
.call(d3.axisBottom(x));
svg.append("g")
.call(d3.axisLeft(y));
//add title
svg.append("g")
.attr("transform", "translate(0, -10)")
.append("text")
.text("study_no: "+study);
}
function processData(data) {
//console.log(data);
let datapoints = {};
for (let datafile of data) {
//get metadata
let filename = datafile.input_filename;
let date_regex = /([0-9]{4})\-([0-9]{2})\-([0-9]{2})/;
let data_date_match = filename.match(date_regex);
let data_date = data_date_match[1]+'-'+data_date_match[2]+'-'+data_date_match[3];
//let data_date = date_parser(data_date_match[0]);
let ignore_keys = ['input_filename'];
for (let study in datafile) {
//skip if key (study) is in ignore_keys
if (ignore_keys.indexOf(study) !== -1) {
continue;
}
if (typeof datapoints[study] === "undefined") {
datapoints[study] = [];
}
datapoints[study].push({'date': data_date, 'mean': datafile[study].proc_times.mean});
}
}
console.log(datapoints);
//now go through the compiled data (by study) and display graphs
for (let study in datapoints) {
renderGraph(datapoints, study)
}
}
function passData(parse_error, node_data) {
console.log(parse_error);
processData(node_data);
}