Skip to content

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

Merged
merged 24 commits into from
Feb 22, 2021

Conversation

nadav-pesach
Copy link
Contributor

No description provided.

Copy link
Member

@yammesicka yammesicka left a 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 :)

<div class="col-4">
<div class="card-body">
<canvas id="myChart" width="400" height="400"></canvas>
<script src="../static/graph.js"></script>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer loading all the scripts in the end of the body tag

Copy link
Contributor Author

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:

<script src="{{ url_for('static', path='/graph.js') }}"></script>

@@ -0,0 +1,47 @@
function makeGraph(events) {
Copy link
Member

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 :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@@ -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)
Copy link
Member

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 :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

db, user_id, start_date_graph, end_date_graph
)
events_for_graph = {
str(start_date_graph + timedelta(i)): 0 for i in range(8)}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why 8?

Copy link
Contributor Author

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


start_date_graph, end_date_graph = calc_dates_range_for_agenda(0, 0, 7)

events_objects_for_graph = agenda_events.get_events_per_dates(
Copy link
Member

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 :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@codecov-io
Copy link

codecov-io commented Feb 9, 2021

Codecov Report

Merging #243 (2e25250) into develop (b8f94b2) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff            @@
##           develop     #243   +/-   ##
========================================
  Coverage    98.16%   98.17%           
========================================
  Files           70       70           
  Lines         3000     3012   +12     
========================================
+ Hits          2945     2957   +12     
  Misses          55       55           
Impacted Files Coverage Δ
app/internal/agenda_events.py 100.00% <100.00%> (ø)
app/routers/agenda.py 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b8f94b2...2e25250. Read the comment docs.

Copy link
Member

@yammesicka yammesicka left a 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 :)

@@ -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
Copy link
Member

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


get_a_week_int = 6
start_date_graph, end_date_graph = calc_dates_range_for_agenda(
0, 0, get_a_week_int)
Copy link
Member

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@@ -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
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

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
Copy link
Member

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

db, user_id, start_date_graph, end_date_graph
)
events_for_graph = {
str(start_date_graph +
Copy link
Member

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

<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>
Copy link
Member

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@@ -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:
Copy link
Member

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]

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@@ -60,4 +69,5 @@ <h1 id="dates">{{ start_date.strftime("%d/%m/%Y") }} - {{ end_date.strftime("%d/
{% endfor %}
</div>

</div>
Copy link
Member

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@@ -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>
Copy link
Member

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

"""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)
Copy link
Member

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, ..

Copy link
Contributor Author

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment on lines 97 to 106
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)
}
Copy link
Member

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@yammesicka
Copy link
Member

Probably the last set of fixes :)

@yammesicka
Copy link
Member

Resolve conflicts and send it to me for merge

@yammesicka yammesicka merged commit 9c9c499 into PythonFreeCourse:develop Feb 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants