Spaces:
Runtime error
Runtime error
style table
Browse files- src/read_logs.py +80 -33
src/read_logs.py
CHANGED
@@ -20,9 +20,9 @@ class LogAnalyser:
|
|
20 |
|
21 |
self.path = container_param.selectbox(
|
22 |
'Select the log path', log_file_paths)
|
23 |
-
self.df_path=f'data/df/{self.path.split("/")[-1]}'
|
24 |
-
if 'button1_counter' not in st.session_state:
|
25 |
-
|
26 |
# if 'df' not in st.session_state:
|
27 |
# self.df=0
|
28 |
st.markdown(self.get_text())
|
@@ -41,14 +41,14 @@ class LogAnalyser:
|
|
41 |
'''
|
42 |
|
43 |
def display_logs(self):
|
44 |
-
self.container_param.markdown(
|
45 |
-
|
46 |
-
|
47 |
if exists(self.df_path):
|
48 |
self.df = pd.read_csv(self.df_path)
|
49 |
else:
|
50 |
self.df = self.get_log()
|
51 |
-
|
52 |
# if 'path' not in st.session_state:
|
53 |
# st.session_state.path=self.path
|
54 |
# if 'df' not in st.session_state or st.session_state.path!=self.path:
|
@@ -56,6 +56,7 @@ class LogAnalyser:
|
|
56 |
# st.session_state.path=self.path
|
57 |
|
58 |
self.update_df()
|
|
|
59 |
def update_df(self):
|
60 |
reaction_weight = set_input(self.container_param,
|
61 |
label='Reaction Weight w', min_value=0.0, max_value=1.0, value=0.5, step=0.01,
|
@@ -73,12 +74,16 @@ class LogAnalyser:
|
|
73 |
step=.01,)
|
74 |
table_mode = self.container_param.radio(
|
75 |
"Table Style:", ["Dataframe", "Table"])
|
76 |
-
|
|
|
|
|
|
|
77 |
for story_id in self.df.Story.unique():
|
78 |
reaction_num = 0
|
79 |
-
|
80 |
-
|
81 |
-
|
|
|
82 |
for i, (index, row) in enumerate(dfs.iterrows()):
|
83 |
if row.Emotion == 'neutral':
|
84 |
reaction_show = False
|
@@ -96,50 +101,92 @@ class LogAnalyser:
|
|
96 |
self.df.at[index, 'probability_emote'] = probability_emote
|
97 |
self.df.at[index, 'random_value'] = random_value
|
98 |
self.df.at[index, 'reaction_show'] = reaction_show
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
99 |
for story_id in self.df.Story.unique():
|
100 |
dfs = self.df[(self.df.Story == story_id)].copy()
|
101 |
-
|
|
|
|
|
|
|
|
|
102 |
dfs.drop(c, axis=1, inplace=True)
|
|
|
103 |
st.markdown(f'#### Story {story_id}')
|
104 |
dfs = dfs.style
|
105 |
-
|
106 |
-
|
107 |
-
|
|
|
|
|
|
|
108 |
'selector': 'tr:hover',
|
109 |
'props': 'font-size: 1.01em;' # background-color: #eeee66;
|
110 |
-
|
111 |
-
|
112 |
if table_mode == 'Dataframe':
|
113 |
-
st.dataframe(dfs)
|
|
|
114 |
elif table_mode == 'Table':
|
115 |
st.table(dfs)
|
116 |
-
|
117 |
-
|
|
|
|
|
|
|
|
|
118 |
|
119 |
@staticmethod
|
120 |
@st.cache
|
121 |
-
def
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
|
|
128 |
else:
|
129 |
-
|
130 |
-
|
131 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
132 |
@staticmethod
|
133 |
@st.cache
|
134 |
def rower(data):
|
135 |
s = data.index % 2 != 0
|
136 |
s = pd.concat([pd.Series(s)] * data.shape[1],
|
137 |
-
axis=1)
|
138 |
-
z = pd.DataFrame(np.where(s, 'background-color:#
|
139 |
index=data.index, columns=data.columns)
|
140 |
return z
|
141 |
|
142 |
-
|
143 |
def get_log(self):
|
144 |
df = pd.DataFrame(data=[], columns=[])
|
145 |
log_dict = dict()
|
|
|
20 |
|
21 |
self.path = container_param.selectbox(
|
22 |
'Select the log path', log_file_paths)
|
23 |
+
self.df_path = f'data/df/{self.path.split("/")[-1]}'
|
24 |
+
# if 'button1_counter' not in st.session_state:
|
25 |
+
# st.session_state.button1_counter = 0
|
26 |
# if 'df' not in st.session_state:
|
27 |
# self.df=0
|
28 |
st.markdown(self.get_text())
|
|
|
41 |
'''
|
42 |
|
43 |
def display_logs(self):
|
44 |
+
# self.container_param.markdown(
|
45 |
+
# f'st.session_state.button1_counter: {st.session_state.button1_counter}')
|
46 |
+
|
47 |
if exists(self.df_path):
|
48 |
self.df = pd.read_csv(self.df_path)
|
49 |
else:
|
50 |
self.df = self.get_log()
|
51 |
+
|
52 |
# if 'path' not in st.session_state:
|
53 |
# st.session_state.path=self.path
|
54 |
# if 'df' not in st.session_state or st.session_state.path!=self.path:
|
|
|
56 |
# st.session_state.path=self.path
|
57 |
|
58 |
self.update_df()
|
59 |
+
|
60 |
def update_df(self):
|
61 |
reaction_weight = set_input(self.container_param,
|
62 |
label='Reaction Weight w', min_value=0.0, max_value=1.0, value=0.5, step=0.01,
|
|
|
74 |
step=.01,)
|
75 |
table_mode = self.container_param.radio(
|
76 |
"Table Style:", ["Dataframe", "Table"])
|
77 |
+
self.show_pe_data = self.container_param.checkbox(
|
78 |
+
'Show Probability Emote', value=True, key='show_pe_data_log')
|
79 |
+
df_reaction_pattern = pd.DataFrame()
|
80 |
+
reaction_pattern_dict = dict()
|
81 |
for story_id in self.df.Story.unique():
|
82 |
reaction_num = 0
|
83 |
+
def get_subset_condition(data):
|
84 |
+
return (data.Story == story_id) & (data.Turn == 'user')
|
85 |
+
subset_condition = get_subset_condition(self.df)
|
86 |
+
dfs = self.df[subset_condition]
|
87 |
for i, (index, row) in enumerate(dfs.iterrows()):
|
88 |
if row.Emotion == 'neutral':
|
89 |
reaction_show = False
|
|
|
101 |
self.df.at[index, 'probability_emote'] = probability_emote
|
102 |
self.df.at[index, 'random_value'] = random_value
|
103 |
self.df.at[index, 'reaction_show'] = reaction_show
|
104 |
+
s = ''
|
105 |
+
df_edit = self.df[get_subset_condition(self.df)].reaction_show.copy()
|
106 |
+
df_edit=df_edit.dropna()
|
107 |
+
for v in df_edit:
|
108 |
+
s += str(int(v))
|
109 |
+
# df_reaction_pattern.at[story_id]
|
110 |
+
# reaction_pattern_dict['story_id']=story_id
|
111 |
+
reaction_pattern_dict['reaction_pattern']=s
|
112 |
+
df_reaction_pattern = pd.concat(
|
113 |
+
[df_reaction_pattern, pd.DataFrame(reaction_pattern_dict, index=[f'Story_{story_id}'])])
|
114 |
+
# st.markdown(df_edit)
|
115 |
+
# st.markdown(s)
|
116 |
+
|
117 |
for story_id in self.df.Story.unique():
|
118 |
dfs = self.df[(self.df.Story == story_id)].copy()
|
119 |
+
columns2hide = ['Unnamed: 0', 'Story', ]
|
120 |
+
if not self.show_pe_data:
|
121 |
+
columns2hide += [
|
122 |
+
"reaction_frequency", "probability_emote", "random_value", "reaction_show"]
|
123 |
+
for c in columns2hide:
|
124 |
dfs.drop(c, axis=1, inplace=True)
|
125 |
+
|
126 |
st.markdown(f'#### Story {story_id}')
|
127 |
dfs = dfs.style
|
128 |
+
dfs = dfs.hide_index()
|
129 |
+
if self.show_pe_data:
|
130 |
+
dfs = dfs.apply(self.dfstyle_color_text_col, axis=1)
|
131 |
+
# dfs = dfs.applymap(self.dfstyle_color_text)
|
132 |
+
dfs = dfs.apply(self.rower, axis=None)
|
133 |
+
dfs = dfs.set_table_styles([{
|
134 |
'selector': 'tr:hover',
|
135 |
'props': 'font-size: 1.01em;' # background-color: #eeee66;
|
136 |
+
}]) # .hide_index()
|
137 |
+
|
138 |
if table_mode == 'Dataframe':
|
139 |
+
st.dataframe(dfs)
|
140 |
+
st.dataframe(df_reaction_pattern.iloc[story_id-1] ) # set_na_rep(" ").s
|
141 |
elif table_mode == 'Table':
|
142 |
st.table(dfs)
|
143 |
+
st.table(df_reaction_pattern.iloc[story_id-1] )
|
144 |
+
# print(dfs.render())
|
145 |
+
if table_mode == 'Dataframe':
|
146 |
+
st.dataframe(df_reaction_pattern)
|
147 |
+
elif table_mode == 'Table':
|
148 |
+
st.table(df_reaction_pattern)
|
149 |
|
150 |
@staticmethod
|
151 |
@st.cache
|
152 |
+
def dfstyle_color_text_col(s):
|
153 |
+
result = ['background-color: white']*len(s)
|
154 |
+
if s.Emotion == 'neutral' and s.Turn == 'user':
|
155 |
+
result[2:-1] = ['color: #992222']+['color: #333333']+['color: #fcfcfc']*3
|
156 |
+
if s.reaction_show == 1:
|
157 |
+
result[-1] = 'color: #222222'
|
158 |
+
elif s.reaction_show == 0:
|
159 |
+
result[-1] = 'color: #222222'
|
160 |
else:
|
161 |
+
print(s.reaction_show)
|
162 |
+
print(type(s.reaction_show))
|
163 |
+
result[4:] = ['color: #fcfcfc']*4
|
164 |
+
# if s.probability_emote!=s.probability_emote:
|
165 |
+
# result[5] = 'color: #eeeeee'
|
166 |
+
return result
|
167 |
+
# @staticmethod
|
168 |
+
# @st.cache
|
169 |
+
# def dfstyle_color_text(val):
|
170 |
+
# if type(val)==str:
|
171 |
+
# color = 'red' if val =='neutral' else 'black'
|
172 |
+
# # elif type(val)==float:
|
173 |
+
# # color = 'red' if val > .50000 else 'black'
|
174 |
+
# elif val==None:
|
175 |
+
# color = '#ffffff'
|
176 |
+
# else:
|
177 |
+
# color = None
|
178 |
+
# return 'color: %s' % color if color is not None else ''
|
179 |
+
|
180 |
@staticmethod
|
181 |
@st.cache
|
182 |
def rower(data):
|
183 |
s = data.index % 2 != 0
|
184 |
s = pd.concat([pd.Series(s)] * data.shape[1],
|
185 |
+
axis=1)
|
186 |
+
z = pd.DataFrame(np.where(s, 'background-color:#f9f9f9', ''),
|
187 |
index=data.index, columns=data.columns)
|
188 |
return z
|
189 |
|
|
|
190 |
def get_log(self):
|
191 |
df = pd.DataFrame(data=[], columns=[])
|
192 |
log_dict = dict()
|