Maelstromeous / ps2alerts-ws

The websocket server behind the website PS2Alerts.com
MIT License
0 stars 0 forks source link

Batch Processing Documentation #9

Open Maelstromeous opened 8 years ago

Maelstromeous commented 8 years ago

Batch update interval found on line 2212

There is a batch updating system for incremental updates of metrics. This is to prevent a query overload of the Database as it would otherwise be doing on every single instance of the metric.

Faction Stats

Object: factionUpdates Updater: updateFactionStats Processor: batchUpdateFactionStats Table: ws_factions AND ws_factions_totals

{
    12345: { // ResultID
        killsVS: 0,
        killsNC: 0,
        killsTR: 0,
        deathsVS: 0,
        deathsNC: 0,
        deathsTR: 0,
        teamKillsVS: 0,
        teamKillsNC: 0,
        teamKillsTR: 0,
        suicidesVS: 0,
        suicidesNC: 0,
        suicidesTR: 0,
        totalKills: 0,
        totalDeaths: 0,
        totalTKs: 0,
        totalSuicides: 0
    };
}

Each value gets incremented using the function updateFactionStats. This takes the combatArray and generates metrics based off the values of that object.

Batch function batchUpdateFactionStats is then called which takes the object's values and commits them to database.

XP Totals

Object: xpTotalsUpdates Updater: insertExperience Processor: batchUpdateXpTotals Table: ws_xp_totals

Line 2822 checks if the object key exists, if not, initializes it. Line 2827 then increments the record.

xpTotalsUpdates {
    4: 12345,
    5: 67890
}

Contains any of the following keys:

var allowedXPTypes = [4,5,6,7,8,10,11,15,16,25,26,29,26,32,34,37,51,53,54,55,56,131,132,133,134,135,136,137,138,139,140,141,142,201,236,237,240,241,270,272,275,276,277,278,279,293,294,370,437,438,439,556,557,579,584,592];

Outfit Totals

Object: outfitTotalsUpdates Updater: insertOutfitStats Processor: batchUpdateOutfitTotals Table: ws_outfits AND ws_outfits_total @ Line 1872 and beyond, each outfit (killer and/or victim) ID is checked and created if necessary. This includes initializing the resultID object.

@ Line 1906 and beyond, the metrics are calculated.

outfitTotalsUpdates[resultID][deathOutfit] =
{
    outfitKills: 0,
    outfitDeaths: 0,
    outfitTKs: 0,
    outfitSuicides: 0,
    world: worldID,
    outfitName: combatArray.vOutfit.name,
    outfitTag: combatArray.vOutfit.tag,
    outfitFaction: combatArray.victimFaction,
};

This batch updater does twofold updates for the total for the outfit globally, and just for the alert itself, via increment statements. e.g. SET outfitKills=outfitKills+1234

Class Totals

Object: classTotalsUpdates AND classPlayerUpdates Updater: insertClassStats Processor: batchUpdateClassTotals Table: ws_classes

Very similar to Outfit Totals, however they are using loadoutIDs instead of outfit IDs.

classTotalsUpdates[resultID][victimLoadout] =
{
    kills: 0,
    deaths: 0,
    teamkills: 0,
    suicides: 0
};

classPlayerUpdates

However, this function also does something extra, which is process individual player class statistics as well, which starts on line 2920.

This object has two levels of indentation:

classPlayerUpdates[resultID][attackerLoadout][attackerID] =
{
    kills: 0,
    deaths: 0,
    teamkills: 0,
    suicides: 0
};

The processing for both the class and the individual players starts on line 2961.

Maelstromeous commented 8 years ago

@KBraham Moved this into it's own issue for you for easier tracking.

Maelstromeous commented 8 years ago

Documentation complete.