-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
1542 lines (1369 loc) · 60.2 KB
/
app.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
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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
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
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#-*- coding: utf-8 -*-
import base64
import io
import os
import json
import requests
from pandas.io.json import json_normalize
import numpy as np
import pandas as pd
from sqlalchemy.sql.elements import Null
from sqlalchemy.sql.schema import Column
import xlsxwriter
import sqlalchemy as sa
from dash import Dash
import dash
import dash_auth
from dash.dependencies import Input, Output, State
import dash_core_components as dcc
import dash_bootstrap_components as dbc
import dash_html_components as html
import dash_table
import plotly.graph_objects as go
import plotly.express as px
from random import randint
import flask
from sqlalchemy import insert
from sqlalchemy import MetaData
###################################################################################
###################################################################################
#################################### APP SETUP ####################################
###################################################################################
###################################################################################
# Keep this out of source code repository - save in a file or a database
external_stylesheets = [dbc.themes.LUX]
app = Dash(__name__, external_stylesheets=external_stylesheets)
# import here a VALID_USERNAME_PASSWORD_PAIRS dictionary
auth = dash_auth.BasicAuth(
app,
VALID_USERNAME_PASSWORD_PAIRS
)
server = app.server
app.config.suppress_callback_exceptions = True
### API setup
# Add here the following variables:
# api_url = the Démarches Simplifiées API URL,
# api_token = your unique token
# api_id_demarche = your demarche_id
api_headers = {'Content-Type': 'application/json',
'Authorization': f'{api_token}'
}
###################################################################################
###################################################################################
################################## AUTHENTICATION #################################
###################################################################################
###################################################################################
########### DataFrames
from plotly.subplots import make_subplots
PAGE_SIZE = 15
eng = sa.create_engine(YOUR_DB_DSN) #Change to your db !
# TODO: copy title of columns into a row and always query that row + candidate. Maybe import SQL with row name empty > use the first row
dfquestions = pd.read_sql("""SELECT "questions" FROM public."fieldmap";""", eng)
#### Titles
title = dbc.Row(
[
dbc.Col(
[
html.Br(),
html.Br(),
html.H1(
children="Evaluation des candidatures EIG 5",
style={"textAlign": "center"},
),
html.Br(),
html.Br(),
html.Br(),
],
width=9,
)
],
justify="center",
)
evaltitle = dbc.Card(
dbc.CardBody(
[
dbc.Row(
[
dbc.Col(
[
html.H3(
children="Evaluation",
style={"textAlign": "center"}
),
],
width=9,
)
],
justify="center",
)
]
),
color="light",
)
tabletitle = dbc.Card(
dbc.CardBody(
[
dbc.Row(
[
dbc.Col(
[
html.H3(
children="Aperçu des candidatures et de leur évaluation",
style={"textAlign": "center"},
)
],
width=9,
)
],
justify="center",
)
]
),
color="light",
)
eytitle = dbc.Card(
dbc.CardBody(
[
dbc.Row(
[
dbc.Col(
[
html.H3(
children="Classification des candidatures par EY",
style={"textAlign": "center"},
)
],
width=9,
)
],
justify="center",
)
]
),
color="light",
)
statstitle = dbc.Card(
dbc.CardBody(
[
dbc.Row(
[
dbc.Col(
[
html.H3(
children="Statistiques et Graphiques",
style={"textAlign": "center"},
)
],
width=9,
)
],
justify="center",
)
]
),
color="light",
)
registertitle = dbc.Card(
dbc.CardBody(
[
dbc.Row(
[
dbc.Col(
[
html.H3(
children="évaluatrices & évaluateurs: s'enregistrer",
style={"textAlign": "center"},
)
],
width=9,
)
],
justify="center",
)
]
),
color="light",
)
### First row: Job filters + dropdown of jury
jury = dbc.Form(
[
dbc.FormGroup(
[
dbc.Col(
[
dbc.Label(
"Je suis :",
html_for = "jury-dropdown",
color="info",
style={"margin-left": "15px", "font-size":"large"}
),
dbc.FormText(
"Si votre nom ne figure pas dans le menu, cliquez sur l'onglet 'S'enregistrer'",
style={"font-style": "italic", "margin-left": "15px"},
color="secondary",
),
html.Br(),
html.Div(id='jury-update'),
html.Br(),
dbc.Alert(
"Afin d'éviter toute erreur, veillez à bien renseigner ces deux champs !",
dismissable='True',
color="warning",
),
]
)
]
)
]
)
jobfilters = dbc.Form(
[
dbc.FormGroup(
[
dbc.Label(
"Je souhaite évaluer une candidature...",
html_for="jobs-row",
color="info",
style={"margin-left": "15px", "font-size":"large"},
),
dbc.FormText(
"Sélectionnez un métier",
style={"font-style": "italic", "margin-left": "15px"},
color="secondary",
),
html.Br(),
dbc.Row(
[
dbc.Col(
[
dcc.RadioItems(
id="jobs-row",
options=[
{"label": "Data scientist", "value": "Data scientist"},
{"label": "Développeur / développeuse", "value":"Développeur / développeuse"},
{"label": "Designer", "value": "Designer"},
{"label":"Data engineer", "value":"Data engineer"},
{"label": "Juriste", "value":"Juriste"},
{"label":"Géomaticien / géomaticienne" , "value" : "Géomaticien / géomaticienne"},
{"label": "Autre", "value": "Autre"},
],
inputStyle={"margin-right": "10px", "margin-left": "10px"},
labelStyle={"display": "inline-block"},
persistence=True
),
html.Br(),
dbc.Button(
"Evaluer une candidature",
id="pick-evaluation",
color="info",
n_clicks=0,
style={"margin-right": "10px", "margin-left": "10px"}
),
html.Br(),
html.Br(),
html.Div(id='info-refresh'),
],
),
],
)
],
)
]
)
toprow = dbc.Card(
dbc.CardBody(
[
dbc.Row(
[
dbc.Col(
[
jury,
],
),
dbc.Col(
[
jobfilters,
],
)
],
justify="center",
)
]
),
color="info",
outline=True,
)
###################################################################################
###################################################################################
##################################### LAYOUT ######################################
###################################################################################
###################################################################################
second_row = html.Div(
[
dbc.Row(
[
dbc.Col(
[
dbc.Card(
[
dbc.CardBody(
[
html.H5(
"Candidature à évaluer", className="card-title"
),
html.P(
"""
Voici une des candidatures qui restent à évaluer.
Vous pouvez aussi choisir de sélectionner un autre profil si vous le
souhaitez en rafraîchissant la page et en cliquant à nouveau sur le
bouton "Evaluer une candidature".
"""
),
html.Br(),
],
),
], color="light",
),
], width=6,
),
dbc.Col(
[
dbc.Card(
[
dbc.CardBody(
[
html.H5(children="Votre évaluation", className="card-title"),
dcc.Markdown(
"""
Pour compléter votre évaluation de la candidature, veuillez remplir chacun des champs ci-dessous.
"""
),
html.Br(),
html.Br(),
],
),
], color="light",
),
], width=6,
),
]
),
html.Br(),
]
)
third_row = html.Div(
[
dbc.Row(
[
dbc.Col(
[
dbc.Card(
[
dbc.CardBody(
[
dbc.Row(
[
dbc.Col(
[
html.Div(
"Dossier Numéro :",
style={"margin-left": "15px", "margin-left": "15px", "font-size":"small"},
),
], width={"size": 3},
),
dbc.Col(
[
html.Div(
id="candidate_id",
style={"margin-left": "15px", "margin-left": "15px", "font-size":"small"},
),
], width={"size": 3},
),
], align="center",
),
html.Br(),
dbc.Row(
[
dbc.Col(
[
dbc.Button(
"Obtenir le CV",
id="cv-button",
color="info",
n_clicks=0,
block=True,
)
], width={"size": 4},
),
dbc.Col(
[
html.Div(
id='cv-url',
)
], width={"size": 8},
),
], align="center",
),
html.Br(),
dbc.Row(
[
dbc.Col(
[
dbc.Button(
"Portfolio",
id="portfolio-button",
color="info",
outline=True,
n_clicks=0,
block=True,
)
], width={"size": 4},
),
dbc.Col(
[
html.Div(
id='portfolio-url',
)
], width={"size": 8},
),
], align="center",
),
],
),
], color="light",
),
html.Br(),
html.Div(id="candidate-placeholder"),
], width=6,
),
dbc.Col(
[
dbc.Form(
[
dbc.FormGroup(
[
dcc.Markdown(
"**Compétences techniques** *(compétences métier et clarté dans la communication, degré d'expérience...)*"
),
dbc.InputGroup(
[
dbc.InputGroupAddon(
"Compétences techniques", addon_type="prepend"
),
dbc.Textarea(id='competences-techniques-appreciation'),
],
className="mb-3",
id="competences-tech",
),
dbc.Row(
[
dbc.Col(
[
dbc.Label(
"Score (1 = non qualifié, 5 = expert) :"
)
],
align="left",
),
dbc.Col(
[
dcc.RadioItems(
id="competences-techniques-score",
options=[
{"label": "1", "value": "1"},
{"label": "2", "value": "2"},
{"label": "3", "value": "3"},
{"label": "4", "value": "4"},
{"label": "5", "value": "5"},
],
inputStyle={
"margin-right": "10px",
"margin-left": "10px",
},
labelStyle={"display": "inline-block"},
)
]
),
html.Br(),
]
),
],
),
dbc.FormGroup(
[
dcc.Markdown(
"**Capacité à travailler en équipe-projet au sein d’un environnement administratif** *(mener un projet de bout en bout, travailler en équipe interdisciplinaire, s'adapter à la culture de l'administration d'accueil...)*"
),
dbc.InputGroup(
[
dbc.InputGroupAddon(
"Travail d'équipe", addon_type="prepend"
),
dbc.Textarea(id="travail-equipe-appreciation"),
],
className="mb-3",
id="travail-equipe",
),
dbc.Row(
[
dbc.Col(
[
dbc.Label(
"Score (1 = non qualifié, 5 = expert) :"
)
],
align="left",
),
dbc.Col(
[
dcc.RadioItems(
id="travail-equipe-score",
options=[
{"label": "1", "value": "1"},
{"label": "2", "value": "2"},
{"label": "3", "value": "3"},
{"label": "4", "value": "4"},
{"label": "5", "value": "5"},
],
inputStyle={
"margin-right": "10px",
"margin-left": "10px",
},
labelStyle={"display": "inline-block"},
)
]
),
]
),
html.Br(),
]
),
dbc.FormGroup(
[
dcc.Markdown(
"**Esprit EIG ** *(engagement pour l'intérêt général, motivation, apport souhaité auprès de la communauté...)*"
),
dbc.InputGroup(
[
dbc.InputGroupAddon("Esprit EIG", addon_type="prepend"),
dbc.Textarea(id="esprit-eig-appreciation"),
],
className="mb-3",
id="esprit-eig",
),
dbc.Row(
[
dbc.Col(
[
dbc.Label(
"Score (1 = non qualifié, 5 = expert) :"
)
],
align="left",
),
dbc.Col(
[
dcc.RadioItems(
id="esprit-eig-score",
options=[
{"label": "1", "value": "1"},
{"label": "2", "value": "2"},
{"label": "3", "value": "3"},
{"label": "4", "value": "4"},
{"label": "5", "value": "5"},
],
inputStyle={
"margin-right": "10px",
"margin-left": "10px",
},
labelStyle={"display": "inline-block"},
)
]
),
]
),
html.Br(),
]
),
dbc.FormGroup(
[
dcc.Markdown(
"**Impression générale** *(Points forts et points faibles de la candidature)*"
),
dbc.InputGroup(
[
dbc.InputGroupAddon(
"Impression générale", addon_type="prepend"
),
dbc.Textarea(id="impression-generale"),
],
className="mb-3",
id="impression"
),
html.Br(),
dcc.Markdown(
"**Votre verdict: **"
),
dcc.RadioItems(
id="next-steps",
options=[
{"label": "Coup de coeur", "value": "Coup de coeur"},
{"label": "Avis neutre", "value": "Avis neutre"},
{"label": "Avis défavorable", "value": "Avis défavorable"},
],
inputStyle={"margin-right": "10px", "margin-left": "10px"},
labelStyle={"display": "inline-block"},
),
html.Br(),
]
),
html.Br(),
dbc.Button(
"Enregistrer mon évaluation",
id="save-eval",
n_clicks=0,
color="info",
),
html.Div(id="placeholder", children=[]),
#dcc.Interval(id='interval', interval=1000),
]
),
], width=6,
),
],
),
],
)
### Tabs
tab1_content = dbc.Card(
dbc.CardBody(
[
evaltitle,
html.Br(),
dcc.Interval(id='interval_pg', interval=86400000*7, n_intervals=0),
dbc.Row(
[
dbc.Col(
toprow,
width={"size": 8, "offset": 2},
),
],
),
html.Br(),
second_row,
html.Br(),
third_row
],
)
)
### Tab 2: table
tab2_content = dbc.Card(
dbc.CardBody(
[
tabletitle,
html.Br(),
dbc.Row(
[
html.P("""Ce tableau est interactif, vous pouvez trier par ordre croissant ou décroissant,
utiliser et combiner les filtres pour chaque colonne (attention aux majuscules, les filtres
sont sensibles à la casse !).
"""),
html.P("""En bas de page, un bouton vous permet de télécharger les données au
format Excel.
"""),
], justify='center',
),
html.Br(),
dbc.Row(
[
dbc.Col(
[
dcc.Interval(id='interval_pg2', interval=86400000*7, n_intervals=0),
html.Div(id='sql-db'),
html.Br(),
html.Br(),
dbc.Row(
[
dbc.Col(
[
dbc.Button(
'Exporter vers Excel',
id="download-button",
color="info",
n_clicks=0,
block=True,
),
dcc.Download(id="download-df"),
], width={"size": 2, "offset":5},
),
dbc.Col(
[
# Create notification when saving to excel
html.Div(id='csv_placeholder', children=[]),
dcc.Store(id="store", data=0),
dcc.Interval(id='interval', interval=1000),
], width={"offset":1},
),
]
),
],
width=12,
),
],
justify="center",
),
]
),
className="mt-3",
)
### Tab 2: EY table
tab2ey_content = dbc.Card(
dbc.CardBody(
[
eytitle,
dbc.Row(
[
dbc.Col(
[
dcc.Interval(id='interval_pg3', interval=86400000*7, n_intervals=0),
html.Div(id='ey-table'),
],
width=12,
),
],
justify="center",
),
]
),
className="mt-3",
)
### Tab 3: graphs
tab3_content = dbc.Card(
dbc.CardBody(
[
statstitle,
dcc.Graph(id='piechart'),
#fig.update_layout(margin=dict(t=10, b=10, r=10, l=10))
]
),
className="mt-3",
)
### Tab 4: Registration
tab4_content = dbc.Card(
dbc.CardBody(
[
registertitle,
html.Br(),
html.Br(),
dbc.Row(
[
html.P("Si votre nom n'apparaît pas dans le menu du premier onglet, vous pouvez l'ajouter ici."),
], justify='center',
),
dbc.Row(
[
html.P("Vous pouvez ensuite rafraîchir la page."),
], justify='center',
),
html.Br(),
dbc.Row(
[
dbc.Col(
[
dbc.InputGroup(
[
dbc.InputGroupAddon(
"Votre nom et prénom",
addon_type="prepend"
),
dbc.Textarea(id='new-jury-name'),
]
),
], width=4,
),
dbc.Col(
[
dbc.Button('Enregistrer',id='register-jury', n_clicks=0, color='info'),
], width=1
),
], align='center',
justify = 'center',
),
dbc.Row(
[
html.Div(id='jury-placeholder'),
], align='center',
justify='center',
),
]
),
className="mt-3",
)
### Assembling tabs
tabs = dbc.Tabs(
[
dbc.Tab(tab1_content, label="Evaluation"),
dbc.Tab(tab2_content, label="Aperçu des candidatures et de leur évaluation"),
dbc.Tab(tab2ey_content, label="Classification des candidatures par EY"),
dbc.Tab(tab3_content, label="Statistiques & Graphiques"),
dbc.Tab(tab4_content, label="S'enregistrer"),
]
)
######## Layout
app.layout = html.Div(
[
title,
tabs
]
)
###################################################################################
###################################################################################
#################################### CALLBACKS ####################################
###################################################################################
###################################################################################
### Callback: Get a priority random new candidate when pressing the button
@app.callback(
[Output('candidate-placeholder', 'children'),
Output('candidate_id','children'),
Output('info-refresh','children')],
Input('pick-evaluation', 'n_clicks'),
State('jury-dropdown', 'value'),
State('jobs-row', 'value'),
prevent_initial_call=False
)
def draw_candidate(nclicks, jury, job):
""" Callback to write into SQL from the evaluation module """
no_alert = html.Div()
no_output = dbc.Col([
html.Br(),
dbc.Alert("Veuillez sélectionner une candidature",color="warning")
])
output = dbc.Alert(
"Pour évaluer une autre candidature, veuillez rafraîchir la page",
dismissable='True',
color="info",
id='info-refresh',
),
no_candidate_id = ''
input_triggered = dash.callback_context.triggered[0]['prop_id'].split('.')[0]
if nclicks <1:
return no_output, no_candidate_id, no_alert
else:
myquery = """SELECT * FROM public.applications WHERE "Q2hhbXAtMTY4MDI3Ng" = %s AND eval_count < 1 AND "jury_name" NOT LIKE %s ORDER BY RANDOM() LIMIT 1;"""
df_apps = pd.read_sql(myquery, con=eng, params=(job, jury))
candidate_id = df_apps['dossier_id']
dff_apps = df_apps.drop(columns=['index', 'app_id','dossier_id', 'eval_count', 'jury_name'])
dff_apps = dff_apps.rename(index = {0:'Réponses'})
dff_apps = dff_apps.transpose()
dff_apps = dff_apps['Réponses'].reset_index(drop=True)
table_applis = pd.concat([dfquestions,dff_apps], axis=1)
table = dash_table.DataTable(
id="candidate-dossier-table",
columns=[{"name": i, "id": i} for i in table_applis.columns],
data=table_applis.to_dict("records"),
style_header={
'backgroundColor': 'white',
'fontWeight': 'bold',
'font-size': "large",
},
style_table={'overflowX': 'auto'},
style_cell={
'padding-left': '10px',
'padding-right': '10px',
'padding-top': '10px',
'padding-bottom': '10px',
'textAlign': 'left',
'font-family':'Nunito Sans',
'whiteSpace': 'normal',
'height': 'auto',
},
)
return table, candidate_id, output
### Callback: call API to get CV
@app.callback(
Output('cv-url', 'children'),
Input('cv-button', 'n_clicks'),
State('candidate_id','children'),
)
def get_cv(nclicks, dossier_id):
no_output = html.Div( "⬅️ Cliquez pour obtenir le CV",style={"margin-left": "15px", "margin-right": "15px", "font-size":"small"})
input_triggered = dash.callback_context.triggered[0]['prop_id'].split('.')[0]
if nclicks <1:
return no_output
else:
q1 = ("""
query{
dossier(number: %s) {
champs{
...on PieceJustificativeChamp {
file {