Skip to content

Commit

Permalink
New version of the Nimbledroid endpoint
Browse files Browse the repository at this point in the history
This new version includes the latest version for a product.
  • Loading branch information
armenzg committed Oct 4, 2018
1 parent 853b6ad commit fb8c0b7
Showing 1 changed file with 43 additions and 2 deletions.
45 changes: 43 additions & 2 deletions src/utils/apis/queryNimbledroidData.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,51 @@ import asyncRedis from 'async-redis';

const client = asyncRedis.createClient(process.env.REDIS_URL);

const latest = (a, b) => {
let latestVersion = a;
let n = 0;
while (n <= a.length - 1 && latestVersion === a) {
if (a[n] < b[n]) {
latestVersion = b;
} else {
break;
}
n += 1;
}
return latestVersion;
};

const moreData = (data, packageId) => {
let latestVersion = ['0', '0', '0', '0'];
const scenarios = {};
// eslint-disable-next-line camelcase
data.forEach(({ added, profiles, version_name }) => {
latestVersion = latest(latestVersion, version_name.split('.'));
// eslint-disable-next-line camelcase
profiles.forEach(({ scenario_name, time_in_ms }) => {
if (!scenarios[scenario_name]) {
scenarios[scenario_name] = [];
}
scenarios[scenario_name].push({
date: added,
ms: time_in_ms,
});
});
});
return {
meta: {
latestVersion: latestVersion.join('.'),
packageId,
},
scenarios,
};
};

const optimizedData = (data, packageId) => {
const newData = {};
data.forEach(({ added, profiles }) => {
// eslint-disable-next-line camelcase
profiles.forEach(({ scenario_name, status, time_in_ms }) => {
profiles.forEach(({ scenario_name, time_in_ms }) => {
if (!newData[scenario_name]) {
newData[scenario_name] = [];
}
Expand All @@ -29,7 +69,8 @@ const queryNimbledroidData = async (product, version) => {
if (data.length === 0) {
throw Error('The script that fetches data should have run before hitting the API.');
}
return version === '2' ? optimizedData(data, product) : data;
// Drop support for version 1
return version === '3' ? moreData(data, product) : optimizedData(data, product);
};

export default queryNimbledroidData;

0 comments on commit fb8c0b7

Please sign in to comment.