Open
Conversation
Author
|
monthly.js const fs = require("fs");
const path = require("path");
const FOLDER = "./top500"; // Folder containing 30 JSON files
const domainStats = {};
// Read all files matching the pattern
const files = fs.readdirSync(FOLDER).filter(f => f.startsWith("top500-2025-06") && f.endsWith(".json"));
for (const file of files) {
const lines = fs.readFileSync(path.join(FOLDER, file), "utf-8").split("\n").filter(Boolean);
for (const line of lines) {
try {
const { position, domain_name } = JSON.parse(line.trim());
if (!domainStats[domain_name]) {
domainStats[domain_name] = [];
}
domainStats[domain_name].push(position);
} catch (e) {
console.error(`Error parsing line in ${file}:`, line);
}
}
}
// Utility to calculate average
function average(arr) {
return arr.reduce((sum, val) => sum + val, 0) / arr.length;
}
// Utility to calculate median
function median(arr) {
const sorted = [...arr].sort((a, b) => a - b);
const mid = Math.floor(sorted.length / 2);
return sorted.length % 2 === 0
? (sorted[mid - 1] + sorted[mid]) / 2
: sorted[mid];
}
// Create result array with domain + average + median
const result = Object.entries(domainStats).map(([domain, positions]) => ({
domain,
count: positions.length,
avg: average(positions),
median: median(positions)
}));
// Sort by average position (you can change to median if preferred)
result.sort((a, b) => a.avg - b.avg);
// Output top N or all
for (let i = 0; i < result.length; i++) {
const { domain, avg, median, count } = result[i];
console.log(`${i + 1}. ${domain} | avg: ${avg.toFixed(2)} | median: ${median} | days: ${count}`);
}
const outputPath = path.join(FOLDER, "top500-2025-06-monthly.json");
const outputLines = result.map((entry, i) => JSON.stringify({
position: i + 1,
domain_name: entry.domain,
avg: Number(entry.avg.toFixed(2)),
median: entry.median,
days: entry.count
}));
fs.writeFileSync(outputPath, outputLines.join("\n"), "utf-8");
console.log(`Saved to ${outputPath}`); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
position
The domain’s rank position in the monthly list, sorted by average rank ascending (1 = best rank).
domain_name
The domain’s name (e.g., "google.com", "kkgde4d1.click").
avg
The average position of the domain across all days it appeared in the daily top 500 lists. This is a decimal number representing the mean rank.
median
The median position of the domain across all days it appeared. The median is less sensitive to outliers compared to average.
days
The count of days in the month the domain appeared in the daily top 500 lists (maximum 30 for June).