File size: 9,903 Bytes
5ee67ed 754eac0 5ee67ed df1a031 e55152e df1a031 7e97826 df1a031 a31da46 df1a031 5ee67ed f4e2c17 5ee67ed f4e2c17 5ee67ed f4e2c17 5ee67ed f4e2c17 5ee67ed f4e2c17 5ee67ed f4e2c17 5ee67ed f4e2c17 754eac0 5ee67ed f4e2c17 5ee67ed df1a031 e55152e 5ee67ed df1a031 7e97826 df1a031 8430df0 df1a031 a31da46 df1a031 e55152e 595b9b9 e55152e 39704ea e55152e 7e97826 e55152e a31da46 e55152e 23feb2a 595b9b9 23feb2a 965d54c 23feb2a 7e97826 23feb2a 7e97826 23feb2a a31da46 23feb2a 5ee67ed |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 |
# set path
import glob, os, sys;
sys.path.append('../utils')
#import needed libraries
import seaborn as sns
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import streamlit as st
from st_aggrid import AgGrid
import logging
logger = logging.getLogger(__name__)
from io import BytesIO
import xlsxwriter
import plotly.express as px
from pandas.api.types import (
is_categorical_dtype,
is_datetime64_any_dtype,
is_numeric_dtype,
is_object_dtype,
is_list_like)
def netzero():
if 'key1' in st.session_state:
df = st.session_state['key1'].copy()
df = df[(df.TargetLabel==True) & (df.NetzeroLabel==True)].reset_index(drop=True)
df['Parameter'] = df.apply(lambda x: 'T_Netzero_C' if ((x['NetzeroLabel'] == True) &
(x['ConditionalLabel'] == True))
else 'T_Netzero', axis=1)
#df = df[['text','page','Parameter']]
df['keep'] = True
st.session_state['netzero_hits'] = df
def netzero_display():
if 'key1' in st.session_state:
st.caption(""" **{}** is splitted into **{}** paragraphs/text chunks."""\
.format(os.path.basename(st.session_state['filename']),
len(st.session_state['key0'])))
hits = st.session_state['netzero_hits']
if len(hits) !=0:
# collecting some statistics
count_target = sum(hits['TargetLabel'] == True)
count_netzero = sum(hits['NetzeroLabel'] == True)
c1, c2 = st.columns([1,1])
with c1:
st.write('**NetZero Related Paragraphs**: `{}`'.format(count_netzero))
st.write('----------------')
#st.dataframe(hits[['keep','text','Parameter','page']])
else:
st.info("🤔 No Netzero paragraph found")
def targets():
def check_param(x):
temp = []
# GHG Target
if all([x['Transport'],x['ConditionalLabel'],x['GHGLabel']]):
temp.append('T_Transport_C')
if all([x['Transport'],not x['ConditionalLabel'],x['GHGLabel']]):
temp.append('T_Transport_Unc')
if all([x['Economy-wide'],x['ConditionalLabel'],x['GHGLabel']]):
temp.append('T_Economy_C')
if all([x['Economy-wide'],not x['ConditionalLabel'],x['GHGLabel']]):
temp.append('T_Economy_Unc')
if all([x['Energy'],x['ConditionalLabel'],x['GHGLabel']]):
temp.append('T_Energy_C')
if all([x['Energy'],not x['ConditionalLabel'],x['GHGLabel']]):
temp.append('T_Energy_Unc')
# NonGHG Target
if all([x['Transport'],x['ConditionalLabel'],x['NonGHGLabel'],x['MitigationLabel']]):
temp.append('T_Transport_O_C')
if all([x['Transport'],not x['ConditionalLabel'],x['NonGHGLabel'],x['MitigationLabel']]):
temp.append('T_Transport_O_Unc')
if all([x['Economy-wide'],x['ConditionalLabel'],x['NonGHGLabel'],x['MitigationLabel']]):
temp.append('T_Economy_O_C')
if all([x['Economy-wide'],not x['ConditionalLabel'],x['NonGHGLabel'],x['MitigationLabel']]):
temp.append('T_Economy_O_Unc')
if all([x['Energy'],x['ConditionalLabel'],x['NonGHGLabel'],x['MitigationLabel']]):
temp.append('T_Energy_O_C')
if all([x['Energy'],not x['ConditionalLabel'],x['NonGHGLabel'],x['MitigationLabel']]):
temp.append('T_Energy_O_Unc')
# Adaptation Target
if all([x['ConditionalLabel'],x['NonGHGLabel'],x['AdaptationLabel']]):
temp.append('T_Adaptation_C')
if all([not x['ConditionalLabel'],x['NonGHGLabel'],x['AdaptationLabel']]):
temp.append('T_Adaptation_Unc')
return temp
if 'key1' in st.session_state:
df = st.session_state['key1'].copy()
df = df[df.TargetLabel==True].reset_index(drop=True)
df['Parameter'] = df.apply(lambda x: check_param(x), axis=1)
#df = df[['text','page','Parameter']]
df['keep'] = True
st.session_state['target_hits'] = df
def target_display():
if 'key1' in st.session_state:
st.caption(""" **{}** is splitted into **{}** paragraphs/text chunks."""\
.format(os.path.basename(st.session_state['filename']),
len(st.session_state['key0'])))
hits = st.session_state['target_hits']
if len(hits) !=0:
# collecting some statistics
count_target = sum(hits['TargetLabel'] == True)
count_ghg = sum(hits['GHGLabel'] == True)
count_transport = sum(hits['Transport'] == True)
count_nonghg = sum(hits['NonGHGLabel'] == True)
c1, c2 = st.columns([1,1])
with c1:
st.write('**Target Related Paragraphs**: `{}`'.format(count_target))
st.write('**Transport Target Related Paragraphs**: `{}`'.format(count_transport))
with c2:
st.write('**GHG Target Related Paragraphs**: `{}`'.format(count_ghg))
st.write('**NonGHG Target Related Paragraphs**: `{}`'.format(count_nonghg))
st.write('----------------')
#st.dataframe(hits[['keep','text','Parameter','page']])
else:
st.info("🤔 No Targets Found")
def mitigation():
if 'key1' in st.session_state:
df = st.session_state['key1'].copy()
temp = np.where((df.ActionLabel==True) | (df.PolicyLabel==True) | (df.PlansLabel==True))
df = df.loc[temp]
df = df.reset_index(drop=True)
df = df[(df.MitigationLabel == True)&(df.Transport == True)].reset_index(drop=True)
categories = ['Active mobility','Alternative fuels','Aviation improvements',
'Comprehensive transport planning','Digital solutions','Economic instruments',
'Education and behavioral change','Electric mobility',
'Freight efficiency improvements','Improve infrastructure','Land use',
'Other Transport Category','Public transport improvement',
'Shipping improvements','Transport demand management','Vehicle improvements']
df['Parameter'] = df.apply(lambda x: [i for i in categories if x[i]==True],axis=1)
non_target = ['Action','Policy','Plans']
df['Type'] = df.apply(lambda x: [i for i in non_target if x[i+'Label']==True],axis=1)
df['keep'] = True
st.session_state['mitigation_hits'] = df
def mitigation_display():
if 'key1' in st.session_state:
st.caption(""" **{}** is splitted into **{}** paragraphs/text chunks."""\
.format(os.path.basename(st.session_state['filename']),
len(st.session_state['key0'])))
hits = st.session_state['mitigation_hits']
if len(hits) !=0:
# collecting some statistics
count_mitigation = sum(hits['MitigationLabel'] == True)
count_action = sum(hits['ActionLabel'] == True)
count_policy = sum(hits['PolicyLabel'] == True)
count_plans = sum(hits['PlansLabel'] == True)
c1, c2 = st.columns([1,1])
with c1:
st.write('**Transport Mitgation Related Paragraphs**: `{}`'.format(count_mitigation))
st.write('**Transport Action Related Paragraphs**: `{}`'.format(count_action))
with c2:
st.write('**Transport Policy Related Paragraphs**: `{}`'.format(count_policy))
st.write('**Transport Plans Related Paragraphs**: `{}`'.format(count_plans))
st.write('----------------')
#st.dataframe(hits[['keep','text','Parameter','Type','page']])
else:
st.info("🤔 No Tranport Mitigation paragraph found")
def adaptation():
if 'key1' in st.session_state:
df = st.session_state['key1'].copy()
temp = np.where((df.ActionLabel==True) | (df.PolicyLabel==True) | (df.PlansLabel==True))
df = df.loc[temp]
df = df.reset_index(drop=True)
df = df[(df.AdaptationLabel == True)&(df.Transport == True)].reset_index(drop=True)
non_target = ['Action','Policy','Plans']
df['Type'] = df.apply(lambda x: [i for i in non_target if x[i+'Label']==True],axis=1)
df['keep'] = True
st.session_state['adaptation_hits'] = df
def adaptation_display():
if 'key1' in st.session_state:
st.caption(""" **{}** is splitted into **{}** paragraphs/text chunks."""\
.format(os.path.basename(st.session_state['filename']),
len(st.session_state['key0'])))
hits = st.session_state['adaptation_hits']
if len(hits) !=0:
# collecting some statistics
count_adaptation = sum(hits['AdaptationLabel'] == True)
count_action = sum(hits['ActionLabel'] == True)
count_policy = sum(hits['PolicyLabel'] == True)
count_plans = sum(hits['PlansLabel'] == True)
c1, c2 = st.columns([1,1])
with c1:
st.write('**Transport Adaptation Related Paragraphs**: `{}`'.format(count_adaptation))
st.write('**Transport Action Related Paragraphs**: `{}`'.format(count_action))
with c2:
st.write('**Transport Policy Related Paragraphs**: `{}`'.format(count_policy))
st.write('**Transport Plans Related Paragraphs**: `{}`'.format(count_plans))
st.write('----------------')
#st.dataframe(hits[['keep','text','Type','page']])
else:
st.info("🤔 No Tranport Adaptation paragraph found")
|