policy download
Browse files- appStore/policyaction.py +108 -75
appStore/policyaction.py
CHANGED
@@ -293,6 +293,39 @@ def filter_dataframe(df: pd.DataFrame) -> pd.DataFrame:
|
|
293 |
st.session_state['action_hits'] = df
|
294 |
|
295 |
return
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
296 |
#count_netzero = sum(hits['Netzero Label'] == 'NETZERO')
|
297 |
#count_ghg = sum(hits['GHG Label'] == 'GHG')
|
298 |
#count_economy = sum([True if 'Economy-wide' in x else False
|
@@ -363,82 +396,82 @@ def filter_dataframe(df: pd.DataFrame) -> pd.DataFrame:
|
|
363 |
# st.info("π€ No Actions found")
|
364 |
|
365 |
|
366 |
-
def policy_display():
|
367 |
-
|
368 |
-
|
369 |
|
370 |
|
371 |
-
|
372 |
-
|
373 |
-
|
374 |
-
|
375 |
-
|
376 |
-
|
377 |
-
|
378 |
-
|
379 |
-
|
380 |
-
|
381 |
|
382 |
-
|
383 |
-
|
384 |
-
|
385 |
-
|
386 |
-
|
387 |
-
|
388 |
-
|
389 |
-
|
390 |
-
|
391 |
-
|
392 |
-
#
|
393 |
-
|
394 |
-
|
395 |
-
|
396 |
-
|
397 |
-
|
398 |
-
|
399 |
-
|
400 |
-
|
401 |
-
|
402 |
-
|
403 |
-
|
404 |
-
|
405 |
-
|
406 |
-
|
407 |
-
|
408 |
-
|
409 |
-
|
410 |
-
|
411 |
-
|
412 |
-
|
413 |
-
|
414 |
-
|
415 |
-
|
416 |
-
|
417 |
-
|
418 |
-
|
419 |
-
|
420 |
-
|
421 |
-
|
422 |
-
|
423 |
-
|
424 |
-
|
425 |
-
|
426 |
-
|
427 |
-
|
428 |
-
|
429 |
-
|
430 |
-
|
431 |
-
|
432 |
-
|
433 |
-
|
434 |
-
|
435 |
-
|
436 |
|
437 |
-
|
438 |
-
|
439 |
-
|
440 |
-
|
441 |
-
|
442 |
-
|
443 |
-
|
444 |
-
|
|
|
293 |
st.session_state['action_hits'] = df
|
294 |
|
295 |
return
|
296 |
+
def policy_display():
|
297 |
+
if 'key1' in st.session_state:
|
298 |
+
df = st.session_state.key1
|
299 |
+
st.caption(""" **{}** is splitted into **{}** paragraphs/text chunks."""\
|
300 |
+
.format(os.path.basename(st.session_state['filename']),
|
301 |
+
len(df)))
|
302 |
+
hits = df[df['Policies_Plans Label'] == 'Policy and Plans']
|
303 |
+
range_val = min(5,len(hits))
|
304 |
+
if range_val !=0:
|
305 |
+
count_action = len(hits)
|
306 |
+
hits.drop(columns=['Target Label','Target Score','Netzero Score',
|
307 |
+
'Netzero Label','GHG Label',
|
308 |
+
'GHG Score','Action Label','Policies_Plans Label',
|
309 |
+
'Action Score','Conditional Score'],inplace=True)
|
310 |
+
hits = hits.sort_values(by=['Action Score'], ascending=False)
|
311 |
+
hits = hits.reset_index(drop=True)
|
312 |
+
|
313 |
+
st.write('----------------')
|
314 |
+
|
315 |
+
|
316 |
+
st.caption("Filter table to select rows to keep for Policies and Plans category")
|
317 |
+
filter_dataframe(hits)
|
318 |
+
# filtered_df = filtered_df[filtered_df.keep == True]
|
319 |
+
# st.write('Explore the data')
|
320 |
+
# AgGrid(hits)
|
321 |
+
|
322 |
+
|
323 |
+
with st.sidebar:
|
324 |
+
st.write('-------------')
|
325 |
+
df_xlsx = to_excel(df)
|
326 |
+
st.download_button(label='π₯ Download Result',
|
327 |
+
data=df_xlsx ,
|
328 |
+
file_name= os.path.splitext(os.path.basename(st.session_state['filename']))[0]+'.xlsx')
|
329 |
#count_netzero = sum(hits['Netzero Label'] == 'NETZERO')
|
330 |
#count_ghg = sum(hits['GHG Label'] == 'GHG')
|
331 |
#count_economy = sum([True if 'Economy-wide' in x else False
|
|
|
396 |
# st.info("π€ No Actions found")
|
397 |
|
398 |
|
399 |
+
# def policy_display():
|
400 |
+
# if 'key1' in st.session_state:
|
401 |
+
# df = st.session_state.key1
|
402 |
|
403 |
|
404 |
+
# df['Policy_check'] = df['Policy-Action Label'].apply(lambda x: True if 'Policies & Plans' in x else False)
|
405 |
+
# hits = df[df['Policy_check'] == True]
|
406 |
+
# # hits['GHG Label'] = hits['GHG Label'].apply(lambda i: _lab_dict[i])
|
407 |
+
# range_val = min(5,len(hits))
|
408 |
+
# if range_val !=0:
|
409 |
+
# count_policy = len(hits)
|
410 |
+
# #count_netzero = sum(hits['Netzero Label'] == 'NETZERO')
|
411 |
+
# #count_ghg = sum(hits['GHG Label'] == 'GHG')
|
412 |
+
# #count_economy = sum([True if 'Economy-wide' in x else False
|
413 |
+
# # for x in hits['Sector Label']])
|
414 |
|
415 |
+
# # count_df = df['Target Label'].value_counts()
|
416 |
+
# # count_df = count_df.rename('count')
|
417 |
+
# # count_df = count_df.rename_axis('Target Label').reset_index()
|
418 |
+
# # count_df['Label_def'] = count_df['Target Label'].apply(lambda x: _lab_dict[x])
|
419 |
+
|
420 |
+
# # fig = px.bar(count_df, y="Label_def", x="count", orientation='h', height=200)
|
421 |
+
# # c1, c2 = st.columns([1,1])
|
422 |
+
# # with c1:
|
423 |
+
# # st.write('**Target Paragraphs**: `{}`'.format(count_target))
|
424 |
+
# # st.write('**NetZero Related Paragraphs**: `{}`'.format(count_netzero))
|
425 |
+
# #
|
426 |
+
# # # st.plotly_chart(fig,use_container_width= True)
|
427 |
+
# #
|
428 |
+
# # count_netzero = sum(hits['Netzero Label'] == 'NETZERO')
|
429 |
+
# # count_ghg = sum(hits['GHG Label'] == 'LABEL_2')
|
430 |
+
# # count_economy = sum([True if 'Economy-wide' in x else False
|
431 |
+
# # for x in hits['Sector Label']])
|
432 |
+
# # with c2:
|
433 |
+
# # st.write('**GHG Related Paragraphs**: `{}`'.format(count_ghg))
|
434 |
+
# # st.write('**Economy-wide Related Paragraphs**: `{}`'.format(count_economy))
|
435 |
+
# # st.write('-------------------')
|
436 |
+
# # hits = hits.sort_values(by=['Relevancy'], ascending=False)
|
437 |
+
# # netzerohit = hits[hits['Netzero Label'] == 'NETZERO']
|
438 |
+
# # if not netzerohit.empty:
|
439 |
+
# # netzerohit = netzerohit.sort_values(by = ['Netzero Score'], ascending = False)
|
440 |
+
# # # st.write('-------------------')
|
441 |
+
# # st.markdown("###### Netzero paragraph ######")
|
442 |
+
# # st.write('**Netzero paragraph** `page {}`: {}'.format(netzerohit.iloc[0]['page'],
|
443 |
+
# # netzerohit.iloc[0]['text'].replace("\n", " ")))
|
444 |
+
# # st.write("")
|
445 |
+
# # else:
|
446 |
+
# # st.info("π€ No Netzero paragraph found")
|
447 |
+
|
448 |
+
# # st.write("**Result {}** `page {}` (Relevancy Score: {:.2f})'".format(i+1,hits.iloc[i]['page'],hits.iloc[i]['Relevancy'])")
|
449 |
+
# # st.write('-------------------')
|
450 |
+
# st.write("")
|
451 |
+
# st.markdown("###### Top few Policy/Plans Classified paragraph/text results from list of {} classified paragraphs ######".format(count_policy))
|
452 |
+
# st.markdown("""<hr style="height:10px;border:none;color:#097969;background-color:#097969;" /> """, unsafe_allow_html=True)
|
453 |
+
# range_val = min(5,len(hits))
|
454 |
+
# for i in range(range_val):
|
455 |
+
# # the page number reflects the page that contains the main paragraph
|
456 |
+
# # according to split limit, the overlapping part can be on a separate page
|
457 |
+
# st.write('**Result {}** : `page {}`, `Sector: {}`,\
|
458 |
+
# `Indicators: {}`, `Adapt-Mitig :{}`'\
|
459 |
+
# .format(i+1,
|
460 |
+
# hits.iloc[i]['page'], hits.iloc[i]['Sector Label'],
|
461 |
+
# hits.iloc[i]['Indicator Label'],hits.iloc[i]['Adapt-Mitig Label']))
|
462 |
+
# st.write("\t Text: \t{}".format(hits.iloc[i]['text'].replace("\n", " ")))
|
463 |
+
# hits = hits.reset_index(drop =True)
|
464 |
+
# st.write('----------------')
|
465 |
+
# st.write('Explore the data')
|
466 |
+
# st.write(hits)
|
467 |
+
# df.drop(columns = ['Policy_check'],inplace=True)
|
468 |
+
# df_xlsx = to_excel(df)
|
469 |
|
470 |
+
# with st.sidebar:
|
471 |
+
# st.write('-------------')
|
472 |
+
# st.download_button(label='π₯ Download Result',
|
473 |
+
# data=df_xlsx ,
|
474 |
+
# file_name= os.path.splitext(st.session_state['filename'])[0]+'.xlsx')
|
475 |
+
|
476 |
+
# else:
|
477 |
+
# st.info("π€ No Policy/Plans found")
|