Skip to content

Commit

Permalink
Merge branch 'master' into sqlite-overhaul
Browse files Browse the repository at this point in the history
  • Loading branch information
Nathaniel Moschkin committed Dec 6, 2023
2 parents 3bf564d + e98c73b commit e66223f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 10 deletions.
21 changes: 13 additions & 8 deletions app/logic/telemetry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Op } from 'sequelize';
import { Voyage } from '../models/VoyageRecord';
import fs from 'fs';

type CrewPeople = {
export interface Voyager {
crewSymbol: string,
seats: { seat_skill: string, seat_index: number, crewCount: number, averageDuration: number }[],
averageDuration: number,
Expand Down Expand Up @@ -41,7 +41,7 @@ async function recordVoyage(voyagers: string[]) {
return true;
}

async function recordVoyageCalc({ voyagers, estimatedDuration, primary_skill, secondary_skill, am_traits, ship_trait }: { voyagers: string[]; estimatedDuration: number; primary_skill?: string; secondary_skill?: string, am_traits?: string[], ship_trait?: string }) {
async function recordVoyageCalc({ voyagers, estimatedDuration, primary_skill, secondary_skill, am_traits, ship_trait, extra_stats }: { voyagers: string[]; estimatedDuration: number; primary_skill?: string; secondary_skill?: string, am_traits?: string[], ship_trait?: string, extra_stats?: any }) {
// for (let i in voyagers) {
// const crewSymbol = voyagers[i];
// await VoyageRecord.create({ crewSymbol, estimatedDuration });
Expand All @@ -55,7 +55,8 @@ async function recordVoyageCalc({ voyagers, estimatedDuration, primary_skill, se
primary_skill,
secondary_skill,
am_traits,
ship_trait
ship_trait,
extra_stats
});

return true;
Expand All @@ -72,14 +73,18 @@ export async function loadStats() {
let dailyfile = `${path}/daily_stats.json`;

if (fs.existsSync(dailyfile)) {
return JSON.parse(fs.readFileSync(dailyfile, 'utf-8')) as { [key: string]: CrewPeople[] };
return JSON.parse(fs.readFileSync(dailyfile, 'utf-8')) as { [key: string]: Voyager[] };
}

return {};
}

export async function createStats(force?: boolean) {
let mynow = new Date();
mynow.setMinutes(0);
mynow.setSeconds(0);
mynow.setMilliseconds(0);

let path = `${process.env.PROFILE_DATA_PATH}/stats`;
if (!fs.existsSync(path)) {
fs.mkdirSync(path);
Expand All @@ -93,14 +98,14 @@ export async function createStats(force?: boolean) {
fs.rmSync(dailyfile);
}
else {
setTimeout(() => createStats(), 1000 * 60 * 60);
setTimeout(() => createStats(), 1000 * 60 * 30);
return;
}
}

let result = await getVoyageStats();
fs.writeFileSync(dailyfile, JSON.stringify(result));
setTimeout(() => createStats(), 1000 * 60 * 60);
setTimeout(() => createStats(), 1000 * 60 * 30);
}

async function getVoyageStats() {
Expand All @@ -122,7 +127,7 @@ async function getVoyageStats() {
];

const records = await Voyage.findAll({ where: { voyageDate: { [Op.gte]: one80DaysAgo }}});
const output = {} as { [key: string]: CrewPeople[] };
const output = {} as { [key: string]: Voyager[] };

const dsets = [{
date: new Date(Date.now() - (180 * 24 * 60 * 60 * 1000)),
Expand All @@ -142,7 +147,7 @@ async function getVoyageStats() {
console.log(`From ${d} as '${fn}'...`);
let results = records.filter(r => r.voyageDate.getTime() >= dset.date.getTime());

const cp = {} as { [key: string]: CrewPeople };
const cp = {} as { [key: string]: Voyager };

for (let res of results) {
let seat = 0;
Expand Down
8 changes: 6 additions & 2 deletions app/models/VoyageRecord.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,10 @@ export class Voyage extends Model {

@Column
ship_trait?: string;
}


@Column(DataType.JSON)
extra_stats?: any
}

@Table
export class Historical extends Model {
Expand Down Expand Up @@ -70,5 +71,8 @@ export class Historical extends Model {

@Column
ship_trait?: string;

@Column(DataType.JSON)
extra_stats?: any
}

1 change: 1 addition & 0 deletions app/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import expressWinston from 'express-winston';
import { ApiController } from './controllers';
import { Logger, DataCoreAPI, createStats } from './logic';
import { sequelize } from './sequelize';
import { Voyage } from './models/VoyageRecord';

require('dotenv').config();

Expand Down

0 comments on commit e66223f

Please sign in to comment.