Skip to content

Commit

Permalink
added more study stats
Browse files Browse the repository at this point in the history
  • Loading branch information
Jorrit Poelen committed Jan 10, 2014
1 parent 17b2a4f commit 841d897
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 16 deletions.
24 changes: 18 additions & 6 deletions globi-data-dist.js
Expand Up @@ -115,12 +115,24 @@ globiData.findStudyStats = function (search, callback) {
var studyStats = [];
for (var i = 0; i < resp.data.length; i++) {
var row = resp.data[i];
var reference = row[2];
var name = row[3];
if (name && name.length > 0) {
reference = name + ' ' + reference;
}
studyStats[i] = { reference: reference, totalInteractions: row[4], totalSourceTaxa: row[5], totalTargetTaxa: row[6]};
var reference = '';
if (row.length > 8 && row[8].length > 0) {
reference = row[8];
} else {
reference = row[2];
var name = row[3];
if (name && name.length > 0) {
reference = name + ' ' + reference;
}
}
var stats = { reference: reference, totalInteractions: row[4], totalSourceTaxa: row[5], totalTargetTaxa: row[6]};
if (row.length > 9 && row[9].length > 0) {
stats.doi = row[9];
}
if (row.length > 10 && row[10].length > 0) {
stats.source = row[10];
}
studyStats[i] = stats;
}
callback(studyStats);
}
Expand Down
28 changes: 22 additions & 6 deletions globi-data.js
Expand Up @@ -113,12 +113,28 @@ globiData.findStudyStats = function (search, callback) {
var studyStats = [];
for (var i = 0; i < resp.data.length; i++) {
var row = resp.data[i];
var reference = row[2];
var name = row[3];
if (name && name.length > 0) {
reference = name + ' ' + reference;
}
studyStats[i] = { reference: reference, totalInteractions: row[4], totalSourceTaxa: row[5], totalTargetTaxa: row[6]};
var reference = '';
var citation = row[8];
if (citation && citation.length > 0) {
reference = row[8];
} else {
reference = row[2];
var name = row[3];
if (name && name.length > 0) {
reference = name + ' ' + reference;
}
}
var stats = { reference: reference, totalInteractions: row[4], totalSourceTaxa: row[5], totalTargetTaxa: row[6]};
var doi = row[9];
if (doi && doi.length > 0) {
stats.doi = row[9];
}

var source = row[10];
if (source && source.length > 0) {
stats.source = row[10];
}
studyStats[i] = stats;
}
callback(studyStats);
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "globi-data",
"version": "0.0.15",
"version": "0.0.16",
"description": "Find out who eats who in the world: what do rats (Rattus rattus) eat?, or what do hardhead catfish (Ariopsis felis) eat?. Data provided by EOL's GloBI (Global Biotic Interactions) http://github.com/jhpoelen/eol-globi-data .",
"main": "globi-data.js",
"directories": {
Expand Down
8 changes: 5 additions & 3 deletions test/stats.js
Expand Up @@ -34,11 +34,12 @@ test('find statistics by studies from specific source', function (t) {
});

test('get statistics for studies', function (t) {
t.plan(5);
t.plan(6);
var callback = function (statList) {
t.ok(statList.length > 0, 'should get at least one entry');
var stats = statList[0];
t.ok(stats.reference, 'should have a reference');
t.ok(stats.source, 'should have a source');
t.ok(stats.totalInteractions > 0, 'should get at least one interaction');
t.ok(stats.totalSourceTaxa > 0, 'should get at least one interaction');
t.ok(stats.totalTargetTaxa > 0, 'should get at least one interaction');
Expand All @@ -47,14 +48,15 @@ test('get statistics for studies', function (t) {
});

test('get statistics for studies for specific source', function (t) {
t.plan(5);
t.plan(6);
var callback = function (statList) {
t.ok(statList.length > 0, 'should get at least one entry');
var stats = statList[0];
t.ok(stats.reference, 'should have a reference');
t.equal(stats.source, 'SPIRE');
t.ok(stats.totalInteractions > 0, 'should get at least one interaction');
t.ok(stats.totalSourceTaxa > 0, 'should get at least one interaction');
t.ok(stats.totalTargetTaxa > 0, 'should get at least one interaction');
};
globiData.findStudyStats({source:'SPIRE'}, callback);
});
});

0 comments on commit 841d897

Please sign in to comment.