Skip to content

Commit

Permalink
Add npd15, Fix versions.json
Browse files Browse the repository at this point in the history
  • Loading branch information
tamaina committed Nov 26, 2023
1 parent 50422a2 commit 4b91054
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 21 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ You can get the following information under https://instanceapp.misskey.page
icon: Bool, // Icon Image existance
nodeinfo: Object | null, // nodeinfo
meta: Object | null, // result of api/meta
npd15: Number // Number of Notes per Day (15-day average)
stats: Object, // deprecated (result of api/stats)
}, ...
Expand Down
1 change: 0 additions & 1 deletion data/instances.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2704,4 +2704,3 @@
# uz
- url: misskey.uz
langs: ['uz']

62 changes: 42 additions & 20 deletions getInstancesInfos.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,16 @@ async function getVersions() {
const link = res1.headers.get("link")
const max = link && Math.min(Number(maxRegExp.exec(link)[1]), repo === "misskey-dev/misskey" ? 99999 : 4)

let vcnt = 0;
/**
* バージョンカウント
*/
let versionCount = 0;

/**
* バリュー算出用のバージョンカウント
* これを上げるとインスタンスバリューは下がる
*/
let valueCount = 0;

const resp = (await Promise.all([Promise.resolve(res1), ...(!link ? []
: Array(max - 1).fill()
Expand All @@ -277,18 +286,23 @@ async function getVersions() {
}
versions.set(version, {
repo,
count: vcnt,
count: versionCount,
valueCount,
hasVulnerability: hasVulnerability(repo, version),
});

// バージョンカウントアップ
// これを上げるとインスタンスバリューは下がる
versionCount++;

if (repo === 'misskey-dev/misskey' && version.indexOf('-') >= 0) {
// misskey-dev/misskeyかつプレリリースっぽければカウントアップしない
} else {
vcnt++;
valueCount++;
}
}

// used for versionOutput
return json.map(release => release.tag_name);
},
e => {
glog(repo, "Error(json)", e)
Expand Down Expand Up @@ -337,14 +351,14 @@ export const getInstancesInfos = async function () {
const sem1 = semver.clean(nodeinfo.software.version, { loose: true })
if (versions.has(sem1)) return { just: true, ...versions.get(sem1) };
const sem2 = semver.valid(semver.coerce(nodeinfo.software.version))
let current = { repo: 'misskey-dev/misskey', count: 1500 };
let current = { repo: 'misskey-dev/misskey', count: 999999, valueCount: 999999 };
for (const [key, value] of versions.entries()) {
if (sem1 && sem1.startsWith(key)) {
if (value.count === 0) return { just: false, ...value };
else if (current.count >= value.count) current = { just: false, ...value };
if (value.valueCount === 0) return { just: false, ...value };
else if (current.valueCount >= value.valueCount) current = { just: false, ...value };
} else if (sem2 && value.repo == 'misskey-dev/misskey' && sem2.startsWith(key)) {
if (value.count === 0) return { just: false, ...value };
else if (current.count >= value.count) current = { just: false, ...value };
if (value.valueCount === 0) return { just: false, ...value };
else if (current.valueCount >= value.valueCount) current = { just: false, ...value };
}
}
return current
Expand All @@ -359,28 +373,35 @@ export const getInstancesInfos = async function () {
};

const meta = (await fetchJson('POST', `https://${instance.url}/api/meta`)) || null;
const stat = (await fetchJson('POST', `https://${instance.url}/api/stats`)) || null;
const NoteChart = (await fetchJson('POST', `https://${instance.url}/api/charts/notes`, { span: "day", limit: 15 })) || null;
const stats = (await fetchJson('POST', `https://${instance.url}/api/stats`)) || null;
const noteChart = (await fetchJson('POST', `https://${instance.url}/api/charts/notes`, { span: "day", limit: 15 })) || null;

if (nodeinfo && meta && stat && NoteChart) {
if (nodeinfo && meta && stats && noteChart) {
if (meta) {
delete meta.emojis;
delete meta.announcements;
}

/* インスタンスバリューの算出 */
/* インスタンスバリューの算出 */
let value = 0

/* ノート増加数の15日間の平均 */
let npd15 = 0

// 1. バージョンのリリース順をもとに並び替え
value += 100000 - (versionInfo.count - 30) * 7200
value += 100000 - (versionInfo.valueCount - 30) * 7200

// (基準値に影響があるかないか程度に色々な値を考慮する)
if (NoteChart && Array.isArray(NoteChart.local?.inc)) {
if (noteChart && Array.isArray(noteChart.local?.inc)) {
// 2.
const arr = NoteChart.local?.inc.filter(e => e !== 0)
const nli15 = noteChart.local?.inc.filter(e => e !== 0)

// ノート増加数の15日間の平均 * 1
// eslint-disable-next-line no-mixed-operators
if (arr.length > 0) value += (arr.reduce((prev, current) => prev + current) / arr.length);
if (nli15.length > 0) {
npd15 = nli15.reduce((prev, current) => prev + current) / nli15.length;
// 2. ノート増加数の15日間の平均 * 1
// eslint-disable-next-line no-mixed-operators
value += npd15 * 1;
}

// もし統計の数が15日に満たない場合、新規インスタンス特典を付与
// value += (15 - arr.length) * 360
Expand All @@ -390,7 +411,8 @@ export const getInstancesInfos = async function () {
value,
meta,
nodeinfo,
stats: stat,
stats,
npd15,
name: instance.name || nodeinfo.metadata.nodeName || meta.name || instance.url,
description: nodeinfo.metadata.nodeDescription || meta.description || (instance.description || null),
langs: instance.langs || ['ja', 'en', 'de', 'fr', 'zh', 'ko', 'ru', 'th', 'es'],
Expand Down

0 comments on commit 4b91054

Please sign in to comment.