restructure download
Browse files- appStore/policyaction.py +84 -7
- appStore/target.py +0 -7
appStore/policyaction.py
CHANGED
@@ -28,17 +28,60 @@ classifier_identifier = 'policyaction'
|
|
28 |
params = get_classifier_params(classifier_identifier)
|
29 |
|
30 |
@st.cache_data
|
31 |
-
def to_excel(df
|
|
|
|
|
|
|
|
|
|
|
32 |
len_df = len(df)
|
33 |
output = BytesIO()
|
34 |
writer = pd.ExcelWriter(output, engine='xlsxwriter')
|
35 |
df.to_excel(writer, index=False, sheet_name='rawdata')
|
36 |
-
if '
|
37 |
-
|
38 |
-
|
39 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
40 |
# hits = hits.drop(columns = ['Target Score','Netzero Score','GHG Score'])
|
41 |
-
hits.to_excel(writer,index=False,sheet_name = 'Action')
|
42 |
workbook = writer.book
|
43 |
# worksheet = writer.sheets['Sheet1']
|
44 |
# worksheet.data_validation('L2:L{}'.format(len_df),
|
@@ -59,6 +102,37 @@ def to_excel(df, hits):
|
|
59 |
writer.save()
|
60 |
processed_data = output.getvalue()
|
61 |
return processed_data
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
62 |
def app():
|
63 |
|
64 |
### Main app code ###
|
@@ -106,10 +180,11 @@ def action_display():
|
|
106 |
# filtered_df = filtered_df[filtered_df.keep == True]
|
107 |
# st.write('Explore the data')
|
108 |
# AgGrid(hits)
|
109 |
-
|
110 |
|
111 |
with st.sidebar:
|
112 |
st.write('-------------')
|
|
|
113 |
st.download_button(label='📥 Download Result',
|
114 |
data=df_xlsx ,
|
115 |
file_name= os.path.splitext(os.path.basename(st.session_state['filename']))[0]+'.xlsx')
|
@@ -202,6 +277,8 @@ def filter_dataframe(df: pd.DataFrame) -> pd.DataFrame:
|
|
202 |
if user_text_input:
|
203 |
df = df[df[column].str.contains(user_text_input)]
|
204 |
df['keep'] = True
|
|
|
|
|
205 |
df = st.data_editor(
|
206 |
df,
|
207 |
column_config={
|
|
|
28 |
params = get_classifier_params(classifier_identifier)
|
29 |
|
30 |
@st.cache_data
|
31 |
+
def to_excel(df):
|
32 |
+
# df['Target Validation'] = 'No'
|
33 |
+
# df['Netzero Validation'] = 'No'
|
34 |
+
# df['GHG Validation'] = 'No'
|
35 |
+
# df['Adapt-Mitig Validation'] = 'No'
|
36 |
+
# df['Sector'] = 'No'
|
37 |
len_df = len(df)
|
38 |
output = BytesIO()
|
39 |
writer = pd.ExcelWriter(output, engine='xlsxwriter')
|
40 |
df.to_excel(writer, index=False, sheet_name='rawdata')
|
41 |
+
if 'target_hits' in st.session_state:
|
42 |
+
target_hits = st.session_state['target_hits']
|
43 |
+
if 'keep' in target_hits.columns:
|
44 |
+
target_hits = target_hits[target_hits.keep == True]
|
45 |
+
target_hits = target_hits.reset_index(drop=True)
|
46 |
+
target_hits.drop(columns = ['keep'], inplace=True)
|
47 |
+
target_hits.to_excel(writer,index=False,sheet_name = 'Target')
|
48 |
+
else:
|
49 |
+
target_hits = target_hits.sort_values(by=['Target Score'], ascending=False)
|
50 |
+
target_hits = target_hits.reset_index(drop=True)
|
51 |
+
target_hits.to_excel(writer,index=False,sheet_name = 'Target')
|
52 |
+
|
53 |
+
else:
|
54 |
+
target_hits = df[df['Target Label'] == True]
|
55 |
+
target_hits.drop(columns=['Target Label','Netzero Score','GHG Score','Action Label',
|
56 |
+
'Action Score','Policies_Plans Label','Indicator Label',
|
57 |
+
'Policies_Plans Score','Conditional Score'],inplace=True)
|
58 |
+
target_hits = target_hits.sort_values(by=['Target Score'], ascending=False)
|
59 |
+
target_hits = target_hits.reset_index(drop=True)
|
60 |
+
target_hits.to_excel(writer,index=False,sheet_name = 'Target')
|
61 |
+
|
62 |
+
|
63 |
+
if 'action_hits' in st.session_state:
|
64 |
+
action_hits = st.session_state['action_hits']
|
65 |
+
if 'keep' in action_hits.columns:
|
66 |
+
action_hits = action_hits[action_hits.keep == True]
|
67 |
+
action_hits = action_hits.reset_index(drop=True)
|
68 |
+
action_hits.drop(columns = ['keep'], inplace=True)
|
69 |
+
action_hits.to_excel(writer,index=False,sheet_name = 'Action')
|
70 |
+
else:
|
71 |
+
action_hits = action_hits.sort_values(by=['Action Score'], ascending=False)
|
72 |
+
action_hits = action_hits.reset_index(drop=True)
|
73 |
+
action_hits.to_excel(writer,index=False,sheet_name = 'Action')
|
74 |
+
else:
|
75 |
+
action_hits = df[df['Action Label'] == True]
|
76 |
+
action_hits.drop(columns=['Target Label','Target Score','Netzero Score',
|
77 |
+
'Netzero Label','GHG Label',
|
78 |
+
'GHG Score','Action Label','Policies_Plans Label',
|
79 |
+
'Policies_Plans Score','Conditional Score'],inplace=True)
|
80 |
+
action_hits = action_hits.sort_values(by=['Action Score'], ascending=False)
|
81 |
+
action_hits = action_hits.reset_index(drop=True)
|
82 |
+
action_hits.to_excel(writer,index=False,sheet_name = 'Action')
|
83 |
+
|
84 |
# hits = hits.drop(columns = ['Target Score','Netzero Score','GHG Score'])
|
|
|
85 |
workbook = writer.book
|
86 |
# worksheet = writer.sheets['Sheet1']
|
87 |
# worksheet.data_validation('L2:L{}'.format(len_df),
|
|
|
102 |
writer.save()
|
103 |
processed_data = output.getvalue()
|
104 |
return processed_data
|
105 |
+
# def to_excel(df, hits):
|
106 |
+
# len_df = len(df)
|
107 |
+
# output = BytesIO()
|
108 |
+
# writer = pd.ExcelWriter(output, engine='xlsxwriter')
|
109 |
+
# df.to_excel(writer, index=False, sheet_name='rawdata')
|
110 |
+
# if 'keep' in hits.columns:
|
111 |
+
# hits = hits[hits.keep == True]
|
112 |
+
# hits = hits.reset_index(drop=True)
|
113 |
+
# hits.drop(columns = ['keep'], inplace=True)
|
114 |
+
# # hits = hits.drop(columns = ['Target Score','Netzero Score','GHG Score'])
|
115 |
+
# hits.to_excel(writer,index=False,sheet_name = 'Action')
|
116 |
+
# workbook = writer.book
|
117 |
+
# # worksheet = writer.sheets['Sheet1']
|
118 |
+
# # worksheet.data_validation('L2:L{}'.format(len_df),
|
119 |
+
# # {'validate': 'list',
|
120 |
+
# # 'source': ['No', 'Yes', 'Discard']})
|
121 |
+
# # worksheet.data_validation('M2:L{}'.format(len_df),
|
122 |
+
# # {'validate': 'list',
|
123 |
+
# # 'source': ['No', 'Yes', 'Discard']})
|
124 |
+
# # worksheet.data_validation('N2:L{}'.format(len_df),
|
125 |
+
# # {'validate': 'list',
|
126 |
+
# # 'source': ['No', 'Yes', 'Discard']})
|
127 |
+
# # worksheet.data_validation('O2:L{}'.format(len_df),
|
128 |
+
# # {'validate': 'list',
|
129 |
+
# # 'source': ['No', 'Yes', 'Discard']})
|
130 |
+
# # worksheet.data_validation('P2:L{}'.format(len_df),
|
131 |
+
# # {'validate': 'list',
|
132 |
+
# # 'source': ['No', 'Yes', 'Discard']})
|
133 |
+
# writer.save()
|
134 |
+
# processed_data = output.getvalue()
|
135 |
+
# return processed_data
|
136 |
def app():
|
137 |
|
138 |
### Main app code ###
|
|
|
180 |
# filtered_df = filtered_df[filtered_df.keep == True]
|
181 |
# st.write('Explore the data')
|
182 |
# AgGrid(hits)
|
183 |
+
|
184 |
|
185 |
with st.sidebar:
|
186 |
st.write('-------------')
|
187 |
+
df_xlsx = to_excel(df)
|
188 |
st.download_button(label='📥 Download Result',
|
189 |
data=df_xlsx ,
|
190 |
file_name= os.path.splitext(os.path.basename(st.session_state['filename']))[0]+'.xlsx')
|
|
|
277 |
if user_text_input:
|
278 |
df = df[df[column].str.contains(user_text_input)]
|
279 |
df['keep'] = True
|
280 |
+
df = df[['keep','text','Action Score','Conditional Label',
|
281 |
+
'Sector Label','Adapt-Mitig Label','Indicator Label','page']]
|
282 |
df = st.data_editor(
|
283 |
df,
|
284 |
column_config={
|
appStore/target.py
CHANGED
@@ -52,9 +52,6 @@ def to_excel(df):
|
|
52 |
target_hits.drop(columns = ['keep'], inplace=True)
|
53 |
target_hits.to_excel(writer,index=False,sheet_name = 'Target')
|
54 |
else:
|
55 |
-
target_hits.drop(columns=['Target Label','Netzero Score','GHG Score','Action Label',
|
56 |
-
'Action Score','Policies_Plans Label','Indicator Label',
|
57 |
-
'Policies_Plans Score','Conditional Score'],inplace=True)
|
58 |
target_hits = target_hits.sort_values(by=['Target Score'], ascending=False)
|
59 |
target_hits = target_hits.reset_index(drop=True)
|
60 |
target_hits.to_excel(writer,index=False,sheet_name = 'Target')
|
@@ -77,10 +74,6 @@ def to_excel(df):
|
|
77 |
action_hits.drop(columns = ['keep'], inplace=True)
|
78 |
action_hits.to_excel(writer,index=False,sheet_name = 'Action')
|
79 |
else:
|
80 |
-
action_hits.drop(columns=['Target Label','Target Score','Netzero Score',
|
81 |
-
'Netzero Label','GHG Label',
|
82 |
-
'GHG Score','Action Label','Policies_Plans Label',
|
83 |
-
'Policies_Plans Score','Conditional Score'],inplace=True)
|
84 |
action_hits = action_hits.sort_values(by=['Action Score'], ascending=False)
|
85 |
action_hits = action_hits.reset_index(drop=True)
|
86 |
action_hits.to_excel(writer,index=False,sheet_name = 'Action')
|
|
|
52 |
target_hits.drop(columns = ['keep'], inplace=True)
|
53 |
target_hits.to_excel(writer,index=False,sheet_name = 'Target')
|
54 |
else:
|
|
|
|
|
|
|
55 |
target_hits = target_hits.sort_values(by=['Target Score'], ascending=False)
|
56 |
target_hits = target_hits.reset_index(drop=True)
|
57 |
target_hits.to_excel(writer,index=False,sheet_name = 'Target')
|
|
|
74 |
action_hits.drop(columns = ['keep'], inplace=True)
|
75 |
action_hits.to_excel(writer,index=False,sheet_name = 'Action')
|
76 |
else:
|
|
|
|
|
|
|
|
|
77 |
action_hits = action_hits.sort_values(by=['Action Score'], ascending=False)
|
78 |
action_hits = action_hits.reset_index(drop=True)
|
79 |
action_hits.to_excel(writer,index=False,sheet_name = 'Action')
|