diff --git a/local-run.js b/local-run.js index 1083c95..f8af24f 100644 --- a/local-run.js +++ b/local-run.js @@ -14,25 +14,27 @@ const doProcess = async () => { await handler({ // crealmIds: [100, 104, 106, 1070, 1071, 1072, 11, 1129, 113, 1136, 1138, 114, 1147, 115, 1151, 1168], // dungeonIds: [391,392,370,369], - crealmIds: [ - 3694, 1168, 151, 4, 5, 3661, 127, 9, 121, 11, - 12, 1190, 104, 155, 3693, 47, 52, 53, 54, 55, - 1129, 57, 58, 3684, 60, 61, 63, 64, 3683, 67, - 1175, 69, 77, 71, 157, 73, 96, 75, 76, 78, - 154, 1136, 84, 86, 113, 125, 1138, 99, 100, 106, - 1185, 114, 115, 117, 118, 120, 158, 160, 162, 163, - 1070, 1071, 1072, 1147, 1151, 1184, 3678, 3685, 1426, 3675, - 1171, 1425, 1427, 1428, 3676, 3207, 3208, 3209, 3234, 3721, - 3726, 3723, 3725 - ], - dungeonIds: [ + // crealmIds: [ + // 3694, 1168, 151, 4, 5, 3661, 127, 9, 121, 11, + // 12, 1190, 104, 155, 3693, 47, 52, 53, 54, 55, + // 1129, 57, 58, 3684, 60, 61, 63, 64, 3683, 67, + // 1175, 69, 77, 71, 157, 73, 96, 75, 76, 78, + // 154, 1136, 84, 86, 113, 125, 1138, 99, 100, 106, + // 1185, 114, 115, 117, 118, 120, 158, 160, 162, 163, + // 1070, 1071, 1072, 1147, 1151, 1184, 3678, 3685, 1426, 3675, + // 1171, 1425, 1427, 1428, 3676, 3207, 3208, 3209, 3234, 3721, + // 3726, 3723, 3725 + // ], + // dungeonIds: [ 227 //166, 169, 227, //234, 369, 370, - 391, 392 - ], - period: 874, - afterEpoch: 0,//Date.now()-86360, - isAGlobalScan: true + // 391, 392 + // 391 + // ], + // period: 999 + // period: 875, + // afterEpoch: 0,//Date.now()-86360, + // isAGlobalScan: true }); console.log('success.'); diff --git a/src/get-snapshot.js b/src/get-snapshot.js index 4918de0..2433d29 100644 --- a/src/get-snapshot.js +++ b/src/get-snapshot.js @@ -1,11 +1,61 @@ const { queueUntilResolved, - getMythicLeaderboard + getMythicLeaderboard, + getDb } = require('@dungeoneer-io/nodejs-utils'); const { mapApiRunToRun } = require('./bapi-mapper/run-snapshot'); +const { + COLLECTIONS, + DATABASES +} = require('./entity-enums'); + +const getPeriodFixture = async (periodid) => { + const fixtureCollection = await getDb() + .db(DATABASES.DEFAULT) + .collection(COLLECTIONS.PERIODFIXTURES); + + console.log(`retrieving snapshot ${ periodid }`); + let snapshot; + + if (periodid) { + snapshot = await fixtureCollection.findOne({ _id: periodid }); + } + if (!snapshot) { + console.log('undefined or unavailable fixture, using latest'); + snapshot = await fixtureCollection.findOne({}, { sort: {$natural:-1}}); + } + + const periodFixture = { + dungeonIds: Object.keys(snapshot.dungeonMap), + crealmIds: [...new Set(Object.values(snapshot.rlmToCrlm))], + period: snapshot._id + }; + + return periodFixture; +}; const getSnapshot = async (lambdaEvent) => { - const { crealmIds, dungeonIds, period, afterEpoch = 0, isAGlobalScan = false } = lambdaEvent; + let { + crealmIds, + dungeonIds, + period, + afterEpoch = 0, + isAGlobalScan = false + } = lambdaEvent; + + if (!crealmIds || !dungeonIds || !period) { + const periodFixture = await getPeriodFixture(period); + + if (!crealmIds) { + crealmIds = periodFixture.crealmIds; + } + + if (!dungeonIds) { + dungeonIds = [periodFixture.dungeonIds[0]]; + } + + period = periodFixture.period; + } const fetchLeaderboardAndTransformResult = async ({ afterEpoch,