-
Notifications
You must be signed in to change notification settings - Fork 36
Add office filter to leaderboard #48
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -42,3 +42,5 @@ | |
| GRAVATAR = 'backup' | ||
|
|
||
| ORG_TITLE = 'All Company' | ||
| TEAMS_TITLE = 'All Teams' | ||
| OFFICES_TITLE = 'All Offices' | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,3 @@ | ||
| username,first_name,last_name,department,photo_url | ||
| john,John,Doe,,https://placehold.it/100x100 | ||
| janet,Janet,Doe,,https://placehold.it/100x100 | ||
| username,first_name,last_name,department,office,photo_url | ||
| john,John,Doe,,San Francisco,https://placehold.it/100x100 | ||
| janet,Janet,Doe,,San Francisco,https://placehold.it/100x100 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,7 +9,7 @@ | |
| from models.toggle import LOVE_SENDING_ENABLED | ||
|
|
||
|
|
||
| def top_lovers_and_lovees(utc_week_start, dept=None, limit=20): | ||
| def top_lovers_and_lovees(utc_week_start, dept=None, office=None, limit=20): | ||
| """Synchronously return a list of (employee key, sent love count) and a list of | ||
| (employee key, received love count), each sorted in descending order of love sent | ||
| or received. | ||
|
|
@@ -22,11 +22,12 @@ def top_lovers_and_lovees(utc_week_start, dept=None, limit=20): | |
| if c.sent_count == 0: | ||
| continue | ||
| employee_key = c.key.parent() | ||
| if dept: | ||
| employee = employee_key.get() | ||
| if employee.meta_department == dept or employee.department == dept: | ||
| lovers.append((employee_key, c.sent_count)) | ||
| else: | ||
| employee = employee_key.get() | ||
| if ( | ||
| not dept or (employee.meta_department == dept or employee.department == dept) | ||
| ) and ( | ||
| not office or employee.office.startswith(office) | ||
| ): | ||
| lovers.append((employee_key, c.sent_count)) | ||
|
|
||
| received = sorted(sent, key=lambda c: c.received_count, reverse=True) | ||
|
|
@@ -37,14 +38,15 @@ def top_lovers_and_lovees(utc_week_start, dept=None, limit=20): | |
| if c.received_count == 0: | ||
| continue | ||
| employee_key = c.key.parent() | ||
| if dept: | ||
| employee = employee_key.get() | ||
| if employee.meta_department == dept or employee.department == dept: | ||
| lovees.append((employee_key, c.received_count)) | ||
| else: | ||
| employee = employee_key.get() | ||
| if ( | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not blocking but I think this could need a comment saying what condition we are looking for to append en employee to the list. |
||
| not dept or (employee.meta_department == dept or employee.department == dept) | ||
| ) and ( | ||
| not office or employee.office.startswith(office) | ||
| ): | ||
| lovees.append((employee_key, c.received_count)) | ||
|
|
||
| return (lovers, lovees) | ||
| return lovers, lovees | ||
|
|
||
|
|
||
| def rebuild_love_count(): | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| # -*- coding: utf-8 -*- | ||
| import yaml | ||
|
|
||
|
|
||
| _offices = yaml.safe_load(open('offices.yaml')) | ||
| OFFICES = set(_offices['Offices']) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| Offices: | ||
| - Office Location 1 | ||
| - Office Location 2 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,7 +21,7 @@ <h1>Lovers of the Week</h1> | |
| <div class="form-group"> | ||
| <label class="sr-only" for="department">Department</label> | ||
| <select name="department" class="form-control" id="department" style="font-size: 18px;"> | ||
| <option value="" {% if not selected_dept %}selected{% endif%}>{{ org_title }}</option> | ||
| <option value="" {% if not selected_dept %}selected{% endif%}>{{ teams_title }}</option> | ||
| {% for meta_dept in departments|sort %} | ||
| <option {% if selected_dept == meta_dept %}selected{% endif %} value="{{ meta_dept }}">{{ meta_dept }}</option> | ||
| {% if meta_dept in sub_departments %} | ||
|
|
@@ -32,6 +32,15 @@ <h1>Lovers of the Week</h1> | |
| {% endfor %} | ||
| </select> | ||
| </div> | ||
| <div class="form-group"> | ||
| <label class="sr-only" for="office">Department</label> | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I assume this should be Office not Department? |
||
| <select name="office" class="form-control" id="office" style="font-size: 18px;"> | ||
| <option value="" {% if not selected_office %}selected{% endif%}>{{ offices_title }}</option> | ||
| {% for office in offices|sort %} | ||
| <option {% if selected_office == office %}selected{% endif %} value="{{ office }}">{{ office }}</option> | ||
| {% endfor %} | ||
| </select> | ||
| </div> | ||
| </form> | ||
| </div> | ||
| </div> | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,6 +20,7 @@ | |
| import logic.love_link | ||
| import logic.love_count | ||
| import logic.subscription | ||
| import logic.office | ||
| from errors import NoSuchEmployee | ||
| from errors import NoSuchLoveLink | ||
| from errors import TaintedLove | ||
|
|
@@ -159,6 +160,7 @@ def explore(): | |
| def leaderboard(): | ||
| timespan = request.args.get('timespan', TIMESPAN_THIS_WEEK) | ||
| department = request.args.get('department', None) | ||
| office = request.args.get('office', None) | ||
|
|
||
| # If last week, we need to subtract *before* getting the week limits to | ||
| # avoid being off by one hour on weeks that include a DST transition | ||
|
|
@@ -167,7 +169,11 @@ def leaderboard(): | |
| utc_now -= timedelta(days=7) | ||
| utc_week_start, _ = utc_week_limits(utc_now) | ||
|
|
||
| top_lovers, top_lovees = logic.love_count.top_lovers_and_lovees(utc_week_start, dept=department) | ||
| top_lovers, top_lovees = logic.love_count.top_lovers_and_lovees( | ||
| utc_week_start, | ||
| dept=department, | ||
| office=office | ||
| ) | ||
|
|
||
| top_lover_dicts = [ | ||
| { | ||
|
|
@@ -197,9 +203,12 @@ def leaderboard(): | |
| top_lovers=top_lover_dicts, | ||
| departments=logic.department.META_DEPARTMENTS, | ||
| sub_departments=logic.department.META_DEPARTMENT_MAP, | ||
| offices=logic.office.OFFICES, | ||
| selected_dept=department, | ||
| selected_timespan=timespan, | ||
| selected_timespan=timespan, selected_office=office, | ||
| org_title=config.ORG_TITLE, | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder if org_title is still being used? If not it should be removed here and in the config. |
||
| teams_title=config.TEAMS_TITLE, | ||
| offices_title=config.OFFICES_TITLE | ||
| ) | ||
|
|
||
|
|
||
|
|
||
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.
Not blocking but I think this could need a comment saying what condition we are looking for to append an employee to the list.
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.
Maybe even better to extract this into a function with a little docstring to keep things DRY. Thoughts?