Skip to content

Commit

Permalink
feat: Add additional skew information
Browse files Browse the repository at this point in the history
Signed-off-by: Gordon Smith <[email protected]>
  • Loading branch information
GordonSmith committed Jul 8, 2024
1 parent 72287f3 commit d2026a0
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions packages/comms/src/ecl/workunit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export interface IPropertyValue {
Max?: string;
Delta?: string;
StdDev?: string;
StdDevs?: number;

// Related properties ---
SkewMin?: string;
Expand All @@ -58,6 +59,8 @@ export interface IScope {
__children?: IScope[];
__formattedProps: { [key: string]: any };
__groupedProps: { [key: string]: IPropertyValue };
__StdDevs: number,
__StdDevsSource: string,
id: string;
name: string;
type: string;
Expand Down Expand Up @@ -121,10 +124,21 @@ function formatValue(item: IScope, key: string): string | undefined {

type DedupProperties = { [key: string]: boolean };

function safeParseFloat(val: string | undefined): number | undefined {
if (val === undefined) return undefined;
const retVal = parseFloat(val);
return isNaN(retVal) ? undefined : retVal;
}

function formatValues(item: IScope, key: string, dedup: DedupProperties): IPropertyValue | null {
const keyParts = splitMetric(key);
if (!dedup[keyParts.measure]) {
dedup[keyParts.label] = true;
const avg = safeParseFloat(item[`${keyParts.measure}Avg${keyParts.label}`]);
const min = safeParseFloat(item[`${keyParts.measure}Min${keyParts.label}`]);
const max = safeParseFloat(item[`${keyParts.measure}Max${keyParts.label}`]);
const stdDev = safeParseFloat(item[`${keyParts.measure}StdDev${keyParts.label}`]);
const StdDevs = Math.max((avg - min) / stdDev, (max - avg) / stdDev);

return {
Key: `${keyParts.measure}${keyParts.label}`,
Expand All @@ -136,6 +150,7 @@ function formatValues(item: IScope, key: string, dedup: DedupProperties): IPrope
Max: formatValue(item, `${keyParts.measure}Max${keyParts.label}`),
Delta: formatValue(item, `${keyParts.measure}Delta${keyParts.label}`),
StdDev: formatValue(item, `${keyParts.measure}StdDev${keyParts.label}`),
StdDevs: isNaN(StdDevs) ? undefined : StdDevs,

// Related properties ---
SkewMin: formatValue(item, `SkewMin${keyParts.label}`),
Expand Down Expand Up @@ -720,6 +735,9 @@ export class Workunit extends StateObject<UWorkunitState, IWorkunitState> implem
Label: scope["Label"],
__formattedProps: formattedProps,
__groupedProps: {},
__groupedRawProps: {},
__StdDevs: 0,
__StdDevsSource: "",
...props
};
if (normalizedScope[DEFINITION_LIST]) {
Expand All @@ -745,6 +763,10 @@ export class Workunit extends StateObject<UWorkunitState, IWorkunitState> implem
const row = formatValues(normalizedScope, key, dedup);
if (row) {
normalizedScope.__groupedProps[row.Key] = row;
if (!isNaN(row.StdDevs) && normalizedScope.__StdDevs < row.StdDevs) {
normalizedScope.__StdDevs = row.StdDevs;
normalizedScope.__StdDevsSource = row.Key;
}
}
}
}
Expand Down

0 comments on commit d2026a0

Please sign in to comment.