mbosse99 commited on
Commit
5067887
·
1 Parent(s): ff71abc

added assessment tool

Browse files
Files changed (1) hide show
  1. app.py +177 -85
app.py CHANGED
@@ -1,38 +1,46 @@
1
- import requests
2
  import json
3
  import os
4
  import uuid
 
 
 
5
  import streamlit as st
6
  from azure.cosmos import CosmosClient
7
- from datetime import datetime, timedelta
8
- from ParamClasses import CreateParams, AppointmentDBItem, Attendee, Appointment
9
  from dotenv import load_dotenv
10
 
 
 
11
  load_dotenv()
12
 
 
13
  def create_meeting(input_params) -> dict:
14
  try:
15
- url = f"{os.environ.get('BASE_API')}/api/create-appointment"
16
- response = requests.post(url=url,data=input_params)
17
- response.raise_for_status()
 
 
18
  return response.json()
19
- except Exception as e:
20
  print(f"Fehler beim erstellen des Termins: {str(e)}")
21
  st.error("Something went wrong, please contact the site admin.", icon="🚨")
22
-
 
23
  def adjust_datetime(original_datetime_str, offset_option):
24
  # Konvertiere den originalen DateTime-String in ein datetime-Objekt
25
- original_datetime = datetime.strptime(original_datetime_str, "%Y-%m-%dT%H:%M:%S.%fZ")
 
 
26
 
27
  # Überprüfe das Vorzeichen im Offset-String
28
- if offset_option.startswith('+'):
29
  # Wenn das Vorzeichen ein Pluszeichen ist, negiere den Offset
30
- offset_option = '-' + offset_option[1:]
31
- elif offset_option.startswith('-'):
32
- offset_option = '+' + offset_option[1:]
33
  else:
34
  # Wenn kein Vorzeichen vorhanden ist, füge ein Minuszeichen hinzu
35
- offset_option = '' + offset_option
36
 
37
  # Konvertiere die Offset-Option von String zu integer
38
  offset_hours = int(offset_option)
@@ -47,145 +55,229 @@ def adjust_datetime(original_datetime_str, offset_option):
47
  adjusted_datetime_str = adjusted_datetime.strftime("%Y-%m-%dT%H:%M:%S.%fZ")
48
  return adjusted_datetime_str
49
 
 
50
  def write_interview_db_object(interview_data):
51
  try:
52
  db_client: CosmosClient = st.session_state["cosmos_db"]
53
  database = db_client.get_database_client("appointment-database")
54
  container = database.get_container_client("appointments")
55
  container.create_item(body=interview_data)
56
- except Exception as e:
57
  print(f"Fehler beim erstellen des Appointment DB items: {str(e)}")
58
  st.error("Something went wrong, please contact the site admin.", icon="🚨")
59
 
 
60
  def write_assessment_db_object(interview_data):
61
  try:
62
  db_client: CosmosClient = st.session_state["cosmos_db"]
63
  database = db_client.get_database_client("assessment-database")
64
  container = database.get_container_client("assessments")
65
  container.create_item(body=interview_data)
66
- except Exception as e:
67
  print(f"Fehler beim erstellen des Assessment DB items: {str(e)}")
68
  st.error("Something went wrong, please contact the site admin.", icon="🚨")
69
-
 
70
  def create_button_handler():
71
  with st.spinner("Creating the appointment..."):
72
- start_date_utc_str = datetime.strptime(str(st.session_state["date_input"])+" "+str(st.session_state["time_input"]),"%Y-%m-%d %H:%M:%S").strftime("%Y-%m-%dT%H:%M:%S.%fZ")
73
- start_date_str = adjust_datetime(start_date_utc_str, st.session_state["time_zone_option"])
74
- end_date = datetime.strptime(str(st.session_state["date_input"])+" "+str(st.session_state["time_input"]),"%Y-%m-%d %H:%M:%S") + timedelta(minutes=st.session_state["duration_input"])
 
 
 
 
 
 
 
 
 
 
 
 
75
  end_date_utc_str = end_date.strftime("%Y-%m-%dT%H:%M:%S.%fZ")
