feat: add cron

This commit is contained in:
TrèsAbhi committed 2024-06-28 20:08:50 -05:00
1 parent ffaa368f81
commit ed17366365
10 files changed
+87 -21

No files matched your search

+2 -2
View File
@@ -2,8 +2,8 @@ name: CD Averages
on:
workflow_dispatch:
# schedule:
# - cron: '0 12 * * 0'
schedule:
- cron: '0 0 * * 2'
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
BIN
View File
Binary file not shown.
+22 -16
View File
@@ -11,7 +11,9 @@ import {
AverageDefinitionsEntrySubPartial,
} from '../src/core/blitzkit/averageDefinitions';
import { averageDefinitionsAllStatsKeys } from '../src/core/blitzkit/averageDefinitions/constants';
import { commitAssets } from '../src/core/blitzkit/commitAssets';
import { fetchPreDiscoveredIds } from '../src/core/blitzkit/fetchPreDiscoveredIds';
import { encodeToBase64 } from '../src/core/protobuf/encodeToBase64';
interface DataPoint {
x: number;
@@ -21,7 +23,7 @@ interface DataPoint {
const MAX_ACTIVITY_TIME = 1000 * 60 * 60 * 24 * 120;
const MIN_BATTLES = 5000;
const RUN_TIME = 1000 * 60;
const RUN_TIME = 1000 * 60 * 60 * 5.9;
const THREADS = 10;
const PLAYER_IDS_PER_CALL = 100;
@@ -39,7 +41,8 @@ const regionalIndices: Record<Region, number> = {
eu: 0,
};
let regionIndex = 0;
let playerCount = 0;
let checkedPlayers = 0;
let includedPlayers = 0;
const availableRegions = [...REGIONS];
const tankIds: number[] = [];
const tanksSorted: Record<number, AverageDefinitionsAllStats[]> = {};
@@ -50,6 +53,7 @@ times(THREADS, async () => {
const region = availableRegions[regionIndex];
const idIndex = regionalIndices[region];
const ids = playerIds[region].slice(idIndex, idIndex + PLAYER_IDS_PER_CALL);
checkedPlayers += PLAYER_IDS_PER_CALL;
const accountInfo = await getAccountInfo(region, ids, undefined, {
fields: 'last_battle_time,statistics.all.battles',
});
@@ -70,7 +74,7 @@ times(THREADS, async () => {
info.statistics.all.battles > MIN_BATTLES
);
});
playerCount += filteredIds.length;
includedPlayers += filteredIds.length;
const players = await Promise.all(
filteredIds.map((id) => getTankStats(region, id)),
);
@@ -109,7 +113,7 @@ times(THREADS, async () => {
async function postWork() {
console.log(
`Generating statistics based off ${playerCount} players and ${tankIds.length} tanks...`,
`Generating statistics based off ${includedPlayers.toLocaleString()} players (${checkedPlayers.toLocaleString()} checked in total) and ${tankIds.length} tanks...`,
);
const averages: AverageDefinitions = {};
@@ -157,21 +161,23 @@ async function postWork() {
entry.mu[key] = mu;
entry.sigma[key] = sigma;
entry.r[key] = r;
entry.r[key] = isNaN(r) ? 0 : r;
});
averages[id] = entry as AverageDefinitionsEntry;
});
// commitAssets(
// 'averages',
// [
// {
// path: 'definitions/averages.cdon.lz4',
// content: superCompress(averages),
// encoding: 'base64',
// },
// ],
// production,
// );
commitAssets(
'averages',
[
{
path: 'definitions/averages.pb',
content: await encodeToBase64('blitzkit.AverageDefinitions', {
averages,
}),
encoding: 'base64',
},
],
production,
);
}
-2
View File
@@ -5,7 +5,6 @@ export async function commitAssets(
message: string,
changes: FileChange[],
production: boolean,
verbose = true,
) {
console.log(`Committing ${message}...`);
@@ -17,6 +16,5 @@ export async function commitAssets(
production ? 'main' : 'dev',
`${message} - ${new Date().toDateString()}`,
changes,
verbose,
);
}
-1
View File
@@ -14,7 +14,6 @@ export default async function commitMultipleFiles(
branch: string,
message: string,
changes: FileChange[],
verbose = false,
) {
const latestCommitSha = (
await octokit.git.getRef({
+6
View File
@@ -0,0 +1,6 @@
import { lookup } from './lookup';
export async function decode(proto: string, data: Uint8Array) {
const Message = await lookup(proto);
return Message.decode(data).toJSON();
}
+6
View File
@@ -0,0 +1,6 @@
import { lookup } from './lookup';
export async function encode(proto: string, data: any) {
const Message = await lookup(proto);
return Message.encode(Message.create(data)).finish();
}
+6
View File
@@ -0,0 +1,6 @@
import { encode } from './encode';
export async function encodeToBase64(proto: string, data: any) {
const array = await encode(proto, data);
return Buffer.from(array).toString('base64');
}
+10
View File
@@ -0,0 +1,10 @@
import { Root } from 'protobufjs';
export async function lookup(proto: string) {
const root = await new Root().load(
`src/protos/${proto.split('.')[0]}.proto`,
{ keepCase: true },
);
return root.lookupType(proto);
}
+35
View File
@@ -0,0 +1,35 @@
syntax = "proto3";
package blitzkit;
message AverageDefinitions {
map<uint32, Tank> averages = 1;
}
message Tank {
uint32 samples = 1;
AverageDefinitionsAllStats mu = 2;
AverageDefinitionsAllStats sigma = 3;
AverageDefinitionsAllStats r = 4;
}
message AverageDefinitionsAllStats {
float battles = 1;
float capture_points = 2;
float damage_dealt = 3;
float damage_received = 4;
float dropped_capture_points = 5;
float frags = 6;
float frags8p = 7;
float hits = 8;
float losses = 9;
float max_frags = 10;
float max_xp = 11;
float shots = 12;
float spotted = 13;
float survived_battles = 14;
float win_and_survived = 15;
float wins = 16;
float xp = 17;
float battle_life_time = 18;
}