Compare commits

..
6 Commits
12 changed files with 741 additions and 346 deletions

No files matched your search

+91 -23
View File
@@ -959,8 +959,8 @@ paths:
/ledgers/{ledgerId}/profit:
get:
tags:
- transaction
summary: Get the daily profit series for a single ledger
- profit
summary: Get the daily profit series for a single or combined ledger
operationId: profitPerDayInLedger
parameters:
- name: ledgerId
@@ -972,8 +972,8 @@ paths:
format: uuid
responses:
"200":
description: "Daily profit for the ledger, ascending by date, only for days\
\ with ISK activity"
description: "Daily profit for the ledger, ascending by date. For a combined\
\ ledger, per-date values are merged across its covered main ledgers."
content:
'*/*':
schema:
@@ -981,14 +981,15 @@ paths:
items:
$ref: "#/components/schemas/DailyProfitResponse"
"400":
description: The ledger is the system ledger or a combined ledger
description: The ledger is the system ledger
"404":
description: No ledger with this id
/ledgers/{ledgerId}/margin:
get:
tags:
- transaction
summary: Get the daily FIFO-realized profit series for a single ledger
- profit
summary: Get the daily FIFO-realized margin series for a single or combined
ledger
operationId: marginPerDayInLedger
parameters:
- name: ledgerId
@@ -1000,10 +1001,11 @@ paths:
format: uuid
responses:
"200":
description: "Daily FIFO-realized profit for the ledger, ascending by date,\
\ only for days with a sale. iskIn is the sum of that day's profitable\
\ trades, iskOut is the sum of that day's losing trades (as a positive\
\ deficit); profit is iskIn minus iskOut."
description: "Daily FIFO-realized margin for the ledger, ascending by date.\
\ iskIn is the sum of that day's profitable consumptions, iskOut is the\
\ sum of that day's losing consumptions (as a positive deficit); profit\
\ is iskIn minus iskOut. For a combined ledger, per-date values are merged\
\ across its covered main ledgers."
content:
'*/*':
schema:
@@ -1011,7 +1013,7 @@ paths:
items:
$ref: "#/components/schemas/DailyProfitResponse"
"400":
description: The ledger is the system ledger or a combined ledger
description: The ledger is the system ledger
"404":
description: No ledger with this id
/ledgers/{ledgerId}/balance:
@@ -1037,12 +1039,41 @@ paths:
$ref: "#/components/schemas/BalanceResponse"
"404":
description: No ledger with this id
/ledgers/{ledgerId}/balance/daily-valuation:
get:
tags:
- ledger
summary: Get the daily mark-to-market valuation series of a ledger's held balance
(items and ISK)
operationId: dailyValuationForLedger
parameters:
- name: ledgerId
in: path
description: Id of the ledger
required: true
schema:
type: string
format: uuid
responses:
"200":
description: "Daily average/highest/lowest valuation for the ledger, ascending\
\ by date. For a combined ledger, this is the per-date sum of its covered\
\ main ledgers' valuations."
content:
'*/*':
schema:
type: array
items:
$ref: "#/components/schemas/DailyBalanceResponse"
"400":
description: The ledger is the system ledger
"404":
description: No ledger with this id
/corporations:
get:
tags:
- corporation
summary: "Resolve public information for several corporation ids at once, silently\
\ omitting ids ESI cannot resolve"
summary: Resolve public information for several corporation ids at once
operationId: findCorporations
parameters:
- name: ids
@@ -1056,13 +1087,15 @@ paths:
format: int64
responses:
"200":
description: The corporations that resolved; unknown ids are omitted
description: The resolved corporations
content:
'*/*':
schema:
type: array
items:
$ref: "#/components/schemas/CorporationResponse"
"404":
description: Returned when no corporation exists for one of the given ids
/corporations/{corporationId}:
get:
tags:
@@ -1086,7 +1119,7 @@ paths:
schema:
$ref: "#/components/schemas/CorporationResponse"
"404":
description: Returned when ESI has no corporation with the given id
description: Returned when no corporation exists with the given id
/characters:
get:
tags:
@@ -1119,17 +1152,27 @@ paths:
get:
tags:
- acquisition
summary: "Find the caller's acquisitions, optionally filtered by ledger, market\
summary: "Find the caller's acquisitions, optionally filtered by ledgers, market\
\ type and consumption state"
operationId: findAllAcquisitions
parameters:
- name: ledgerId
in: query
description: Only return acquisitions held in this ledger
description: "Only return acquisitions held in this ledger (deprecated, use\
\ ledgerIds)"
required: false
schema:
type: string
format: uuid
- name: ledgerIds
in: query
description: Only return acquisitions held in these ledgers
required: false
schema:
type: array
items:
type: string
format: uuid
- name: marketTypeId
in: query
description: Only return acquisitions of this market type
@@ -2260,6 +2303,36 @@ components:
required:
- quantity
- typeId
DailyBalanceResponse:
type: object
description: "Mark-to-market value of a ledger's held balance (items and ISK)\
\ for a single day: average, highest and lowest."
properties:
date:
type: string
format: date
description: The UTC (EVE) day this valuation is for.
example: 2026-06-22
averageValue:
type: number
description: ISK balance plus held item balance valued at that day's average
price.
example: 1.5E8
highestValue:
type: number
description: ISK balance plus held item balance valued at that day's highest
price.
example: 1.6E8
lowestValue:
type: number
description: ISK balance plus held item balance valued at that day's lowest
price.
example: 1.4E8
required:
- averageValue
- date
- highestValue
- lowestValue
CorporationResponse:
type: object
description: An EVE Online corporation.
@@ -2310,10 +2383,6 @@ components:
format: uuid
description: Ledger the acquisition is held in.
example: 3fa85f64-5717-4562-b3fc-2c963f66afa6
source:
$ref: "#/components/schemas/ActivitySourceResponse"
description: "Where the acquisition came from: a character, a corporation,\
\ or nothing."
marketTypeId:
type: integer
format: int64
@@ -2345,5 +2414,4 @@ components:
- marketTypeId
- quantity
- remaining
- source
- unitCost
+1 -1
View File
@@ -43,7 +43,7 @@ const select = (item?: T) => {
const submit = () => {
if (currentIndex.value >= 0 && currentIndex.value < props.items.length) {
select(props.items[currentIndex.value]);
} else if (modelValue.value === undefined && props.items.length > 0) {
} else if (props.items.length > 0) {
select(props.items[0]);
}
};
+285 -159
View File
@@ -35,10 +35,6 @@ export interface AcquisitionResponse {
* Ledger the acquisition is held in.
*/
'ledgerId': string;
/**
* Where the acquisition came from: a character, a corporation, or nothing.
*/
'source': ActivitySourceResponse;
/**
* EVE market type (item) id that was acquired.
*/
@@ -211,6 +207,27 @@ export interface CreateMainLedgerRequest {
*/
'name': string;
}
/**
* Mark-to-market value of a ledger\'s held balance (items and ISK) for a single day: average, highest and lowest.
*/
export interface DailyBalanceResponse {
/**
* The UTC (EVE) day this valuation is for.
*/
'date': string;
/**
* ISK balance plus held item balance valued at that day\'s average price.
*/
'averageValue': number;
/**
* ISK balance plus held item balance valued at that day\'s highest price.
*/
'highestValue': number;
/**
* ISK balance plus held item balance valued at that day\'s lowest price.
*/
'lowestValue': number;
}
/**
* Profit for a single day: ISK in, ISK out, and their difference.
*/
@@ -919,14 +936,15 @@ export const AcquisitionApiAxiosParamCreator = function (configuration?: Configu
return {
/**
*
* @summary Find the caller\'s acquisitions, optionally filtered by ledger, market type and consumption state
* @param {string} [ledgerId] Only return acquisitions held in this ledger
* @summary Find the caller\'s acquisitions, optionally filtered by ledgers, market type and consumption state
* @param {string} [ledgerId] Only return acquisitions held in this ledger (deprecated, use ledgerIds)
* @param {Array<string>} [ledgerIds] Only return acquisitions held in these ledgers
* @param {number} [marketTypeId] Only return acquisitions of this market type
* @param {boolean} [includeConsumed] Include fully consumed acquisitions (no remaining stock)
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
findAllAcquisitions: async (ledgerId?: string, marketTypeId?: number, includeConsumed?: boolean, options: RawAxiosRequestConfig = {}): Promise<RequestArgs> => {
findAllAcquisitions: async (ledgerId?: string, ledgerIds?: Array<string>, marketTypeId?: number, includeConsumed?: boolean, options: RawAxiosRequestConfig = {}): Promise<RequestArgs> => {
const localVarPath = `/acquisitions`;
// use dummy base URL string because the URL constructor only accepts absolute URLs.
const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL);
@@ -943,6 +961,10 @@ export const AcquisitionApiAxiosParamCreator = function (configuration?: Configu
localVarQueryParameter['ledgerId'] = ledgerId;
}
if (ledgerIds) {
localVarQueryParameter['ledgerIds'] = ledgerIds;
}
if (marketTypeId !== undefined) {
localVarQueryParameter['marketTypeId'] = marketTypeId;
}
@@ -973,15 +995,16 @@ export const AcquisitionApiFp = function(configuration?: Configuration) {
return {
/**
*
* @summary Find the caller\'s acquisitions, optionally filtered by ledger, market type and consumption state
* @param {string} [ledgerId] Only return acquisitions held in this ledger
* @summary Find the caller\'s acquisitions, optionally filtered by ledgers, market type and consumption state
* @param {string} [ledgerId] Only return acquisitions held in this ledger (deprecated, use ledgerIds)
* @param {Array<string>} [ledgerIds] Only return acquisitions held in these ledgers
* @param {number} [marketTypeId] Only return acquisitions of this market type
* @param {boolean} [includeConsumed] Include fully consumed acquisitions (no remaining stock)
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
async findAllAcquisitions(ledgerId?: string, marketTypeId?: number, includeConsumed?: boolean, options?: RawAxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<Array<AcquisitionResponse>>> {
const localVarAxiosArgs = await localVarAxiosParamCreator.findAllAcquisitions(ledgerId, marketTypeId, includeConsumed, options);
async findAllAcquisitions(ledgerId?: string, ledgerIds?: Array<string>, marketTypeId?: number, includeConsumed?: boolean, options?: RawAxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<Array<AcquisitionResponse>>> {
const localVarAxiosArgs = await localVarAxiosParamCreator.findAllAcquisitions(ledgerId, ledgerIds, marketTypeId, includeConsumed, options);
const localVarOperationServerIndex = configuration?.serverIndex ?? 0;
const localVarOperationServerBasePath = operationServerMap['AcquisitionApi.findAllAcquisitions']?.[localVarOperationServerIndex]?.url;
return (axios, basePath) => createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration)(axios, localVarOperationServerBasePath || basePath);
@@ -997,15 +1020,16 @@ export const AcquisitionApiFactory = function (configuration?: Configuration, ba
return {
/**
*
* @summary Find the caller\'s acquisitions, optionally filtered by ledger, market type and consumption state
* @param {string} [ledgerId] Only return acquisitions held in this ledger
* @summary Find the caller\'s acquisitions, optionally filtered by ledgers, market type and consumption state
* @param {string} [ledgerId] Only return acquisitions held in this ledger (deprecated, use ledgerIds)
* @param {Array<string>} [ledgerIds] Only return acquisitions held in these ledgers
* @param {number} [marketTypeId] Only return acquisitions of this market type
* @param {boolean} [includeConsumed] Include fully consumed acquisitions (no remaining stock)
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
findAllAcquisitions(ledgerId?: string, marketTypeId?: number, includeConsumed?: boolean, options?: RawAxiosRequestConfig): AxiosPromise<Array<AcquisitionResponse>> {
return localVarFp.findAllAcquisitions(ledgerId, marketTypeId, includeConsumed, options).then((request) => request(axios, basePath));
findAllAcquisitions(ledgerId?: string, ledgerIds?: Array<string>, marketTypeId?: number, includeConsumed?: boolean, options?: RawAxiosRequestConfig): AxiosPromise<Array<AcquisitionResponse>> {
return localVarFp.findAllAcquisitions(ledgerId, ledgerIds, marketTypeId, includeConsumed, options).then((request) => request(axios, basePath));
},
};
};
@@ -1016,15 +1040,16 @@ export const AcquisitionApiFactory = function (configuration?: Configuration, ba
export class AcquisitionApi extends BaseAPI {
/**
*
* @summary Find the caller\'s acquisitions, optionally filtered by ledger, market type and consumption state
* @param {string} [ledgerId] Only return acquisitions held in this ledger
* @summary Find the caller\'s acquisitions, optionally filtered by ledgers, market type and consumption state
* @param {string} [ledgerId] Only return acquisitions held in this ledger (deprecated, use ledgerIds)
* @param {Array<string>} [ledgerIds] Only return acquisitions held in these ledgers
* @param {number} [marketTypeId] Only return acquisitions of this market type
* @param {boolean} [includeConsumed] Include fully consumed acquisitions (no remaining stock)
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
public findAllAcquisitions(ledgerId?: string, marketTypeId?: number, includeConsumed?: boolean, options?: RawAxiosRequestConfig) {
return AcquisitionApiFp(this.configuration).findAllAcquisitions(ledgerId, marketTypeId, includeConsumed, options).then((request) => request(this.axios, this.basePath));
public findAllAcquisitions(ledgerId?: string, ledgerIds?: Array<string>, marketTypeId?: number, includeConsumed?: boolean, options?: RawAxiosRequestConfig) {
return AcquisitionApiFp(this.configuration).findAllAcquisitions(ledgerId, ledgerIds, marketTypeId, includeConsumed, options).then((request) => request(this.axios, this.basePath));
}
}
@@ -1839,7 +1864,7 @@ export const CorporationApiAxiosParamCreator = function (configuration?: Configu
},
/**
*
* @summary Resolve public information for several corporation ids at once, silently omitting ids ESI cannot resolve
* @summary Resolve public information for several corporation ids at once
* @param {Array<number>} ids Corporation ids to resolve, e.g. ids&#x3D;98000001,98000002
* @param {*} [options] Override http request option.
* @throws {RequiredError}
@@ -1898,7 +1923,7 @@ export const CorporationApiFp = function(configuration?: Configuration) {
},
/**
*
* @summary Resolve public information for several corporation ids at once, silently omitting ids ESI cannot resolve
* @summary Resolve public information for several corporation ids at once
* @param {Array<number>} ids Corporation ids to resolve, e.g. ids&#x3D;98000001,98000002
* @param {*} [options] Override http request option.
* @throws {RequiredError}
@@ -1930,7 +1955,7 @@ export const CorporationApiFactory = function (configuration?: Configuration, ba
},
/**
*
* @summary Resolve public information for several corporation ids at once, silently omitting ids ESI cannot resolve
* @summary Resolve public information for several corporation ids at once
* @param {Array<number>} ids Corporation ids to resolve, e.g. ids&#x3D;98000001,98000002
* @param {*} [options] Override http request option.
* @throws {RequiredError}
@@ -1958,7 +1983,7 @@ export class CorporationApi extends BaseAPI {
/**
*
* @summary Resolve public information for several corporation ids at once, silently omitting ids ESI cannot resolve
* @summary Resolve public information for several corporation ids at once
* @param {Array<number>} ids Corporation ids to resolve, e.g. ids&#x3D;98000001,98000002
* @param {*} [options] Override http request option.
* @throws {RequiredError}
@@ -2045,6 +2070,40 @@ export const LedgerApiAxiosParamCreator = function (configuration?: Configuratio
options: localVarRequestOptions,
};
},
/**
*
* @summary Get the daily mark-to-market valuation series of a ledger\'s held balance (items and ISK)
* @param {string} ledgerId Id of the ledger
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
dailyValuationForLedger: async (ledgerId: string, options: RawAxiosRequestConfig = {}): Promise<RequestArgs> => {
// verify required parameter 'ledgerId' is not null or undefined
assertParamExists('dailyValuationForLedger', 'ledgerId', ledgerId)
const localVarPath = `/ledgers/{ledgerId}/balance/daily-valuation`
.replace('{ledgerId}', encodeURIComponent(String(ledgerId)));
// use dummy base URL string because the URL constructor only accepts absolute URLs.
const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL);
let baseOptions;
if (configuration) {
baseOptions = configuration.baseOptions;
}
const localVarRequestOptions = { method: 'GET', ...baseOptions, ...options};
const localVarHeaderParameter = {} as any;
const localVarQueryParameter = {} as any;
localVarHeaderParameter['Accept'] = '*/*';
setSearchParams(localVarUrlObj, localVarQueryParameter);
let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers};
return {
url: toPathString(localVarUrlObj),
options: localVarRequestOptions,
};
},
/**
*
* @summary Find all ledgers owned by the authenticated user
@@ -2256,6 +2315,19 @@ export const LedgerApiFp = function(configuration?: Configuration) {
const localVarOperationServerBasePath = operationServerMap['LedgerApi.createMainLedger']?.[localVarOperationServerIndex]?.url;
return (axios, basePath) => createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration)(axios, localVarOperationServerBasePath || basePath);
},
/**
*
* @summary Get the daily mark-to-market valuation series of a ledger\'s held balance (items and ISK)
* @param {string} ledgerId Id of the ledger
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
async dailyValuationForLedger(ledgerId: string, options?: RawAxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<Array<DailyBalanceResponse>>> {
const localVarAxiosArgs = await localVarAxiosParamCreator.dailyValuationForLedger(ledgerId, options);
const localVarOperationServerIndex = configuration?.serverIndex ?? 0;
const localVarOperationServerBasePath = operationServerMap['LedgerApi.dailyValuationForLedger']?.[localVarOperationServerIndex]?.url;
return (axios, basePath) => createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration)(axios, localVarOperationServerBasePath || basePath);
},
/**
*
* @summary Find all ledgers owned by the authenticated user
@@ -2351,6 +2423,16 @@ export const LedgerApiFactory = function (configuration?: Configuration, basePat
createMainLedger(createMainLedgerRequest: CreateMainLedgerRequest, options?: RawAxiosRequestConfig): AxiosPromise<MainLedgerResponse> {
return localVarFp.createMainLedger(createMainLedgerRequest, options).then((request) => request(axios, basePath));
},
/**
*
* @summary Get the daily mark-to-market valuation series of a ledger\'s held balance (items and ISK)
* @param {string} ledgerId Id of the ledger
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
dailyValuationForLedger(ledgerId: string, options?: RawAxiosRequestConfig): AxiosPromise<Array<DailyBalanceResponse>> {
return localVarFp.dailyValuationForLedger(ledgerId, options).then((request) => request(axios, basePath));
},
/**
*
* @summary Find all ledgers owned by the authenticated user
@@ -2431,6 +2513,17 @@ export class LedgerApi extends BaseAPI {
return LedgerApiFp(this.configuration).createMainLedger(createMainLedgerRequest, options).then((request) => request(this.axios, this.basePath));
}
/**
*
* @summary Get the daily mark-to-market valuation series of a ledger\'s held balance (items and ISK)
* @param {string} ledgerId Id of the ledger
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
public dailyValuationForLedger(ledgerId: string, options?: RawAxiosRequestConfig) {
return LedgerApiFp(this.configuration).dailyValuationForLedger(ledgerId, options).then((request) => request(this.axios, this.basePath));
}
/**
*
* @summary Find all ledgers owned by the authenticated user
@@ -3636,6 +3729,175 @@ export class MarketHistoryAdminControllerApi extends BaseAPI {
/**
* ProfitApi - axios parameter creator
*/
export const ProfitApiAxiosParamCreator = function (configuration?: Configuration) {
return {
/**
*
* @summary Get the daily FIFO-realized margin series for a single or combined ledger
* @param {string} ledgerId Id of the ledger
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
marginPerDayInLedger: async (ledgerId: string, options: RawAxiosRequestConfig = {}): Promise<RequestArgs> => {
// verify required parameter 'ledgerId' is not null or undefined
assertParamExists('marginPerDayInLedger', 'ledgerId', ledgerId)
const localVarPath = `/ledgers/{ledgerId}/margin`
.replace('{ledgerId}', encodeURIComponent(String(ledgerId)));
// use dummy base URL string because the URL constructor only accepts absolute URLs.
const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL);
let baseOptions;
if (configuration) {
baseOptions = configuration.baseOptions;
}
const localVarRequestOptions = { method: 'GET', ...baseOptions, ...options};
const localVarHeaderParameter = {} as any;
const localVarQueryParameter = {} as any;
localVarHeaderParameter['Accept'] = '*/*';
setSearchParams(localVarUrlObj, localVarQueryParameter);
let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers};
return {
url: toPathString(localVarUrlObj),
options: localVarRequestOptions,
};
},
/**
*
* @summary Get the daily profit series for a single or combined ledger
* @param {string} ledgerId Id of the ledger
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
profitPerDayInLedger: async (ledgerId: string, options: RawAxiosRequestConfig = {}): Promise<RequestArgs> => {
// verify required parameter 'ledgerId' is not null or undefined
assertParamExists('profitPerDayInLedger', 'ledgerId', ledgerId)
const localVarPath = `/ledgers/{ledgerId}/profit`
.replace('{ledgerId}', encodeURIComponent(String(ledgerId)));
// use dummy base URL string because the URL constructor only accepts absolute URLs.
const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL);
let baseOptions;
if (configuration) {
baseOptions = configuration.baseOptions;
}
const localVarRequestOptions = { method: 'GET', ...baseOptions, ...options};
const localVarHeaderParameter = {} as any;
const localVarQueryParameter = {} as any;
localVarHeaderParameter['Accept'] = '*/*';
setSearchParams(localVarUrlObj, localVarQueryParameter);
let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers};
return {
url: toPathString(localVarUrlObj),
options: localVarRequestOptions,
};
},
}
};
/**
* ProfitApi - functional programming interface
*/
export const ProfitApiFp = function(configuration?: Configuration) {
const localVarAxiosParamCreator = ProfitApiAxiosParamCreator(configuration)
return {
/**
*
* @summary Get the daily FIFO-realized margin series for a single or combined ledger
* @param {string} ledgerId Id of the ledger
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
async marginPerDayInLedger(ledgerId: string, options?: RawAxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<Array<DailyProfitResponse>>> {
const localVarAxiosArgs = await localVarAxiosParamCreator.marginPerDayInLedger(ledgerId, options);
const localVarOperationServerIndex = configuration?.serverIndex ?? 0;
const localVarOperationServerBasePath = operationServerMap['ProfitApi.marginPerDayInLedger']?.[localVarOperationServerIndex]?.url;
return (axios, basePath) => createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration)(axios, localVarOperationServerBasePath || basePath);
},
/**
*
* @summary Get the daily profit series for a single or combined ledger
* @param {string} ledgerId Id of the ledger
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
async profitPerDayInLedger(ledgerId: string, options?: RawAxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<Array<DailyProfitResponse>>> {
const localVarAxiosArgs = await localVarAxiosParamCreator.profitPerDayInLedger(ledgerId, options);
const localVarOperationServerIndex = configuration?.serverIndex ?? 0;
const localVarOperationServerBasePath = operationServerMap['ProfitApi.profitPerDayInLedger']?.[localVarOperationServerIndex]?.url;
return (axios, basePath) => createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration)(axios, localVarOperationServerBasePath || basePath);
},
}
};
/**
* ProfitApi - factory interface
*/
export const ProfitApiFactory = function (configuration?: Configuration, basePath?: string, axios?: AxiosInstance) {
const localVarFp = ProfitApiFp(configuration)
return {
/**
*
* @summary Get the daily FIFO-realized margin series for a single or combined ledger
* @param {string} ledgerId Id of the ledger
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
marginPerDayInLedger(ledgerId: string, options?: RawAxiosRequestConfig): AxiosPromise<Array<DailyProfitResponse>> {
return localVarFp.marginPerDayInLedger(ledgerId, options).then((request) => request(axios, basePath));
},
/**
*
* @summary Get the daily profit series for a single or combined ledger
* @param {string} ledgerId Id of the ledger
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
profitPerDayInLedger(ledgerId: string, options?: RawAxiosRequestConfig): AxiosPromise<Array<DailyProfitResponse>> {
return localVarFp.profitPerDayInLedger(ledgerId, options).then((request) => request(axios, basePath));
},
};
};
/**
* ProfitApi - object-oriented interface
*/
export class ProfitApi extends BaseAPI {
/**
*
* @summary Get the daily FIFO-realized margin series for a single or combined ledger
* @param {string} ledgerId Id of the ledger
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
public marginPerDayInLedger(ledgerId: string, options?: RawAxiosRequestConfig) {
return ProfitApiFp(this.configuration).marginPerDayInLedger(ledgerId, options).then((request) => request(this.axios, this.basePath));
}
/**
*
* @summary Get the daily profit series for a single or combined ledger
* @param {string} ledgerId Id of the ledger
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
public profitPerDayInLedger(ledgerId: string, options?: RawAxiosRequestConfig) {
return ProfitApiFp(this.configuration).profitPerDayInLedger(ledgerId, options).then((request) => request(this.axios, this.basePath));
}
}
/**
* ReprocessingApi - axios parameter creator
*/
@@ -4192,74 +4454,6 @@ export const TransactionApiAxiosParamCreator = function (configuration?: Configu
let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers};
return {
url: toPathString(localVarUrlObj),
options: localVarRequestOptions,
};
},
/**
*
* @summary Get the daily FIFO-realized profit series for a single ledger
* @param {string} ledgerId Id of the ledger
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
marginPerDayInLedger: async (ledgerId: string, options: RawAxiosRequestConfig = {}): Promise<RequestArgs> => {
// verify required parameter 'ledgerId' is not null or undefined
assertParamExists('marginPerDayInLedger', 'ledgerId', ledgerId)
const localVarPath = `/ledgers/{ledgerId}/margin`
.replace('{ledgerId}', encodeURIComponent(String(ledgerId)));
// use dummy base URL string because the URL constructor only accepts absolute URLs.
const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL);
let baseOptions;
if (configuration) {
baseOptions = configuration.baseOptions;
}
const localVarRequestOptions = { method: 'GET', ...baseOptions, ...options};
const localVarHeaderParameter = {} as any;
const localVarQueryParameter = {} as any;
localVarHeaderParameter['Accept'] = '*/*';
setSearchParams(localVarUrlObj, localVarQueryParameter);
let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers};
return {
url: toPathString(localVarUrlObj),
options: localVarRequestOptions,
};
},
/**
*
* @summary Get the daily profit series for a single ledger
* @param {string} ledgerId Id of the ledger
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
profitPerDayInLedger: async (ledgerId: string, options: RawAxiosRequestConfig = {}): Promise<RequestArgs> => {
// verify required parameter 'ledgerId' is not null or undefined
assertParamExists('profitPerDayInLedger', 'ledgerId', ledgerId)
const localVarPath = `/ledgers/{ledgerId}/profit`
.replace('{ledgerId}', encodeURIComponent(String(ledgerId)));
// use dummy base URL string because the URL constructor only accepts absolute URLs.
const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL);
let baseOptions;
if (configuration) {
baseOptions = configuration.baseOptions;
}
const localVarRequestOptions = { method: 'GET', ...baseOptions, ...options};
const localVarHeaderParameter = {} as any;
const localVarQueryParameter = {} as any;
localVarHeaderParameter['Accept'] = '*/*';
setSearchParams(localVarUrlObj, localVarQueryParameter);
let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers};
return {
url: toPathString(localVarUrlObj),
options: localVarRequestOptions,
@@ -4287,32 +4481,6 @@ export const TransactionApiFp = function(configuration?: Configuration) {
const localVarOperationServerBasePath = operationServerMap['TransactionApi.finAllTransactionsInLedger']?.[localVarOperationServerIndex]?.url;
return (axios, basePath) => createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration)(axios, localVarOperationServerBasePath || basePath);
},
/**
*
* @summary Get the daily FIFO-realized profit series for a single ledger
* @param {string} ledgerId Id of the ledger
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
async marginPerDayInLedger(ledgerId: string, options?: RawAxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<Array<DailyProfitResponse>>> {
const localVarAxiosArgs = await localVarAxiosParamCreator.marginPerDayInLedger(ledgerId, options);
const localVarOperationServerIndex = configuration?.serverIndex ?? 0;
const localVarOperationServerBasePath = operationServerMap['TransactionApi.marginPerDayInLedger']?.[localVarOperationServerIndex]?.url;
return (axios, basePath) => createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration)(axios, localVarOperationServerBasePath || basePath);
},
/**
*
* @summary Get the daily profit series for a single ledger
* @param {string} ledgerId Id of the ledger
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
async profitPerDayInLedger(ledgerId: string, options?: RawAxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<Array<DailyProfitResponse>>> {
const localVarAxiosArgs = await localVarAxiosParamCreator.profitPerDayInLedger(ledgerId, options);
const localVarOperationServerIndex = configuration?.serverIndex ?? 0;
const localVarOperationServerBasePath = operationServerMap['TransactionApi.profitPerDayInLedger']?.[localVarOperationServerIndex]?.url;
return (axios, basePath) => createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration)(axios, localVarOperationServerBasePath || basePath);
},
}
};
@@ -4332,26 +4500,6 @@ export const TransactionApiFactory = function (configuration?: Configuration, ba
finAllTransactionsInLedger(ledgerId: string, options?: RawAxiosRequestConfig): AxiosPromise<Array<TransactionResponse>> {
return localVarFp.finAllTransactionsInLedger(ledgerId, options).then((request) => request(axios, basePath));
},
/**
*
* @summary Get the daily FIFO-realized profit series for a single ledger
* @param {string} ledgerId Id of the ledger
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
marginPerDayInLedger(ledgerId: string, options?: RawAxiosRequestConfig): AxiosPromise<Array<DailyProfitResponse>> {
return localVarFp.marginPerDayInLedger(ledgerId, options).then((request) => request(axios, basePath));
},
/**
*
* @summary Get the daily profit series for a single ledger
* @param {string} ledgerId Id of the ledger
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
profitPerDayInLedger(ledgerId: string, options?: RawAxiosRequestConfig): AxiosPromise<Array<DailyProfitResponse>> {
return localVarFp.profitPerDayInLedger(ledgerId, options).then((request) => request(axios, basePath));
},
};
};
@@ -4369,28 +4517,6 @@ export class TransactionApi extends BaseAPI {
public finAllTransactionsInLedger(ledgerId: string, options?: RawAxiosRequestConfig) {
return TransactionApiFp(this.configuration).finAllTransactionsInLedger(ledgerId, options).then((request) => request(this.axios, this.basePath));
}
/**
*
* @summary Get the daily FIFO-realized profit series for a single ledger
* @param {string} ledgerId Id of the ledger
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
public marginPerDayInLedger(ledgerId: string, options?: RawAxiosRequestConfig) {
return TransactionApiFp(this.configuration).marginPerDayInLedger(ledgerId, options).then((request) => request(this.axios, this.basePath));
}
/**
*
* @summary Get the daily profit series for a single ledger
* @param {string} ledgerId Id of the ledger
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
public profitPerDayInLedger(ledgerId: string, options?: RawAxiosRequestConfig) {
return TransactionApiFp(this.configuration).profitPerDayInLedger(ledgerId, options).then((request) => request(this.axios, this.basePath));
}
}
+1
View File
@@ -1,5 +1,6 @@
export * from './ledger';
export * from './balanceAppraisal';
export * from './statistics';
export {default as LedgerLabel} from './LedgerLabel.vue';
export {default as LedgerSelect} from './LedgerSelect.vue';
+19
View File
@@ -0,0 +1,19 @@
import {describe, expect, test} from 'vitest';
import {latestDailyBalanceValue} from './statistics';
import type {DailyBalanceResponse} from '@/generated/mammon';
const balance = (date: string, averageValue: number): DailyBalanceResponse => ({
date, averageValue, highestValue: averageValue, lowestValue: averageValue,
});
describe('latestDailyBalanceValue', () => {
test('returns the average value of the most recent day in range', () => {
const result = latestDailyBalanceValue([balance('2026-08-01', 100), balance('2026-08-02', 150)]);
expect(result).toBe(150);
});
test('returns zero for an empty range', () => {
expect(latestDailyBalanceValue([])).toBe(0);
});
});
+11
View File
@@ -0,0 +1,11 @@
import type {DailyBalanceResponse} from "@/generated/mammon";
export const StatisticsModes = {
CashFlow: 'CASH_FLOW',
Margin: 'MARGIN',
DailyBalance: 'DAILY_BALANCE',
} as const;
export type StatisticsMode = typeof StatisticsModes[keyof typeof StatisticsModes];
export const latestDailyBalanceValue = (range: DailyBalanceResponse[]): number =>
range.at(-1)?.averageValue ?? 0;
+2
View File
@@ -12,6 +12,7 @@ import {
LocationApi,
MarketApi,
MeResponse,
ProfitApi,
ReprocessingApi,
RuleBookApi,
RuleScriptApi,
@@ -108,6 +109,7 @@ export const postLogout = (): Promise<void> =>
export const ledgerApi = new LedgerApi(undefined, mammonUrl, mammonAxiosInstance);
export const transactionApi = new TransactionApi(undefined, mammonUrl, mammonAxiosInstance);
export const profitApi = new ProfitApi(undefined, mammonUrl, mammonAxiosInstance);
export const characterApi = new CharacterApi(undefined, mammonUrl, mammonAxiosInstance);
export const corporationApi = new CorporationApi(undefined, mammonUrl, mammonAxiosInstance);
export const ruleBookApi = new RuleBookApi(undefined, mammonUrl, mammonAxiosInstance);
+2 -2
View File
@@ -55,7 +55,7 @@ const submit = async () => {
select(v);
await nextTick();
} else if (modelValue.value === undefined && suggestions.value.length > 0) {
} else if (suggestions.value.length > 0) {
select(suggestions.value[0]);
await nextTick();
}
@@ -92,7 +92,7 @@ watchEffect(async () => {
<img v-if="modelValue?.id" :src="`https://images.evetech.net/types/${modelValue.id}/icon?size=32`" alt="" />
<input type="text" v-model="name" @keyup.enter="submit" @keyup.down="moveDown" @keyup.up="moveUp" />
</div>
<div v-if="suggestions.length > 1" class="z-20 absolute w-96">
<div v-if="suggestions.length > 0" class="z-20 absolute w-96">
<div v-bind="containerProps" class="rounded-b" style="height: 300px">
<div v-bind="wrapperProps">
<div v-for="s in list" :key="s.index" class="hover:bg-slate-700" :class="{'bg-slate-500': s.index !== currentIndex, 'bg-emerald-500': s.index === currentIndex}" @click="select(s.data)">
+156
View File
@@ -0,0 +1,156 @@
<script setup lang="ts">
import {computed, ref, watch} from "vue";
import {
CategoryScale,
Chart as ChartJS,
type ChartData,
type ChartDataset,
type ChartOptions,
Filler,
Legend,
LinearScale,
LineController,
LineElement,
PointElement,
Tooltip,
} from "chart.js";
import {Chart} from "vue-chartjs";
import {latestDailyBalanceValue} from "@/ledger";
import {ledgerApi} from "@/mammon";
import {useProcessedResource} from "@/activity";
import {DailyBalanceResponse} from "@/generated/mammon";
import {IskLabel} from "@/market";
import {formatIsk} from "@/formaters";
import {DualRangeSlider} from "@/components";
ChartJS.register(
CategoryScale, LinearScale,
LineController, LineElement, PointElement,
Tooltip, Legend, Filler,
);
const props = defineProps<{ ledgerId: string }>();
const dailyBalances = useProcessedResource<DailyBalanceResponse[]>(async () => {
if (!props.ledgerId) {
return [];
}
const {data} = await ledgerApi.dailyValuationForLedger(props.ledgerId);
return data;
}, []);
const dates = computed(() => dailyBalances.value.map(b => b.date));
const from = ref(0);
const to = ref(0);
watch(dates, d => {
from.value = 0;
to.value = Math.max(d.length - 1, 0);
}, {immediate: true});
const maxIndex = computed(() => Math.max(dates.value.length - 1, 0));
const dailyBalanceRange = computed(() => dailyBalances.value.slice(from.value, to.value + 1));
const hasData = computed(() => dailyBalances.value.length > 0);
const baseline = computed(() => dailyBalanceRange.value[0]?.averageValue ?? 0);
const total = computed(() => latestDailyBalanceValue(dailyBalanceRange.value) - baseline.value);
const chartData = computed<ChartData<'line'>>(() => {
const highest: ChartDataset<'line'> = {
label: 'Highest',
data: dailyBalanceRange.value.map(b => b.highestValue - baseline.value),
borderColor: 'transparent',
backgroundColor: 'rgba(56, 189, 248, 0.15)',
pointRadius: 0,
tension: 0.2,
fill: '+1',
order: 2,
};
const lowest: ChartDataset<'line'> = {
label: 'Lowest',
data: dailyBalanceRange.value.map(b => b.lowestValue - baseline.value),
borderColor: 'transparent',
backgroundColor: 'rgba(56, 189, 248, 0.15)',
pointRadius: 0,
tension: 0.2,
fill: false,
order: 2,
};
const average: ChartDataset<'line'> = {
type: 'line',
label: 'Average',
data: dailyBalanceRange.value.map(b => b.averageValue - baseline.value),
borderColor: '#38bdf8',
backgroundColor: 'rgba(56, 189, 248, 0.15)',
pointBackgroundColor: ctx => (Number(ctx.dataset.data[ctx.dataIndex]) < 0 ? '#f87171' : '#34d399'),
pointBorderColor: ctx => (Number(ctx.dataset.data[ctx.dataIndex]) < 0 ? '#f87171' : '#34d399'),
segment: {
borderColor: ctx => ((ctx.p0.parsed.y ?? 0) < 0 || (ctx.p1.parsed.y ?? 0) < 0 ? '#f87171' : '#34d399'),
},
fill: false,
tension: 0.2,
order: 1,
};
return {
labels: dailyBalanceRange.value.map(b => b.date),
datasets: [highest, lowest, average],
};
});
const chartOptions = computed<ChartOptions<'line'>>(() => ({
responsive: true,
maintainAspectRatio: false,
interaction: {mode: 'index', intersect: false},
plugins: {
legend: {display: true},
tooltip: {
callbacks: {
label: ctx => `${ctx.dataset.label}: ${formatIsk(ctx.parsed.y ?? 0)}`,
},
},
},
scales: {
x: {stacked: false},
y: {
position: 'left',
stacked: false,
ticks: {
callback: value => formatIsk(Number(value)),
},
grid: {
lineWidth: ctx => (ctx.tick.value === 0 ? 2 : 1),
color: ctx => (ctx.tick.value === 0 ? 'rgba(226, 232, 240, 0.6)' : 'rgba(148, 163, 184, 0.2)'),
},
}
},
}));
</script>
<template>
<div class="flex justify-end mb-4">
<span class="mr-2">Change:</span>
<IskLabel :amount="total" />
</div>
<p v-if="!hasData" class="text-center text-gray-400 mt-8">No daily balance recorded for this ledger</p>
<template v-else>
<div class="h-96">
<Chart type="line" :data="chartData" :options="chartOptions" />
</div>
<div class="flex items-center gap-3 mt-4">
<span class="text-sm w-24 text-gray-400">{{ dates[from] }}</span>
<DualRangeSlider class="grow" :min="0" :max="maxIndex" v-model:from="from" v-model:to="to" />
<span class="text-sm w-24 text-right text-gray-400">{{ dates[to] }}</span>
</div>
</template>
</template>
+154
View File
@@ -0,0 +1,154 @@
<script setup lang="ts">
import {computed, ref, watch} from "vue";
import {
BarController,
BarElement,
CategoryScale,
Chart as ChartJS,
type ChartData,
type ChartDataset,
type ChartOptions,
Filler,
Legend,
LinearScale,
LineController,
LineElement,
PointElement,
Tooltip,
} from "chart.js";
import {Chart} from "vue-chartjs";
import {StatisticsModes, type StatisticsMode} from "@/ledger";
import {profitApi} from "@/mammon";
import {useProcessedResource} from "@/activity";
import {DailyProfitResponse} from "@/generated/mammon";
import {IskLabel} from "@/market";
import {formatIsk} from "@/formaters";
import {DualRangeSlider} from "@/components";
ChartJS.register(
CategoryScale, LinearScale,
BarController, BarElement,
LineController, LineElement, PointElement,
Tooltip, Legend, Filler,
);
const props = defineProps<{ ledgerId: string; mode: StatisticsMode }>();
const profits = useProcessedResource<DailyProfitResponse[]>(async () => {
if (!props.ledgerId) {
return [];
}
const {data} = props.mode === StatisticsModes.Margin
? await profitApi.marginPerDayInLedger(props.ledgerId)
: await profitApi.profitPerDayInLedger(props.ledgerId);
return data;
}, []);
const dates = computed(() => profits.value.map(p => p.date));
const from = ref(0);
const to = ref(0);
watch(dates, d => {
from.value = 0;
to.value = Math.max(d.length - 1, 0);
}, {immediate: true});
const maxIndex = computed(() => Math.max(dates.value.length - 1, 0));
const profitRange = computed(() => profits.value.slice(from.value, to.value + 1));
const total = computed(() => profitRange.value.reduce((sum, p) => sum + p.profit, 0));
const hasData = computed(() => profits.value.length > 0);
const cumulativeProfit = computed(() => {
let running = 0;
return profitRange.value.map(p => (running += p.profit));
});
const chartData = computed<ChartData<'bar' | 'line'>>(() => {
const cumulative: ChartDataset<'line'> = {
type: 'line',
label: 'Cumulative profit',
data: cumulativeProfit.value,
borderColor: '#38bdf8',
backgroundColor: 'rgba(56, 189, 248, 0.15)',
pointBackgroundColor: '#38bdf8',
fill: true,
tension: 0.2,
yAxisID: 'y',
order: 0,
};
const iskIn: ChartDataset<'bar'> = {
type: 'bar',
label: 'ISK in',
data: profitRange.value.map(p => p.iskIn),
backgroundColor: 'rgba(16, 185, 129, 0.7)',
yAxisID: 'y',
order: 1,
};
const iskOut: ChartDataset<'bar'> = {
type: 'bar',
label: 'ISK out',
data: profitRange.value.map(p => -p.iskOut),
backgroundColor: 'rgba(180, 83, 9, 0.7)',
yAxisID: 'y',
order: 1,
};
return {
labels: profitRange.value.map(p => p.date),
datasets: [cumulative, iskIn, iskOut],
};
});
const chartOptions = computed<ChartOptions<'bar' | 'line'>>(() => ({
responsive: true,
maintainAspectRatio: false,
interaction: {mode: 'index', intersect: false},
plugins: {
legend: {display: true},
tooltip: {
callbacks: {
label: ctx => `${ctx.dataset.label}: ${formatIsk(ctx.parsed.y ?? 0)}`,
},
},
},
scales: {
x: {stacked: true},
y: {
position: 'left',
stacked: true,
ticks: {
callback: value => formatIsk(Number(value)),
},
}
},
}));
</script>
<template>
<div class="flex justify-end mb-4">
<span class="mr-2">Total profit:</span>
<IskLabel :amount="total" />
</div>
<p v-if="!hasData" class="text-center text-gray-400 mt-8">No trade profit recorded for this ledger</p>
<template v-else>
<div class="h-96">
<Chart type="bar" :data="chartData" :options="chartOptions" />
</div>
<div class="flex items-center gap-3 mt-4">
<span class="text-sm w-24 text-gray-400">{{ dates[from] }}</span>
<DualRangeSlider class="grow" :min="0" :max="maxIndex" v-model:from="from" v-model:to="to" />
<span class="text-sm w-24 text-right text-gray-400">{{ dates[to] }}</span>
</div>
</template>
</template>
+2 -2
View File
@@ -1,6 +1,6 @@
<script setup lang="ts">
import {RouterLink, RouterView} from 'vue-router';
import {appraiseItemBalances, getLedgerBalance, isMain, LedgerLabel, useLedgerParam} from "@/ledger";
import {appraiseItemBalances, getLedgerBalance, LedgerLabel, useLedgerParam} from "@/ledger";
import {routeNames} from "@/routes.ts";
import {getMarketTypes, getPrices, IskLabel} from "@/market";
import {useMarketLocationStore} from '@/market/location';
@@ -53,7 +53,7 @@ const itemAppraisal = computedAsync(async () => {
<RouterLink :to="{name: routeNames.listLedgerAcquisitions}" class="tab">
<span>Acquisitions</span>
</RouterLink>
<RouterLink v-if="isMain(ledger)" :to="{name: routeNames.viewLedgerStatistics}" class="tab">
<RouterLink :to="{name: routeNames.viewLedgerStatistics}" class="tab">
<span>Statistics</span>
</RouterLink>
</div>
+17 -159
View File
@@ -1,174 +1,33 @@
<script setup lang="ts">
import {computed, ref, watch} from "vue";
import {
BarController,
BarElement,
CategoryScale,
Chart as ChartJS,
type ChartData,
type ChartDataset,
type ChartOptions,
Filler,
Legend,
LinearScale,
LineController,
LineElement,
PointElement,
Tooltip,
} from "chart.js";
import {Chart} from "vue-chartjs";
import {useLedgerParam} from "@/ledger";
import {transactionApi} from "@/mammon";
import {useProcessedResource} from "@/activity";
import {DailyProfitResponse} from "@/generated/mammon";
import {IskLabel} from "@/market";
import {formatIsk} from "@/formaters";
import {DualRangeSlider} from "@/components";
import {ref} from "vue";
import {StatisticsModes, type StatisticsMode, useLedgerParam} from "@/ledger";
import DailyBalanceChart from "./DailyBalanceChart.vue";
import ProfitChart from "./ProfitChart.vue";
ChartJS.register(
CategoryScale, LinearScale,
BarController, BarElement,
LineController, LineElement, PointElement,
Tooltip, Legend, Filler,
);
const {ledgerId, ledger} = useLedgerParam();
const {ledgerId} = useLedgerParam();
const mode = ref<StatisticsMode>(StatisticsModes.DailyBalance);
const ProfitModes = {
CashFlow: 'CASH_FLOW',
Margin: 'MARGIN',
} as const;
type ProfitMode = typeof ProfitModes[keyof typeof ProfitModes];
const mode = ref<ProfitMode>(ProfitModes.CashFlow);
const profits = useProcessedResource<DailyProfitResponse[]>(async () => {
if (!ledgerId.value) {
return [];
}
const {data} = mode.value === ProfitModes.Margin
? await transactionApi.marginPerDayInLedger(ledgerId.value)
: await transactionApi.profitPerDayInLedger(ledgerId.value);
return data;
}, []);
const from = ref(0);
const to = ref(0);
watch(() => profits.value.length, length => {
from.value = 0;
to.value = Math.max(length - 1, 0);
}, {immediate: true});
const maxIndex = computed(() => Math.max(profits.value.length - 1, 0));
const range = computed(() => profits.value.slice(from.value, to.value + 1));
const total = computed(() => range.value.reduce((sum, p) => sum + p.profit, 0));
const cumulativeProfit = computed(() => {
let running = 0;
return range.value.map(p => (running += p.profit));
});
const chartData = computed<ChartData<'bar' | 'line'>>(() => {
const cumulative: ChartDataset<'line'> = {
type: 'line',
label: 'Cumulative profit',
data: cumulativeProfit.value,
borderColor: '#38bdf8',
backgroundColor: 'rgba(56, 189, 248, 0.15)',
pointBackgroundColor: '#38bdf8',
fill: true,
tension: 0.2,
yAxisID: 'y',
order: 0,
};
const iskIn: ChartDataset<'bar'> = {
type: 'bar',
label: 'ISK in',
data: range.value.map(p => p.iskIn),
backgroundColor: 'rgba(16, 185, 129, 0.7)',
yAxisID: 'y',
order: 1,
};
const iskOut: ChartDataset<'bar'> = {
type: 'bar',
label: 'ISK out',
data: range.value.map(p => -p.iskOut),
backgroundColor: 'rgba(180, 83, 9, 0.7)',
yAxisID: 'y',
order: 1,
};
return {
labels: range.value.map(p => p.date),
datasets: [cumulative, iskIn, iskOut],
};
});
const chartOptions = computed<ChartOptions<'bar' | 'line'>>(() => ({
responsive: true,
maintainAspectRatio: false,
interaction: {mode: 'index', intersect: false},
plugins: {
legend: {display: true},
tooltip: {
callbacks: {
label: ctx => `${ctx.dataset.label}: ${formatIsk(Math.abs(ctx.parsed.y ?? 0))}`,
},
},
},
scales: {
x: {
stacked: true,
},
y: {
position: 'left',
stacked: true,
ticks: {
callback: value => formatIsk(Math.abs(Number(value))),
},
}
},
}));
const isDailyBalance = (mode: StatisticsMode): mode is typeof StatisticsModes.DailyBalance =>
mode === StatisticsModes.DailyBalance;
</script>
<template>
<div class="mt-4">
<div v-if="ledger" class="mt-4">
<div class="flex justify-center mb-4">
<div class="flex bg-slate-600 rounded-s-md p-1">
<button class="switch" :class="{active: mode === ProfitModes.CashFlow}" @click="mode = ProfitModes.CashFlow">Cash Flow</button>
<button class="switch" :class="{active: mode === StatisticsModes.DailyBalance}" @click="mode = StatisticsModes.DailyBalance">Daily Balance</button>
</div>
<div class="switch flex bg-slate-600 rounded-e-md p-1">
<button class="switch" :class="{active: mode === ProfitModes.Margin}" @click="mode = ProfitModes.Margin">Margin</button>
<div class="flex bg-slate-600 p-1">
<button class="switch" :class="{active: mode === StatisticsModes.Margin}" @click="mode = StatisticsModes.Margin">Margin</button>
</div>
<div class="flex bg-slate-600 rounded-e-md p-1">
<button class="switch" :class="{active: mode === StatisticsModes.CashFlow}" @click="mode = StatisticsModes.CashFlow">Cash Flow</button>
</div>
</div>
<div class="flex justify-end mb-4">
<span class="mr-2">Total profit:</span>
<IskLabel :amount="total" />
</div>
<p v-if="profits.length === 0" class="text-center text-gray-400 mt-8">
No trade profit recorded for this ledger
</p>
<template v-else>
<div class="h-96">
<Chart type="bar" :data="chartData" :options="chartOptions" />
</div>
<div class="flex items-center gap-3 mt-4">
<span class="text-sm w-24 text-gray-400">{{ profits[from]?.date }}</span>
<DualRangeSlider class="grow" :min="0" :max="maxIndex" v-model:from="from" v-model:to="to" />
<span class="text-sm w-24 text-right text-gray-400">{{ profits[to]?.date }}</span>
</div>
</template>
<DailyBalanceChart v-if="isDailyBalance(mode)" :ledger-id="ledgerId" />
<ProfitChart v-else :ledger-id="ledgerId" :mode="mode" />
</div>
</template>
@@ -182,4 +41,3 @@ button.switch {
}
}
</style>