Kaadan commited on
Commit
92cfefe
·
1 Parent(s): 29ada2b

increas estimated time

Browse files
backend/integrations/ai_integration/mock_ai_generator.py CHANGED
@@ -416,17 +416,40 @@ class MockAIGenerator(AIGeneratorInterface):
416
  Returns:
417
  String response from the AI containing the estimated duration
418
  """
419
- # For the mock implementation, we'll return a simple response with a number
420
- # based on the length of the prompt and keywords
421
  import random
422
-
 
 
423
  # Count the number of questions mentioned in the prompt
424
  question_count = prompt.count("Question ") # Count occurrences of "Question "
425
 
426
- # Estimate duration based on question count (3 minutes per question, with some randomness)
427
- estimated_minutes = max(5, question_count * 3 + random.randint(-2, 5))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
428
 
 
 
 
 
 
 
 
429
  # Ensure it's within reasonable bounds
430
  estimated_minutes = min(180, max(5, estimated_minutes))
431
-
432
  return f"{estimated_minutes} minutes"
 
416
  Returns:
417
  String response from the AI containing the estimated duration
418
  """
419
+ # For the mock implementation, we'll return a response with a number
420
+ # based on the length of the prompt and keywords, following the same logic as the AI service
421
  import random
422
+ import re
423
+
424
+ # Extract information from the prompt to determine duration
425
  # Count the number of questions mentioned in the prompt
426
  question_count = prompt.count("Question ") # Count occurrences of "Question "
427
 
428
+ # Extract seniority level from the prompt
429
+ seniority_match = re.search(r'- Seniority: (\w+)', prompt)
430
+ seniority = seniority_match.group(1).lower() if seniority_match else 'junior'
431
+
432
+ # Count text-based questions mentioned in the prompt
433
+ text_questions = prompt.count("(Text-based question requiring written response)")
434
+
435
+ # Calculate base duration (at least 2 minutes per question)
436
+ base_duration = question_count * 2
437
+
438
+ # Adjust based on job seniority
439
+ if seniority in ['senior', 'lead']:
440
+ base_duration = int(base_duration * 1.5) # 50% more time for senior roles
441
+ elif seniority in ['mid', 'intermediate']:
442
+ base_duration = int(base_duration * 1.2) # 20% more time for mid-level roles
443
+ # Junior/intern roles get the base time (2 min per question)
444
 
445
+ # Adjust based on question complexity (text-based questions take more time)
446
+ if text_questions > 0:
447
+ base_duration += text_questions * 2 # Additional 2 minutes per text question
448
+
449
+ # Add some randomness to simulate realistic variations
450
+ estimated_minutes = max(5, base_duration + random.randint(-1, 3))
451
+
452
  # Ensure it's within reasonable bounds
453
  estimated_minutes = min(180, max(5, estimated_minutes))
454
+
455
  return f"{estimated_minutes} minutes"
