Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions utils/convertToChartData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export async function createChartData(
metadata: Metadata;
startTime: number;
endTime: number;
categories?: { [key: string]: string[] };
},
replaces: string[],
): Promise<{ realTimeData: ChartSection[]; documentedData: ChartSection[] }> {
Expand Down Expand Up @@ -89,7 +90,7 @@ export async function createChartData(
// nulls come from the following function
await appendMissingDataSections(chartData, protocol, data);
const consolidated = consolidateDuplicateKeys(chartData);
return consolidated;
return mapToServerData(consolidated, data.categories);
}
}
function nullsInApiData(res: any): boolean {
Expand All @@ -106,6 +107,7 @@ async function appendMissingDataSections(
metadata: Metadata;
startTime: number;
endTime: number;
categories?: { [key: string]: string[] };
},
) {
const incompleteSections = data.metadata.incompleteSections;
Expand Down Expand Up @@ -179,6 +181,7 @@ function appendForecast(
metadata: Metadata;
startTime: number;
endTime: number;
categories?: { [key: string]: string[] };
},
) {
let err: boolean = false;
Expand Down Expand Up @@ -400,16 +403,28 @@ function discreet(raw: RawResult, config: ChartConfig): ChartData {
return { timestamps, unlocked, apiData, isContinuous: false };
}

export function mapToServerData(testData: ChartSection[]) {
export function mapToServerData(
testData: ChartSection[],
categories?: { [key: string]: string[] }
) {
const serverData: any[] = testData.map((s: ChartSection) => {
const label = s.section;
let category: string | undefined;
if (categories) {
for (const [cat, sections] of Object.entries(categories)) {
if (sections.includes(label)) {
category = cat;
break;
}
}
}

const data = s.data.timestamps.map((timestamp: number, i: number) => ({
timestamp,
unlocked: s.data.unlocked[i],
}));

return { label, data };
return { label, category, data };
});

return serverData;
Expand Down
Loading