Skip to content

Commit

Permalink
Adds support for any null field in telemetry JSON.
Browse files Browse the repository at this point in the history
  • Loading branch information
mntone committed Jun 20, 2024
1 parent a47f5f1 commit ff3aed0
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
6 changes: 3 additions & 3 deletions src/modules/telemetry/models/telemetry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ export type ShakeGameKingEvent = ShakeBaseEvent & {
export type ShakeGameUpdateEvent = ShakeBaseEvent & {
event: 'game_update'
color: ShakeColor
count: number
count?: number
unstable: boolean
} & ({
wave: number
amount: number
wave?: number
amount?: number
quota: number
} | {
wave: 'extra'
Expand Down
24 changes: 19 additions & 5 deletions src/modules/telemetry/utils/processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,24 @@ export class TelemetryProcessor {
const diffTimestamp = ev.timestamp - this.#waveData.startTimestamp
if (diffTimestamp <= this.#baseCount) {
currentWave = this.#currentWave // Restore
} else {
} else if (currentWave !== undefined) {
// The "wave" is clearly strange
const nextWave = this.#currentWave + Math.min(5, Math.floor(diffTimestamp / 108))
if (ev.wave < this.#currentWave || ev.wave > nextWave) {
if (currentWave < this.#currentWave || currentWave > nextWave) {
return // DISPOSE!!
}
} else {
return // DISPOSE!!
}
} else if (currentWave === undefined) {
return // DISPOSE!!
}

if (this.#currentWave !== currentWave) {
if (ev.count === undefined) {
return // DISPOSE!!
}

this.#quotaCounter.reset(ev.quota)
this.#baseCount = ev.count
this.#currentWave = currentWave
Expand All @@ -94,13 +102,13 @@ export class TelemetryProcessor {
const newWaveData: ShakeDefaultWave = {
wave: currentWave as DefaultWaveType,
startTimestamp: ev.timestamp,
amount: ev.amount,
amount: ev.amount ?? 0 /* MAYBE 0 */,
quota: this.#quotaCounter.mode,
updates: [
{
timestamp: ev.timestamp,
count: ev.count,
amount: ev.amount,
amount: ev.amount ?? 0 /* MAYBE 0 */,
unstable: ev.unstable,
},
],
Expand All @@ -120,6 +128,8 @@ export class TelemetryProcessor {
currentWaveData.endTimestamp = ev.timestamp
}
break
case undefined:
break
default:
if (this.#baseCount >= 100) {
this.#baseCount = ev.count
Expand All @@ -135,6 +145,10 @@ export class TelemetryProcessor {
throw Error('Wave update is empty.')
}

if (ev.amount === undefined) {
return // DISPOSE!!
}

const diffAmount = ev.amount - lastUpdate.amount
if (diffAmount < 0) {
return // DISPOSE!!
Expand All @@ -153,7 +167,7 @@ export class TelemetryProcessor {
// Create new update data
const newUpdateData: ShakeUpdate = {
timestamp: ev.timestamp,
count: ev.count,
count: ev.count ?? Math.floor(currentWaveData.startTimestamp - ev.timestamp + 100),
amount: ev.amount,
unstable: ev.unstable,
} as const
Expand Down

0 comments on commit ff3aed0

Please sign in to comment.