Skip to content
This repository has been archived by the owner on Jan 16, 2024. It is now read-only.

Commit

Permalink
chore(utils:processing): use array to filter out keys from `ProblemVe…
Browse files Browse the repository at this point in the history
…rdictMap`

  ## what
  - use array to filter out keys from `ProblemVerdictMap`
    - use an array to filter which keys to keep in `ProblemVerdictMap`
    - filter out keys from ProblemVerdictMap using the array
    - update references
      - setting `tooltipTitle`
      - setting `fill`

  ## how

  ## why
  - to keep up with the changes in `ProblemVerdictMap`
    - check c041074
  - be default `ProblemVerdictMap` contains all verdicts
    - don't need to show all of them in a bar chart

  ## where
  - ./src/utils/dataProcessing.ts

  ## usage
  • Loading branch information
Clumsy-Coder committed Jan 7, 2024
1 parent c041074 commit 2ab82d3
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/utils/dataProcessing.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Problem, ProblemVerdictColors, ProblemVerdictMap } from "@/types";
import { Problem, ProblemVerdictMap, ProblemVerdictType } from "@/types";

export type processedProblemVerdictBarChartType = {
/**
Expand All @@ -21,14 +21,24 @@ export type processedProblemVerdictBarChartType = {
fill: string;
};
export const processProblemNumBarChartData = (data: Problem) => {
// filter out the ProblemVerdictMap object and keep keys from `filter` array
const filter = ["ac", "pe", "wa", "tle", "mle", "ce", "re", "ole"]
// const filteredVerdicts: Record<string, ProblemVerdictType> = {}
// filter.forEach(( key: string ) => {
// filteredVerdicts[key] = ProblemVerdictMap[key]
// })
//
// obtained from https://stackoverflow.com/a/69676994/3053548
const filteredVerdicts: Record<string, ProblemVerdictType> = Object.fromEntries(filter.map(k => [k, ProblemVerdictMap[k]]))

const processedData:processedProblemVerdictBarChartType[] = []

for(const [key, value] of Object.entries(ProblemVerdictMap)) {
for(const [key, value] of Object.entries(filteredVerdicts)) {
processedData.push({
name: key.toUpperCase(),
verdict: data[key as keyof Problem] as number,
tooltipTitle: value,
fill: ProblemVerdictColors[key],
tooltipTitle: value.title,
fill: ProblemVerdictMap[key].bgHex,
})
}

Expand Down

0 comments on commit 2ab82d3

Please sign in to comment.