days and filter

This commit is contained in:
2023-09-16 12:10:45 +02:00
parent c889a813f3
commit 145af06874
7 changed files with 132 additions and 86 deletions

View File

@@ -13,10 +13,8 @@ export type MarketOrderHistory = {
}
export type MarketResult = {
type: MarketType,
q1: number,
median: number,
q3: number,
type: MarketType;
history: MarketOrderHistory[];
}
export type HistoryQuartils = {
@@ -26,14 +24,16 @@ export type HistoryQuartils = {
q3: number,
}
export const getHistory = async (regionId: number, tyeId: number): Promise<MarketOrderHistory[]> => (await esiAxiosInstance.get(`/markets/${regionId}/history/`, { params: { type_id: tyeId } })).data;
export const getHistory = async (regionId: number, tyeId: number): Promise<MarketOrderHistory[]> => (await esiAxiosInstance.get(`/markets/${regionId}/history/`, { params: { type_id: tyeId } })).data;
export const getHistoryQuartils = (history: MarketOrderHistory[], days?: number): HistoryQuartils => {
const now = Date.now();
export const getHistoryQuartils = (history: MarketOrderHistory[]): HistoryQuartils => {
const volumes = history
.flatMap(h => {
const volume = h.volume;
if (volume === 0) {
if (volume === 0 || (days && new Date(h.date).getTime() < now - days * 24 * 60 * 60 * 1000)) {
return [];
}