refactor: define hydrogen BI metric semantics
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
export type MetricDomain = 'mileage';
|
||||
export type MetricUnit = 'km' | 'percent' | 'vehicle' | 'timestamp';
|
||||
export type MetricAggregation = 'sum' | 'weighted-ratio' | 'distinct-count' | 'latest';
|
||||
export type MetricDomain = 'mileage' | 'hydrogen';
|
||||
export type MetricUnit = 'km' | 'kg' | 'cny' | 'percent' | 'vehicle' | 'station' | 'order' | 'timestamp';
|
||||
export type MetricAggregation = 'sum' | 'count' | 'derived' | 'weighted-ratio' | 'distinct-count' | 'latest';
|
||||
export type MetricTimeSemantics = 'flow' | 'snapshot' | 'freshness';
|
||||
|
||||
export interface MetricDefinition {
|
||||
@@ -14,10 +14,10 @@ export interface MetricDefinition {
|
||||
formula: string;
|
||||
sources: readonly string[];
|
||||
dimensions: readonly string[];
|
||||
drillEntity: 'vehicle' | 'assessment-target';
|
||||
drillEntity: 'vehicle' | 'assessment-target' | 'hydrogen-station' | 'hydrogen-customer' | 'hydrogen-order';
|
||||
}
|
||||
|
||||
export const METRIC_CATALOG_VERSION = 1;
|
||||
export const METRIC_CATALOG_VERSION = 2;
|
||||
|
||||
const MILEAGE_METRICS: readonly MetricDefinition[] = [
|
||||
{
|
||||
@@ -87,7 +87,117 @@ const MILEAGE_METRICS: readonly MetricDefinition[] = [
|
||||
},
|
||||
];
|
||||
|
||||
export const METRIC_CATALOG: readonly MetricDefinition[] = MILEAGE_METRICS;
|
||||
const HYDROGEN_METRICS: readonly MetricDefinition[] = [
|
||||
{
|
||||
id: 'hydrogen.refuel_mass',
|
||||
domain: 'hydrogen',
|
||||
label: '加氢量',
|
||||
description: '有效加氢账本订单的实际加注质量之和。',
|
||||
unit: 'kg',
|
||||
aggregation: 'sum',
|
||||
timeSemantics: 'flow',
|
||||
formula: "SUM(amount_kg) WHERE del_flag = '0'",
|
||||
sources: ['hydrogen_fuel_ledger'],
|
||||
dimensions: ['date', 'station', 'region', 'customer', 'payer', 'plate'],
|
||||
drillEntity: 'hydrogen-order',
|
||||
},
|
||||
{
|
||||
id: 'hydrogen.refuel_cost',
|
||||
domain: 'hydrogen',
|
||||
label: '加氢成本',
|
||||
description: '有效加氢订单记录的站点结算成本之和,不代表客户应收。',
|
||||
unit: 'cny',
|
||||
aggregation: 'sum',
|
||||
timeSemantics: 'flow',
|
||||
formula: "SUM(cost_total) WHERE del_flag = '0'",
|
||||
sources: ['hydrogen_fuel_ledger'],
|
||||
dimensions: ['date', 'station', 'region', 'customer', 'payer', 'plate'],
|
||||
drillEntity: 'hydrogen-order',
|
||||
},
|
||||
{
|
||||
id: 'hydrogen.customer_revenue',
|
||||
domain: 'hydrogen',
|
||||
label: '客户收入',
|
||||
description: '有效加氢订单账本中客户应收金额 fee_total 之和。',
|
||||
unit: 'cny',
|
||||
aggregation: 'sum',
|
||||
timeSemantics: 'flow',
|
||||
formula: "SUM(fee_total) WHERE del_flag = '0'",
|
||||
sources: ['hydrogen_fuel_ledger'],
|
||||
dimensions: ['date', 'station', 'region', 'customer', 'plate'],
|
||||
drillEntity: 'hydrogen-customer',
|
||||
},
|
||||
{
|
||||
id: 'hydrogen.customer_order_cost',
|
||||
domain: 'hydrogen',
|
||||
label: '客户单成本',
|
||||
description: '存在客户单价或客户应收金额的订单,其站点结算成本之和。',
|
||||
unit: 'cny',
|
||||
aggregation: 'sum',
|
||||
timeSemantics: 'flow',
|
||||
formula: "SUM(cost_total) WHERE del_flag = '0' AND (customer_price > 0 OR fee_total > 0)",
|
||||
sources: ['hydrogen_fuel_ledger'],
|
||||
dimensions: ['date', 'station', 'region', 'customer', 'plate'],
|
||||
drillEntity: 'hydrogen-customer',
|
||||
},
|
||||
{
|
||||
id: 'hydrogen.customer_order_gross_profit',
|
||||
domain: 'hydrogen',
|
||||
label: '客户单毛利',
|
||||
description: '客户收入减去客户单对应的站点结算成本,不包含公司承担订单及其他经营费用。',
|
||||
unit: 'cny',
|
||||
aggregation: 'derived',
|
||||
timeSemantics: 'flow',
|
||||
formula: 'hydrogen.customer_revenue - hydrogen.customer_order_cost',
|
||||
sources: ['hydrogen_fuel_ledger'],
|
||||
dimensions: ['date', 'station', 'region', 'customer'],
|
||||
drillEntity: 'hydrogen-customer',
|
||||
},
|
||||
{
|
||||
id: 'hydrogen.refuel_order_count',
|
||||
domain: 'hydrogen',
|
||||
label: '加氢订单数',
|
||||
description: '有效加氢账本订单数量。',
|
||||
unit: 'order',
|
||||
aggregation: 'count',
|
||||
timeSemantics: 'flow',
|
||||
formula: "COUNT(*) WHERE del_flag = '0'",
|
||||
sources: ['hydrogen_fuel_ledger'],
|
||||
dimensions: ['date', 'station', 'region', 'customer', 'payer', 'plate'],
|
||||
drillEntity: 'hydrogen-order',
|
||||
},
|
||||
{
|
||||
id: 'hydrogen.station_count',
|
||||
domain: 'hydrogen',
|
||||
label: '有加注站点数',
|
||||
description: '所选时间和筛选范围内产生有效加氢订单的去重站点数量。',
|
||||
unit: 'station',
|
||||
aggregation: 'distinct-count',
|
||||
timeSemantics: 'flow',
|
||||
formula: "COUNT(DISTINCT station_id) WHERE del_flag = '0'",
|
||||
sources: ['hydrogen_fuel_ledger', 'hydrogen_station'],
|
||||
dimensions: ['date', 'region', 'payer'],
|
||||
drillEntity: 'hydrogen-station',
|
||||
},
|
||||
{
|
||||
id: 'hydrogen.vehicle_count',
|
||||
domain: 'hydrogen',
|
||||
label: '加氢车辆数',
|
||||
description: '所选时间和筛选范围内产生有效加氢订单的去重车牌数量。',
|
||||
unit: 'vehicle',
|
||||
aggregation: 'distinct-count',
|
||||
timeSemantics: 'flow',
|
||||
formula: "COUNT(DISTINCT plate_number) WHERE del_flag = '0'",
|
||||
sources: ['hydrogen_fuel_ledger'],
|
||||
dimensions: ['date', 'station', 'region', 'customer', 'payer'],
|
||||
drillEntity: 'vehicle',
|
||||
},
|
||||
];
|
||||
|
||||
export const METRIC_CATALOG: readonly MetricDefinition[] = [
|
||||
...MILEAGE_METRICS,
|
||||
...HYDROGEN_METRICS,
|
||||
];
|
||||
|
||||
export function isMetricDomain(value: string): value is MetricDomain {
|
||||
return METRIC_CATALOG.some(metric => metric.domain === value);
|
||||
|
||||
Reference in New Issue
Block a user