Skip to content

Commit

Permalink
fix statistics for new stables adapters
Browse files Browse the repository at this point in the history
  • Loading branch information
mcm1957 committed Feb 13, 2024
1 parent 59a0ba2 commit ae3cac1
Showing 1 changed file with 25 additions and 15 deletions.
40 changes: 25 additions & 15 deletions lib/check.js
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,10 @@ async function doIt() {
const stable = await getUrl('http://repo.iobroker.live/sources-dist.json');
const statistic = await getUrl('https://www.iobroker.net/data/statistics.json');

comments.push({text:`\n`, noDecorate: true});
comments.push({text:`Adapter releases: https://www.iobroker.dev/adapter/${adapterName}/releases`, noDecorate: true});
comments.push({text:`Adapter statistic: https://www.iobroker.dev/adapter/${adapterName}/statistics`, noDecorate: true});

const now = new Date();
const totalUser = statistic['adapters'][adapterName];

Expand All @@ -351,27 +355,33 @@ async function doIt() {
const latestUser = statistic['versions'][adapterName][latestRelease];
const latestUserPercent = (latestUser/totalUser * 100).toFixed(2);

const stableRelease = latest[adapterName].stable;
const stableTime = new Date(stable[adapterName].versionDate);
const stableTimeStr = stableTime.getDate() +'.'+ (stableTime.getMonth()+1) +'.'+ stableTime.getFullYear();
const stableDaysOld = Math.floor((now.getTime() - stableTime.getTime()) / ONE_DAY);
const stableUser = statistic['versions'][adapterName][stableRelease];
const stableUserPercent = (stableUser/totalUser * 100).toFixed(2);

comments.push({text:`\n`, noDecorate: true});
comments.push({text:`Adapter releases: https://www.iobroker.dev/adapter/${adapterName}/releases`, noDecorate: true});
comments.push({text:`Adapter statistic: https://www.iobroker.dev/adapter/${adapterName}/statistics`, noDecorate: true});
comments.push({text:``, noDecorate: true});

comments.push({text:`**History and usage information for release ${latestRelease}:**`, noDecorate: true});

comments.push({text:``, noDecorate: true});
comments.push({text:`${latestRelease} created ${latestTimeStr} (${latestDaysOld} days old)`, noDecorate: true});
comments.push({text:`${latestUser} users (${latestUserPercent}%)`, noDecorate: true});

comments.push({text:``, noDecorate: true});
comments.push({text:`${stableRelease} (stable) created ${stableTimeStr} (${stableDaysOld} days old)`, noDecorate: true});
comments.push({text:`${stableUser} users (stable) (${stableUserPercent}%)`, noDecorate: true});
if (stable[adapterName]) {

const stableRelease = latest[adapterName].stable;
const stableTime = new Date(stable[adapterName].versionDate);
const stableTimeStr = stableTime.getDate() +'.'+ (stableTime.getMonth()+1) +'.'+ stableTime.getFullYear();
const stableDaysOld = Math.floor((now.getTime() - stableTime.getTime()) / ONE_DAY);
const stableUser = statistic['versions'][adapterName][stableRelease];
const stableUserPercent = (stableUser/totalUser * 100).toFixed(2);

comments.push({text:``, noDecorate: true});
comments.push({text:`${stableRelease} (stable) created ${stableTimeStr} (${stableDaysOld} days old)`, noDecorate: true});
comments.push({text:`${stableUser} users (stable) (${stableUserPercent}%)`, noDecorate: true});

} else {

comments.push({text:``, noDecorate: true});
comments.push({text:`stable release not yet available`, noDecorate: true});

}


comments.push({text:``, noDecorate: true});
comments.push({text:`**Please verify that this PR really tries to update to release ${latestRelease}!**\n`, noDecorate: true});
Expand Down Expand Up @@ -419,7 +429,7 @@ async function doIt() {
}

// activate for debugging purposes
// process.env.GITHUB_REF = 'refs/pull/3295/merge';
process.env.GITHUB_REF = 'refs/pull/3305/merge';
//process.env.OWN_GITHUB_TOKEN = 'add-token-here';
// process.env.GITHUB_EVENT_PATH = __dirname + '/../event.json';

Expand Down

0 comments on commit ae3cac1

Please sign in to comment.