Skip to content

Commit

Permalink
rename all category_totals to camelCase
Browse files Browse the repository at this point in the history
  • Loading branch information
0xbrayo committed Mar 23, 2024
1 parent dab842e commit 12d6e53
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/components/PieChart.vue
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@ const chartOptions = {
const summaries = ref(props.summaries)
const uniqueCategoriesSet: Set<string> = new Set()
summaries.value?.forEach((summary) => {
for (const category in summary.category_totals) {
for (const category in summary.categoryTotals) {
uniqueCategoriesSet.add(category)
}
})
const uniqueCategories = Array.from(uniqueCategoriesSet)
const categoryTotals: number[] = []
for (const category of uniqueCategories) {
const categoryTotal = summaries.value?.reduce((acc, summary) => {
return acc + (summary.category_totals[category] || 0)
return acc + (summary.categoryTotals[category] || 0)
}, 0)
categoryTotals.push(categoryTotal || 0)
}
Expand Down
6 changes: 3 additions & 3 deletions src/components/StackedBarChart.vue
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ const uniqueWeekDays = uniqueDatesSorted.map((date) => {
})
const uniqueCategoriesSet: Set<string> = new Set()
summaries.value?.forEach((summary) => {
for (const category in summary?.category_totals) {
for (const category in summary?.categoryTotals) {
uniqueCategoriesSet.add(category)
}
})
Expand All @@ -75,9 +75,9 @@ uniqueCategories.forEach((category) => {
})
summaries.value?.forEach((summary) => {
for (const category in summary?.category_totals) {
for (const category in summary?.categoryTotals) {
const dateIndex = uniqueDatesSorted.indexOf(summary?.date)
categoryValues[category][dateIndex] = summary?.category_totals[category]
categoryValues[category][dateIndex] = summary?.categoryTotals[category]
}
})
chartData.value.datasets = uniqueCategories.map((category) => {
Expand Down
10 changes: 5 additions & 5 deletions src/firebase/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,19 @@ import type { ScreenTimeData, ScreenTimeSummary } from '@/types'

export function dataToSummary(data: ScreenTimeData): ScreenTimeSummary {
const total = data.events.reduce((acc, event) => acc + event.duration, 0)
const category_totals: { [key: string]: number } = {}
const categoryTotals: { [key: string]: number } = {}
data.events.forEach((event) => {
const category = event.data.category
if (!category_totals[category]) {
category_totals[category] = 0
if (!categoryTotals[category]) {
categoryTotals[category] = 0
}
category_totals[category] += event.duration
categoryTotals[category] += event.duration
})
return {
userId: data.userId,
total,
date: data.date,
category_totals
categoryTotals
}
}

Expand Down

0 comments on commit 12d6e53

Please sign in to comment.