Skip to content

Commit 749faf8

Browse files
committed
Merge branch 'feature/change-employee-status' into dev
2 parents 96dc85c + 9b9855a commit 749faf8

4 files changed

Lines changed: 238 additions & 217 deletions

File tree

AI/src/api/roster.py

Lines changed: 30 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,6 @@ def get_recommendations(request: SkillRequest):
173173
# INIT: user request parameters
174174
project_description = request.description
175175
required_positions = request.positions
176-
position_names = [p.name for p in required_positions]
177176
required_skills = request.skills
178177

179178
# MAIN
@@ -189,67 +188,49 @@ def get_recommendations(request: SkillRequest):
189188
skill_ids = user.get("skills", [])
190189
skills = list(database.get_collection("skills").find({"_id": {"$in": skill_ids}}, {"name": 1}))
191190
user_skills = [clean_skills_name(skill["name"]) for skill in skills]
191+
required_skills = [clean_skills_name(skill) for skill in required_skills]
192192

193193
matched_count = len(set(required_skills) & set(user_skills))
194194
total = len(set(required_skills))
195+
print("Yang cocok: ", matched_count)
196+
print("Butuh brp: ", total)
195197
matched_count_score = matched_count / total
198+
print("Required skills: ", required_skills)
199+
print("User skills: ", user_skills)
196200
logs["skill_matching_time"] += time.time() - start_time
197201

198202
# 2. workload counter
199203
start_time = time.time()
200204
project_pipeline = [
201-
{"$match": {"userId": user_id}}, # filter by user
202-
{
203-
"$lookup": {
204-
"from": "projects", # collection to join
205-
"localField": "projectId", # field in projectassignments
206-
"foreignField": "_id", # field in projects
207-
"as": "project" # output array field name
208-
}
209-
},
210-
{
211-
"$lookup": {
212-
"from": "positions",
213-
"localField": "user.positionId",
205+
{"$match": {"userId": user_id}},
206+
{"$lookup": {
207+
"from": "projects",
208+
"localField": "projectId",
214209
"foreignField": "_id",
215-
"as": "position"
216-
}
217-
},
218-
{"$unwind": "$position"},
219-
220-
# lookup the project
221-
{
222-
"$lookup": {
223-
"from": "projects",
224-
"localField": "projectId",
225-
"foreignField": "_id",
226-
"as": "project"
227-
}
228-
},
210+
"as": "project"
211+
}},
229212
{"$unwind": "$project"},
230-
231-
# project active + position name in required list
232-
{
233-
"$match": {
234-
"project.status": "active",
235-
"position.name": {"$in": position_names}
236-
}
237-
},
238-
239-
{
240-
"$project": {
241-
"_id": 0,
242-
"project": 1,
243-
"user._id": 1,
244-
"user.name": 1,
245-
"position.name": 1
246-
}
247-
}
213+
{"$match": {"project.status": "active"}},
214+
{"$group": {"_id": "$project._id"}},
215+
{"$count": "total"}
248216
]
249217

250-
project_assignments = list(database.get_collection("projectassignments").aggregate(project_pipeline))
251-
project_count = len(project_assignments)
252-
project_count_score = 1.0 if project_count == 0 else 1.0 / project_count
218+
result = list(database.get_collection("projectassignments").aggregate(project_pipeline))
219+
project_count = result[0]["total"] if result else 0
220+
221+
# project_assignments = list(database.get_collection("projectassignments").aggregate(project_pipeline))
222+
print(result)
223+
# project_count = len(project_assignments)
224+
print("Proyek gweh: ", project_count)
225+
226+
if project_count == 0:
227+
project_count_score = 1.0
228+
elif project_count >= 5:
229+
project_count_score = 0.0
230+
else:
231+
# menurun 0.2 tiap project
232+
project_count_score = 1.0 - (project_count * 0.2)
233+
#project_count_score = 1.0 if project_count == 0 else 1.0 / project_count
253234
logs["workload_calculation_time"] += time.time() - start_time
254235

255236
# 3. Embedding vector

0 commit comments

Comments
 (0)