Advertisement
Guest User

Untitled

a guest
May 31st, 2021
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.04 KB | None | 0 0
  1. #!/usr/bin/python
  2. # -*- coding: utf-8 -*-
  3. #
  4. # Simulation of coincidental deaths in vaccination.
  5. #
  6. # Code4food at lihkg
  7.  
  8. import random
  9. import sys
  10.  
  11. # Approx population of USA
  12. POPULATION=328000000
  13.  
  14. # Approx yearly deaths in USA due to heart disease and stroke.
  15. SUDDEN_DEATHS=800000
  16.  
  17. # As of 5/30 in at least one does in USA is 167,733,972
  18. TOTAL_DOSES=167000000
  19.  
  20. # Days of vaccination, assume same daily rate.
  21. N_DAYS=90
  22.  
  23. def main():
  24.   scale = 0.1  # my computer is too slow for scale of 1.0 :-)
  25.   p_sudden_death = float(SUDDEN_DEATHS) / POPULATION
  26.   sample_population_size = int(POPULATION * scale)
  27.  
  28.   sample_population = list(range(sample_population_size))
  29.   random.shuffle(sample_population)
  30.  
  31.   # choose the people who will die in this year suddenly
  32.   # and pick the days they will die.
  33.   n_sudden_deaths = int(sample_population_size * p_sudden_death)
  34.   sudden_death_events = {}
  35.   for s in sample_population[0:n_sudden_deaths]:
  36.     sudden_death_events[s] = random.randint(1,365)
  37.  
  38.   n_sample_doses = int(TOTAL_DOSES * scale)
  39.  
  40.   # Spread out vaccinations in N_DAYS evenly.
  41.   prev = 0
  42.   daily_doses = []
  43.   for d in range(N_DAYS):
  44.     current = int(float(d + 1) / N_DAYS * n_sample_doses)
  45.     daily_doses.append(current - prev)
  46.     prev = current
  47.  
  48.   # Simulate vaccination in N days.
  49.   count = {}
  50.   cursor = 0
  51.   random.shuffle(sample_population)
  52.   for day, doses in enumerate(daily_doses, start=1):
  53.     # simulate n doses and ingore people already dead.
  54.     for i in range(doses):
  55.       death_day = -1
  56.       # Loop exits when death day is at or after today.
  57.       while death_day < day:
  58.         s = sample_population[cursor]
  59.         death_day = sudden_death_events.get(s, 9999)
  60.         cursor = cursor + 1
  61.  
  62.       # record if the person dies within 7 days of vaccination。
  63.       if death_day < day + 7:
  64.         days_between = death_day - day
  65.         count[days_between] = count.get(days_between,0) + 1
  66.    
  67.   print count
  68.   print "sum = %d" % sum(count.values())
  69.   return 0
  70.  
  71. if __name__ == "__main__":
  72.   sys.exit(main())
  73.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement