-
Notifications
You must be signed in to change notification settings - Fork 0
/
elgiganten_view.py
177 lines (152 loc) · 7.03 KB
/
elgiganten_view.py
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
import streamlit as st
import pandas as pd
import plotly.graph_objects as go
from src.utils import *
from src.utils_page2 import applicant_compare
import matplotlib.colors
def elgiganten_view(df, compare_candidates, ckey_list):
#Define show variables in df
#variables = ['Python_score', 'Education_level', 'Faculty', 'Years_experience', 'factor1', 'factor2', 'ID']
variables = ['Education', 'Faculty', 'Workfields', 'Years Experience', 'Strength', 'Skills', 'ID', 'unique_color']
df_plot =df
df = df[df.columns.intersection(variables)]
#st.dataframe(df)
#Define common parameters, if compare_length is sufficient
if int(len(compare_candidates)) == 2 or len(compare_candidates) == 3:
#if st.checkbox('Show only differences'):
# st.write('write')
index1 = int(compare_candidates[0][-1])
index2 = int(compare_candidates[1][-1])
#Show page for two candidates
if int(len(compare_candidates)) == 2:
#define indexes for df
indexes = [index1, index2]
identify_IDs = pd.DataFrame(df_plot.iloc[indexes])
#Create dataframe
df = pd.DataFrame(df.iloc[indexes]).transpose()
df = df.astype(str)
values = [list(df.index), list(df[df.columns[0]]), list(df[df.columns[1]])]
IDs = list(df.iloc[-2])
uni_colors = list(df.iloc[-1])
uni_colors_rgba = [f"rgba{matplotlib.colors.to_rgb(x)}"[:-1]+", 0.3)" for x in uni_colors]#B4FBB8
differences = [list(i) for i in (zip(values[0],values[1], values[2])) if len(set(i[1:]))!=1]
value_header = [['Variable'], IDs[0], IDs[1]]
compare_these = list(identify_IDs['Name'])
individual1 = applicant_compare(identify_IDs,compare_these[0])
individual2 = applicant_compare(identify_IDs,compare_these[1])
match_individual = go.Figure(data=[individual1,individual2],
layout=go.Layout(polar={'radialaxis': {'visible': False}},width=550, height=400,showlegend=True))
match_individual.update_polars(radialaxis_range=[0,10])
#Show page for three candidates
if len(compare_candidates) == 3:
#Define indexes
index3 = int(compare_candidates[2][-1])
indexes = [index1, index2, index3]
identify_IDs = pd.DataFrame(df_plot.iloc[indexes])
#Create dataframe
df = pd.DataFrame(df.iloc[indexes]).transpose()
values = [list(df.index), list(df[df.columns[0]]), list(df[df.columns[1]]), list(df[df.columns[2]])]
IDs = list(df.iloc[-2])
value_header = [['Variable'], IDs[0], IDs[1], IDs[2]]
uni_colors = list(df.iloc[-1])
uni_colors_rgba = [f"rgba{matplotlib.colors.to_rgb(x)}"[:-1]+", 0.3)" for x in uni_colors]#B4FBB8
differences = [list(i) for i in (zip(values[0],values[1], values[2], values[3])) if len(set(i[1:]))!=1]
compare_these = list(identify_IDs['Name'])
individual1 = applicant_compare(identify_IDs,compare_these[0])
individual2 = applicant_compare(identify_IDs,compare_these[1])
individual3 = applicant_compare(identify_IDs,compare_these[2])
match_individual = go.Figure(data=[individual1,individual2,individual3],
layout=go.Layout(polar={'radialaxis': {'visible': False}},width=550, height=400,showlegend=True))
match_individual.update_polars(radialaxis_range=[0,10])
fig = go.Figure(data=[go.Table(
columnwidth = [15,20, 20, 20],
header = dict(
values = value_header,
line_color='darkslategray',
fill_color='darkgrey',
align=['left','center'],
font=dict(color='white', size=12),
height=40
),
cells=dict(
#values=values,
values = [i[:-2] for i in values],
line_color='white',
fill=dict(color=['lightgrey']+ uni_colors_rgba),
align=['left', 'center'],
font_size=12,
height=50)
)
])
fig.update_layout(
autosize=False,
width=500,
height=500,
margin=dict(
l=50,
r=50,
b=100,
t=100,
pad=10
)
)
#define layout
col1_a, col2_a = st.columns(2)
comparison_box_a = col1_a.empty()
comparison_box_b = col2_a.empty()
col1_b, col2_b = st.columns([9, 3])
comparison_box_c = col2_b.empty()
col1_c, col2_c = st.columns([9, 3])
comparison_box_d = col2_c.empty()
with comparison_box_c.container():
if st.checkbox('Show only differences', help='Check this box to only show variables where the candidates differ'):
fig = go.Figure(data=[go.Table(
columnwidth = [15,20, 20, 20],
header = dict(
values = value_header,
line_color='darkslategray',
fill_color='darkgrey',
align=['left','center'],
font=dict(color='white', size=12),
height=40
),
cells=dict(
#values=values,
values = [i[:-2] for i in [i for i in zip(*differences)]],
line_color='white',
fill=dict(color=['lightgrey']+ uni_colors_rgba),
align=['left', 'center'],
font_size=12,
height=50)
)
])
fig.update_layout(
autosize=False,
width=500,
height=500,
margin=dict(
l=50,
r=50,
b=100,
t=100,
pad=10
)
)
with comparison_box_a.container():
st.write(match_individual)
with comparison_box_b.container():
st.plotly_chart(fig)
with comparison_box_d.container():
if st.button('Clear comparisons'):
for key in ckey_list:
st.session_state[key] = False
with comparison_box_a.container():
comparison_box_a.empty()
with comparison_box_b.container():
comparison_box_b.empty()
with comparison_box_c.container():
comparison_box_c.empty()
with comparison_box_d.container():
comparison_box_d.empty()
else:
st.warning('Choose 2 or 3 candidates to compare')