-
Notifications
You must be signed in to change notification settings - Fork 52
feat: busiest day of the week graph #243
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great start! I've added few insights. Please take a look :)
app/templates/agenda.html
Outdated
<div class="col-4"> | ||
<div class="card-body"> | ||
<canvas id="myChart" width="400" height="400"></canvas> | ||
<script src="../static/graph.js"></script> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prefer loading all the script
s in the end of the body
tag
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done!
and also changed to:
app/static/graph.js
Outdated
@@ -0,0 +1,47 @@ | |||
function makeGraph(events) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Which graph? Please change the names in the code to be more indicative :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
app/routers/agenda.py
Outdated
@@ -39,6 +40,18 @@ def agenda( | |||
"""Route for the agenda page, using dates range or exact amount of days.""" | |||
|
|||
user_id = 1 # there is no user session yet, so I use user id- 1. | |||
|
|||
start_date_graph, end_date_graph = calc_dates_range_for_agenda(0, 0, 7) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why 7? Try to avoid magic numbers :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
app/routers/agenda.py
Outdated
db, user_id, start_date_graph, end_date_graph | ||
) | ||
events_for_graph = { | ||
str(start_date_graph + timedelta(i)): 0 for i in range(8)} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why 8?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
well when it was 7 it actually returned 8 days
I changed it to return only a week
app/routers/agenda.py
Outdated
|
||
start_date_graph, end_date_graph = calc_dates_range_for_agenda(0, 0, 7) | ||
|
||
events_objects_for_graph = agenda_events.get_events_per_dates( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The name of the variables here can be a bit better :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
Codecov Report
@@ Coverage Diff @@
## develop #243 +/- ##
========================================
Coverage 98.16% 98.17%
========================================
Files 70 70
Lines 3000 3012 +12
========================================
+ Hits 2945 2957 +12
Misses 55 55
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome! I've added few of my insights. Please take a look :)
app/routers/agenda.py
Outdated
@@ -39,6 +40,21 @@ def agenda( | |||
"""Route for the agenda page, using dates range or exact amount of days.""" | |||
|
|||
user_id = 1 # there is no user session yet, so I use user id- 1. | |||
|
|||
get_a_week_int = 6 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why the get
prefix? Also, it looks like a constant, consider changing it to ALL_CAPITAL
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
app/routers/agenda.py
Outdated
|
||
get_a_week_int = 6 | ||
start_date_graph, end_date_graph = calc_dates_range_for_agenda( | ||
0, 0, get_a_week_int) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider changing to keyword arguments to make it more readable
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
app/routers/agenda.py
Outdated
@@ -39,6 +40,21 @@ def agenda( | |||
"""Route for the agenda page, using dates range or exact amount of days.""" | |||
|
|||
user_id = 1 # there is no user session yet, so I use user id- 1. | |||
|
|||
get_a_week_int = 6 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move all the logic to another function, preferably in a different file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
app/routers/agenda.py
Outdated
timedelta(i)): 0 for i in range(get_a_week_int + 1)} | ||
|
||
for event_obj in events_this_week: | ||
events_for_graph[str(event_obj.start.date())] += 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prefer splitting this to two lines for the sake of readability
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
app/routers/agenda.py
Outdated
db, user_id, start_date_graph, end_date_graph | ||
) | ||
events_for_graph = { | ||
str(start_date_graph + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm sure we can make these three lines bit more readable :) Please fix the line splitting
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
app/templates/agenda.html
Outdated
<div class="card-body"> | ||
<canvas id="myChart" width="400" height="400"></canvas> | ||
<div class="container" id="graph"> | ||
<script src="https://cdn.jsdelivr.net/npm/chart.js@2.8.0"></script> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move to the end of the <body>
block
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
app/internal/agenda_events.py
Outdated
@@ -89,3 +90,22 @@ def get_events_in_time_frame( | |||
"""Yields all user's events in a time frame.""" | |||
events = get_all_user_events(db, user_id) | |||
yield from filter_dates(events, start_date, end_date) | |||
|
|||
|
|||
def make_dict_for_graph_data(db: Session, user_id: int) -> Dict: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Specify what types the Dict
contains: Dict[key, value]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
app/templates/agenda.html
Outdated
@@ -60,4 +69,5 @@ <h1 id="dates">{{ start_date.strftime("%d/%m/%Y") }} - {{ end_date.strftime("%d/ | |||
{% endfor %} | |||
</div> | |||
|
|||
</div> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You sure you need to close this div here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
app/templates/base.html
Outdated
@@ -75,6 +75,8 @@ | |||
<!-- This bootstrap version is needed here because of the toggler bug in the beta version--> | |||
<script src="https://stackpath.bootstrapcdn.com/bootstrap/5.0.0-alpha2/js/bootstrap.bundle.min.js" integrity="sha384-BOsAfwzjNJHrJ8cZidOg56tcQWfp6y72vEJ8xQ9w6Quywb24iOsW913URv1IS4GD" crossorigin="anonymous"></script> | |||
<script src="{{ url_for('static', path='/horoscope.js') }}"></script> | |||
<script src="{{ url_for('static', path='/graph.js') }}"></script> | |||
<script src="https://cdn.jsdelivr.net/npm/chart.js@2.8.0"></script> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We already have Chart.js 2.9.4 included, see few lines above
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
app/internal/agenda_events.py
Outdated
"""create a dict with number of events per day for current week""" | ||
WEEK_DAYS = 6 | ||
start_date, end_date = agenda.calc_dates_range_for_agenda( | ||
0, 0, WEEK_DAYS) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add parameter names to make the call more understandable: X=0, Y=0, ..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I actually changed it to make it more readable
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
app/internal/agenda_events.py
Outdated
WEEK_DAYS = 6 | ||
start_date, end_date = agenda.calc_dates_range_for_agenda( | ||
0, 0, WEEK_DAYS) | ||
|
||
events_this_week = get_events_per_dates( | ||
db, user_id, start_date, end_date | ||
) | ||
events_for_graph = { | ||
str(start_date + timedelta(i)): 0 for i in range(WEEK_DAYS + 1) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be on a separate function
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
Probably the last set of fixes :) |
Resolve conflicts and send it to me for merge |
No description provided.