Skip to content

Commit

Permalink
fixed db
Browse files Browse the repository at this point in the history
  • Loading branch information
TheCharmingSociopath committed Apr 30, 2021
1 parent dc64859 commit 44d4433
Show file tree
Hide file tree
Showing 18 changed files with 173 additions and 166 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

# Setting up the data

`bash initialize.sh`
`bash ./setup.sh`

# Usage

Expand Down
Binary file modified db.sqlite3
Binary file not shown.
21 changes: 6 additions & 15 deletions demo/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

NUMBER_OF_PEOPLE_BUFFER = 0
if DEBUG:
NUMBER_OF_PEOPLE_BUFFER = 10
NUMBER_OF_PEOPLE_BUFFER = 25

CURRENT_ACTIVE_PRIORITY = 1
LAST_DISPATCH = datetime.now()
Expand Down Expand Up @@ -61,24 +61,15 @@ def DistributeCenterToState(number):

def StatewisePopulation():
global NUMBER_OF_PEOPLE_BUFFER
lst = []
for person in Population.objects.all():
if person.priority <= CURRENT_ACTIVE_PRIORITY and person.vaccination_status != "vaccinated":
lst.append(person.state.state_code)
lst = [person.state.state_code for person in Population.objects.all() if person.priority <= CURRENT_ACTIVE_PRIORITY and person.vaccination_status != "vaccinated"]
statewise_population = dict(Counter(lst))
for key in STATES:
if key not in statewise_population:
statewise_population[key] = NUMBER_OF_PEOPLE_BUFFER
return statewise_population, Normalise(copy.deepcopy(statewise_population))

def StatewiseTotalPopulation():
lst = []
for person in Population.objects.all():
lst.append(person.state.state_code)
statewise_population = dict(Counter(lst))
for key in STATES:
if key not in statewise_population:
statewise_population[key] = 0
statewise_population = { state.state_code : state.state_population for state in States.objects.all() }
return statewise_population

def StatewiseVaccinationCenterPopulationRatio(statewise_population):
Expand All @@ -90,7 +81,6 @@ def StatewiseVaccinationCenterPopulationRatio(statewise_population):
def StatewiseInfectionGradient():
global LAST_DISPATCH, PREVIOUS_ACTIVE_CASES, NUMBER_OF_PEOPLE_BUFFER
number_of_active_cases = {state.state_code : state.number_of_active_cases for state in States.objects.all() }

number_of_days = (datetime.now() - LAST_DISPATCH).days

if number_of_days == 0: # Return the current infection count the first time
Expand Down Expand Up @@ -122,7 +112,7 @@ def GetStateWiseDistribution():
state = States.objects.get(state_code=st)
ret.append({
'state_name' : state.name,
'population' : population[st]*1000000 + random.randint(100001,1000000),
'population' : population[st],
'active_case' : state.number_of_active_cases,
'number_of_people_vaccinated' : state.number_of_people_vaccinated,
'number_of_vaccine_available' : state.number_of_vaccines
Expand Down Expand Up @@ -203,4 +193,5 @@ def PrepareDistrictVaccinatedActiveMap():
def GetState(centre_id):
state_id = VaccinationCenter.objects.get(pk=centre_id).state.id
state_name = States.objects.get(pk=state_id).name
return state_name
return state_name

18 changes: 18 additions & 0 deletions demo/migrations/0006_states_state_population.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 3.2 on 2021-04-30 12:28

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('demo', '0005_auto_20210430_1000'),
]

operations = [
migrations.AddField(
model_name='states',
name='state_population',
field=models.IntegerField(default=0),
),
]
18 changes: 18 additions & 0 deletions demo/migrations/0007_alter_population_profession.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 3.2 on 2021-04-30 12:41

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('demo', '0006_states_state_population'),
]

