Skip to content

Commit

Permalink
Improve date format on dashboard's weekly chart
Browse files Browse the repository at this point in the history
  • Loading branch information
eddyharrington committed Apr 1, 2021
1 parent ac09299 commit 8208532
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion static/js/dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ function loadWeeklySpendingCharts(weeklySpending) {
let spendingChart = new Chart(chartElement, {
type: 'line',
data: {
labels: [weeklySpending[0].startOfWeek.slice(5) + " - " + weeklySpending[0].endOfWeek.slice(5), weeklySpending[1].startOfWeek.slice(5) + " - " + weeklySpending[1].endOfWeek.slice(5), weeklySpending[2].startOfWeek.slice(5) + " - " + weeklySpending[2].endOfWeek.slice(5), weeklySpending[3].startOfWeek.slice(5) + " - " + weeklySpending[3].endOfWeek.slice(5)],
labels: [weeklySpending[0].startOfWeek.slice(0, 6) + " - " + weeklySpending[0].endOfWeek.slice(0, 6), weeklySpending[1].startOfWeek.slice(0, 6) + " - " + weeklySpending[1].endOfWeek.slice(0, 6), weeklySpending[2].startOfWeek.slice(0, 6) + " - " + weeklySpending[2].endOfWeek.slice(0, 6), weeklySpending[3].startOfWeek.slice(0, 6) + " - " + weeklySpending[3].endOfWeek.slice(0, 6)],
datasets: [{
label: 'Total $ Spent',
data: [(Math.round(weeklySpending[0].amount * 100) / 100), (Math.round(weeklySpending[1].amount * 100) / 100), (Math.round(weeklySpending[2].amount * 100) / 100), (Math.round(weeklySpending[3].amount * 100) / 100)],
Expand Down
6 changes: 3 additions & 3 deletions tendie_dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,11 @@ def getWeeklySpending(weekNames, userID):

# Loop through each week and store the name/amount in a dict
for name in weekNames:
week["endOfWeek"] = str(name["endofweek"])
week["startOfWeek"] = str(name["startofweek"])
week["endOfWeek"] = name['endofweek'].strftime('%b %d')
week["startOfWeek"] = name['startofweek'].strftime('%b %d')
results = db.execute(
"SELECT SUM(amount) AS amount FROM expenses WHERE user_id = :usersID AND date_part('year', date(expensedate)) = date_part('year', date(:weekName)) AND date_part('week', date(expensedate)) = date_part('week',date(:weekName))",
{"usersID": userID, "weekName": week["endOfWeek"]}).fetchall()
{"usersID": userID, "weekName": str(name["endofweek"])}).fetchall()
weekSpending = convertSQLToDict(results)

# Set the amount to 0 if there are no expenses for a given week
Expand Down

0 comments on commit 8208532

Please sign in to comment.