76
- end_date_str = adjust_datetime(end_date_utc_str, st.session_state["time_zone_option"])
77
- request_params = json.dumps({
78
- "appointment": {
79
- "start_time": start_date_str,
80
- "end_time": end_date_str
81
- },
82
- "subject": st.session_state["subject_input"],
83
- "recruiter": {
84
- "email": "",#st.session_state["recruiter_mail"],
85
- "name": ""#st.session_state["recruiter_mail"]
86
- },
87
- "client": {
88
- "email": "",#st.session_state["client_mail"],
89
- "name": ""#st.session_state["client_mail"]
90
- },
91
- "candidate": {
92
- "email": "",#st.session_state["candidate_mail"],
93
- "name": ""#st.session_state["candidate_mail"]
 
94
  }
95
- })
96
  appointment_response = create_meeting(request_params)
97
  st.session_state["appointment_response"] = appointment_response
98
  if st.session_state["assessment_toggle"]:
99
  assessment_id = str(uuid.uuid4())
100
  st.session_state["assessment_db_id"] = assessment_id
101
  db_item = {
102
- "id":assessment_id,
103
- "zoom_meeting_id":str(appointment_response["zoom_meeting"]["id"]),
104
- "assessment_title":st.session_state["subject_input"],
105
- "start_time":start_date_str,
106
- "end_time":end_date_str,
107
- "meeting_url":appointment_response["zoom_meeting"]["start_url"],
108
- "environment":str(["us"]),
109
- "process_status":"assessment_scheduled",
 
 
110
  "recruiter": {
111
- "email": "",#str(st.session_state["recruiter_mail"]),
112
- "name": ""#str(st.session_state["recruiter_mail"])
113
  },
114
  "client": {
115
- "email": "",#str(st.session_state["client_mail"]),
116
- "name": ""#str(st.session_state["client_mail"])
117
  },
118
  "candidate": {
119
- "email": "",#str(st.session_state["candidate_mail"]),
120
- "name": ""#str(st.session_state["candidate_mail"])
121
  },
122
- "interview_transcript": "",
123
  "questions": [],
124
- "coding_tasks": []
 
125
  }
126
  write_assessment_db_object(db_item)
127
  else:
128
  db_item = {
129
- "id":str(uuid.uuid4()),
130
- "zoom_meeting_id":str(appointment_response["zoom_meeting"]["id"]),
131
- "process_id":str(uuid.uuid4()),
132
- "job_title":st.session_state["subject_input"],
133
- "start_time":start_date_str,
134
- "end_time":end_date_str,
135
- "meeting_url":appointment_response["zoom_meeting"]["start_url"],
136
- "environment":str(["us"]),
137
- "process_status":"interview_scheduled",
138
  "recruiter": {
139
- "email": "",#str(st.session_state["recruiter_mail"]),
140
- "name": ""#str(st.session_state["recruiter_mail"])
141
  },
142
  "client": {
143
- "email": "",#str(st.session_state["client_mail"]),
144
- "name": ""#str(st.session_state["client_mail"])
145
  },
146
  "candidate": {
147
- "email": "",#str(st.session_state["candidate_mail"]),
148
- "name": ""#str(st.session_state["candidate_mail"])
149
  },
150
- "summary_recruiter":"",
151
- "summary_client":"",
152
- "summary_candidate":""
153
  }
154
  write_interview_db_object(db_item)
155
-
 
156
  if "appointment_response" not in st.session_state:
157
  st.session_state["appointment_response"] = None
158
  if "cosmos_db" not in st.session_state:
159
  # Cosmos DB Client erstellen
160
- client = CosmosClient(os.environ.get('DB_CONNECTION'), os.environ.get('DB_KEY'))
161
  st.session_state["cosmos_db"] = client
162
  if "assessment_db_id" not in st.session_state:
163
  st.session_state["assessment_db_id"] = None
 
 
164
 
165
  col1, col2 = st.columns([2, 1])
166
 
167
  col1.title("Appointment Tool")
168
- col2.image("https://www.workgenius.com/wp-content/uploads/2023/03/WorkGenius_navy-1.svg")
 
 
169
 
170
  st.write("Please enter the date, time and duration for the appointment to be created.")
171
 
172
- st.date_input("Date of the appointment",format="DD/MM/YYYY", key="date_input")
173
  now = datetime.now()
174
  rounded_now = now + timedelta(minutes=30 - now.minute % 30)
175
  st.time_input("Starting time of the appointment", value=rounded_now, key="time_input")
176
- st.selectbox("Please select your time zone (based on UTC time)",options=["+10","+9","+8","+7","+6","+5","+4","+3","+2","+1","0","-1","-2","-3","-4","-5","-6","-7","-8","-9","-10"],index=10, key="time_zone_option")
177
- st.select_slider("Duration of the appointment in minutes",[15,30,45,60],value=30, key="duration_input")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
178
  st.text_input("Enter the subject of the meeting", key="subject_input")