operations = [
migrations.AlterField(
model_name='population',
name='profession',
field=models.CharField(choices=[('medical_worker', 'Medical Worker'), ('teacher', 'Teacher'), ('engineer', 'Engineer'), ('student', 'Student')], max_length=255),
),
]
Binary file modified demo/migrations/__pycache__/0001_initial.cpython-38.pyc
Binary file not shown.
Binary file modified demo/migrations/__pycache__/__init__.cpython-38.pyc
Binary file not shown.
3 changes: 2 additions & 1 deletion demo/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class States(models.Model):
number_of_vaccines = models.IntegerField(default=0)
number_of_people_vaccinated = models.IntegerField(default=0)
state_code = models.CharField(max_length=10, choices=state_codes, default="IN-AN")
state_population = models.IntegerField(default=0)

class Districts(models.Model):
name = models.CharField(max_length=255)
Expand All @@ -17,7 +18,7 @@ class Districts(models.Model):

class Population(models.Model):
vaccination_status_choices = (("unregistered", "Unregistered"), ("registered_1", "Registered for Dose 1"), ("dose_1_administered", "Dose 1 administered"), ("registered_2", "Registered for Dose 2"), ("vaccinated", "Vaccinated"))
profession_choices = (("medical_worker", "Medical Worker"), ("teacher", "Teacher"))
profession_choices = (("medical_worker", "Medical Worker"), ("teacher", "Teacher"), ("engineer", "Engineer"), ("student", "Student"))
adhaar = models.CharField(max_length=20, primary_key=True)
name = models.CharField(max_length=255)
age = models.IntegerField()
Expand Down
2 changes: 1 addition & 1 deletion demo/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def AdminDistributeView(request):
pass
else: # GET request
centre_vaccine_count = GetCenterVaccinationStore()
return render(request, "admin-distribute.html", {'centre_vaccine_count': centre_vaccine_count})
return render(request, "admin-distribute.html", {'centre_vaccine_count': centre_vaccine_count, 'current_active_priority' : CURRENT_ACTIVE_PRIORITY})


def AdminView(request):
Expand Down
111 changes: 111 additions & 0 deletions populate_database.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
import os
os.environ.setdefault('DJANGO_SETTINGS_MODULE','VaccineDistribution.settings')

import django
django.setup()

from demo.models import States, Districts, Population, VaccinationCenter, CenterVaccinationStore
import random, string, uuid, csv
from datetime import datetime


STATES = ['IN-AN', 'IN-AP', 'IN-AR', 'IN-AS', 'IN-BR', 'IN-CH', 'IN-CT', 'IN-DN', 'IN-DL', 'IN-GA', 'IN-GJ', 'IN-HR', 'IN-HP', 'IN-JK', 'IN-JH', 'IN-KA', 'IN-KL', 'IN-LA', 'IN-LD', 'IN-MP', 'IN-MH', 'IN-MN', 'IN-ML', 'IN-MZ', 'IN-NL', 'IN-OR', 'IN-PY', 'IN-PB', 'IN-RJ', 'IN-SK', 'IN-TN', 'IN-TG', 'IN-TR', 'IN-UP', 'IN-UT', 'IN-WB']
POPULATION = [417036, 53903393, 1570458, 35607039, 124799926, 1158473, 29436231, 615724, 18710922, 1586250, 63872399, 28204692, 7451955, 13606320, 38593948, 67562686, 35699443, 289023, 73183, 85358965, 123144223, 3091545, 3366710, 1239244, 2249695, 46356334, 1413542, 30141373, 81032689, 690251, 77841267, 39362732, 4169794, 237882725, 11250858, 99609303]

def PopulateVaccinationCenter(n):
sids = [state for state in States.objects.all()]
dids = [district for district in Districts.objects.all()]
for i in range(n):
district = random.choice(dids)
state = random.choice(sids)
number_of_vaccines = random.randint(0, 100)
address = ''.join(random.SystemRandom().choice(string.ascii_letters) for _ in range(50))
_, _ = VaccinationCenter.objects.get_or_create(district=district, state=state, number_of_vaccines=number_of_vaccines, address=address)

def PopulateCenterVaccinationStore():
# sids = [state.id for state in States.objects.all()]
# dids = [district.id for district in Districts.objects.all()]
# district = models.ForeignKey(Districts, on_delete=models.CASCADE)
# state = models.ForeignKey(States, on_delete=models.CASCADE)
number_of_vaccines = 10000
# address = models.CharField(max_length=1023)
_, _ = CenterVaccinationStore.objects.get_or_create(number_of_vaccines=number_of_vaccines)

