-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #44 from net-tech/v2
- Loading branch information
Showing
11 changed files
with
257 additions
and
733 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
node_modules | ||
node_modules | ||
dist | ||
.DS_STORE |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,10 @@ | ||
# Beemo Time Difference Calculator - Unofficial | ||
# Beemo Join Difference Calculator - Unofficial | ||
|
||
This small app allows you to see the time between joins of account in a [Beemo](https://beemo.gg) raid log. An example output when using the CLI would be | ||
``` | ||
Detected 940 joins. Average difference between join times rounded is 17 seconds (17762.668085106383ms). | ||
Analyzed 14827 joins. Average difference between join times is 66ms. | ||
22 times out of 940 were 0ms apart. (This happened 0.02% of the time in this raid) | ||
These are the indexes of the 0ms apart times: 100, 109, 220, 233, 237, 242, 249, 448, 459, 460 and 12 more. | ||
Took 300.43ms. | ||
573 joins out of 14826 happened at the same time (0.039% of all) | ||
``` | ||
|
||
While in general this tool offers no real practical use, it was fun to build an can provide interesting statistics. | ||
While in general this tool offers no real practical use, it was fun to build and can provide interesting statistics. |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,29 @@ | ||
{ | ||
"name": "beemo-time-diff", | ||
"version": "1.1.2", | ||
"version": "2.0.0", | ||
"main": "./src/index.ts", | ||
"license": "MIT", | ||
"type": "module", | ||
"author": "net-tech-", | ||
"scripts": { | ||
"dev": "ts-node ./src/index.ts" | ||
"start": "tsc && node ./dist/index.js" | ||
}, | ||
"dependencies": { | ||
"@types/cli-progress": "^3.11.0", | ||
"@types/ms": "^0.7.31", | ||
"@types/node": "^20.4.2", | ||
"@types/prompt": "^1.1.5", | ||
"axios": "^1.4.0", | ||
"cli-progress": "^3.12.0", | ||
"ms": "^2.1.3", | ||
"pino": "^8.14.1", | ||
"pino-pretty": "^10.0.1", | ||
"prompt": "^1.3.0" | ||
} | ||
"pretty-ms": "^8.0.0", | ||
"prompts": "^2.4.2" | ||
}, | ||
"devDependencies": { | ||
"@types/cli-progress": "^3.11.0", | ||
"@types/node": "^20.5.3", | ||
"@types/prompts": "^2.4.4", | ||
"bun-types": "latest" | ||
}, | ||
"peerDependencies": { | ||
"typescript": "^5.0.0" | ||
}, | ||
"engines": { | ||
"node": ">=18.15.0" | ||
}, | ||
"packageManager": "[email protected]" | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,89 @@ | ||
import prompt from "prompt" | ||
import { log } from "./services/logger" | ||
import TimeService from "./services/time" | ||
import ms from "ms" | ||
|
||
const schema = { | ||
properties: { | ||
url: { | ||
description: "Enter the Beemo raid result url", | ||
hidden: false, | ||
required: true, | ||
}, | ||
}, | ||
} | ||
import prompts from "prompts" | ||
import cliProgress from "cli-progress" | ||
import prettyMs from "pretty-ms" | ||
|
||
prompt.start() | ||
export const LOG_DOMAINS = ["logs.beemo.gg", "archive.ayu.dev"] | ||
|
||
prompt.get(schema, (err: any, result: { url: string }) => { | ||
try { | ||
if (err) { | ||
if (err.message === "canceled") { | ||
log.info("Exiting.") | ||
return | ||
const response = await prompts( | ||
{ | ||
type: "text", | ||
name: "url", | ||
message: | ||
"Please enter the link of the raid log:", | ||
validate: (url) => { | ||
const domain = url.split("/")[2] | ||
if (!LOG_DOMAINS.includes(domain)) { | ||
return `Supported domains: ${LOG_DOMAINS.join(", ")}.` | ||
} | ||
return true | ||
} | ||
|
||
log.fatal(err, "Error getting input.") | ||
return | ||
}, | ||
{ | ||
onCancel: () => { | ||
process.exit(0) | ||
}, | ||
} | ||
) | ||
|
||
console.info(`Starting time difference calculation for ${response.url}.`) | ||
|
||
const text = await fetch(response.url, { | ||
method: "GET", | ||
headers: { | ||
"Content-Type": "text/plain", | ||
"User-Agent": "Beemo Log Analyzer (https://github.com/net-tech/beemo-time-diff)" | ||
} | ||
}) | ||
.then((response) => response.text()) | ||
.then((text) => text) | ||
.catch((error) => { | ||
console.error(error, "Error getting text from URL.") | ||
process.exit(1) | ||
}) | ||
|
||
const joinDates = text.match(/\d\d:\d\d:\d\d\.\d\d\d(\+|\-)\d\d\d\d/gmi) | ||
|
||
// The day month and year is at the top of the log | ||
const logDate = text.match(/\d\d\d\d\/\d\d\/\d\d/gm)?.[0] ?? "1970/01/01" | ||
const [year, month, day] = logDate.split("/") | ||
|
||
const url = result.url | ||
if (!joinDates || !logDate) { | ||
console.error("No dates found in text.") | ||
process.exit(1) | ||
} | ||
|
||
log.info(`Starting time difference calculation for ${url}.`) | ||
const parsedDates: Date[] = [] | ||
const joinDifference: number[] = [] | ||
const zeroDiffIndexes: number[] = [] | ||
|
||
TimeService.timeDifference(url) | ||
.then((result) => { | ||
const zerosString = | ||
result.zeros.count > 0 | ||
? `\n\n${result.zeros.count} times out of ${result.joinCount} were 0ms apart. (This happened ${result.zeros.chanceRounded}% of the time in this raid)\n\nThese are the indexes of the 0ms apart times: ${result.zeros.indexListString}.` | ||
: "" | ||
const progressBar = new cliProgress.SingleBar({}, cliProgress.Presets.shades_classic) | ||
|
||
const averageTime = ms(result.averageTime.averageRounded) | ||
progressBar.start(joinDates.length, 0) | ||
|
||
log.info( | ||
`Detected ${result.joinCount} joins. Average difference between join times rounded is ${averageTime}ms (${result.averageTime.averageRaw}ms).${zerosString}.` | ||
) | ||
}) | ||
.catch((error) => { | ||
log.fatal(error, "Error getting time difference.") | ||
}) | ||
} catch (error) { | ||
log.fatal(error, "Error getting input.") | ||
for (let i = 0; i < joinDates.length; i++) { | ||
progressBar.increment() | ||
const date = new Date(`${year}-${month}-${day}T${joinDates[i]}`) | ||
// We always want the time in UTC-0, if the join date ends with 0700, we want to add 7 hours to the time to get UTC-0. | ||
if (joinDates[i].endsWith("-0700")) { | ||
date.setUTCHours(date.getUTCHours() + 7) | ||
} | ||
}) | ||
parsedDates.push(date) | ||
|
||
// Calculate the difference between the current and previous join time | ||
if (i === 0) continue | ||
|
||
const diff = parsedDates[i].getTime() - parsedDates[i - 1].getTime() | ||
joinDifference.push(diff) | ||
if (diff === 0) { | ||
zeroDiffIndexes.push(i) | ||
} | ||
} | ||
|
||
const zeroDiffOcc = zeroDiffIndexes.length / joinDifference.length | ||
|
||
const averageJoinDiff = joinDifference.reduce((a, b) => a + b) / joinDifference.length | ||
|
||
progressBar.stop() | ||
|
||
console.info( | ||
`\nAnalyzed ${joinDates.length} joins. Average difference between join times is ${prettyMs(averageJoinDiff)}. ${zeroDiffIndexes.length > 0 ? `\n\n${zeroDiffIndexes.length} joins out of ${joinDifference.length} happened at the same time (${zeroDiffOcc.toPrecision(2)}% of all)` : ""}`) |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.