Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,10 @@
"start": "tsc && node ./dist/index.js"
},
"dependencies": {
"cli-progress": "^3.12.0",
"pretty-ms": "^8.0.0",
"prompts": "^2.4.2"
"pretty-ms": "^8.0.0"
},
"devDependencies": {
"@types/cli-progress": "^3.11.0",
"@types/node": "^20.5.3",
"@types/prompts": "^2.4.4",
"@types/node": "^20.6.3",
"bun-types": "latest"
},
"peerDependencies": {
Expand Down
98 changes: 10 additions & 88 deletions pnpm-lock.yaml

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

55 changes: 16 additions & 39 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1,20 @@
import prompts from "prompts"
import cliProgress from "cli-progress"
import prettyMs from "pretty-ms"

export const LOG_DOMAINS = ["logs.beemo.gg", "archive.ayu.dev"]

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
}
},
{
onCancel: () => {
process.exit(0)
},
}
)
const url = process.argv.find((arg) => arg.startsWith("http"))

console.info(`Starting time difference calculation for ${response.url}.`)
if (!url) {
console.error("No URL provided.")
process.exit(1)
} else if (!LOG_DOMAINS.some((domain) => url.includes(domain))) {
console.error("Invalid log URL. Beemo logs use the logs.beemo.gg or archive.ayu.dev domains.")
process.exit(1)
}

console.info("Analysis in progress...")

const text = await fetch(response.url, {
const text = await fetch(url, {
method: "GET",
headers: {
"Content-Type": "text/plain",
Expand All @@ -41,11 +28,9 @@ const text = await fetch(response.url, {
process.exit(1)
})

const joinDates = text.match(/\d\d:\d\d:\d\d\.\d\d\d(\+|\-)\d\d\d\d/gmi)
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 logDate = text.match(/\d\d\d\d\/\d\d\/\d\d/gm)?.[0].replaceAll("/", "-") ?? "1970-01-01"

if (!joinDates || !logDate) {
console.error("No dates found in text.")
Expand All @@ -56,20 +41,14 @@ const parsedDates: Date[] = []
const joinDifference: number[] = []
const zeroDiffIndexes: number[] = []

const progressBar = new cliProgress.SingleBar({}, cliProgress.Presets.shades_classic)

progressBar.start(joinDates.length, 0)

for (let i = 0; i < joinDates.length; i++) {
progressBar.increment()
const date = new Date(`${year}-${month}-${day}T${joinDates[i]}`)
for await (const [i] of joinDates.entries()) {
const date = new Date(`${logDate}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()
Expand All @@ -83,7 +62,5 @@ 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)` : ""}`)
`\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)` : ""}`)
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"compilerOptions": {
"module": "ESNext",
"module": "NodeNext",
"moduleResolution": "NodeNext",
"target": "ESNext",
"esModuleInterop": true,
Expand Down