Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions snippets/apply_vaccine.py
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"]):
Copy link
Owner Author

Choose a reason for hiding this comment

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

if (isEligible(ind)):
   # then do something

if ind["hasFirstJab"]:
inject_second_jab(ind)
else:
inject_first_jab(ind)
ndoses = ndoses - 1

Choose a reason for hiding this comment

The 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

Choose a reason for hiding this comment

The 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'?

Copy link
Owner Author

Choose a reason for hiding this comment

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

Using raise allows me to do stuff like

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