Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support multiple game modes #535

Merged
merged 11 commits into from
Jun 25, 2024
Merged
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
4 changes: 2 additions & 2 deletions src/tarkov-data-manager/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -1883,7 +1883,7 @@ app.get('/presets', async (req, res) => {
<h5></h5>
<h6></h6>
<div class="row">
<form class="col s12 post-url" method="post" action="/presets">
<form class="col s12 post-url" method="put" action="/presets">
<div class="row">
<div class="input-field s12">
<input value="" id="append_name" type="text" class="validate append_name" name="append_name" placeholder=" ">
Expand All @@ -1895,7 +1895,7 @@ app.get('/presets', async (req, res) => {
</div>
</div>
<div class="modal-footer">
<a href="#!" class="waves-effect waves-green btn edit-wipe-save">Save</a>
<a href="#!" class="waves-effect waves-green btn edit-preset-save">Save</a>
<a href="#!" class="modal-close waves-effect waves-green btn-flat">Close</a>
</div>
</div>
Expand Down
10 changes: 5 additions & 5 deletions src/tarkov-data-manager/jobs/archive-prices.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ class ArchivePricesJob extends DataJob {

// archive max_days_per_run number of days
for (let i = 0; i < max_days_per_run; i++) {
for (let gameMode = 0; gameMode < 2; gameMode++) {
const gameModeName = gameMode ? 'pve' : 'regular';
for (const gameMode of this.gameModes) {
const gameModeName = gameMode.name;
// get the price with the oldest timestamp
const oldestPrice = await this.query(`
SELECT * FROM price_data
WHERE timestamp < ? AND game_mode = ?
ORDER BY timestamp
LIMIT 1
`, [cutoff, gameMode]);
`, [cutoff, gameMode.value]);
if (oldestPrice.length === 0) {
this.logger.success(`No ${gameModeName} prices found before ${cutoff}`);
return;
Expand All @@ -47,12 +47,12 @@ class ArchivePricesJob extends DataJob {
FROM price_data
WHERE timestamp >= ? AND timestamp < ? + INTERVAL 1 DAY AND game_mode = ?
GROUP BY item_id
`, [archiveDate, archiveDate, gameMode]);
`, [archiveDate, archiveDate, gameMode.value]);

// add min and average prices to price archive insert
const insertValues = [];
for (const itemPrice of itemPrices) {
insertValues.push(itemPrice.item_id, archiveDate, itemPrice.min_price, Math.round(itemPrice.avg_price), gameMode);
insertValues.push(itemPrice.item_id, archiveDate, itemPrice.min_price, Math.round(itemPrice.avg_price), gameMode.value);
}

// insert archived prices
Expand Down
4 changes: 2 additions & 2 deletions src/tarkov-data-manager/jobs/game-data.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ class GameDataJob extends DataJob {
await this.jobManager.runJob('update-tc-data', {parent: this});

this.logger.log('Updating handbook...');
await tarkovData.handbook(true).catch(error => {
await tarkovData.handbook({download: true}).catch(error => {
this.logger.error(error);
return tarkovData.handbook(false);
return tarkovData.handbook({download: true});
});

const subJobs = [
Expand Down
30 changes: 13 additions & 17 deletions src/tarkov-data-manager/jobs/update-archived-prices.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,12 @@ class UpdateArchivedPricesJob extends DataJob {
}

async run() {
this.kvData = {
regular: {},
pve: {},
};
for (let pve = 0; pve < 2; pve++) {
this.kvData = {};
for (const gameMode of this.gameModes) {
this.kvData[gameMode.name] = {};
let kvName = this.kvName;
let gameMode = 'regular';
if (pve) {
kvName = 'archived_price_pve_data';
gameMode = 'pve';
if (gameMode.name !== 'regular') {
kvName += `_${gameMode.name}`;
}
let dateCutoff = new Date(0);
const archivedPrices = await fs.readFile(path.join(import.meta.dirname, '..', 'dumps', `${kvName}.json`)).then(buffer => {
Expand All @@ -30,7 +26,7 @@ class UpdateArchivedPricesJob extends DataJob {
if (error.code !== 'ENOENT') {
console.log(error);
}
this.logger.log(`Generating full archived ${gameMode} prices`);
this.logger.log(`Generating full archived ${gameMode.name} prices`);
return {};
});

Expand All @@ -45,7 +41,7 @@ class UpdateArchivedPricesJob extends DataJob {
});
}

this.logger.log(`Using ${gameMode} query cutoff of ${dateCutoff}`);
this.logger.log(`Using ${gameMode.name} query cutoff of ${dateCutoff}`);

const batchSize = this.maxQueryRows;
let offset = 0;
Expand All @@ -62,12 +58,12 @@ class UpdateArchivedPricesJob extends DataJob {
game_mode = ?
ORDER BY price_date, item_id
LIMIT ?, ?
`, [dateCutoff, pve, offset, batchSize]);
`, [dateCutoff, gameMode.value, offset, batchSize]);
queryResults.forEach(r => archivedPriceData.push(r));
if (queryResults.length > 0) {
this.logger.log(`Retrieved ${offset + queryResults.length} ${gameMode} prices through ${queryResults[queryResults.length-1].price_date}${queryResults.length === batchSize ? '...' : ''}`);
this.logger.log(`Retrieved ${offset + queryResults.length} ${gameMode.name} prices through ${queryResults[queryResults.length-1].price_date}${queryResults.length === batchSize ? '...' : ''}`);
} else {
this.logger.log(`Retrieved no ${gameMode} prices`);
this.logger.log(`Retrieved no ${gameMode.name} prices`);
}
if (queryResults.length !== batchSize) {
break;
Expand All @@ -87,9 +83,9 @@ class UpdateArchivedPricesJob extends DataJob {
});
}

this.kvData[gameMode][this.apiType] = archivedPrices;
await this.cloudflarePut(this.kvData[gameMode], kvName);
this.logger.log(`Uploaded ${gameMode} prices`);
this.kvData[gameMode.name][this.apiType] = archivedPrices;
await this.cloudflarePut(this.kvData[gameMode.name], this.kvName, gameMode.name);
this.logger.log(`Uploaded ${gameMode.name} prices`);
}

this.logger.success('Done with archived prices');
Expand Down
37 changes: 20 additions & 17 deletions src/tarkov-data-manager/jobs/update-barters.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import remoteData from '../modules/remote-data.mjs';
import DataJob from '../modules/data-job.mjs';

const skipOffers = {
jaeger: {
'5c0647fdd443bc2504c2d371': { // jaeger
4: [
{
reward: '5c110624d174af029e69734c', // T-7 Thermal Goggles with a Night Vision mount
Expand All @@ -19,7 +19,7 @@ const skipOffers = {
}
],
},
peacekeeper: {
'5935c25fb3acc3127c3d8cd9': { // peacekeeper
1: [
{
reward: '5c110624d174af029e69734c', // T-7 Thermal Goggles with a Night Vision mount
Expand All @@ -42,7 +42,7 @@ class UpdateBartersJob extends DataJob {
async run() {
[this.tasks, this.traders, this.traderAssorts, this.itemData, this.items, this.en] = await Promise.all([
this.jobManager.jobOutput('update-quests', this),
this.jobManager.jobOutput('update-traders', this),
tarkovData.traders(),
this.jobManager.jobOutput('update-trader-assorts', this, true),
remoteData.get(),
tarkovData.items(),
Expand Down Expand Up @@ -102,16 +102,16 @@ class UpdateBartersJob extends DataJob {
if (this.skipOffer(offer, requirements.map(r => r.requirement_item_id))) {
continue;
}
const trader = this.traders.find(t => t.id === offer.trader_id);
const traderName = this.en[`${offer.trader_id} Nickname`];
const questUnlock = this.getQuestUnlock(offer);
const assort = this.traderAssorts[trader.id]?.find(assort => assort.id === offer.id);
const assort = this.traderAssorts[offer.trader_id]?.find(assort => assort.id === offer.id);
const barter = {
id: offer.id,
trader_id: trader.id,
trader_name: this.en[trader.name],
trader: `${this.en[trader.name]} LL${offer.min_level}`,
source: `${this.en[trader.name]} LL${offer.min_level}`,
sourceName: trader.normalizedName,
trader_id: offer.trader_id,
trader_name: traderName,
trader: `${traderName} LL${offer.min_level}`,
source: `${traderName} LL${offer.min_level}`,
sourceName: this.normalizeName(traderName),
level: offer.min_level,
taskUnlock: questUnlock ? questUnlock.id : null,
rewardItems: [
Expand Down Expand Up @@ -183,17 +183,21 @@ class UpdateBartersJob extends DataJob {
this.logger.log(`Unpacked ${ammoPacks} ammo pack barters`);

await this.cloudflarePut({Barter: this.barters});

// exclude Ref from PVE barters
const pveBarters = this.barters.filter(b => b.trader_id !== '6617beeaa9cfa777ca915b7c');
await this.cloudflarePut({Barter: pveBarters}, `${this.kvName}_pve`);

return this.barters;
}

getQuestUnlock = (offer) => {
if (!offer.locked) {
return null;
}
const trader = this.traders.find(t => t.id === offer.trader_id);
const itemId = offer.item_id;
for (const quest of this.tasks) {
const match = unlockMatches(itemId, quest.startRewards, trader.id) || unlockMatches(itemId, quest.finishRewards, trader.id);
const match = unlockMatches(itemId, quest.startRewards, offer.trader_id) || unlockMatches(itemId, quest.finishRewards, offer.trader_id);
if (match) {
return {
id: quest.id,
Expand All @@ -202,19 +206,18 @@ class UpdateBartersJob extends DataJob {
};
}
}
this.logger.warn(`Could not find quest unlock for trader offer ${offer.id}: ${trader.normalizedName} ${offer.min_level} ${this.itemData.get(itemId).name} ${itemId}`);
this.logger.warn(`Could not find quest unlock for trader offer ${offer.id}: ${this.locales.en[`${offer.trader_id} Nickname`]} ${offer.min_level} ${this.itemData.get(itemId).name} ${itemId}`);
return null;
}

skipOffer = (offer, requirements) => {
const trader = this.traders.find(t => t.id === offer.trader_id);
if (!skipOffers[trader.normalizedName]) {
if (!skipOffers[offer.trader_id]) {
return false;
}
if (!skipOffers[trader.normalizedName][offer.min_level]) {
if (!skipOffers[offer.trader_id][offer.min_level]) {
return false;
}
const rewardOffers = skipOffers[trader.normalizedName][offer.min_level].filter(o => o.reward === offer.item_id);
const rewardOffers = skipOffers[offer.trader_id][offer.min_level].filter(o => o.reward === offer.item_id);
if (rewardOffers.length === 0) {
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion src/tarkov-data-manager/jobs/update-game-status.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class UpdateGameStatusJob extends DataJob {
}

async run() {
const status = await tarkovData.status(true);
const status = await tarkovData.status({download: true});

if (status.global.message === 'Access denied' && status.global.status !== null && status.global.status !== undefined) {
status.global.message = ''
Expand Down
3 changes: 1 addition & 2 deletions src/tarkov-data-manager/jobs/update-hideout.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import got from 'got';

import DataJob from '../modules/data-job.mjs';
import tarkovData from '../modules/tarkov-data.mjs';
import normalizeName from '../modules/normalize-name.js';
import s3 from '../modules/upload-s3.mjs';

const skipAreas = {
Expand Down Expand Up @@ -39,7 +38,7 @@ class UpdateHideoutJob extends DataJob {
const stationData = {
id: station._id,
name: this.addTranslation(`hideout_area_${station.type}_name`),
normalizedName: normalizeName(this.getTranslation(`hideout_area_${station.type}_name`)),
normalizedName: this.normalizeName(this.getTranslation(`hideout_area_${station.type}_name`)),
areaType: station.type,
levels: [],
imageLink: `https://${process.env.S3_BUCKET}/station-unknown.png`,
Expand Down
30 changes: 13 additions & 17 deletions src/tarkov-data-manager/jobs/update-historical-prices.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,12 @@ class UpdateHistoricalPricesJob extends DataJob {
}

async run() {
this.kvData = {
regular: {},
pve: {},
};
for (let pve = 0; pve < 2; pve++) {
this.kvData = {};
for (const gameMode of this.gameModes) {
this.kvData[gameMode.name] = {};
let kvName = this.kvName;
let gameMode = 'regular';
if (pve) {
kvName = 'historical_price_pve_data';
gameMode = 'pve';
if (gameMode.name !== 'regular') {
kvName += `_${gameMode.name}`;
}
const priceWindow = new Date(new Date().setDate(new Date().getDate() - historicalPriceDays));
const itemPriceData = await fs.readFile(path.join(import.meta.dirname, '..', 'dumps', `${kvName}.json`)).then(buffer => {
Expand All @@ -32,7 +28,7 @@ class UpdateHistoricalPricesJob extends DataJob {
if (error.code !== 'ENOENT') {
console.log(error);
}
this.logger.log(`Generating full ${gameMode} historical prices`);
this.logger.log(`Generating full ${gameMode.name} historical prices`);
return {};
});

Expand All @@ -48,7 +44,7 @@ class UpdateHistoricalPricesJob extends DataJob {
});
}

this.logger.log(`Using ${gameMode} query cutoff of ${dateCutoff}`);
this.logger.log(`Using ${gameMode.name} query cutoff of ${dateCutoff}`);

const batchSize = this.maxQueryRows;
let offset = 0;
Expand All @@ -66,12 +62,12 @@ class UpdateHistoricalPricesJob extends DataJob {
GROUP BY item_id, timestamp
ORDER BY timestamp, item_id
LIMIT ?, ?
`, [dateCutoff, pve, offset, batchSize]);
`, [dateCutoff, gameMode.value, offset, batchSize]);
queryResults.forEach(r => historicalPriceData.push(r));
if (queryResults.length > 0) {
this.logger.log(`Retrieved ${offset + queryResults.length} ${gameMode} prices through ${queryResults[queryResults.length-1].timestamp}${queryResults.length === batchSize ? '...' : ''}`);
this.logger.log(`Retrieved ${offset + queryResults.length} ${gameMode.name} prices through ${queryResults[queryResults.length-1].timestamp}${queryResults.length === batchSize ? '...' : ''}`);
} else {
this.logger.log(`Retrieved no ${gameMode} prices`);
this.logger.log(`Retrieved no ${gameMode.name} prices`);
}
if (queryResults.length !== batchSize) {
break;
Expand All @@ -91,9 +87,9 @@ class UpdateHistoricalPricesJob extends DataJob {
});
}

this.kvData[gameMode][this.apiType] = itemPriceData;
await this.cloudflarePut(this.kvData[gameMode], kvName);
this.logger.log(`Uploaded ${gameMode} historical prices`);
this.kvData[gameMode.name][this.apiType] = itemPriceData;
await this.cloudflarePut(this.kvData[gameMode.name], this.kvName, gameMode.name);
this.logger.log(`Uploaded ${gameMode.name} historical prices`);
}
this.logger.success('Done with historical prices');
return this.kvData;
Expand Down
Loading
Loading