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
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@
"dev": "ts-node ./src/index.ts"
},
"dependencies": {
"@sapphire/stopwatch": "^1.5.0",
"@sapphire/time-utilities": "^1.7.8",
"@types/cli-progress": "^3.11.0",
"@types/ms": "^0.7.31",
"@types/node": "^18.11.13",
"@types/prompt": "^1.1.4",
"axios": "^1.1.3",
"cli-progress": "^3.11.2",
"ms": "^2.1.3",
"pino": "^8.7.0",
"pino-pretty": "^9.1.1",
"prompt": "^1.3.0"
Expand Down
6 changes: 3 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import prompt from "prompt"
import { log } from "./services/logger"
import TimeService from "./services/time"
import { DurationFormatter } from "@sapphire/time-utilities"
import ms from "ms"

const schema = {
properties: {
Expand Down Expand Up @@ -38,10 +38,10 @@ prompt.get(schema, (err: any, result: { url: string }) => {
? `\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 averageTime = new DurationFormatter().format(parseInt(result.averageTime.averageRounded))
const averageTime = ms(result.averageTime.averageRounded)

log.info(
`Detected ${result.joinCount} joins. Average difference between join times rounded is ${averageTime} (${result.averageTime.averageRaw}ms).${zerosString}\n\nTook ${result.timeTaken}.`
`Detected ${result.joinCount} joins. Average difference between join times rounded is ${averageTime}ms (${result.averageTime.averageRaw}ms).${zerosString}.`
)
})
.catch((error) => {
Expand Down
30 changes: 0 additions & 30 deletions src/services/text.ts

This file was deleted.

66 changes: 43 additions & 23 deletions src/services/time.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,31 @@
import { Stopwatch } from "@sapphire/stopwatch"
import TextService from "./text"
import { log } from "./logger"
import { timeDifferenceResult } from "../types/time"
import { logDomains } from "../types/general"
import { logDomains, timeDifferenceResult } from "../types/master"
import cliProgress from "cli-progress"
import axios from "axios"

class TimeService {

/**
* Gets text from a URL.
* @param url The URL to get the text from.
* @returns The text from the URL.
*/
public static getText(url: string) {
log.debug(`Getting text from ${url}.`)
return new Promise((resolve, reject) => {
axios
.get(url)
.then((response) => {
log.debug(`Got text from ${url}.`)
resolve(response.data)
})
.catch((error) => {
log.error(error, `Error getting text from ${url}.`)
reject(error)
})
})
}

public static async timeDifference(
url: string
): Promise<timeDifferenceResult> {
Expand All @@ -15,7 +36,7 @@ class TimeService {
process.exit(1)
}

const text = await TextService.getText(url)
const text = await this.getText(url)
.then((text) => text as string)
.catch((error) => {
log.fatal(error, "Error getting text from URL.")
Expand All @@ -24,8 +45,6 @@ class TimeService {

log.debug("Got text from URL.")

const time = new Stopwatch()

const times = text.match(/\d\d:\d\d:\d\d\.\d\d\d-\d\d\d\d/g)
const zeros: number[] = []
const diffs: number[] = []
Expand All @@ -35,28 +54,29 @@ class TimeService {
process.exit(1)
}

const dates = times.map(
(time) =>
new Date(
Date.parse(
`${new Intl.DateTimeFormat("en-CA", {
timeZone: "America/Los_Angeles",
}).format(Date.now())}T${time.replace(/(\d\d)(\d\d)$/, "$1:$2")}`
)
const bar1 = new cliProgress.SingleBar({}, cliProgress.Presets.shades_classic)
bar1.start(times.length, 0)

const dates: Date[] = []
for (let i = 0; i < times.length; i++) {
bar1.increment()
const date = new Date(
Date.parse(
`${new Intl.DateTimeFormat("en-CA", {
timeZone: "America/Los_Angeles",
}).format(Date.now())}T${times[i].replace(/(\d\d)(\d\d)$/, "$1:$2")}`
)
)
)
dates.push(date)
}

for (let i = 1; i < dates.length; i++) {
bar1.update(i + 1)
const diff = dates[i].getTime() - dates[i - 1].getTime()
diffs.push(diff)
if (diff === 0) {
zeros.push(i)
}
log.debug(
`Difference between join time of ID ${times[i]} and ID ${
times[i - 1]
} is ${diff}ms.`
)
}

const zerosList =
Expand All @@ -65,7 +85,8 @@ class TimeService {
: zeros.join(", ")
const chance = zeros.length / diffs.length
const average = diffs.reduce((a, b) => a + b) / diffs.length
time.stop()

bar1.stop()

return {
averageTime: {
Expand All @@ -79,7 +100,6 @@ class TimeService {
indexArray: zeros,
},
joinCount: diffs.length,
timeTaken: time.toString(),
}
}
}
Expand Down
3 changes: 0 additions & 3 deletions src/types/general.ts

This file was deleted.

5 changes: 3 additions & 2 deletions src/types/time.ts → src/types/master.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const logDomains = ["logs.beemo.gg", "archive.ayu.dev"]

interface averageTime {
averageRaw: number
averageRounded: string
Expand All @@ -14,7 +16,6 @@ interface timeDifferenceResult {
averageTime: averageTime
zeros: zeros
joinCount: number
timeTaken: string
}

export { timeDifferenceResult }
export { logDomains, timeDifferenceResult }
98 changes: 52 additions & 46 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7,49 +7,17 @@
resolved "https://registry.yarnpkg.com/@colors/colors/-/colors-1.5.0.tgz#bb504579c1cae923e6576a4f5da43d25f97bdbd9"
integrity sha512-ooWCrlZP11i8GImSjTHYHLkvFDP48nS4+204nGb1RiX/WXYHmJA2III9/e2DWVabCESdW7hBAEzHRqUn9OUVvQ==

"@sapphire/cron@^1.0.0":
version "1.0.0"
resolved "https://registry.yarnpkg.com/@sapphire/cron/-/cron-1.0.0.tgz#55728f3477c5c1d50a877367d5f10cc84d3af03f"
integrity sha512-pKYfpnHiDFknur3yoquA8cqbJZS140y2oqjshwGGmtjiuIbUngQhPHGwdWHNDKDrF6EKbOK06nd2URE+0eUrfQ==
dependencies:
"@sapphire/utilities" "^3.9.3"

"@sapphire/duration@^1.0.0":
version "1.0.0"
resolved "https://registry.yarnpkg.com/@sapphire/duration/-/duration-1.0.0.tgz#baec4898ee71099093580db774474b25167150ff"
integrity sha512-B+6nKYnBmIlqqbamcR4iBvbQHz6/Kq2JUVM0rA3lQ+aYUYDdcA1Spt66CKtPWwdTYEtSv0VY6Jv27WCtFNYTUg==

"@sapphire/stopwatch@^1.5.0":
version "1.5.0"
resolved "https://registry.yarnpkg.com/@sapphire/stopwatch/-/stopwatch-1.5.0.tgz#4acf7352f969f0c81d69a838ecbfc8b6026ff660"
integrity sha512-DtyKugdy3JTqm6JnEepTY64fGJAqlusDVrlrzifEgSCfGYCqpvB+SBldkWtDH+z+zLcp+PyaFLq7xpVfkhmvGg==
dependencies:
tslib "^2.4.0"

"@sapphire/time-utilities@^1.7.8":
version "1.7.8"
resolved "https://registry.yarnpkg.com/@sapphire/time-utilities/-/time-utilities-1.7.8.tgz#b96cf739e58b1a9776f8c84abcb5915b020bf84d"
integrity sha512-T6X/nwCvKhxmNRexgmA3KwLt3Z+xzlErkre4viflx46hHOmNNb3hoIyQtekgHYrabEaHWNbqW4PW7gC3hBc+ag==
"@types/cli-progress@^3.11.0":
version "3.11.0"
resolved "https://registry.yarnpkg.com/@types/cli-progress/-/cli-progress-3.11.0.tgz#ec79df99b26757c3d1c7170af8422e0fc95eef7e"
integrity sha512-XhXhBv1R/q2ahF3BM7qT5HLzJNlIL0wbcGyZVjqOTqAybAnsLisd7gy1UCyIqpL+5Iv6XhlSyzjLCnI2sIdbCg==
dependencies:
"@sapphire/cron" "^1.0.0"
"@sapphire/duration" "^1.0.0"
"@sapphire/timer-manager" "^1.0.0"
"@sapphire/timestamp" "^1.0.0"

"@sapphire/timer-manager@^1.0.0":
version "1.0.0"
resolved "https://registry.yarnpkg.com/@sapphire/timer-manager/-/timer-manager-1.0.0.tgz#e8ecf15a7042ee611048b4f90fab1399653d3934"
integrity sha512-vxxnv75QPMGKt6IB6nL2xRJfwzcUQ9DBGzJLg6G8eS5O4u7j3IR/yr/GQsa4gIpjw6kQOgn8lUdnSTlpnERTbQ==

"@sapphire/timestamp@^1.0.0":
version "1.0.0"
resolved "https://registry.yarnpkg.com/@sapphire/timestamp/-/timestamp-1.0.0.tgz#572571e8cfc3515265d719704fb2818135f3ad31"
integrity sha512-80g0xYP4zxsgNizMO0HVf+LcM1mD/jxke4feSytDzw8u1pEPr1APfIz3Ix7JB9VI113p0KjLBMywl+ceaN7jrw==
"@types/node" "*"

"@sapphire/utilities@^3.9.3":
version "3.11.0"
resolved "https://registry.yarnpkg.com/@sapphire/utilities/-/utilities-3.11.0.tgz#2dccfb332dc5c119e1425cce6b2c64160b770bad"
integrity sha512-ich7J+329UTEgWxgk8b871rMhbFW/hvXdabdiKaUKd6g10eIMkIakWf+EGkDQsiDSiebIXll9TIPPmWtN3cVSw==
"@types/ms@^0.7.31":
version "0.7.31"
resolved "https://registry.yarnpkg.com/@types/ms/-/ms-0.7.31.tgz#31b7ca6407128a3d2bbc27fe2d21b345397f6197"
integrity sha512-iiUgKzV9AuaEkZqkOLDIvlQiL6ltuZd9tGcW3gwpnX8JbuiuhFlEGmmFXEXkN50Cvq7Os88IY2v0dkDqXYWVgA==

"@types/node@*", "@types/node@^18.11.13":
version "18.11.13"
Expand All @@ -76,6 +44,11 @@ abort-controller@^3.0.0:
dependencies:
event-target-shim "^5.0.0"

ansi-regex@^5.0.1:
version "5.0.1"
resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-5.0.1.tgz#082cb2c89c9fe8659a311a53bd6a4dc5301db304"
integrity sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==

async@3.2.3:
version "3.2.3"
resolved "https://registry.yarnpkg.com/async/-/async-3.2.3.tgz#ac53dafd3f4720ee9e8a160628f18ea91df196c9"
Expand Down Expand Up @@ -132,6 +105,13 @@ buffer@^6.0.3:
base64-js "^1.3.1"
ieee754 "^1.2.1"

cli-progress@^3.11.2:
version "3.11.2"
resolved "https://registry.yarnpkg.com/cli-progress/-/cli-progress-3.11.2.tgz#f8c89bd157e74f3f2c43bcfb3505670b4d48fc77"
integrity sha512-lCPoS6ncgX4+rJu5bS3F/iCz17kZ9MPZ6dpuTtI0KXKABkhyXIdYB3Inby1OpaGti3YlI3EeEkM9AuWpelJrVA==
dependencies:
string-width "^4.2.3"

colorette@^2.0.7:
version "2.0.19"
resolved "https://registry.yarnpkg.com/colorette/-/colorette-2.0.19.tgz#cdf044f47ad41a0f4b56b3a0d5b4e6e1a2d5a798"
Expand Down Expand Up @@ -164,6 +144,11 @@ delayed-stream@~1.0.0:
resolved "https://registry.yarnpkg.com/delayed-stream/-/delayed-stream-1.0.0.tgz#df3ae199acadfb7d440aaae0b29e2272b24ec619"
integrity sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==

emoji-regex@^8.0.0:
version "8.0.0"
resolved "https://registry.yarnpkg.com/emoji-regex/-/emoji-regex-8.0.0.tgz#e818fd69ce5ccfcb404594f842963bf53164cc37"
integrity sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==

end-of-stream@^1.1.0:
version "1.4.4"
resolved "https://registry.yarnpkg.com/end-of-stream/-/end-of-stream-1.4.4.tgz#5ae64a5f45057baf3626ec14da0ca5e4b2431eb0"
Expand Down Expand Up @@ -257,6 +242,11 @@ inherits@2, inherits@^2.0.3:
resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.4.tgz#0fa2c64f932917c3433a0ded55363aae37416b7c"
integrity sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==

is-fullwidth-code-point@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz#f116f8064fe90b3f7844a38997c0b75051269f1d"
integrity sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==

isstream@0.1.x:
version "0.1.2"
resolved "https://registry.yarnpkg.com/isstream/-/isstream-0.1.2.tgz#47e63f7af55afa6f92e1500e690eb8b8529c099a"
Expand Down Expand Up @@ -296,6 +286,11 @@ minimist@^1.2.6:
resolved "https://registry.yarnpkg.com/minimist/-/minimist-1.2.7.tgz#daa1c4d91f507390437c6a8bc01078e7000c4d18"
integrity sha512-bzfL1YUZsP41gmu/qjrEk0Q6i2ix/cVeAhbCbqH9u3zYutS1cLg00qhrD0M2MVdCcx4Sc0UpP2eBWo9rotpq6g==

ms@^2.1.3:
version "2.1.3"
resolved "https://registry.yarnpkg.com/ms/-/ms-2.1.3.tgz#574c8138ce1d2b5861f0b44579dbadd60c6615b2"
integrity sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==

mute-stream@~0.0.4:
version "0.0.8"
resolved "https://registry.yarnpkg.com/mute-stream/-/mute-stream-0.0.8.tgz#1630c42b2251ff81e2a283de96a5497ea92e5e0d"
Expand Down Expand Up @@ -470,13 +465,29 @@ stack-trace@0.0.x:
resolved "https://registry.yarnpkg.com/stack-trace/-/stack-trace-0.0.10.tgz#547c70b347e8d32b4e108ea1a2a159e5fdde19c0"
integrity sha512-KGzahc7puUKkzyMt+IqAep+TVNbKP+k2Lmwhub39m1AsTSkaDutx56aDCo+HLDzf/D26BIHTJWNiTG1KAJiQCg==

string-width@^4.2.3:
version "4.2.3"
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
dependencies:
emoji-regex "^8.0.0"
is-fullwidth-code-point "^3.0.0"
strip-ansi "^6.0.1"

string_decoder@^1.1.1:
version "1.3.0"
resolved "https://registry.yarnpkg.com/string_decoder/-/string_decoder-1.3.0.tgz#42f114594a46cf1a8e30b0a84f56c78c3edac21e"
integrity sha512-hkRX8U1WjJFd8LsDJ2yQ/wWWxaopEsABU1XfkM8A+j0+85JAGppt16cr1Whg6KIbb4okU6Mql6BOj+uup/wKeA==
dependencies:
safe-buffer "~5.2.0"

strip-ansi@^6.0.1:
version "6.0.1"
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
dependencies:
ansi-regex "^5.0.1"

strip-json-comments@^3.1.1:
version "3.1.1"
resolved "https://registry.yarnpkg.com/strip-json-comments/-/strip-json-comments-3.1.1.tgz#31f1281b3832630434831c310c01cccda8cbe006"
Expand All @@ -489,11 +500,6 @@ thread-stream@^2.0.0:
dependencies:
real-require "^0.2.0"

tslib@^2.4.0:
version "2.4.1"
resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.4.1.tgz#0d0bfbaac2880b91e22df0768e55be9753a5b17e"
integrity sha512-tGyy4dAjRIEwI7BzsB0lynWgOpfqjUdq91XXAlIWD2OwKBH7oCl/GZG/HT4BOHrTlPMOASlMQ7veyTqpmRcrNA==

util-deprecate@^1.0.1:
version "1.0.2"
resolved "https://registry.yarnpkg.com/util-deprecate/-/util-deprecate-1.0.2.tgz#450d4dc9fa70de732762fbd2d4a28981419a0ccf"
Expand Down