Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

proposal: add total data per world #19

Open
rmobis opened this issue Feb 5, 2024 · 2 comments
Open

proposal: add total data per world #19

rmobis opened this issue Feb 5, 2024 · 2 comments

Comments

@rmobis
Copy link

rmobis commented Feb 5, 2024

I propose we add <world-name>/_total.json files which would include the sum of killed bosses/players for that given world.

This could be useful in a few scenarios, but the one I used it for is to analyze how my world compares to other worlds in regards to boss hunting and analyzing which ones are easier and which ones are harder to find. GuildStats provides such information in their bosses page for that world or in the specific boss page, but they don't track as many creatures and bosses as this repository does.

I've quickly hacked the code below to alleviate my immediate needs, but it could be very easily be polished and adapted to do a complete job for all worlds. Let me know if you're interested and I'll work on a PR.

Initial Hacky Implementation

import fs from 'node:fs/promises';
import glob from 'glob';
import { toPrettyName } from './normalize-names.mjs';

const fileNames = glob.sync('./data/etebra/*.json', {
	ignore: [
		'./data/etebra/latest.json',
	],
});

// race => totalKilled
const map = new Map();

for (const fileName of fileNames) {
	const json = await fs.readFile(fileName, 'utf8');
	const stats = JSON.parse(json).killstatistics.entries;

	for (const {race, last_day_killed} of stats) {
		if (last_day_killed <= 0) continue;

		map.set(race, (map.get(race) ?? 0) + last_day_killed);
	}
}


const entries = [...map.entries()];
const sorted = entries
	.filter(([_race, kills]) => kills > 0)
	.map(([race, kills]) => {
		return [toPrettyName(race), kills];
	})
	.sort((a, b) => {
		if (a[1] === b[1]) {
			return a[0].localeCompare(b[0]);
		}

		return a[1] - b[1];
	});

{
	const object = Object.fromEntries(sorted);
	const json = JSON.stringify(object, null, '\t');
	await fs.writeFile('./data/etebra/_total.json', `${json}\n`);
}
@mathiasbynens
Copy link
Member

Interested!

@mathiasbynens
Copy link
Member

Rather than a standalone script, we should integrate this into https://github.com/tibiamaps/tibia-kill-stats/blob/main/analyze-global-total-kills.mjs to avoid reading all the same files from disk again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants