Skip to content

Commit

Permalink
Merge pull request #274 from naxa-developers/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
sijandh35 authored May 12, 2021
2 parents fabc58b + b438e7e commit 0ccc1f7
Show file tree
Hide file tree
Showing 102 changed files with 612,448 additions and 509 deletions.
6 changes: 4 additions & 2 deletions core/admin.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from django.contrib import admin
from .models import Partner, Program, Sector, SubSector, MarkerCategory, MarkerValues, Province, District, GapaNapa, \
FiveW, Indicator, IndicatorValue, TravelTime, GisLayer, Project, PartnerContact, Output, ProvinceDummy, \
Notification, BudgetToSecondTier, BudgetToFirstTier, Cmp, Filter, GisStyle, GisPop, NepalSummary, FeedbackForm,FAQ,TermsAndCondition
Notification, BudgetToSecondTier, BudgetToFirstTier, Cmp, Filter, GisStyle, GisPop, NepalSummary, FeedbackForm,FAQ,TermsAndCondition,NationalStatistic,Manual

# Register your models here.

Expand Down Expand Up @@ -33,4 +33,6 @@
admin.site.register(NepalSummary)
admin.site.register(FeedbackForm)
admin.site.register(FAQ)
admin.site.register(TermsAndCondition)
admin.site.register(TermsAndCondition)
admin.site.register(NationalStatistic)
admin.site.register(Manual)
107 changes: 41 additions & 66 deletions core/filters.py
Original file line number Diff line number Diff line change
@@ -1,36 +1,41 @@
from .models import FiveW
from django.db.models import Sum
from django.db.models import Q


def fivew(supplier, program, component, sector, sub_sector, markers, markers_value, count):
name_list = ['supplier', 'program', 'component', 'sector', 'sub_sector', 'markers', 'markers_value']
value_list = [supplier, program, component, sector, sub_sector, markers, markers_value]
def fivew(supplier, program, component, sector, sub_sector, markers, markers_value, count, stat):
name_list = ['supplier', 'program', 'component', 'sector', 'sub_sector', 'markers', 'markers_value', 'stat']
value_list = [supplier, program, component, sector, sub_sector, markers, markers_value, stat]
key_list = ['supplier_id__in', 'program_id__in', 'component_id__code__in', 'program_id__sector__id__in',
'program_id__sub_sector__id__in',
'program_id__marker_category__id__in', 'program_id__marker_value__id__in']
'program_id__marker_category__id__in', 'program_id__marker_value__id__in', 'status__in']
filter_dict = {}
for index, x in enumerate(value_list):
if x and name_list[index] not in count:
filter_dict[key_list[index]] = x

dat_values = FiveW.objects.filter(**filter_dict).values('id', 'allocated_budget', 'province_id__code',
'district_id__code', 'municipality_id__code',
'component_id',
'program_id', 'allocated_budget', 'program_id__name',
'component_id__name', 'supplier_id__name',
'program_id__sector__name', 'program_id__sub_sector__name',
'program_id__marker_category__name',
'program_id__marker_value__value').distinct()

dat_values = dat_values.exclude(
municipality_id__code='-1',
district_id__code='-1',
province_id__code='-1')
# print(dat_values.aggregate(Sum('allocated_budget')))
dat_values = FiveW.objects.filter(**filter_dict).values('id')

return dat_values


def fivew_province(province, supplier, program, component, sector, sub_sector, markers, markers_value, count):
def fivew_province(province, supplier, program, component, sector, sub_sector, markers, markers_value, count, stat):
name_list = ['province', 'supplier', 'program', 'component', 'sector', 'sub_sector', 'markers', 'markers_value',
'stat']
value_list = [province, supplier, program, component, sector, sub_sector, markers, markers_value, stat]
key_list = ['province_id__in', 'supplier_id__in', 'program_id__in', 'component_id__code__in',
'program_id__sector__id__in', 'program_id__sub_sector__id__in',
'program_id__marker_category__id__in', 'program_id__marker_value__id__in', 'status__in']
filter_dict = {}
for index, x in enumerate(value_list):
if x and name_list[index] not in count:
filter_dict[key_list[index]] = x

dat_values = FiveW.objects.filter(**filter_dict).values('id')
return dat_values


