Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix fail Distr page #52

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
124 changes: 73 additions & 51 deletions CassandraBackend.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ function CassandraBackend(name, config, callback) {
self.testScores = [];
self.topFailsArray = [];
self.testByScoreToCommit = [];
self.latestResults = [];
self.latestResults = {};

self.tasks =[getCommits.bind(this), initLatestResults.bind(this), getTests.bind(this), initTestPQ.bind(this), initTopFails.bind(this)];
// Load all the tests from Cassandra - do this when we see a new commit hash
Expand Down Expand Up @@ -117,7 +117,7 @@ function initLatestResults(cb) {
}

var lastCommit = this.commits[0] && this.commits[0].hash.toString();
var skips = {}, cql;
var skips = {}, cql, fails = {};

if (this.commits.length === 1) {
var queryCB = function (err, results) {
Expand All @@ -135,16 +135,23 @@ function initLatestResults(cb) {
} else {
skips[counts.skips] += 1;
}
if (!fails[counts.fails]) {
fails[counts.fails] = 1;
} else {
fails[counts.fails]++;
}
});
this.latestResults[lastCommit] = skips;
this.latestResults[lastCommit] = {};
this.latestResults[lastCommit].skips = skips;
this.latestResults[lastCommit].fails = fails;
}
};
// since only one commit in db, skips/fails stats can be computed with current commit
cql = 'select score from test_by_score where commit = ?';
this.client.execute(cql, [lastCommit], this.consistencies.write, queryCB.bind(this));
} else {
// fill this by latest results
cql = 'select skipstats from revision_summary where revision = ?';
cql = 'select skipstats, failstats from revision_summary where revision = ?';
var queryCB2 = function (err, results) {
if (err) {
console.log("err: " + err);
Expand All @@ -160,8 +167,14 @@ function initLatestResults(cb) {
} else {
skips[counts.skips] += 1;
}
if (!fails[counts.fails]) {
fails[counts.fails] = 1;
} else {
fails[counts.fails]++;
}
});
this.latestResults[lastCommit] = skips;
this.latestResults[lastCommit].skips = skips;
this.latestResults[lastCommit].fails = fails;
}
};
var queryCB1 = function (err, results) {
Expand All @@ -173,7 +186,8 @@ function initLatestResults(cb) {
var secondLastCommit = this.commits[1].hash.toString();
this.client.execute(cql, [secondLastCommit], this.consistencies.write, queryCB2.bind(this));
} else {
this.latestResults[lastCommit] = results.rows[0].skipstats;
this.latestResults[lastCommit].skips = results.rows[0].skipstats;
this.latestResults[lastCommit].fails = results.rows[0].failstats;
}
};
this.client.execute(cql, [lastCommit], this.consistencies.write, queryCB1.bind(this));
Expand Down Expand Up @@ -435,17 +449,26 @@ CassandraBackend.prototype.updateCommits = function (lastCommitTimestamp, commit
self = this;

if (this.latestResults[commit]) {
skips = {value: this.latestResults[commit], hint: 'map'};
this.latestResults[commit] = {};
skips = {value: this.latestResults[commit].skips, hint: 'map'};
fails = {value: this.latestResults[commit].fails, hint: 'map'};
} else if(this.commits.length >1){
this.latestResults[commit] = this.latestResults[this.commits[1].hash];
skips = {value: this.latestResults[this.commits[1].hash], hint: 'map'};
this.latestResults[commit] = {};
this.latestResults[commit].skips = this.latestResults[this.commits[1].hash].skips;
this.latestResults[commit].fails = this.latestResults[this.commits[1].hash].fails;
skips = {value: this.latestResults[this.commits[1].hash].skips, hint: 'map'};
fails = {value: this.latestResults[this.commits[1].hash].fails, hint: 'map'};
} else {
this.latestResults[commit] = {};
skips = {value: {}, hint: 'map'};
fails = {value: {}, hint: 'map'};
this.latestResults[commit].skips = {};
this.latestResults[commit].fails = {};
}

this.getStatistics(function (err, result) {
cql = 'insert into revision_summary (revision, errors, skips, fails, numtests, skipstats) values (?, ? , ? , ?, ?, ?);';
args = [new Buffer(commit), result.averages.errors, result.averages.skips, result.averages.fails, result.averages.numtests, skips];
cql = 'insert into revision_summary (revision, errors, skips, fails, numtests, skipstats, failstats) values (?, ? , ? , ?, ?, ?, ?);';
args = [new Buffer(commit), result.averages.errors, result.averages.skips, result.averages.fails, result.averages.numtests, skips, fails];
self.client.execute(cql, args, self.consistencies.write, function(err, result) {
if (err) {
console.log(err);
Expand Down Expand Up @@ -781,23 +804,30 @@ CassandraBackend.prototype.addResult = function (test, commit, result, cb) {
skips, counts;

var score = statsScore(skipCount, failCount, errorCount);
cql = 'UPDATE revision_summary SET skipstats = ? WHERE revision = ?';
cql = 'UPDATE revision_summary SET skipstats = ?, failstats = ? WHERE revision = ?';

//Update latest results array
if (this.commits.length > 1 && this.testScores[test.toString()] != score ) {
counts = countScore(score);
skips = this.latestResults[commit.toString()];
skips = this.latestResults[commit.toString()].skips;
fails = this.latestResults[commit.toString()].fails;

if (!skips[counts.skips]) {
skips[counts.skips] = 1;
} else {
skips[counts.skips] += 1;
}

this.latestResults[commit.toString()] = skips;
if (!fails[counts.fails]) {
fails[counts.fails] = 1;
} else {
fails[counts.fails]++;
}
this.latestResults[commit.toString()].skips = skips;
this.latestResults[commit.toString()].fails = fails;

args = {value: skips, hint: 'map'};
this.client.execute(cql, [args, commit], this.consistencies.write, function (err, result) {
args2 = {value: fails, hint: 'map'};
this.client.execute(cql, [args, args2, commit], this.consistencies.write, function (err, result) {
if (err) {
console.log(err);
}
Expand All @@ -806,22 +836,33 @@ CassandraBackend.prototype.addResult = function (test, commit, result, cb) {
} else {

counts = countScore(score);
skips = this.latestResults[commit.toString()];
skips = this.latestResults[commit.toString()].skips;
fails = this.latestResults[commit.toString()].fails;

// update stats
if (!skips) {
skips = [];
}
if (!fails) {
fails = [];
}
if (!skips[counts.skips]) {
skips[counts.skips] = 1;
} else {
skips[counts.skips] += 1;
}
this.latestResults[commit.toString()] = skips;
if (!fails[counts.fails]) {
fails[counts.fails] = 1;
} else {
fails[counts.fails]++;
}
this.latestResults[commit.toString()].skips = skips;
this.latestResults[commit.toString()].fails = fails;

// update db with stats
args = {value: skips, hint: 'map'};
this.client.execute(cql, [args, commit] , this.consistencies.write, function (err, result) {
args2 = {value: fails, hint: 'map'};
this.client.execute(cql, [args, args2, commit] , this.consistencies.write, function (err, result) {
if (err) {
console.log(err);
}
Expand Down Expand Up @@ -919,38 +960,19 @@ CassandraBackend.prototype.getTopFails = function (offset, limit, cb) {
cb(results);
};

CassandraBackend.prototype.getFailsDistr = function(commit, cb) {
var commit = this.commits.length
&& this.commits[this.commits.length - 1]
|| null;
var args = [],
results = {};
CassandraBackend.prototype.getFailsDistr = function(cb) {

var args = [], results = {}, fails;

if (!this.commits.length) {
cb(null, { fails: {}});
} else {
commit = this.commits[0].hash.toString();
fails = this.latestResults[commit].fails;
results = { fails: fails };
}
cb(null, results);

var cql = "select score from test_by_score where commit = ?";
args = args.concat([commit]);
this.client.execute(cql, args, this.consistencies.write, function(err, results) {
if (err) {
console.log("err: " + err);
cb(err);
} else if (!results || !results.rows) {
console.log( 'no seen commits, error in database' );
cb(null);
} else {
//console.log("hooray we have data!: " + JSON.stringify(results, null,'\t'));
var fails = {};
results.rows.forEach(function(item) {
var data = item[0];
var counts = countScore(data);
if (!fails[counts.fails]) {
fails[counts.fails] = 1;
} else {
fails[counts.fails]++;
}
});
results = {fails: fails};
cb(null, results);
}
});
};

CassandraBackend.prototype.getSkipsDistr = function(cb) {
Expand All @@ -959,7 +981,7 @@ CassandraBackend.prototype.getSkipsDistr = function(cb) {
cb(null, { skips: {}});
} else {
commit = this.commits[0].hash.toString();
skips = this.latestResults[commit];
skips = this.latestResults[commit].skips;
results = { skips: skips };
}
cb(null, results);
Expand Down
3 changes: 2 additions & 1 deletion cql/create_everything.cql
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ CREATE TABLE IF NOT EXISTS revision_summary (
skips int,
fails int,
numtests int,
skipstats map<text, int>,
skipstats map<text, int>,
failstats map<text, int>,
PRIMARY KEY(revision)
);
2 changes: 1 addition & 1 deletion server.js
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ var GET_crashers = function( req, res ) {
var GET_failsDistr = function( req, res ) {
res.write('<html><body>\n');
res.write('<h1>Distribution of semantic errors</h1>');
backend.getFailsDistr(null, function(err, result) {
backend.getFailsDistr(function(err, result) {
res.write( '<table><tr style="font-weight:bold"><td style="padding-left:20px;">' + '# errors' );
res.write( '</td><td style="padding-left:20px;">' + '#pages' + '</td></tr>' );
// console.log(result.fails);
Expand Down