def PopulateState():
vac = {}
cases = {}
names = {}
with open('cowin_vaccine_data_statewise.csv', 'r') as fil:
reader = csv.reader(fil)
rows = list(reader)
rows.pop(0)
rows.pop(0)
for state in rows:
code = state[2]
for s in STATES:
# if s[3:] == code:
if s == code:
vac[s] = state[-2]
names[s] = state[1]

with open('state_wise.csv', 'r') as fil:
reader = csv.reader(fil)
rows = list(reader)
rows.pop(0)
rows.pop(0)
for state in rows:
code = state[-5]
for s in STATES:
# if s[3:] == code:
if s == code:
cases[s] = state[4]

for i in range(len(STATES)):
state = STATES[i]
population = POPULATION[i]
name = names[state]
number_of_active_cases = cases[state]
number_of_vaccines = 0
number_of_people_vaccinated = vac[state]
state_code = state
_, _ = States.objects.get_or_create(name=name, number_of_active_cases=number_of_active_cases, number_of_people_vaccinated=number_of_people_vaccinated, number_of_vaccines=number_of_vaccines, state_code=state, state_population=population)

def PopulateDistrict(n):
sids = [state for state in States.objects.all()]
for i in range(n):
name = ''.join(random.SystemRandom().choice(string.ascii_letters) for _ in range(20))
number_of_active_cases = random.randint(100, 100000)
state = random.choice(sids)
_, _ = Districts.objects.get_or_create(name=name, number_of_active_cases=number_of_active_cases, state=state)

def PopulatePopulation(n):
sids = [state for state in States.objects.all()]
dids = [district for district in Districts.objects.all()]
for i in range(n):
profession_choices = ["medical_worker", "teacher", "engineer", "daily_wage_worker"]
adhaar = str(uuid.uuid4())[-12:]
name = ''.join(random.SystemRandom().choice(string.ascii_letters) for _ in range(20))
age = random.randint(18, 95)
address = ''.join(random.SystemRandom().choice(string.ascii_letters) for _ in range(50))
district = random.choice(dids)
state = random.choice(sids)
profession = random.choice(profession_choices)
priority = random.randint(1, 5)
vaccination_status = "unregistered"
vaccine_1_time = datetime.now()
vaccine_2_time = datetime.now()
_, _ = Population.objects.get_or_create(adhaar=adhaar, name=name, age=age, address=address, district=district, state=state, profession=profession, priority=priority, vaccination_status=vaccination_status, vaccine_1_time=vaccine_1_time, vaccine_2_time=vaccine_2_time)

if __name__ == "__main__":
PopulateState()
PopulateDistrict(100)
PopulatePopulation(1000)
PopulateCenterVaccinationStore()
PopulateVaccinationCenter(1000)
state = States.objects.get(state_code='IN-DL')
district = Districts(name="Noida", number_of_active_cases=7542, state=state)
district.save()
shivam = Population(adhaar="111111111111", name="Shivam Bansal", age=20, address="Mukul Mahal, Gau Vihar Colony, Noida", district=district, state=state, profession="student", priority=4, vaccination_status="unregistered", vaccine_1_time=datetime.now(), vaccine_2_time=datetime.now(), vaccination_center_chosen=0)
vacc = VaccinationCenter(district=district, state=state, number_of_vaccines=0, address="BT Hospital, Noida")
shivam.save()
vacc.save()
Empty file added report.md
Empty file.
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
asgiref==3.3.4
Django==3.2
numpy==1.20.2
pandas==1.2.4
python-dateutil==2.8.1
pytz==2021.1
six==1.15.0
Expand Down
21 changes: 0 additions & 21 deletions scripts/initialize.sh

This file was deleted.

30 changes: 0 additions & 30 deletions scripts/populate_Population_model.py

This file was deleted.

59 changes: 0 additions & 59 deletions scripts/populate_State_District_models.py

This file was deleted.

31 changes: 0 additions & 31 deletions scripts/populate_VaccinationCenter_CenterVaccinationStore.py

This file was deleted.

Loading

0 comments on commit 44d4433

Please sign in to comment.