Spaces:
Runtime error
Runtime error
surendra962
commited on
Commit
•
807049f
1
Parent(s):
870dcfe
Upload 4 files
Browse files- Procfile +1 -0
- facility_ranking.py +392 -0
- requirements.txt +4 -0
- setup.sh +13 -0
Procfile
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
web: sh setup.sh && streamlit run facility_ranking.py
|
facility_ranking.py
ADDED
@@ -0,0 +1,392 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import pandas as pd
|
2 |
+
import numpy as np
|
3 |
+
import streamlit as st
|
4 |
+
import base64 # Standard Python Module
|
5 |
+
from io import StringIO, BytesIO # Standard Python Module
|
6 |
+
|
7 |
+
# hide menu and footer
|
8 |
+
st.set_page_config(page_title=None, page_icon=None, layout="wide", initial_sidebar_state="auto", menu_items=None)
|
9 |
+
hide_streamlit_style = """
|
10 |
+
<style>
|
11 |
+
#MainMenu {visibility: hidden;}
|
12 |
+
footer {visibility: hidden;}
|
13 |
+
</style>
|
14 |
+
"""
|
15 |
+
st.markdown(hide_streamlit_style, unsafe_allow_html=True) # unsafe_allow_html allows us to embed html code
|
16 |
+
|
17 |
+
|
18 |
+
|
19 |
+
|
20 |
+
|
21 |
+
def generate_excel_download_link(df):
|
22 |
+
# Credit Excel: https://discuss.streamlit.io/t/how-to-add-a-download-excel-csv-function-to-a-button/4474/5
|
23 |
+
towrite = BytesIO()
|
24 |
+
df.to_excel(towrite, encoding="utf-8", index=False, header=True) # write to BytesIO buffer
|
25 |
+
towrite.seek(0) # reset pointer
|
26 |
+
b64 = base64.b64encode(towrite.read()).decode()
|
27 |
+
href = f'<a href="data:application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;base64,{b64}" download="facility_ranking_SSM.xlsx">Download </a>'
|
28 |
+
return st.markdown(href, unsafe_allow_html=True)
|
29 |
+
|
30 |
+
|
31 |
+
|
32 |
+
|
33 |
+
|
34 |
+
# DE=pd.read_csv('C:/Python/1. Dashboard/Facility ranking/Data/DE.csv')
|
35 |
+
# FPE=pd.read_csv('C:/Python/1. Dashboard/Facility ranking/Data/FPE.csv')
|
36 |
+
# sd=pd.read_csv('C:/Python/1. Dashboard/Facility ranking/Data/SD.csv')
|
37 |
+
|
38 |
+
# width in full screen
|
39 |
+
|
40 |
+
|
41 |
+
st.title('AI Ranking-CPHC Project Jhpiego')
|
42 |
+
# add two columns
|
43 |
+
col1, col2 = st.columns(2)
|
44 |
+
with col1:
|
45 |
+
counts=0
|
46 |
+
|
47 |
+
# file upload
|
48 |
+
upload_file_FPE = st.file_uploader("Upload Facility Profile Entry Data in CSV format", type=['csv'])
|
49 |
+
|
50 |
+
# if upload_file_DE is not None highlight "file not uploaded"
|
51 |
+
|
52 |
+
|
53 |
+
if upload_file_FPE:
|
54 |
+
FPE = pd.read_csv(upload_file_FPE)
|
55 |
+
|
56 |
+
# check the columns heading available in the file
|
57 |
+
required_col=['NIN_2_HFI', 'HFI_Name', 'PHC_CHC_Type',
|
58 |
+
'State_Name', 'District_Name', 'Taluka_Name', 'Block_Name',
|
59 |
+
'Proposed Date', 'Progressive Date',
|
60 |
+
'Total Population in catchment area of facility']
|
61 |
+
if set(required_col).issubset(FPE.columns):
|
62 |
+
st.subheader("Perfect")
|
63 |
+
st.write(FPE.head(3))
|
64 |
+
else:
|
65 |
+
st.subheader(f"Please upload correct file missing columns are {set(required_col)-set(FPE.columns)}")
|
66 |
+
counts=1
|
67 |
+
|
68 |
+
|
69 |
+
# file upload
|
70 |
+
upload_file_DE = st.file_uploader("Upload Daily Entry Data in CSV format", type=['csv'])
|
71 |
+
if upload_file_DE:
|
72 |
+
DE = pd.read_csv(upload_file_DE)
|
73 |
+
|
74 |
+
required_col=['NIN ID', 'Entry Date', 'Footfall Male', 'Footfall Female ',
|
75 |
+
'Footfall Others ', 'Footfall Total', 'Patients received medicines ',
|
76 |
+
'Patients availed diagnostic tests',
|
77 |
+
' Patients availed tele-consulation services ',
|
78 |
+
'Wellness sessions conducted ',
|
79 |
+
'Total participants of Wellness session']
|
80 |
+
if set(required_col).issubset(DE.columns):
|
81 |
+
st.subheader("Perfect")
|
82 |
+
st.write(DE.head(3))
|
83 |
+
else:
|
84 |
+
st.subheader(f"Please upload correct file missing columns are {set(required_col)-set(DE.columns)}")
|
85 |
+
counts=1
|
86 |
+
|
87 |
+
|
88 |
+
# file upload
|
89 |
+
upload_file_SD = st.file_uploader("Upload Service Delivery Data in CSV format", type=['csv'])
|
90 |
+
if upload_file_SD:
|
91 |
+
sd = pd.read_csv(upload_file_SD)
|
92 |
+
|
93 |
+
required_col=['NIN ID', 'Entry Month',
|
94 |
+
'HTN Individuals screened Male', 'HTN Individuals screened Female',
|
95 |
+
'HTN Individuals screened Other', 'HTN Newly diagnosed Male',
|
96 |
+
'HTN Newly diagnosed Female', 'HTN Newly diagnosed Other',
|
97 |
+
'HTN On treatment Male', 'HTN On treatment Female',
|
98 |
+
'HTN On treatment Other', 'DM Individuals screened Male',
|
99 |
+
'DM Individuals screened Female', 'DM Individuals screened Other',
|
100 |
+
'DM Newly diagnosed Male', 'DM Newly diagnosed Female',
|
101 |
+
'DM Newly diagnosed Other', 'DM On treatment Male',
|
102 |
+
'DM On treatment Female', 'DM On treatment Other',
|
103 |
+
'OC Individuals screened Male', 'OC Individuals screened Female',
|
104 |
+
'OC Individuals screened Other', 'OC Newly diagnosed Male',
|
105 |
+
'OC Newly diagnosed Female', 'OC Newly diagnosed Other',
|
106 |
+
'OC On treatment male', 'OC On treatment Female',
|
107 |
+
'OC On treatment Other', 'BC Individuals screened female',
|
108 |
+
'BC Newly diagnosed female', 'BC On treatment female',
|
109 |
+
'CC Individuals screened female', 'CC Newly diagnosed female',
|
110 |
+
'CC On treatment female', 'Individuals referred for screening male',
|
111 |
+
'Individuals referred for screening female',
|
112 |
+
'Individuals referred for screening other', 'Newly diagnosed Male',
|
113 |
+
'Newly diagnosed Female', 'Newly diagnosed Other', 'On treatment Male',
|
114 |
+
'On treatment Female', 'On treatment Other',
|
115 |
+
'Total Patients received antihypertensive medicines at this centre',
|
116 |
+
'Total Patients received ant-diabetic medicines at this centre',
|
117 |
+
'Medicines_TPR_AO_M', 'Total TB patients received DOTS from the centre',
|
118 |
+
'Medicines_CSOM_EOM', 'Availability of functional BP apparatus',
|
119 |
+
'Availability of functional glucometer', 'Closing stock of glucostrips',
|
120 |
+
'Performance/team based incentives for MO/SN/CHO',
|
121 |
+
'Team based incentives for ASHA/MPW']
|
122 |
+
if set(required_col).issubset(sd.columns):
|
123 |
+
st.subheader("Perfect")
|
124 |
+
st.write(sd.head(3))
|
125 |
+
else:
|
126 |
+
st.subheader(f"Please upload correct file missing columns are {set(required_col)-set(sd.columns)}")
|
127 |
+
counts=1
|
128 |
+
|
129 |
+
# if upload_file_FPE and upload_file_DE and upload_file_SD is not None:
|
130 |
+
# markdown processing
|
131 |
+
st.markdown('''
|
132 |
+
# *************************Processing Done: Please check next section**************************
|
133 |
+
''')
|
134 |
+
st.subheader("This tool is developed by : Surendra Mehta Data Analyst Jhpiego India all rights reserved")
|
135 |
+
with col2:
|
136 |
+
|
137 |
+
if counts==0 and upload_file_FPE and upload_file_DE and upload_file_SD:
|
138 |
+
|
139 |
+
|
140 |
+
|
141 |
+
|
142 |
+
# Facility PE cleaning **********************************************************************************************************
|
143 |
+
FPE.rename(columns={'NIN_2_HFI':'NIN ID'}, inplace=True)
|
144 |
+
|
145 |
+
# Total Population in catchment area of facility remove any commas and convert in int format
|
146 |
+
FPE['Total Population in catchment area of facility']=FPE['Total Population in catchment area of facility'].replace({',': ''}, regex=True)
|
147 |
+
FPE['Total Population in catchment area of facility']=FPE['Total Population in catchment area of facility'].astype(int)
|
148 |
+
|
149 |
+
col=['NIN ID', 'HFI_Name', 'PHC_CHC_Type',
|
150 |
+
'State_Name', 'District_Name', 'Taluka_Name', 'Block_Name',
|
151 |
+
'Proposed Date', 'Progressive Date',
|
152 |
+
'Total Population in catchment area of facility']
|
153 |
+
FPE=FPE[col]
|
154 |
+
geo=['HFI_Name', 'PHC_CHC_Type','State_Name', 'District_Name', 'Taluka_Name', 'Block_Name']
|
155 |
+
|
156 |
+
# fill NA if any value is missing in geo
|
157 |
+
FPE[geo]=FPE[geo].fillna('NA')
|
158 |
+
# total facility
|
159 |
+
total_facility=FPE.shape[0]
|
160 |
+
st.write(f"Total facility in facility profile entry is :{total_facility}")
|
161 |
+
|
162 |
+
|
163 |
+
# DE cleaning *******************************************************************************************************************
|
164 |
+
#Entry Date convert in date format in format of 2022-05-09
|
165 |
+
|
166 |
+
DE['Entry Date'] = pd.to_datetime(DE['Entry Date'], format='%Y-%m-%d')
|
167 |
+
DE.head(3)
|
168 |
+
# add month-year column from entry date
|
169 |
+
DE['Month-Year'] = DE['Entry Date'].dt.strftime('%b-%Y')
|
170 |
+
DE['Total'] = DE["Footfall Male"] + DE["Footfall Female "]+DE["Footfall Others "]
|
171 |
+
# if wellness session conducted is yes then 1 else 0
|
172 |
+
DE['Wellness sessions conducted ']=DE['Wellness sessions conducted '].replace({'Yes': 1, 'No': 0})
|
173 |
+
DE['Reporting']=1
|
174 |
+
|
175 |
+
DE_col=['NIN ID','Reporting', 'Total',
|
176 |
+
' Patients availed tele-consulation services ',
|
177 |
+
'Wellness sessions conducted ',
|
178 |
+
'Month-Year']
|
179 |
+
DE=DE[DE_col]
|
180 |
+
#groupby
|
181 |
+
DE=DE.groupby(['NIN ID','Month-Year']).sum().reset_index()
|
182 |
+
|
183 |
+
|
184 |
+
#total facility in DE
|
185 |
+
st.write(f"Total facility in DE is :{DE['NIN ID'].nunique()}")
|
186 |
+
|
187 |
+
# SD cleaning ********************************************************************************************************************
|
188 |
+
|
189 |
+
#Entry Date convert in date format in format of 2022-11-30
|
190 |
+
sd['Entry Month'] = pd.to_datetime(sd['Entry Month'], format='%Y-%m-%d')
|
191 |
+
|
192 |
+
# # add month-year column from entry date
|
193 |
+
sd['Month-Year'] = sd['Entry Month'].dt.strftime('%b-%Y')
|
194 |
+
|
195 |
+
#show all the columns in view
|
196 |
+
pd.set_option('display.max_columns', None)
|
197 |
+
|
198 |
+
int_col=['Individuals empanelled',
|
199 |
+
'Community Based Assessment Checklist filled',
|
200 |
+
'HTN Individuals screened Male', 'HTN Individuals screened Female',
|
201 |
+
'HTN Individuals screened Other', 'HTN Newly diagnosed Male',
|
202 |
+
'HTN Newly diagnosed Female', 'HTN Newly diagnosed Other',
|
203 |
+
'HTN On treatment Male', 'HTN On treatment Female',
|
204 |
+
'HTN On treatment Other', 'DM Individuals screened Male',
|
205 |
+
'DM Individuals screened Female', 'DM Individuals screened Other',
|
206 |
+
'DM Newly diagnosed Male', 'DM Newly diagnosed Female',
|
207 |
+
'DM Newly diagnosed Other', 'DM On treatment Male',
|
208 |
+
'DM On treatment Female', 'DM On treatment Other',
|
209 |
+
'OC Individuals screened Male', 'OC Individuals screened Female',
|
210 |
+
'OC Individuals screened Other', 'OC Newly diagnosed Male',
|
211 |
+
'OC Newly diagnosed Female', 'OC Newly diagnosed Other',
|
212 |
+
'OC On treatment male', 'OC On treatment Female',
|
213 |
+
'OC On treatment Other', 'BC Individuals screened female',
|
214 |
+
'BC Newly diagnosed female', 'BC On treatment female',
|
215 |
+
'CC Individuals screened female', 'CC Newly diagnosed female',
|
216 |
+
'CC On treatment female', 'Individuals referred for screening male',
|
217 |
+
'Individuals referred for screening female',
|
218 |
+
'Individuals referred for screening other', 'Newly diagnosed Male',
|
219 |
+
'Newly diagnosed Female', 'Newly diagnosed Other', 'On treatment Male',
|
220 |
+
'On treatment Female', 'On treatment Other',
|
221 |
+
'Total Patients received antihypertensive medicines at this centre',
|
222 |
+
'Total Patients received ant-diabetic medicines at this centre','Medicines_TPR_AO_M',"Closing stock of glucostrips"]
|
223 |
+
|
224 |
+
|
225 |
+
# convert all the int columns in int format
|
226 |
+
sd_int=sd[int_col].head()
|
227 |
+
# remove any commas in the int columns
|
228 |
+
sd[sd_int.columns] = sd[sd_int.columns].replace({',': ''}, regex=True)
|
229 |
+
#convert all the int columns in int format
|
230 |
+
sd[int_col] = sd[int_col].apply(pd.to_numeric, errors='coerce', axis=1)
|
231 |
+
|
232 |
+
# add total column in sd_int
|
233 |
+
|
234 |
+
#HTN
|
235 |
+
sd['HTN screened '] = sd['HTN Individuals screened Male']+ sd['HTN Individuals screened Female']+ sd['HTN Individuals screened Other']
|
236 |
+
sd['HTN diagnosed '] = sd['HTN Newly diagnosed Male']+ sd['HTN Newly diagnosed Female']+ sd['HTN Newly diagnosed Other']
|
237 |
+
sd['HTN on treatment '] = sd['HTN On treatment Male']+ sd['HTN On treatment Female']+ sd['HTN On treatment Other']
|
238 |
+
|
239 |
+
#DM
|
240 |
+
sd['DM screened '] = sd['DM Individuals screened Male']+ sd['DM Individuals screened Female']+ sd['DM Individuals screened Other']
|
241 |
+
sd['DM diagnosed '] = sd['DM Newly diagnosed Male']+ sd['DM Newly diagnosed Female']+ sd['DM Newly diagnosed Other']
|
242 |
+
sd['DM on treatment '] = sd['DM On treatment Male']+ sd['DM On treatment Female']+ sd['DM On treatment Other']
|
243 |
+
|
244 |
+
#DM
|
245 |
+
sd['OC screened '] = sd['OC Individuals screened Male']+ sd['OC Individuals screened Female']+ sd['OC Individuals screened Other']
|
246 |
+
sd['OC diagnosed '] = sd['OC Newly diagnosed Male']+ sd['OC Newly diagnosed Female']+ sd['OC Newly diagnosed Other']
|
247 |
+
sd['OC on treatment '] = sd['OC On treatment male']+ sd['OC On treatment Female']+ sd['OC On treatment Other']
|
248 |
+
|
249 |
+
|
250 |
+
#referred
|
251 |
+
sd['TB_Referred'] = sd['Individuals referred for screening male']+ sd['Individuals referred for screening female']+ sd['Individuals referred for screening other']
|
252 |
+
|
253 |
+
#Newly diagnosed
|
254 |
+
sd['TB_Newly diagnosed'] = sd['Newly diagnosed Male']+ sd['Newly diagnosed Female']+ sd['Newly diagnosed Other']
|
255 |
+
|
256 |
+
#On treatment
|
257 |
+
sd['TB_On treatment'] = sd['On treatment Male']+ sd['On treatment Female']+ sd['On treatment Other']
|
258 |
+
# if yes than 1 else 0 add both
|
259 |
+
sd["equipments_BP_gluco"]=sd["Availability of functional BP apparatus"].replace({'Yes': 1, 'No': 0})+sd["Availability of functional glucometer"].replace({'Yes': 1, 'No': 0})
|
260 |
+
sd["pbi_tbi"]=sd["Performance/team based incentives for MO/SN/CHO"].replace({'Yes': 1, 'No': 0})+sd["Team based incentives for ASHA/MPW"].replace({'Yes': 1, 'No': 0})
|
261 |
+
|
262 |
+
|
263 |
+
selected_col=['NIN ID', 'Facility Name', 'Facility Type', 'State', 'District',
|
264 |
+
'Taluka', 'Block', 'Entry Month',
|
265 |
+
'Month-Year',
|
266 |
+
'HTN screened ', 'DM screened ',
|
267 |
+
'OC screened ','BC Individuals screened female', 'TB_Referred','equipments_BP_gluco',"pbi_tbi"]
|
268 |
+
sd=sd[selected_col]
|
269 |
+
|
270 |
+
|
271 |
+
# group by NIN-ID and month-year sum
|
272 |
+
sd=sd.groupby(['NIN ID','Month-Year']).sum().reset_index()
|
273 |
+
|
274 |
+
# total facility in SD
|
275 |
+
st.write("Total facility in SD",sd['NIN ID'].nunique())
|
276 |
+
|
277 |
+
|
278 |
+
|
279 |
+
df=pd.merge(DE, sd, on=['NIN ID','Month-Year'], how='outer')
|
280 |
+
#merge with FPE
|
281 |
+
df=pd.merge(FPE,df, on=['NIN ID'], how='outer')
|
282 |
+
|
283 |
+
|
284 |
+
|
285 |
+
#df add a target population column with 80 percent of the total population
|
286 |
+
df['Target Population']=round(df['Total Population in catchment area of facility']*0.8,0)
|
287 |
+
|
288 |
+
|
289 |
+
|
290 |
+
# # all float value in one list
|
291 |
+
# float_col=df.select_dtypes(include=['float']).columns.tolist()
|
292 |
+
|
293 |
+
# # convert all the float columns in int format
|
294 |
+
# df[float_col] = df[float_col].apply(pd.to_numeric, errors='coerce', axis=1)
|
295 |
+
|
296 |
+
# cal_Reporting map value>=20 than 15, IF value >=10 than 10 else 0
|
297 |
+
df['cal_Reporting']=np.where(df['Reporting']>=20,15,np.where(df['Reporting']>=10,10,0))
|
298 |
+
# cal_footfall map if 'Total'/'Target Population'>=1, 15,if 'Total'/'Target Population'>=.8, 10,if 'Total'/'Target Population'>=.5,5, else 0
|
299 |
+
|
300 |
+
df['cal_footfall']=np.where((df['Total']/df['Target Population'])>=1,15,np.where((df['Total']/df['Target Population'])>=.8,10,np.where((df['Total']/df['Target Population'])>=.5,5,0)))
|
301 |
+
# Equipment value AV4=2,10,IF value =1,5,0
|
302 |
+
df['cal_Equipment']=np.where(df['equipments_BP_gluco']==2,10,np.where(df['equipments_BP_gluco']==1,5,0))
|
303 |
+
# pbi_tbi value AV4=2,10,IF value =1,5,0
|
304 |
+
df['cal_pbi_tbi']=np.where(df['pbi_tbi']==2,10,np.where(df['pbi_tbi']==1,5,0))
|
305 |
+
# tb refered value referred/total >=30,10 ,if referred/total >=20,5, else 0
|
306 |
+
df['cal_tb']=np.where((df['TB_Referred']/df['Total'])>=.3,10,np.where((df['TB_Referred']/df['Total'])>=.2,5,0))
|
307 |
+
# teleconsultation value AM4>=30,5,IF(AM4>=15,3,IF(AM4>=1,1,0
|
308 |
+
df['cal_teleconsultation']=np.where(df[' Patients availed tele-consulation services ']>=30,5,np.where(df[' Patients availed tele-consulation services ']>=15,3,np.where(df[' Patients availed tele-consulation services ']>=1,1,0)))
|
309 |
+
# wellness and yoga AQ6>=10,5,IF(AQ6>=5,3,0)
|
310 |
+
df['cal_wellness']=np.where(df['Wellness sessions conducted ']>=10,5,np.where(df['Wellness sessions conducted ']>=5,3,0))
|
311 |
+
# save the df in csv
|
312 |
+
|
313 |
+
|
314 |
+
# pivot table
|
315 |
+
df_pivot=df.pivot_table(index=["NIN ID","HFI_Name","PHC_CHC_Type","State_Name","District_Name","Taluka_Name","Block_Name"],columns='Month-Year',
|
316 |
+
values=['HTN screened ','DM screened ','OC screened ','BC Individuals screened female','cal_Reporting','cal_footfall','cal_Equipment',
|
317 |
+
'cal_pbi_tbi','cal_tb','cal_teleconsultation','cal_wellness'],aggfunc='sum').reset_index()
|
318 |
+
|
319 |
+
# total unique facility in all 3 uploaded data
|
320 |
+
st.write(f"Total facility in all 3 uploaded data {df_pivot['NIN ID'].nunique()}")
|
321 |
+
|
322 |
+
col=[col[0] + '_' + col[1] for col in df_pivot.columns]
|
323 |
+
df_pivot.columns = col
|
324 |
+
df_pivot = df_pivot.reset_index()
|
325 |
+
|
326 |
+
|
327 |
+
|
328 |
+
# filter all columns having "screened" or refered
|
329 |
+
screened_col=[col for col in df_pivot.columns if 'screened' in col]
|
330 |
+
|
331 |
+
# import minmaxscaler
|
332 |
+
from sklearn.preprocessing import MinMaxScaler
|
333 |
+
|
334 |
+
# apply minmaxscaler on screened_col
|
335 |
+
scaler = MinMaxScaler()
|
336 |
+
df_pivot[screened_col] = scaler.fit_transform(df_pivot[screened_col])
|
337 |
+
|
338 |
+
# for each month-year calculate the sum of all the columns
|
339 |
+
unique_month=df['Month-Year'].unique()
|
340 |
+
#drop blank value
|
341 |
+
unique_month=unique_month[~pd.isnull(unique_month)]
|
342 |
+
|
343 |
+
for i in unique_month:
|
344 |
+
df_pivot[i+'_sum']=df_pivot[[col for col in df_pivot.columns if i in col]].sum(axis=1)
|
345 |
+
# add rank column and based on sum of each month-year rank the facility
|
346 |
+
df_pivot[i+'_rank']=df_pivot[i+'_sum'].rank(ascending=False)
|
347 |
+
|
348 |
+
|
349 |
+
|
350 |
+
# For Below month ranking will be calculated st.write(unique_month)
|
351 |
+
st.subheader('Below month ranking will be calculated')
|
352 |
+
st.write(unique_month)
|
353 |
+
|
354 |
+
# calculate the sum of all the month-year sum
|
355 |
+
df_pivot['Overall Score']=df_pivot[[col for col in df_pivot.columns if 'sum' in col]].sum(axis=1)
|
356 |
+
|
357 |
+
|
358 |
+
|
359 |
+
|
360 |
+
|
361 |
+
# keep only ranking and overall score columns
|
362 |
+
sum=[col for col in df_pivot.columns if 'sum' in col]
|
363 |
+
rank=[col for col in df_pivot.columns if 'rank' in col]
|
364 |
+
|
365 |
+
# add both list in one list
|
366 |
+
sum_rank=sum+rank
|
367 |
+
|
368 |
+
|
369 |
+
# all sum and rank columns in df_pivot convert in int format
|
370 |
+
df_pivot[sum_rank] = df_pivot[sum_rank].apply(pd.to_numeric, errors='coerce', axis=1)
|
371 |
+
|
372 |
+
df_rank=df_pivot[['NIN ID_','HFI_Name_','PHC_CHC_Type_', 'State_Name_','District_Name_','Taluka_Name_',
|
373 |
+
'Block_Name_','Overall Score']+sum_rank]
|
374 |
+
|
375 |
+
# df subheader
|
376 |
+
st.subheader("Download the Ranking")
|
377 |
+
generate_excel_download_link(df_rank)
|
378 |
+
|
379 |
+
# df subheader pivot table
|
380 |
+
st.subheader("Detailed calculation download")
|
381 |
+
generate_excel_download_link(df_pivot)
|
382 |
+
|
383 |
+
# subheader download all 3 files analysis
|
384 |
+
st.subheader("Download all 3 files analysis")
|
385 |
+
generate_excel_download_link(df)
|
386 |
+
|
387 |
+
# df subheader
|
388 |
+
|
389 |
+
|
390 |
+
|
391 |
+
|
392 |
+
|
requirements.txt
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
numpy==1.23.5
|
2 |
+
pandas==1.5.2
|
3 |
+
scikit_learn==1.2.0
|
4 |
+
streamlit==1.16.0
|
setup.sh
ADDED
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
mkdir -p ~/.streamlit/
|
2 |
+
|
3 |
+
echo "\
|
4 |
+
[general]\n\
|
5 |
+
email = \"your-email@domain.com\"\n\
|
6 |
+
" > ~/.streamlit/credentials.toml
|
7 |
+
|
8 |
+
echo "\
|
9 |
+
[server]\n\
|
10 |
+
headless = true\n\
|
11 |
+
enableCORS=false\n\
|
12 |
+
port = $PORT\n\
|
13 |
+
" > ~/.streamlit/config.toml
|