-
Notifications
You must be signed in to change notification settings - Fork 7
Room 1 - apply_vaccine_py #7
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: main
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 |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| from vaccine_centers_db import get_center_data | ||
| import collections | ||
| from population import generate_random_population | ||
|
|
||
|
|
||
| class OutOfDosesException(Exception): | ||
| pass | ||
|
|
||
|
|
||
| def lookup_vaccine_name(individual): | ||
| location_day_data = get_center_data(individual.jab_location, individual.date_first_jab) | ||
| return location_day_data.vaccine_name | ||
|
|
||
| def apply_vaccine_to_population(population, ndoses, threshold_age): | ||
| for ind in population: | ||
| if ndoses > 0: | ||
| if (ind["age"] > threshold_age or ind["isAtRisk"]): | ||
| if ind["hasFirstJab"]: | ||
| inject_second_jab(ind) | ||
| else: | ||
| inject_first_jab(ind) | ||
| ndoses = ndoses - 1 | ||
|
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. this line should be indented as now ndoses gets reduced by 1 regardless of what happens in the if |
||
| else: | ||
| raise OutOfDosesException | ||
|
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'm not sure what 'raise' does. How is it different from 'print'?
Owner
Author
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. Using try:
# something
except OutOfDosesException:
# do something else |
||
|
|
||
| N = 100 | ||
| ndoses = 120 | ||
| threshold_age = 70 | ||
| population = generate_random_population(N) | ||
| apply_vaccine_to_population(population, ndoses, threshold_age) | ||
| # Create a dictionary mapping vaccine name to respectice number of occurence. | ||
| # Ex: Counter(["pfizer", "pfizer", "moderna"]) -> {"pfizer": 2, "moderna": 1} | ||
| brand_histogram = collections.Counter([lookup_vaccine_name(ind) for ind in population]) | ||
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.