alan-turing-institute / WimbledonPlanner

Project planning for REG
MIT License
0 stars 0 forks source link

get_preferences availability calculation fails if resource required less than one month #53

Open ots22 opened 4 years ago

ots22 commented 4 years ago

Visiting https://wimbledon-planner.azurewebsites.net/update

I get the following message after about a minute:

Traceback (most recent call last): File "app.py", line 78, in update preferences_table = pref.get_all_preferences_table(wim=vis.wim) File "/WimbledonPlanner/wimbledon/github/preferences_availability.py", line 324, in get_all_preferences_table preferences_with_availability = get_preferences(wim, preference_data_df) File "/WimbledonPlanner/wimbledon/github/preferences_availability.py", line 247, in get_preferences person_availability = get_person_availability(wim, name, first_resreq_date, last_resreq_date) File "/WimbledonPlanner/wimbledon/github/preferences_availability.py", line 122, in get_person_availability average_availability = statistics.mean(availability_range) File "/usr/local/lib/python3.7/statistics.py", line 310, in mean raise StatisticsError('mean requires at least one data point') statistics.StatisticsError: mean requires at least one data point

jack89roberts commented 4 years ago

The bug is something related to matching the dates that projects have resource required with dates that people are available in the github emoji table. I haven't tracked it down and fixed it properly yet, but committed a quick fix that bypasses the issue (return 0 if trying to calculate mean on an empty list, rather than erroring).

So the update link on the web app should be working again, but where zero availability/demand appears on the github emoji table it may be a bug rather than a genuine zero as things stand.

jack89roberts commented 4 years ago

start_date and end_date arguments given to get_person_availability inside get_preferences seem to get set to the same value (start_date = end_date) if the duration of resource required is less than one month. Probably because the resource required info is resampled to be monthly inside the function on line 216:

resreqdf = wim.project_resourcereq.resample('MS').mean()

This incorrectly leads to an empty list of person availability in the get_person_availability function.