history cache

This commit is contained in:
2024-05-22 09:59:13 +02:00
parent e379f490a4
commit f75156bc62
9 changed files with 37 additions and 25 deletions

View File

@@ -1,13 +0,0 @@
import { esiAxiosInstance } from "@/service";
export type MarketOrderHistory = {
average: number;
date: string;
highest: number;
lowest: number;
order_count: number;
volume: number;
}
export const getHistory = async (regionId: number, tyeId: number): Promise<MarketOrderHistory[]> => (await esiAxiosInstance.get(`/markets/${regionId}/history/`, { params: { type_id: tyeId } })).data;

View File

@@ -1,8 +1,7 @@
<script setup lang="ts">
import { LoadingSpinner, Tooltip } from '@/components';
import { formatIsk } from '@/formaters';
import { getHistory, jitaId } from '@/market';
import { getHistoryQuartils } from '@/market/tracking';
import { getHistory, getHistoryQuartils, jitaId } from '@/market';
import { ArrowTrendingDownIcon, ArrowTrendingUpIcon } from '@heroicons/vue/24/outline';
import { computedAsync } from '@vueuse/core';
import { ref, watchEffect } from 'vue';

View File

@@ -0,0 +1,26 @@
import { esiAxiosInstance } from "@/service";
export type EsiMarketOrderHistory = {
average: number;
date: string;
highest: number;
lowest: number;
order_count: number;
volume: number;
}
// TODO use pinia store
const historyCache: { [key: number]: { [key: number]: EsiMarketOrderHistory[] } } = {};
export const getHistory = async (regionId: number, tyeId: number): Promise<EsiMarketOrderHistory[]> => {
if (historyCache[regionId]?.[tyeId]) {
return historyCache[regionId][tyeId];
}
const value = (await esiAxiosInstance.get(`/markets/${regionId}/history/`, { params: { type_id: tyeId } })).data;
historyCache[regionId] = historyCache[regionId] ?? {};
historyCache[regionId][tyeId] = value;
return value;
}

View File

@@ -1,4 +1,4 @@
import { MarketOrderHistory } from "@/market";
import { EsiMarketOrderHistory } from "@/market";
export type HistoryQuartils = {
totalVolume: number,
@@ -7,7 +7,7 @@ export type HistoryQuartils = {
q3: number,
}
export const getHistoryQuartils = (history: MarketOrderHistory[], days?: number): HistoryQuartils => {
export const getHistoryQuartils = (history: EsiMarketOrderHistory[], days?: number): HistoryQuartils => {
const now = Date.now();
const volumes = history
@@ -51,7 +51,7 @@ export const getHistoryQuartils = (history: MarketOrderHistory[], days?: number)
};
}
const estimateVolume = (history: MarketOrderHistory): number => {
const estimateVolume = (history: EsiMarketOrderHistory): number => {
if (history.volume === 0) {
return 0;
}

View File

@@ -0,0 +1,2 @@
export * from './EsiMarketOrderHistory';
export * from './HistoryQuartils';

View File

@@ -1,7 +1,7 @@
export * from './history';
export * from './tax';
export * from './type';
export * from './MarketOrderHistory';
export * from './appraisal';
export * from './market';

View File

@@ -2,11 +2,10 @@
import { SliderCheckbox } from '@/components';
import { SortableHeader, useSort, VirtualScrollTable } from '@/components/table';
import { formatIsk, percentFormater } from '@/formaters';
import { MarketType, MarketTypeLabel, TaxInput, useMarketTaxStore } from "@/market";
import { getHistoryQuartils, MarketType, MarketTypeLabel, TaxInput, useMarketTaxStore } from "@/market";
import { BookmarkSlashIcon, ShoppingCartIcon } from '@heroicons/vue/24/outline';
import { useStorage } from '@vueuse/core';
import { computed, ref } from 'vue';
import { getHistoryQuartils } from './HistoryQuartils';
import { TrackingResult } from './tracking';
type Result = {
@@ -163,4 +162,4 @@ const getLineColor = (result: Result) => {
div.end {
@apply justify-self-end ms-2;
}
</style>
</style>../history/HistoryQuartils

View File

@@ -1,4 +1,3 @@
export * from './HistoryQuartils';
export * from './tracking';
export { default as TrackingResultTable } from './TrackingResultTable.vue';

View File

@@ -1,12 +1,12 @@
import { marbasAxiosInstance, MarbasObject } from "@/marbas";
import { getHistory, jitaId, MarketOrderHistory, MarketType, MarketTypePrice } from "@/market";
import { EsiMarketOrderHistory, getHistory, jitaId, MarketType, MarketTypePrice } from "@/market";
import log from "loglevel";
import { defineStore } from "pinia";
import { computed, ref } from "vue";
export type TrackingResult = {
type: MarketType;
history: MarketOrderHistory[];
history: EsiMarketOrderHistory[];
buy: number,
sell: number,
orderCount: number,