Added function to reformat raw database rows into the line chart array.
This commit is contained in:
33
src/lib/lineChartArray.ts
Normal file
33
src/lib/lineChartArray.ts
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
import { DailyStats } from "@/types/DailyStats";
|
||||||
|
import { LineChartArr, LineChartItem } from "@/types/LineChartStats";
|
||||||
|
|
||||||
|
const lineChartArr = (dailyStatsArr: DailyStats): LineChartArr => {
|
||||||
|
console.log(dailyStatsArr);
|
||||||
|
const lineChartArr = [] as LineChartArr;
|
||||||
|
|
||||||
|
if (dailyStatsArr.length) {
|
||||||
|
dailyStatsArr.forEach((item) => {
|
||||||
|
const { linksDeleted, commandResponses, timesTriggered, createdAt } =
|
||||||
|
item;
|
||||||
|
const day =
|
||||||
|
typeof createdAt === "number"
|
||||||
|
? new Date(createdAt * 1000).getDate()
|
||||||
|
: new Date().getDate();
|
||||||
|
|
||||||
|
const lineChartItem: LineChartItem = {
|
||||||
|
day,
|
||||||
|
"Links Deleted": linksDeleted,
|
||||||
|
Commands: commandResponses,
|
||||||
|
Triggers: timesTriggered
|
||||||
|
};
|
||||||
|
|
||||||
|
lineChartArr.push(lineChartItem);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(lineChartArr);
|
||||||
|
|
||||||
|
return lineChartArr;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default lineChartArr;
|
||||||
Reference in New Issue
Block a user