history cache
This commit is contained in:
@@ -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;
|
|
||||||
@@ -1,8 +1,7 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { LoadingSpinner, Tooltip } from '@/components';
|
import { LoadingSpinner, Tooltip } from '@/components';
|
||||||
import { formatIsk } from '@/formaters';
|
import { formatIsk } from '@/formaters';
|
||||||
import { getHistory, jitaId } from '@/market';
|
import { getHistory, getHistoryQuartils, jitaId } from '@/market';
|
||||||
import { getHistoryQuartils } from '@/market/tracking';
|
|
||||||
import { ArrowTrendingDownIcon, ArrowTrendingUpIcon } from '@heroicons/vue/24/outline';
|
import { ArrowTrendingDownIcon, ArrowTrendingUpIcon } from '@heroicons/vue/24/outline';
|
||||||
import { computedAsync } from '@vueuse/core';
|
import { computedAsync } from '@vueuse/core';
|
||||||
import { ref, watchEffect } from 'vue';
|
import { ref, watchEffect } from 'vue';
|
||||||
|
|||||||
26
src/market/history/EsiMarketOrderHistory.ts
Normal file
26
src/market/history/EsiMarketOrderHistory.ts
Normal 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;
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
import { MarketOrderHistory } from "@/market";
|
import { EsiMarketOrderHistory } from "@/market";
|
||||||
|
|
||||||
export type HistoryQuartils = {
|
export type HistoryQuartils = {
|
||||||
totalVolume: number,
|
totalVolume: number,
|
||||||
@@ -7,7 +7,7 @@ export type HistoryQuartils = {
|
|||||||
q3: number,
|
q3: number,
|
||||||
}
|
}
|
||||||
|
|
||||||
export const getHistoryQuartils = (history: MarketOrderHistory[], days?: number): HistoryQuartils => {
|
export const getHistoryQuartils = (history: EsiMarketOrderHistory[], days?: number): HistoryQuartils => {
|
||||||
const now = Date.now();
|
const now = Date.now();
|
||||||
|
|
||||||
const volumes = history
|
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) {
|
if (history.volume === 0) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
2
src/market/history/index.ts
Normal file
2
src/market/history/index.ts
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
export * from './EsiMarketOrderHistory';
|
||||||
|
export * from './HistoryQuartils';
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
|
export * from './history';
|
||||||
export * from './tax';
|
export * from './tax';
|
||||||
export * from './type';
|
export * from './type';
|
||||||
|
|
||||||
export * from './MarketOrderHistory';
|
|
||||||
export * from './appraisal';
|
export * from './appraisal';
|
||||||
export * from './market';
|
export * from './market';
|
||||||
|
|
||||||
|
|||||||
@@ -2,11 +2,10 @@
|
|||||||
import { SliderCheckbox } from '@/components';
|
import { SliderCheckbox } from '@/components';
|
||||||
import { SortableHeader, useSort, VirtualScrollTable } from '@/components/table';
|
import { SortableHeader, useSort, VirtualScrollTable } from '@/components/table';
|
||||||
import { formatIsk, percentFormater } from '@/formaters';
|
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 { BookmarkSlashIcon, ShoppingCartIcon } from '@heroicons/vue/24/outline';
|
||||||
import { useStorage } from '@vueuse/core';
|
import { useStorage } from '@vueuse/core';
|
||||||
import { computed, ref } from 'vue';
|
import { computed, ref } from 'vue';
|
||||||
import { getHistoryQuartils } from './HistoryQuartils';
|
|
||||||
import { TrackingResult } from './tracking';
|
import { TrackingResult } from './tracking';
|
||||||
|
|
||||||
type Result = {
|
type Result = {
|
||||||
@@ -163,4 +162,4 @@ const getLineColor = (result: Result) => {
|
|||||||
div.end {
|
div.end {
|
||||||
@apply justify-self-end ms-2;
|
@apply justify-self-end ms-2;
|
||||||
}
|
}
|
||||||
</style>
|
</style>../history/HistoryQuartils
|
||||||
@@ -1,4 +1,3 @@
|
|||||||
export * from './HistoryQuartils';
|
|
||||||
export * from './tracking';
|
export * from './tracking';
|
||||||
|
|
||||||
export { default as TrackingResultTable } from './TrackingResultTable.vue';
|
export { default as TrackingResultTable } from './TrackingResultTable.vue';
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
import { marbasAxiosInstance, MarbasObject } from "@/marbas";
|
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 log from "loglevel";
|
||||||
import { defineStore } from "pinia";
|
import { defineStore } from "pinia";
|
||||||
import { computed, ref } from "vue";
|
import { computed, ref } from "vue";
|
||||||
|
|
||||||
export type TrackingResult = {
|
export type TrackingResult = {
|
||||||
type: MarketType;
|
type: MarketType;
|
||||||
history: MarketOrderHistory[];
|
history: EsiMarketOrderHistory[];
|
||||||
buy: number,
|
buy: number,
|
||||||
sell: number,
|
sell: number,
|
||||||
orderCount: number,
|
orderCount: number,
|
||||||
|
|||||||
Reference in New Issue
Block a user