From 36a211e186bae66e21dabe11dc36ea356da2d424 Mon Sep 17 00:00:00 2001 From: Hykilpikonna Date: Tue, 27 Aug 2019 20:55:06 +0800 Subject: [PATCH] [+] Create method to convert chart data --- src/pages/overall/overall.ts | 68 ++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) diff --git a/src/pages/overall/overall.ts b/src/pages/overall/overall.ts index 313b877..9c36c95 100644 --- a/src/pages/overall/overall.ts +++ b/src/pages/overall/overall.ts @@ -8,4 +8,72 @@ import {Course} from '@/components/app/app'; export default class Overall extends Vue { @Prop({required: true}) courses: any; + + get convertCharts() + { + // Null case + if (this.courses == null) return []; + + // Compute the column names + let columns = ['date']; + this.courses.forEach((course: Course) => + { + columns.push(course.name); + }); + + // Find the min date + let minDate: Date = new Date(); + this.courses.forEach((course: Course) => + { + let date = new Date(course.assignments[course.assignments.length - 1].date); + if (date < minDate) minDate = date; + }); + + // Find the dates in between + let now = new Date(); + let dates = []; + for (let date = minDate; date <= now; date.setDate(date.getDate() + 1)) + { + dates.push(new Date(date)); + } + + // Compute the rows data + let rows: {[index: string]: any}[] = []; + let courseAverages = {}; + dates.forEach(date => + { + // Define row object + let row: {[index: string]:any} = {'date': date}; + + // Loop through courses + this.courses.forEach((course: Course) => + { + course.assignments.forEach(assignment => + { + // Date is being looked at + if (new Date(assignment.date) == date) + { + row[course.name] = assignment.score; + } + + // Not now! + if (new Date(assignment.date) > date) + { + // Exit the course loop. + return; + } + }); + }); + + // Add it to the array + rows.push(row); + }); + + console.log(rows); + + return { + columns: columns, + rows: rows + } + } }