def sankey(province, supplier, program, component, sector, sub_sector, markers, markers_value, count):
name_list = ['province', 'supplier', 'program', 'component', 'sector', 'sub_sector', 'markers', 'markers_value']
value_list = [province, supplier, program, component, sector, sub_sector, markers, markers_value]
key_list = ['province_id__in', 'supplier_id__in', 'program_id__in', 'component_id__code__in',
Expand All @@ -41,70 +46,40 @@ def fivew_province(province, supplier, program, component, sector, sub_sector, m
if x and name_list[index] not in count:
filter_dict[key_list[index]] = x

dat_values = FiveW.objects.filter(**filter_dict).values('id', 'allocated_budget', 'province_id__code',
'district_id__code', 'municipality_id__code',
'component_id',
'program_id', 'allocated_budget', 'program_id__name',
'component_id__name', 'supplier_id__name',
'program_id__sector__name', 'program_id__sub_sector__name',
'program_id__marker_category__name',
'program_id__marker_value__value').distinct()

dat_values = dat_values.exclude(
municipality_id__code='-1',
district_id__code='-1',
province_id__code='-1')
dat_values = FiveW.objects.filter(**filter_dict).values('id')

return dat_values


def fivew_municipality(municipality, supplier, program, component, sector, sub_sector, markers, markers_value, count):
name_list = ['municipality', 'supplier', 'program', 'component', 'sector', 'sub_sector', 'markers', 'markers_value']
value_list = [municipality, supplier, program, component, sector, sub_sector, markers, markers_value]
def fivew_municipality(municipality, supplier, program, component, sector, sub_sector, markers, markers_value, count,
stat):
name_list = ['municipality', 'supplier', 'program', 'component', 'sector', 'sub_sector', 'markers', 'markers_value',
'stat']
value_list = [municipality, supplier, program, component, sector, sub_sector, markers, markers_value, stat]
key_list = ['municipality_id__in', 'supplier_id__in', 'program_id__in', 'component_id__code__in',
'program_id__sector__id__in', 'program_id__sub_sector__id__in',
'program_id__marker_category__id__in', 'program_id__marker_value__id__in']
'program_id__marker_category__id__in', 'program_id__marker_value__id__in', 'status__in']
filter_dict = {}
for index, x in enumerate(value_list):
if x and name_list[index] not in count:
filter_dict[key_list[index]] = x

dat_values = FiveW.objects.filter(**filter_dict).values('id', 'allocated_budget', 'province_id__code',
'district_id__code', 'municipality_id__code',
'component_id',
'program_id', 'allocated_budget', 'program_id__name',
'component_id__name', 'supplier_id__name',
'program_id__sector__name', 'program_id__sub_sector__name',
'program_id__marker_category__name',
'program_id__marker_value__value').distinct()
dat_values = dat_values.exclude(
municipality_id__code='-1',
district_id__code='-1',
province_id__code='-1')
dat_values = FiveW.objects.filter(**filter_dict).values('id')

return dat_values


def fivew_district(district, supplier, program, component, sector, sub_sector, markers, markers_value, count):
name_list = ['district', 'supplier', 'program', 'component', 'sector', 'sub_sector', 'markers', 'markers_value']
value_list = [district, supplier, program, component, sector, sub_sector, markers, markers_value]
def fivew_district(district, supplier, program, component, sector, sub_sector, markers, markers_value, count, stat):
name_list = ['district', 'supplier', 'program', 'component', 'sector', 'sub_sector', 'markers', 'markers_value',
'stat']
value_list = [district, supplier, program, component, sector, sub_sector, markers, markers_value, stat]
key_list = ['district_id__in', 'supplier_id__in', 'program_id__in', 'component_id__code__in',
'program_id__sector__id__in', 'program_id__sub_sector__id__in',
'program_id__marker_category__id__in', 'program_id__marker_value__id__in']
'program_id__marker_category__id__in', 'program_id__marker_value__id__in', 'status__in']
filter_dict = {}
for index, x in enumerate(value_list):
if x and name_list[index] not in count:
filter_dict[key_list[index]] = x
print(filter_dict)
dat_values = FiveW.objects.filter(**filter_dict).values('id', 'allocated_budget', 'province_id__code',
'district_id__code', 'municipality_id__code',
'component_id',
'program_id', 'allocated_budget', 'program_id__name',
'component_id__name', 'supplier_id__name',
'program_id__sector__name', 'program_id__sub_sector__name',
'program_id__marker_category__name',
'program_id__marker_value__value').distinct()
dat_values = dat_values.exclude(
municipality_id__code='-1',
district_id__code='-1',
province_id__code='-1'
)
dat_values = FiveW.objects.filter(**filter_dict).values('id')

return dat_values
34 changes: 21 additions & 13 deletions core/management/commands/new_indicator.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from django.core.exceptions import ObjectDoesNotExist, MultipleObjectsReturned
from core.models import Indicator
import math
import json


