- var minTime = d3.max(raw_data.relays.map(function(d) { return d[direction][period] && parseTime(d[direction][period].first); }));
- var maxTime = d3.min(raw_data.relays.map(function(d) { return d[direction][period] && parseTime(d[direction][period].last); }));
- var maxTotalBandwidth = 0;
-
- var data = stack(color.domain().map(function(fingerprint) {
- var relay_data = raw_data["relays"].filter(function(d) { return d.fingerprint == fingerprint; })[0];
- var history = relay_data[direction][period];
-
- var values = [];
- var first = parseTime(history.first);
- var last = parseTime(history.last);
- var i = 0;
- for (var current = minTime; current <= maxTime; current = d3.time.second.offset(current, history.interval)) {
- if (first <= current && current <= last) {
- values.push({ date: current, y: history.factor * history.values[i++] * 8 / 1000000 });
- }
- }
-
- maxTotalBandwidth = maxTotalBandwidth + d3.max(values.map(function(d) { return d.y; }));
+ var minTime = d3.max(raw_data.relays.map(function(d) {
+ return d['read_history'][period] && parseTime(d['read_history'][period].first) &&
+ d['write_history'][period] && parseTime(d['write_history'][period].first);
+ }));
+ var maxTime = d3.min(raw_data.relays.map(function(d) {
+ return d['read_history'][period] && parseTime(d['read_history'][period].last) &&
+ d['write_history'][period] && parseTime(d['write_history'][period].last);
+ }));
+ var maxReadBandwidth = 0;
+ var maxWriteBandwidth = 0;
+
+ var data = color.domain().map(function(fingerprint) {
+ var relay_data = raw_data["relays"].filter(function(d) { return d.fingerprint == fingerprint; })[0];
+ var read_history = relay_data['read_history'][period];
+ var write_history = relay_data['write_history'][period];
+ var read_values = extract_values(read_history, minTime, maxTime);
+ var write_values = extract_values(write_history, minTime, maxTime);
+
+ maxReadBandwidth = maxReadBandwidth + d3.max(read_values.map(function(d) { return d.y; }));
+ maxWriteBandwidth = maxWriteBandwidth + d3.max(write_values.map(function(d) { return d.y; }));
+
+ return {
+ fingerprint: fingerprint,
+ read_values: read_values,
+ write_values: write_values,
+ };
+ });