179
  # recruiter_mail = st.text_input("Please enter the mail of the recruiter", key="recruiter_mail")
180
  # client_mail = st.text_input("Please enter the mail of the client", key="client_mail")
181
  # candidate_mail = st.text_input("Please enter the mail of the candidate", key="candidate_mail")
182
- st.toggle("Activate to create an assessment appointment, otherwise a candidate interview is going to be created", key="assessment_toggle")
183
- st.button("Create appointment", key="create_button", disabled=False if st.session_state["subject_input"] else True, on_click=create_button_handler)
 
 
 
 
 
 
 
 
184
 
185
  if st.session_state["appointment_response"]:
186
  st.success("The appointment was created correctly.")
187
- st.write("Interviewer link: "+os.environ.get('BASE_API')+"/meeting-consent?redirect="+st.session_state["appointment_response"]["zoom_meeting"]["start_url"].replace("https://us06web.zoom.us/", ""))
188
- st.write("Interviewee link: "+os.environ.get('BASE_API')+"/meeting-consent?redirect="+st.session_state["appointment_response"]["zoom_meeting"]["join_url"].replace("https://us06web.zoom.us/", ""))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
189
  if st.session_state["assessment_toggle"]:
190
- st.write("Here is the link for the assessment preparation: https://tensora.ai/workgenius/interview-preparation?assessment-id="+st.session_state["assessment_db_id"])
191
- st.write("Here is the link for the code upload: https://tensora.ai/workgenius/code-upload?assessment-id="+st.session_state["assessment_db_id"])
 
 
 
 
 
 
 
 
1
  import json
2
  import os
3
  import uuid
4
+ from datetime import datetime, timedelta
5
+
6
+ import requests
7
  import streamlit as st
8
  from azure.cosmos import CosmosClient
 
 
9
  from dotenv import load_dotenv
10
 
11
+ from ParamClasses import Appointment, AppointmentDBItem, Attendee, CreateParams
12
+
13
  load_dotenv()
14
 
15
+
16
  def create_meeting(input_params) -> dict:
17
  try:
18
+ url = f"{os.environ.get('BASE_API')}/create/zoom-meeting"
19
+ header = {"x-api-key": os.environ.get("API_KEY")}
20
+ response = requests.post(url=url, data=input_params, headers=header)
21
+ response.raise_for_status()
22
+ print(response.json())
23
  return response.json()
24
+ except Exception as e:
25
  print(f"Fehler beim erstellen des Termins: {str(e)}")
26
  st.error("Something went wrong, please contact the site admin.", icon="🚨")
27
+
28
+
29
  def adjust_datetime(original_datetime_str, offset_option):
30
  # Konvertiere den originalen DateTime-String in ein datetime-Objekt
31
+ original_datetime = datetime.strptime(
32
+ original_datetime_str, "%Y-%m-%dT%H:%M:%S.%fZ"
33
+ )
34
 
35
  # Überprüfe das Vorzeichen im Offset-String
36
+ if offset_option.startswith("+"):
37
  # Wenn das Vorzeichen ein Pluszeichen ist, negiere den Offset
38
+ offset_option = "-" + offset_option[1:]
39
+ elif offset_option.startswith("-"):
40
+ offset_option = "+" + offset_option[1:]
41
  else:
42
  # Wenn kein Vorzeichen vorhanden ist, füge ein Minuszeichen hinzu
43
+ offset_option = "" + offset_option
44
 
45
  # Konvertiere die Offset-Option von String zu integer
46
  offset_hours = int(offset_option)
 
55
  adjusted_datetime_str = adjusted_datetime.strftime("%Y-%m-%dT%H:%M:%S.%fZ")
56
  return adjusted_datetime_str
57
 
58
+
59
  def write_interview_db_object(interview_data):
60
  try:
61
  db_client: CosmosClient = st.session_state["cosmos_db"]
62
  database = db_client.get_database_client("appointment-database")
63
  container = database.get_container_client("appointments")
64
  container.create_item(body=interview_data)
65
+ except Exception as e:
66
  print(f"Fehler beim erstellen des Appointment DB items: {str(e)}")
67
  st.error("Something went wrong, please contact the site admin.", icon="🚨")
68
 
69
+
70
  def write_assessment_db_object(interview_data):
71
  try:
72
  db_client: CosmosClient = st.session_state["cosmos_db"]
73
  database = db_client.get_database_client("assessment-database")