backend/services/ai_service.py CHANGED
@@ -106,15 +106,15 @@ def estimate_assessment_duration(title: str, job_info: dict, questions: List[Ass
106
  prompt = f"""
107
  Based on the following assessment details, estimate how many minutes a candidate would need to complete this assessment.
108
  Consider the complexity of the questions and the job requirements.
109
-
110
  Assessment Title: {title}
111
-
112
  Job Information:
113
  - Title: {job_info.get('title', 'N/A')}
114
  - Seniority: {job_info.get('seniority', 'N/A')}
115
  - Description: {job_info.get('description', 'N/A')}
116
  - Skill Categories: {', '.join(job_info.get('skill_categories', []))}
117
-
118
  Questions Count: {len(questions)}
119
  """
120
 
@@ -129,7 +129,11 @@ def estimate_assessment_duration(title: str, job_info: dict, questions: List[Ass
129
  if additional_note:
130
  prompt += f"\nAdditional Notes: {additional_note}"
131
 
132
- prompt += "\n\nPlease provide only a number representing the estimated duration in minutes."
 
 
 
 
133
 
134
  # Get the AI's estimation
135
  duration_estimate = ai_generator.estimate_duration(prompt)
@@ -138,12 +142,51 @@ def estimate_assessment_duration(title: str, job_info: dict, questions: List[Ass
138
  duration_match = re.search(r'\d+', duration_estimate)
139
  if duration_match:
140
  duration_minutes = int(duration_match.group())
141
- # Ensure the duration is within reasonable bounds (1-180 minutes)
142
- duration_minutes = max(1, min(180, duration_minutes))
143
- logger.info(f"Estimated duration for assessment '{title}': {duration_minutes} minutes")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
144
  return duration_minutes
145
  else:
146
  # If no number is found in the response, return a default duration based on question count
147
- default_duration = min(60, max(5, len(questions) * 3)) # 3 minutes per question, capped at 60
148
- logger.warning(f"No duration found in AI response. Using default: {default_duration} minutes")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
149
  return default_duration
 
106
  prompt = f"""
107
  Based on the following assessment details, estimate how many minutes a candidate would need to complete this assessment.
108
  Consider the complexity of the questions and the job requirements.
109
+
110
  Assessment Title: {title}
111
+
112
  Job Information:
113
  - Title: {job_info.get('title', 'N/A')}
114
  - Seniority: {job_info.get('seniority', 'N/A')}
115
  - Description: {job_info.get('description', 'N/A')}
116
  - Skill Categories: {', '.join(job_info.get('skill_categories', []))}
117
+
118
  Questions Count: {len(questions)}
119
  """
120
 
 
129
  if additional_note:
130
  prompt += f"\nAdditional Notes: {additional_note}"
131
 
132
+ prompt += """
133
+ \n\nPlease provide only a number representing the estimated duration in minutes.
134
+ Consider that each question should take at least 2 minutes to answer, with additional time for complex questions,
135
+ especially for senior roles or text-based questions requiring detailed responses.
136
+ """
137
 
138
  # Get the AI's estimation
139
  duration_estimate = ai_generator.estimate_duration(prompt)
 
142
  duration_match = re.search(r'\d+', duration_estimate)
143
  if duration_match:
144
  duration_minutes = int(duration_match.group())
145
+
146
+ # Apply our own logic to ensure minimum duration per question and adjust based on job seniority
147
+ # Calculate base duration (at least 2 minutes per question)
148
+ base_duration = len(questions) * 2
149
+
150
+ # Adjust based on job seniority
151
+ seniority = job_info.get('seniority', '').lower()
152
+ if seniority in ['senior', 'lead']:
153
+ base_duration = int(base_duration * 1.5) # 50% more time for senior roles
154
+ elif seniority in ['mid', 'intermediate']:
155
+ base_duration = int(base_duration * 1.2) # 20% more time for mid-level roles
156
+ # Junior/intern roles get the base time (2 min per question)
157
+
158
+ # Adjust based on question complexity (text-based questions take more time)
159
+ text_questions = sum(1 for q in questions if q.type == 'text_based')
160
+ if text_questions > 0:
161
+ # Add extra time for text-based questions (they typically take longer)
162
+ base_duration += text_questions * 2 # Additional 2 minutes per text question
163
+
164
+ # Take the maximum of AI estimation and our calculated minimum
165
+ duration_minutes = max(duration_minutes, base_duration)
166
+
167
+ # Ensure the duration is within reasonable bounds (5-180 minutes)
168
+ duration_minutes = max(5, min(180, duration_minutes))
169
+ logger.info(f"Estimated duration for assessment '{title}': {duration_minutes} minutes (AI: {int(duration_match.group())}, calculated min: {base_duration})")
170
  return duration_minutes
171
  else:
172
  # If no number is found in the response, return a default duration based on question count
173
+ # Calculate base duration (at least 2 minutes per question)
174
+ base_duration = len(questions) * 2
175
+
176
+ # Adjust based on job seniority
177
+ seniority = job_info.get('seniority', '').lower()
178
+ if seniority in ['senior', 'lead']:
179
+ base_duration = int(base_duration * 1.5) # 50% more time for senior roles
180
+ elif seniority in ['mid', 'intermediate']:
181
+ base_duration = int(base_duration * 1.2) # 20% more time for mid-level roles
182
+
183
+ # Adjust based on question complexity (text-based questions take more time)
184
+ text_questions = sum(1 for q in questions if q.type == 'text_based')
185
+ if text_questions > 0:
186
+ base_duration += text_questions * 2 # Additional 2 minutes per text question
187
+
188
+ # Ensure minimum duration is at least 5 minutes
189
+ default_duration = max(5, base_duration)
190
+
191
+ logger.warning(f"No duration found in AI response. Using calculated default: {default_duration} minutes")
192
  return default_duration