Skip to content

Commit

Permalink
Fix sorting by date string
Browse files Browse the repository at this point in the history
Contributed on behalf of STMicroelectronics
  • Loading branch information
planger committed Aug 11, 2023
1 parent 81bc64c commit 43fd34f
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions scripts/performance-report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,11 +220,10 @@ export async function generatePerformanceReport(path: string) {

export async function readValuesFromHistory(path: string, values: string[]): Promise<Map<string, ValueHistory>> {
const valueHistoryMap = initializeValueHistoryMap(values);
const files = fs.readdirSync(path).sort();
const files = fs.readdirSync(path)
.filter(file => !file.endsWith('index.html'))
.sort((a, b) => toDate(a).getTime() - toDate(b).getTime());
for (const file of files) {
if (file.endsWith('index.html')) {
continue;
}
const entryLabel = file.substring(0, file.indexOf('.'));
const entries = await readEntries(path + '/' + file, values);
entries.forEach(entry =>
Expand All @@ -243,6 +242,13 @@ export function initializeValueHistoryMap(values: string[]) {
return valueHistoryMap;
}

export function toDate(fileName: string): Date {
const [date, timeString] = fileName.replace('.txt', '').split('T');
const dateFragments = date.split('-').map(str => Number.parseInt(str));
const timeFragments = timeString.split('-').map(str => Number.parseInt(str));
return new Date(dateFragments[0], dateFragments[1], dateFragments[2], timeFragments[0], timeFragments[1], timeFragments[2]);
}

export async function readEntries(path: string, values: string[]): Promise<{ valueLabel: string, entryValue: number }[]> {
const entries: { valueLabel: string, entryValue: number }[] = [];
try {
Expand Down

0 comments on commit 43fd34f

Please sign in to comment.