74
  container = database.get_container_client("assessments")
75
  container.create_item(body=interview_data)
76
+ except Exception as e:
77
  print(f"Fehler beim erstellen des Assessment DB items: {str(e)}")
78
  st.error("Something went wrong, please contact the site admin.", icon="🚨")
79
+
80
+
81
  def create_button_handler():
82
  with st.spinner("Creating the appointment..."):
83
+ start_date_utc_str = datetime.strptime(
84
+ str(st.session_state["date_input"])
85
+ + " "
86
+ + str(st.session_state["time_input"]),
87
+ "%Y-%m-%d %H:%M:%S",
88
+ ).strftime("%Y-%m-%dT%H:%M:%S.%fZ")
89
+ start_date_str = adjust_datetime(
90
+ start_date_utc_str, st.session_state["time_zone_option"]
91
+ )
92
+ end_date = datetime.strptime(
93
+ str(st.session_state["date_input"])
94
+ + " "
95
+ + str(st.session_state["time_input"]),
96
+ "%Y-%m-%d %H:%M:%S",
97
+ ) + timedelta(minutes=st.session_state["duration_input"])
98
  end_date_utc_str = end_date.strftime("%Y-%m-%dT%H:%M:%S.%fZ")
99
+ end_date_str = adjust_datetime(
100
+ end_date_utc_str, st.session_state["time_zone_option"]
101
+ )
102
+ request_params = json.dumps(
103
+ {
104
+ "appointment": {"start_time": start_date_str, "end_time": end_date_str},
105
+ "subject": st.session_state["subject_input"],
106
+ "recruiter": {
107
+ "email": "", # st.session_state["recruiter_mail"],
108
+ "name": "", # st.session_state["recruiter_mail"]
109
+ },
110
+ "client": {
111
+ "email": "", # st.session_state["client_mail"],
112
+ "name": "", # st.session_state["client_mail"]
113
+ },
114
+ "candidate": {
115
+ "email": "", # st.session_state["candidate_mail"],
116
+ "name": "", # st.session_state["candidate_mail"]
117
+ },
118
  }
119
+ )
120
  appointment_response = create_meeting(request_params)
121
  st.session_state["appointment_response"] = appointment_response
122
  if st.session_state["assessment_toggle"]:
123
  assessment_id = str(uuid.uuid4())
124
  st.session_state["assessment_db_id"] = assessment_id
125
  db_item = {
126
+ "id": assessment_id,
127
+ "zoom_meeting_id": str(appointment_response["zoom_meeting"]["id"]),
128
+ "assessment_title": st.session_state["subject_input"],
129
+ "start_time": start_date_str,
130
+ "end_time": end_date_str,
131
+ "callback_url": "http://127.0.0.1:8000/test",
132
+ "authorization_token": "asdf",
133
+ "meeting_url": appointment_response["zoom_meeting"]["start_url"],
134
+ "environment": str(["us"]),
135
+ "process_status": "assessment_scheduled",
136
  "recruiter": {
137
+ "email": "", # str(st.session_state["recruiter_mail"]),
138
+ "name": "", # str(st.session_state["recruiter_mail"])
139
  },
140
  "client": {
141
+ "email": "", # str(st.session_state["client_mail"]),
142
+ "name": "", # str(st.session_state["client_mail"])
143
  },
144
  "candidate": {
145
+ "email": "", # str(st.session_state["candidate_mail"]),
146
+ "name": "", # str(st.session_state["candidate_mail"])
147
  },
148
+ "interview_transcript": [],
149
  "questions": [],
150
+ "coding_tasks": [],
151
+ "transcript_summary": "",
152
  }
153
  write_assessment_db_object(db_item)
154
  else:
155
  db_item = {
156
+ "id": str(uuid.uuid4()),
157
+ "zoom_meeting_id": str(appointment_response["zoom_meeting"]["id"]),
158
+ "process_id": str(uuid.uuid4()),
159
+ "job_title": st.session_state["subject_input"],
160
+ "start_time": start_date_str,
161
+ "end_time": end_date_str,
162
+ "meeting_url": appointment_response["zoom_meeting"]["start_url"],
163
+ "environment": str(["us"]),
164
+ "process_status": "interview_scheduled",
165
  "recruiter": {
166
+ "email": "", # str(st.session_state["recruiter_mail"]),
167
+ "name": "", # str(st.session_state["recruiter_mail"])
168
  },
169
  "client": {
170
+ "email": "", # str(st.session_state["client_mail"]),
171
+ "name": "", # str(st.session_state["client_mail"])
172
  },
173
  "candidate": {
174
+ "email": "", # str(st.session_state["candidate_mail"]),
175
+ "name": "", # str(st.session_state["candidate_mail"])
176
  },
177
+ "summary_recruiter": "",
178
+ "summary_client": "",
179
+ "summary_candidate": "",
180
  }
