Skip to content

Commit

Permalink
feat(data): Add config constants to logs
Browse files Browse the repository at this point in the history
  • Loading branch information
CaedenPH committed Apr 2, 2024
1 parent 6444005 commit 160b2cf
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 7 deletions.
43 changes: 37 additions & 6 deletions src/routes/results.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,49 @@ import { Config } from "../types/Config";
export class ProcessResultsPage {
constructor(private app: Application, private ui: CogSpeedGraphicsHandler) {}

private formatObject(data: object): string {
private formatKey(key: string, capitalise: boolean = false): string {
let result = capitalise ? key[0].toUpperCase() : key[0];
let i = 0;
for (const letter of key.slice(1)) {
i ++;
if (letter === "_") {
continue;
}

if (key[i - 1] === "_") {
result += letter.toUpperCase();
} else {
result += letter;
}
}
return result;
}

private formatKeys(keys: string[]): string {
let result = "";
for (const key of keys) {
result += this.formatKey(key, key !== keys[0]);
}
return result
}

private formatObject(data: Record<string, any>, keys: string[] | null = null): string {
if (!data) return ``;

let formattedData = ``;
for (const [key, value] of Object.entries(data)) {
if (["answerLogs"].includes(key)) continue;
if (typeof value === "object") formattedData += this.formatObject(value);
else formattedData += `${key} = ${value}\n`;

// Add the keys
let copyKeys = null;
if (keys !== null) copyKeys = [...keys, key];
if (typeof value === "object") formattedData += this.formatObject(value, copyKeys);
else formattedData += `${copyKeys ? this.formatKeys(copyKeys): key} = ${value}\n`;
}
return formattedData;
}

private formatData(data: { [key: string]: any }): string {
private formatData(data: Record<string, any>, config: Config): string {
const keys = [
["Num", "roundNumber"],
["Type", "roundType"],
Expand Down Expand Up @@ -86,7 +116,8 @@ export class ProcessResultsPage {
alignment: "center",
content: "Answer logs\n(Rm = rolling mean average)",
},
})
}) +
`\n${this.formatObject(config, [])}`
);
}

Expand Down Expand Up @@ -204,7 +235,7 @@ export class ProcessResultsPage {
);
viewTestLogsButtonContainer.on(
"pointerdown",
this.downloadHandler.bind(this, this.formatData(data), 850 + data.answerLogs.length * 75)
this.downloadHandler.bind(this, this.formatData(data, config), 1850 + data.answerLogs.length * 75)
);

const restartTestButtonContainer = this.ui.createButton(
Expand Down
2 changes: 1 addition & 1 deletion src/routes/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ private async confirmSleepData(sleepData: { [key: string]: any }): Promise<boole
* @returns {Promise<SleepData>} The test data
*/
public async start(skipToDisplay: boolean): Promise<SleepData | false> {
// if (process.env.NODE_ENV === "development") return {fatigueLevel: -1};
if (process.env.NODE_ENV === "development") return {fatigueLevel: -1};

if (skipToDisplay) {
await this.displayReadyDemo(Infinity);
Expand Down

0 comments on commit 160b2cf

Please sign in to comment.