add stat project info (success streak, etc)

This commit is contained in:
oleg 2015-07-12 23:24:09 +03:00
parent fb7ef0f689
commit fede154f78
6 changed files with 93 additions and 10 deletions

View File

@ -11,7 +11,8 @@ http:
port: 3000
storage:
backend: 'memdown'
backend: memdown
# backend: medeadown
notify:
mail:

9
db.js
View File

@ -18,10 +18,19 @@ exports.init = function(dbPath, params, callback) {
id: 1
}},
// note that's unordered projection (coz number is numeric)
// TODO: pick only id as value for that rare used projection
{key: {
projectName: pickProjectName,
number: 1,
id: 1
}},
{key: {
projectName: pickProjectName,
status: 1,
descCreateDate: descCreateDate,
id: 1
}, value: function(build) {
return _(build).pick('id', 'number', 'startDate', 'endDate');
}}
]
});

View File

@ -56,6 +56,7 @@
"gulp-nodemon": "2.0.3",
"gulp-react-jade-amd": "git://github.com/vladimir-polyakov/gulp-react-jade-amd",
"main-bower-files": "2.7.0",
"medeadown": "1.1.7",
"memdown": "1.0.0",
"mocha": "1.18.2",
"nci-yaml-reader": "0.1.0",

View File

@ -3,7 +3,8 @@
var Steppy = require('twostep').Steppy,
_ = require('underscore'),
createBuildDataResource = require('../distributor').createBuildDataResource,
logger = require('../lib/logger')('projects resource');
logger = require('../lib/logger')('projects resource'),
db = require('../db');
module.exports = function(app) {
@ -20,7 +21,53 @@ module.exports = function(app) {
});
resource.use('read', function(req, res) {
res.send(_(app.projects).findWhere(req.data));
var project;
Steppy(
function() {
project = _(app.projects).findWhere(req.data);
// get last done builds to calc avg build time
db.builds.find({
start: {
projectName: project.name,
status: 'done',
descCreateDate: ''
},
limit: 20
}, this.slot());
// get last builds to calc current success streak
var isAllPrevDone = true;
db.builds.count({
start: {
projectName: project.name,
descCreateDate: ''
},
// TODO: find should be implemented at nlevel
filter: function(build) {
if (isAllPrevDone && build.status === 'error') {
isAllPrevDone = false;
}
return isAllPrevDone && build.status === 'done';
}
}, this.slot());
},
function(err, doneBuilds, doneBuildsCount) {
project.lastDoneBuild = doneBuilds[0];
var durationsSum = _(doneBuilds).reduce(function(memo, build) {
return memo + (build.endDate - build.startDate);
}, 0);
project.avgBuildDuration = Math.round(
durationsSum / doneBuilds.length
);
project.doneBuildsStreak = doneBuildsCount
res.send(project);
}
);
});
resource.use('run', function(req, res) {

View File

@ -9,10 +9,33 @@
hr
div.text-muted
p Last successfully build: ...
p Current successfully streak: ...
p Last build time: ...
p Average build time: ...
- var lastDoneBuild = this.state.project.lastDoneBuild;
p Last successfully build:
if lastDoneBuild
| build #
span= lastDoneBuild.number
| at
DateTime(date=new Date(lastDoneBuild.endDate))
else
| -
p Current successfully streak:
if lastDoneBuild
span= this.state.project.doneBuildsStreak
else
| -
p Last build duration:
if lastDoneBuild
span= lastDoneBuild.endDate - lastDoneBuild.startDate
else
| -
p Average build duration:
if this.state.project.avgBuildDuration
span= this.state.project.avgBuildDuration
else
| -
h2
i.fa.fa-fw.fa-history

View File

@ -7,13 +7,15 @@ define([
'app/stores/project',
'app/components/builds/list',
'app/components/common/scm/index',
'templates/app/components/projects/view/index'
'templates/app/components/projects/view/index',
'app/components/common/index'
], function(React, Reflux, ProjectActions, BuildActions,
projectStore, Builds, Scm, template
projectStore, Builds, Scm, template, CommonComponents
) {
template = template.locals({
Builds: Builds,
Scm: Scm
Scm: Scm,
DateTime: CommonComponents.DateTime
});
return React.createClass({