181
  write_interview_db_object(db_item)
182
+
183
+
184
  if "appointment_response" not in st.session_state:
185
  st.session_state["appointment_response"] = None
186
  if "cosmos_db" not in st.session_state:
187
  # Cosmos DB Client erstellen
188
+ client = CosmosClient(os.environ.get("DB_CONNECTION"), os.environ.get("DB_KEY"))
189
  st.session_state["cosmos_db"] = client
190
  if "assessment_db_id" not in st.session_state:
191
  st.session_state["assessment_db_id"] = None
192
+ if "assessment_toggle" not in st.session_state:
193
+ st.session_state["assessment_toggle"] = True
194
 
195
  col1, col2 = st.columns([2, 1])
196
 
197
  col1.title("Appointment Tool")
198
+ col2.image(
199
+ "https://www.workgenius.com/wp-content/uploads/2023/03/WorkGenius_navy-1.svg"
200
+ )
201
 
202
  st.write("Please enter the date, time and duration for the appointment to be created.")
203
 
204
+ st.date_input("Date of the appointment", format="DD/MM/YYYY", key="date_input")
205
  now = datetime.now()
206
  rounded_now = now + timedelta(minutes=30 - now.minute % 30)
207
  st.time_input("Starting time of the appointment", value=rounded_now, key="time_input")
208
+ st.selectbox(
209
+ "Please select your time zone (based on UTC time)",
210
+ options=[
211
+ "+10",
212
+ "+9",
213
+ "+8",
214
+ "+7",
215
+ "+6",
216
+ "+5",
217
+ "+4",
218
+ "+3",
219
+ "+2",
220
+ "+1",
221
+ "0",
222
+ "-1",
223
+ "-2",
224
+ "-3",
225
+ "-4",
226
+ "-5",
227
+ "-6",
228
+ "-7",
229
+ "-8",
230
+ "-9",
231
+ "-10",
232
+ ],
233
+ index=10,
234
+ key="time_zone_option",
235
+ )
236
+ st.select_slider(
237
+ "Duration of the appointment in minutes",
238
+ [15, 30, 45, 60],
239
+ value=30,
240
+ key="duration_input",
241
+ )
242
  st.text_input("Enter the subject of the meeting", key="subject_input")
243
  # recruiter_mail = st.text_input("Please enter the mail of the recruiter", key="recruiter_mail")
244
  # client_mail = st.text_input("Please enter the mail of the client", key="client_mail")
245
  # candidate_mail = st.text_input("Please enter the mail of the candidate", key="candidate_mail")
246
+ # st.toggle(
247
+ # "Activate to create an assessment appointment, otherwise a candidate interview is going to be created",
248
+ # key="assessment_toggle",
249
+ # )
250
+ st.button(
251
+ "Create appointment",
252
+ key="create_button",
253
+ disabled=False if st.session_state["subject_input"] else True,
254
+ on_click=create_button_handler,
255
+ )
256
 
257
  if st.session_state["appointment_response"]:
258
  st.success("The appointment was created correctly.")
259
+ st.write(
260
+ "Interviewer link: "
261
+ + os.environ.get("BASE_API")
262
+ + "/meeting-consent?redirect="
263
+ + st.session_state["appointment_response"]["zoom_meeting"]["start_url"].replace(
264
+ "https://us06web.zoom.us/", ""
265
+ )
266
+ )
267
+ st.write(
268
+ "Interviewee link: "
269
+ + os.environ.get("BASE_API")
270
+ + "/meeting-consent?redirect="
271
+ + st.session_state["appointment_response"]["zoom_meeting"]["join_url"].replace(
272
+ "https://us06web.zoom.us/", ""
273
+ )
274
+ )
275
  if st.session_state["assessment_toggle"]:
276
+ st.write(
277
+ "Here is the link for the assessment tool: https://wg-assessment-app.azurewebsites.net/assessment/"
278
+ + st.session_state["assessment_db_id"]
279
+ )
280
+ st.write(
281
+ "Here is the link for the code upload: https://wg-assessment-app.azurewebsites.net/candidate/"
282
+ + st.session_state["assessment_db_id"]
283
+ )