class Command(BaseCommand):
Expand All @@ -18,35 +19,42 @@ def handle(self, *args, **kwargs):
# print(os.path.exists("/home/sumit/django_projects/dvs/data_csv"))
# print(os.path.isfile(path))
df1 = pd.read_csv(path)
df = df1.fillna('')
df2 = df1.fillna('')
df = df2.drop_duplicates(subset=['Indicators'])
# print(df['Level'][0])
# print(len(df))
upper_range = len(df)
correct_data = []
for row in range(0, upper_range):
if df['Indicator '][row] == '':
if df['Indicators'][row] == '':
pass
else:
try:
try:
test = Indicator.objects.get(indicator=(df['Indicator '][row]).strip())
test.full_title = df['Title '][row]
test = Indicator.objects.get(indicator=(df['Indicators'][row]).strip())
test.full_title = df['Fulltitle'][row]
test.abstract = df['Abstract'][row]
test.category = (df['Category '][row]).strip()
test.source = df['Source '][row]
test.url = df['URL'][row]
test.category = (df['Category'][row]).strip()
test.source = df['Source'][row]
test.url = df['Link'][row]
test.federal_level = 'all'
test.unit = df['Unit'][row]
test.is_dashboard = json.loads(str(df['Show on Dashboard '][row]).lower())
test.is_regional_profile = json.loads(str(df['Show on Profile '][row]).lower())
test.save()
self.stdout.write('Successfully Updated' + str(test.full_title) + 'data')
except ObjectDoesNotExist:
correct_data.append(Indicator(
indicator=(df['Indicator '][row]).strip(),
full_title=df['Title '][row],
indicator=(df['Indicators'][row]).strip(),
full_title=df['Fulltitle'][row],
abstract=df['Abstract'][row],
category=(df['Category '][row]).strip(),
source=df['Source '][row],
url=df['URL'][row],
federal_level='all'
category=(df['Category'][row]).strip(),
source=df['Source'][row],
url=df['Link'][row],
federal_level='all',
unit=df['Unit'][row],
is_dashboard=json.loads(str(df['Show on Dashboard '][row]).lower()),
is_regional_profile=json.loads(str(df['Show on Dashboard '][row]).lower())
))
except Exception as e:
print(e)
Expand Down
38 changes: 26 additions & 12 deletions core/management/commands/new_indicator_data.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,23 @@
from django.core.management.base import BaseCommand
import pandas as pd
from core.models import Indicator, IndicatorValue, GapaNapa, District
from django.core.exceptions import ObjectDoesNotExist


def gapanapa(code):
try:
obj = GapaNapa.objects.get(hlcit_code=str(code))
except ObjectDoesNotExist:
obj = None
return obj


def valuedata(val):
try:
data = float(val)
except:
data = 0
return data


class Command(BaseCommand):
Expand All @@ -12,29 +29,26 @@ def add_arguments(self, parser):
def handle(self, *args, **kwargs):
path = kwargs['path']

df = pd.read_csv(path)
df1 = pd.read_csv(path)
df = df1.fillna('')
upper_range = len(df)
print("Wait Data is being Loaded")
indicator_name = ((path.split('/'))[-1]).replace('.csv', '')

try:
indicator_value = [
IndicatorValue(
indicator_id=Indicator.objects.get(indicator=indicator_name),
gapanapa_id=GapaNapa.objects.get(hlcit_code=df['hlcit_id'][row]),
value=float(df['value'][row]),
indicator_id=Indicator.objects.get(indicator=df['Indicators'][row].strip()),
gapanapa_id=gapanapa(df['Hlcit Id'][row]),
national_average=float(df['National Average '][row]),
province_average=float(df['Province average '][row]),
district_average=float(df['District Average '][row]),
value=valuedata(df['Value'][row]),

) for row in range(0, upper_range)
]
indicator_data = IndicatorValue.objects.bulk_create(indicator_value)

if indicator_data:
self.stdout.write('Successfully loaded Indicator Value ..')
# for row in range(0, upper_range):
# print(df['District_ID'][row])
# d = District.objects.get(code=df['District_ID'][row])
# print(d.name)


except Exception as e:
print(e)
print(e)
20 changes: 20 additions & 0 deletions core/migrations/0171_nationalstatistic.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Generated by Django 2.2.10 on 2021-04-19 09:00

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('core', '0170_auto_20210406_1554'),
]

operations = [
migrations.CreateModel(
name='NationalStatistic',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('url', models.URLField(blank=True, null=True)),
],
),
]
28 changes: 28 additions & 0 deletions core/migrations/0172_auto_20210420_1226.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Generated by Django 2.2.10 on 2021-04-20 06:41

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('core', '0171_nationalstatistic'),
]

operations = [
migrations.AddField(
model_name='indicatorvalue',
name='district_average',
field=models.FloatField(default=0),
),
migrations.AddField(
model_name='indicatorvalue',
name='national_average',
field=models.FloatField(default=0),
),
migrations.AddField(
model_name='indicatorvalue',
name='province_average',
field=models.FloatField(default=0),
),
]
18 changes: 18 additions & 0 deletions core/migrations/0173_indicator_is_regional_profile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 2.2.10 on 2021-04-21 09:11

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('core', '0172_auto_20210420_1226'),
]

operations = [
migrations.AddField(
model_name='indicator',
name='is_regional_profile',
field=models.BooleanField(default=True),
),
]
18 changes: 18 additions & 0 deletions core/migrations/0174_nationalstatistic_title.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 2.2.10 on 2021-04-23 04:51

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('core', '0173_indicator_is_regional_profile'),
]

operations = [
migrations.AddField(
model_name='nationalstatistic',
name='title',
field=models.CharField(blank=True, max_length=500, null=True),
),
]
Loading

0 comments on commit 0ccc1f7

Please sign in to comment.