Skip to content

Commit

Permalink
Default agg to sum and simplified checks
Browse files Browse the repository at this point in the history
  • Loading branch information
Pelotfr committed Nov 22, 2023
1 parent 6441d18 commit a3277f2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const DEFAULT_MAX_LIMIT = 500;
export const DEFAULT_VERBOSE = false;
export const APP_NAME = pkg.name;
export const DEFAULT_SORT_BY = "DESC";
export const DEFAULT_AGGREGATE_FUNCTION = "count";
export const DEFAULT_AGGREGATE_FUNCTION = "sum";

// parse command line options
const opts = program
Expand Down
9 changes: 5 additions & 4 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { z } from 'zod';
import { DEFAULT_SORT_BY, config } from "./config.js";
import { DEFAULT_SORT_BY, DEFAULT_AGGREGATE_FUNCTION, config } from "./config.js";
import { store } from "./clickhouse/stores.js";
import { toText } from './fetch/cors.js';
import { NormalizedHistoryData } from './queries.js';
Expand Down Expand Up @@ -80,19 +80,20 @@ export function parseTimestamp(timestamp?: string|null|number) {
}

export function parseAggregateFunction(aggregate_function?: string|null) {
if (aggregate_function == undefined || aggregate_function == null || aggregate_function == '') return "sum";
// if not defined by user, use default
if (!aggregate_function) return DEFAULT_AGGREGATE_FUNCTION;
// if defined but not valid, return undefined
else if (!z.enum(["min", "max", "avg", "sum", "count", "median"]).safeParse(aggregate_function).success) {
return undefined;
}
return aggregate_function;
}

export function parseHistoryRange(range?: string|null) {
if (range == undefined || range == '') return "24h";
if (!range) return "24h";
if (!z.enum(["24h", "7d", "30d", "90d", "1y", "all"]).safeParse(range).success) {
return undefined;
}
//let interval = range.includes("h") ? 3600 : 86400;

return range;
}
Expand Down

0 comments on commit a3277f2

Please sign in to comment.