diff --git a/src/handlers/aggregate/VehicleAggregateHandler.ts b/src/handlers/aggregate/VehicleAggregateHandler.ts index 5dc8d101..1c95f2c3 100644 --- a/src/handlers/aggregate/VehicleAggregateHandler.ts +++ b/src/handlers/aggregate/VehicleAggregateHandler.ts @@ -161,6 +161,7 @@ export default class VehicleAggregateHandler implements AggregateHandlerInterfac [{ vehicle: event.vehicleId, world: event.instance.world, + ps2AlertsEventType: event.instance.ps2AlertsEventType, }], ), event.instance.duration); @@ -171,6 +172,7 @@ export default class VehicleAggregateHandler implements AggregateHandlerInterfac [{ vehicle: event.vehicleId, world: event.instance.world, + ps2AlertsEventType: event.instance.ps2AlertsEventType, }], Bracket.TOTAL, )); @@ -180,9 +182,10 @@ export default class VehicleAggregateHandler implements AggregateHandlerInterfac event.instance.instanceId, documents.victimDocs, [{ - vehicle: event.attackerVehicleId, + vehicle: event.vehicleId, world: event.instance.world, character: event.character.id, + ps2AlertsEventType: event.instance.ps2AlertsEventType, }], ), event.instance.duration); @@ -191,9 +194,10 @@ export default class VehicleAggregateHandler implements AggregateHandlerInterfac event.instance.instanceId, documents.victimDocs, [{ - vehicle: event.attackerVehicleId, + vehicle: event.vehicleId, world: event.instance.world, character: event.character.id, + ps2AlertsEventType: event.instance.ps2AlertsEventType, }], Bracket.TOTAL, )); diff --git a/src/handlers/aggregate/VehicleDeathEventHandler.ts b/src/handlers/aggregate/VehicleDeathEventHandler.ts index 2007094a..fdd01c48 100644 --- a/src/handlers/aggregate/VehicleDeathEventHandler.ts +++ b/src/handlers/aggregate/VehicleDeathEventHandler.ts @@ -47,6 +47,7 @@ export default class VehicleDeathEventHandler implements AggregateHandlerInterfa [{ instance: event.instance.instanceId, vehicle: event.attackerVehicleId, + ps2AlertsEventType: event.instance.ps2AlertsEventType, }], )); @@ -57,6 +58,7 @@ export default class VehicleDeathEventHandler implements AggregateHandlerInterfa instance: event.instance.instanceId, vehicle: event.attackerVehicleId, character: event.attackerCharacter.id, + ps2AlertsEventType: event.instance.ps2AlertsEventType, }], )); } catch (err) { @@ -79,6 +81,7 @@ export default class VehicleDeathEventHandler implements AggregateHandlerInterfa [{ world: event.instance.world, vehicle: event.attackerVehicleId, + ps2AlertsEventType: event.instance.ps2AlertsEventType, }], ), event.instance.duration); @@ -89,6 +92,7 @@ export default class VehicleDeathEventHandler implements AggregateHandlerInterfa [{ world: event.instance.world, vehicle: event.attackerVehicleId, + ps2AlertsEventType: event.instance.ps2AlertsEventType, }], Bracket.TOTAL, )); @@ -100,7 +104,8 @@ export default class VehicleDeathEventHandler implements AggregateHandlerInterfa [{ world: event.instance.world, vehicle: event.attackerVehicleId, - character: event.character.id, + character: event.attackerCharacter.id, + ps2AlertsEventType: event.instance.ps2AlertsEventType, }], ), event.instance.duration); @@ -111,7 +116,8 @@ export default class VehicleDeathEventHandler implements AggregateHandlerInterfa [{ world: event.instance.world, vehicle: event.attackerVehicleId, - character: event.character.id, + character: event.attackerCharacter.id, + ps2AlertsEventType: event.instance.ps2AlertsEventType, }], Bracket.TOTAL, )); diff --git a/src/handlers/aggregate/global/GlobalCharacterAggregate.ts b/src/handlers/aggregate/global/GlobalCharacterAggregate.ts index b314a515..6d9c4475 100644 --- a/src/handlers/aggregate/global/GlobalCharacterAggregate.ts +++ b/src/handlers/aggregate/global/GlobalCharacterAggregate.ts @@ -31,13 +31,13 @@ export default class GlobalCharacterAggregate implements AggregateHandlerInterfa const victimDocs = []; attackerDocs.push({$setOnInsert: { - world: event.character.world, + world: event.instance.world, character: event.attackerCharacter, ps2AlertsEventType: event.instance.ps2AlertsEventType, }}); victimDocs.push({$setOnInsert: { - world: event.character.world, + world: event.instance.world, character: event.character, ps2AlertsEventType: event.instance.ps2AlertsEventType, }}); @@ -48,7 +48,7 @@ export default class GlobalCharacterAggregate implements AggregateHandlerInterfa // Keep the character's outfit, battle rank and ASP updated attackerDocs.push({ $set: { - 'character.battle_rank': event.attackerCharacter.battleRank, + 'character.battleRank': event.attackerCharacter.battleRank, 'character.asp': event.attackerCharacter.asp, 'character.adjustedBattleRank': event.attackerCharacter.adjustedBattleRank, 'character.outfit': event.attackerCharacter.outfit, @@ -57,7 +57,7 @@ export default class GlobalCharacterAggregate implements AggregateHandlerInterfa victimDocs.push({ $set: { - 'character.battle_rank': event.character.battleRank, + 'character.battleRank': event.character.battleRank, 'character.asp': event.character.asp, 'character.adjustedBattleRank': event.character.adjustedBattleRank, 'character.outfit': event.character.outfit, diff --git a/src/handlers/aggregate/global/GlobalFacilityControlAggregate.ts b/src/handlers/aggregate/global/GlobalFacilityControlAggregate.ts index 1eb62a46..f53de10d 100644 --- a/src/handlers/aggregate/global/GlobalFacilityControlAggregate.ts +++ b/src/handlers/aggregate/global/GlobalFacilityControlAggregate.ts @@ -66,7 +66,8 @@ export default class GlobalFacilityControlAggregate implements AggregateHandlerI documents, [{ world: event.instance.world, - facility: event.facility, + // Match on the id alone: facility metadata changes over time, and a full-object match then misses the row + 'facility.id': event.facility.id, ps2AlertsEventType: event.instance.ps2AlertsEventType, }], Bracket.TOTAL, diff --git a/src/handlers/aggregate/global/GlobalFactionCombatAggregate.ts b/src/handlers/aggregate/global/GlobalFactionCombatAggregate.ts index 77152660..e073aaeb 100644 --- a/src/handlers/aggregate/global/GlobalFactionCombatAggregate.ts +++ b/src/handlers/aggregate/global/GlobalFactionCombatAggregate.ts @@ -10,7 +10,7 @@ import ApiMQGlobalAggregateMessage from '../../../data/ApiMQGlobalAggregateMessa import ApiMQPublisher from '../../../modules/rabbitmq/publishers/ApiMQPublisher'; import {Bracket} from '../../../ps2alerts-constants/bracket'; import ExceptionHandler from '../../system/ExceptionHandler'; -import {format} from 'date-fns'; +import {utcDay} from '../../../utils/utcDay'; @Injectable() export default class GlobalFactionCombatAggregate implements AggregateHandlerInterface { @@ -86,7 +86,8 @@ export default class GlobalFactionCombatAggregate implements AggregateHandlerInt documents, [{ world: event.instance.world, - date: format(new Date(), 'yyyy-MM-dd'), + // An alert counts wholly on the day it started, so a rebuild from per-alert rows can reproduce it + date: utcDay(event.instance.timeStarted), ps2AlertsEventType: event.instance.ps2AlertsEventType, }], ), event.instance.duration); @@ -98,7 +99,8 @@ export default class GlobalFactionCombatAggregate implements AggregateHandlerInt documents, [{ world: event.instance.world, - date: format(new Date(), 'yyyy-MM-dd'), + // An alert counts wholly on the day it started, so a rebuild from per-alert rows can reproduce it + date: utcDay(event.instance.timeStarted), ps2AlertsEventType: event.instance.ps2AlertsEventType, }], Bracket.TOTAL, diff --git a/src/handlers/aggregate/global/GlobalVictoryAggregate.ts b/src/handlers/aggregate/global/GlobalVictoryAggregate.ts index c797723b..8ed8cf1d 100644 --- a/src/handlers/aggregate/global/GlobalVictoryAggregate.ts +++ b/src/handlers/aggregate/global/GlobalVictoryAggregate.ts @@ -9,7 +9,7 @@ import ApiMQGlobalAggregateMessage from '../../../data/ApiMQGlobalAggregateMessa import ApiMQPublisher from '../../../modules/rabbitmq/publishers/ApiMQPublisher'; import {Bracket} from '../../../ps2alerts-constants/bracket'; import ExceptionHandler from '../../system/ExceptionHandler'; -import {format} from 'date-fns'; +import {utcDay} from '../../../utils/utcDay'; @Injectable() export default class GlobalVictoryAggregate implements AggregateHandlerInterface { @@ -49,7 +49,7 @@ export default class GlobalVictoryAggregate implements AggregateHandlerInterface [{ world: event.world, zone: event.zone, - date: format(new Date(), 'yyyy-MM-dd'), + date: utcDay(event.timeEnded ?? new Date()), ps2AlertsEventType: event.ps2AlertsEventType, }], )); @@ -61,7 +61,7 @@ export default class GlobalVictoryAggregate implements AggregateHandlerInterface [{ world: event.world, zone: event.zone, - date: format(new Date(), 'yyyy-MM-dd'), + date: utcDay(event.timeEnded ?? new Date()), ps2AlertsEventType: event.ps2AlertsEventType, }], Bracket.TOTAL, diff --git a/src/handlers/aggregate/instance/InstanceFacilityControlAggregate.ts b/src/handlers/aggregate/instance/InstanceFacilityControlAggregate.ts index 402c4c17..bde8ad1c 100644 --- a/src/handlers/aggregate/instance/InstanceFacilityControlAggregate.ts +++ b/src/handlers/aggregate/instance/InstanceFacilityControlAggregate.ts @@ -49,7 +49,8 @@ export default class InstanceFacilityControlAggregate implements AggregateHandle documents, [{ instance: event.instance.instanceId, - facility: event.facility, + // Match on the id alone: facility metadata changes over time, and a full-object match then misses the row + 'facility.id': event.facility.id, ps2AlertsEventType: event.instance.ps2AlertsEventType, }], )); diff --git a/src/handlers/ps2census/events/FacilityControlEvent.ts b/src/handlers/ps2census/events/FacilityControlEvent.ts index 55badd80..41965908 100644 --- a/src/handlers/ps2census/events/FacilityControlEvent.ts +++ b/src/handlers/ps2census/events/FacilityControlEvent.ts @@ -64,7 +64,8 @@ export default class FacilityControlEvent extends InstanceEvent { this.isDefence = this.oldFaction === this.newFaction; - this.outfitCaptured = event.payload.outfit_id ? event.payload.outfit_id : null; + // Census sends "0" when no outfit took the base, and the string "0" is truthy + this.outfitCaptured = event.payload.outfit_id && event.payload.outfit_id !== '0' ? event.payload.outfit_id : null; // Used to render capture histories on the website // Can't use a switch statement here as TS doesn't understand the faction references that don't exist diff --git a/src/modules/rabbitmq/publishers/ApiMQDelayPublisher.ts b/src/modules/rabbitmq/publishers/ApiMQDelayPublisher.ts index f72e8569..0da31b8d 100644 --- a/src/modules/rabbitmq/publishers/ApiMQDelayPublisher.ts +++ b/src/modules/rabbitmq/publishers/ApiMQDelayPublisher.ts @@ -47,6 +47,11 @@ export default class ApiMQDelayPublisher implements RabbitMQQueueWrapperInterfac return; } + // Delayed messages only feed bracket rows, which Outfit Wars never has; the API would drop them anyway + if (msg.data.instance.startsWith('outfitwars')) { + return; + } + const queue = duration === shortAlert ? this.shortQueue : this.longQueue; try { diff --git a/src/utils/utcDay.ts b/src/utils/utcDay.ts new file mode 100644 index 00000000..3d4ee1a4 --- /dev/null +++ b/src/utils/utcDay.ts @@ -0,0 +1,2 @@ +// Global daily rows are keyed by UTC day, whatever timezone the process runs in +export const utcDay = (date: Date): string => new Date(date).toISOString().slice(0, 10);