Skip to content

Commit

Permalink
Merge pull request #44 from net-tech/v2
Browse files Browse the repository at this point in the history
  • Loading branch information
net-tech authored Aug 22, 2023
2 parents 6cc8f23 + 9128b34 commit 33e9e4a
Show file tree
Hide file tree
Showing 11 changed files with 257 additions and 733 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
node_modules
node_modules
dist
.DS_STORE
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2022 net-tech
Copyright (c) 2023 net-tech-

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
12 changes: 4 additions & 8 deletions README.md
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.
32 changes: 20 additions & 12 deletions package.json
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]"
}
127 changes: 127 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

122 changes: 79 additions & 43 deletions src/index.ts
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)` : ""}`)
12 changes: 0 additions & 12 deletions src/services/logger.ts

This file was deleted.

Loading

0 comments on commit 33e9e4a

Please sign in to comment.