-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
111 lines (80 loc) · 2.73 KB
/
server.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
var redmine = require('./lib/redmine');
var redmineIssue = require('./lib/redmine-issue');
var config = require('./config.json');
var momentRange = require('moment-range');
var r = new redmine(config.host, config.port, config.key);
function getData(callback) {
// Hardcoded project id.
var projectId = 329;
var fromDate = new Date('2014-01-01');
var toDate = Date.now();
var dateRange = momentRange().range(fromDate, toDate);
var dateRangeArray = [];
// Iterate over date range.
dateRange.by('days', function(moment) {
dateRangeArray.push(moment);
});
redmineIssue.getAll(r, {project_id: projectId, status_id: "*"}, function(err, issues) {
if (err) {
console.log('ERROR', err);
}
console.log('Collected issues:', issues.length);
// Prerun status, so it is present later on.
r.getStatuses(function(err, statuses) {
console.log('Statuses', statuses);
var series = {};
// We run through each
for (var i in issues) {
var issue = issues[i];
for (var day in dateRangeArray) {
var thisDate = dateRangeArray[day];
var status = issue.getStatus(thisDate);
//console.log('Status', status);
console.log('Status', statuses[status]);
// Only proceed if the issue has a valid status for that day.
if (status != undefined && statuses[status] != undefined) {
// Ensure status array is defined.
if (series[status] == undefined) {
series[status] = {};
}
// Ensure status for the day is present.
if (series[status][day] == undefined) {
series[status][day] = 0;
}
// Increment the status for that day for the given issue.
series[status][day]++;
console.log(status, day, series[status][day]);
}
}
}
var rickshawSeries = [];
// Restructure data to rickshaw series.
for (var status in statuses) {
var data = [];
for (var day in dateRangeArray) {
var val = 0;
if (series[status] != undefined && series[status][day] != undefined) {
val = series[status][day];
}
data.push({x: parseInt(day), y: parseInt(val)});
}
rickshawSeries.push({
data: data,
name: statuses[status].name,
color: statuses[status].color
});
}
callback(undefined, rickshawSeries);
});
});
}
var express = require('express');
var app = express();
app.get('/data.json', function(req, res){
getData(function(err, data) {
res.send(data);
});
});
app.use(express.static(__dirname + '/app'));
app.listen(3000);
console.log('Listening on port 3000');