Skip to content
Open
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: 6 additions & 2 deletions src/handlers/aggregate/VehicleAggregateHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ export default class VehicleAggregateHandler implements AggregateHandlerInterfac
[{
vehicle: event.vehicleId,
world: event.instance.world,
ps2AlertsEventType: event.instance.ps2AlertsEventType,
}],
), event.instance.duration);

Expand All @@ -171,6 +172,7 @@ export default class VehicleAggregateHandler implements AggregateHandlerInterfac
[{
vehicle: event.vehicleId,
world: event.instance.world,
ps2AlertsEventType: event.instance.ps2AlertsEventType,
}],
Bracket.TOTAL,
));
Expand All @@ -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);

Expand All @@ -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,
));
Expand Down
10 changes: 8 additions & 2 deletions src/handlers/aggregate/VehicleDeathEventHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export default class VehicleDeathEventHandler implements AggregateHandlerInterfa
[{
instance: event.instance.instanceId,
vehicle: event.attackerVehicleId,
ps2AlertsEventType: event.instance.ps2AlertsEventType,
}],
));

Expand All @@ -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) {
Expand All @@ -79,6 +81,7 @@ export default class VehicleDeathEventHandler implements AggregateHandlerInterfa
[{
world: event.instance.world,
vehicle: event.attackerVehicleId,
ps2AlertsEventType: event.instance.ps2AlertsEventType,
}],
), event.instance.duration);

Expand All @@ -89,6 +92,7 @@ export default class VehicleDeathEventHandler implements AggregateHandlerInterfa
[{
world: event.instance.world,
vehicle: event.attackerVehicleId,
ps2AlertsEventType: event.instance.ps2AlertsEventType,
}],
Bracket.TOTAL,
));
Expand All @@ -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);

Expand All @@ -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,
));
Expand Down
8 changes: 4 additions & 4 deletions src/handlers/aggregate/global/GlobalCharacterAggregate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}});
Expand All @@ -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,
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 5 additions & 3 deletions src/handlers/aggregate/global/GlobalFactionCombatAggregate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<DeathEvent> {
Expand Down Expand Up @@ -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);
Expand All @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions src/handlers/aggregate/global/GlobalVictoryAggregate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<MetagameTerritoryInstance> {
Expand Down Expand Up @@ -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,
}],
));
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}],
));
Expand Down
3 changes: 2 additions & 1 deletion src/handlers/ps2census/events/FacilityControlEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions src/modules/rabbitmq/publishers/ApiMQDelayPublisher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 2 additions & 0 deletions src/utils/utcDay.ts
Original file line number Diff line number Diff line change
@@ -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);
Loading