From 91b39fd2ae827b925f1946c617c00a4333bbbeb8 Mon Sep 17 00:00:00 2001 From: Eduardo de Valle Date: Wed, 5 Jun 2024 01:25:15 -0600 Subject: [PATCH 1/5] final sprint survey added to pipTask and userResource --- db/schema.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/db/schema.ts b/db/schema.ts index 001e0a4..2b4bce1 100644 --- a/db/schema.ts +++ b/db/schema.ts @@ -87,6 +87,7 @@ export const taskStatusEnum = pgEnum("status", [ export const pipTask = pgTable("pip_task", { id: serial("id").primaryKey(), sprintSurveyId: integer("sprint_survey_id").references(() => sprintSurvey.id), + finalSurveyId: integer("final_survey_id").references(() => finalSurvey.id), userId: uuid("user_id").references(() => user.id, { onDelete: "cascade" }), title: varchar("title", { length: 64 }), description: varchar("description", { length: 256 }), @@ -121,6 +122,7 @@ export const userResource = pgTable( sprintSurveyId: integer("sprint_survey_id").references( () => sprintSurvey.id, ), + finalSurveyId: integer("final_survey_id").references(() => finalSurvey.id), }, // composite primary key on (userId, resourceId) ); @@ -142,6 +144,7 @@ export const rulerSurveyAnswers = pgTable( emotionId: integer("emotion_id").references(() => rulerEmotion.id), answeredAt: date("answered_at", { mode: "date" }), comment: text("comment"), + processed: boolean("processed").default(false), }, // composite primary key on (userId, rulerSurveyId) ); From 897a7e06416400f610e47f2007da9d854a245644 Mon Sep 17 00:00:00 2001 From: Eduardo de Valle Date: Wed, 5 Jun 2024 01:59:40 -0600 Subject: [PATCH 2/5] bug fixed in the getQuestionSkills function --- app/(base)/profile/[id]/page.tsx | 4 ++++ db/schema.ts | 2 +- services/rag.ts | 23 ++++++++++++++++++++--- 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/app/(base)/profile/[id]/page.tsx b/app/(base)/profile/[id]/page.tsx index d29fc2b..26a5ed1 100644 --- a/app/(base)/profile/[id]/page.tsx +++ b/app/(base)/profile/[id]/page.tsx @@ -6,10 +6,14 @@ import CoWorkersCarousel from "@/components/CoWorkersCarousel"; import ProjectsCarousel from "@/components/ProjectsCarousel"; import ProfileTraits from "@/components/Profile/ProfileTraits"; +import { feedbackAnalysis } from "@/services/rag"; + const Profile: React.FC<{ params: { id: string } }> = async ({ params }) => { const user = await getUserInfoById(params.id); const traits = await getUserSkillsById(params.id); + feedbackAnalysis(53); + return (
diff --git a/db/schema.ts b/db/schema.ts index 2b4bce1..0b4678a 100644 --- a/db/schema.ts +++ b/db/schema.ts @@ -152,7 +152,7 @@ export const rulerSurveyAnswers = pgTable( export const questionTypeEnum = pgEnum("type_question", [ "SPRINT_QUESTION", "COWORKER_QUESTION", - // "COWORKER_COMMENT", + "COWORKER_COMMENT", "FINAL_PROJECT_QUESTION", "FINAL_PROJECT_COMMENT", ]); diff --git a/services/rag.ts b/services/rag.ts index 326c3fa..7c49425 100644 --- a/services/rag.ts +++ b/services/rag.ts @@ -251,6 +251,10 @@ async function processCoworkersOpenFeedback( } } + console.log("Positive comments: ", commentClassifications.positive); + console.log("Negative comments: ", commentClassifications.negative); + console.log("Biased comments: ", commentClassifications.biased); + // ==================== RAG AND WEAKNESSES ANALYSIS ==================== // add the recommended resources of the user @@ -637,6 +641,9 @@ async function getFeedbackClassifications( } } else { // add the negative skills of the question + console.log("Feedback: ", feedback[0]); + console.log("question Skills: ", questionsSkills[feedback[0]]); + console.log("questions: ", questionsSkills); const questionNegativeSkills = questionsSkills[feedback[0]].map( (skillId) => skillId as number, ); @@ -669,10 +676,10 @@ async function getQuestionsSkills( type: string, ): Promise { const questionsSkills: QuestionSkills = {}; - const questions: any[] = []; + let questions: any[] = []; if (type === "COWORKER_QUESTION") { - const questions = await db + questions = await db .select({ questionId: sprintSurveyQuestion.questionId, }) @@ -685,7 +692,7 @@ async function getQuestionsSkills( ), ); } else if (type === "FINAL_PROJECT_QUESTION") { - const questions = await db + questions = await db .select({ questionId: sprintSurveyQuestion.questionId, }) @@ -951,6 +958,10 @@ export async function feedbackAnalysis(sprintSurveyId: number) { // analyze survey only if it has not been processed if (notProcessedSurvey) { + console.log("========================================="); + console.log("START OF SPRINT ANALYSIS"); + console.log("========================================="); + const uniqueProjectUsers = await db .selectDistinct({ userId: projectMember.userId, @@ -972,8 +983,11 @@ export async function feedbackAnalysis(sprintSurveyId: number) { "COWORKER_QUESTION", ); + console.log("=====================, questionSkills: ", questionsSkills); + // iterate through each unique user of the project and read the feedback received for (const userId of Object.keys(orderedFeedback)) { + console.log(userId); const userTasksCount = await db .select({ count: count() }) .from(pipTask) @@ -1016,6 +1030,9 @@ export async function feedbackAnalysis(sprintSurveyId: number) { .set({ processed: true }) .where(eq(sprintSurvey.id, sprintSurveyId)); } + console.log("========================================="); + console.log("END OF SPRINT ANALYSIS"); + console.log("========================================="); } export async function projectAnalysis(finalSurveyId: number) { From 2502ff937d5155865674108f42f5ecc4e423bb6e Mon Sep 17 00:00:00 2001 From: Eduardo de Valle Date: Wed, 5 Jun 2024 09:32:32 -0600 Subject: [PATCH 3/5] id added to the rulerSurveyAnswer table --- db/schema.ts | 1 + services/rag.ts | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/db/schema.ts b/db/schema.ts index 0b4678a..8bde899 100644 --- a/db/schema.ts +++ b/db/schema.ts @@ -140,6 +140,7 @@ export const rulerEmotion = pgTable("ruler_emotion", { export const rulerSurveyAnswers = pgTable( "ruler_survey_answers", { + id: serial("id").primaryKey(), userId: uuid("user_id").references(() => user.id, { onDelete: "cascade" }), emotionId: integer("emotion_id").references(() => rulerEmotion.id), answeredAt: date("answered_at", { mode: "date" }), diff --git a/services/rag.ts b/services/rag.ts index 7c49425..a18bfe7 100644 --- a/services/rag.ts +++ b/services/rag.ts @@ -189,6 +189,10 @@ async function processCoworkersOpenFeedback( joinedFeedbackComments = joinedFeedbackComments.replaceAll("sesgado:", ""); joinedFeedbackComments = joinedFeedbackComments.replaceAll(" ", " "); + console.log("==========================================="); + console.log("COMMENTS PROCESSING"); + console.log("==========================================="); + const openai = new OpenAI({ apiKey: process.env.OPENAI_KEY, }); From ef769cd4c23ff7dccd6d203626e37087a2c66321 Mon Sep 17 00:00:00 2001 From: Eduardo de Valle Date: Wed, 5 Jun 2024 10:10:03 -0600 Subject: [PATCH 4/5] ruler survey id implemented in pipTask and userResource --- db/schema.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/db/schema.ts b/db/schema.ts index 8bde899..dc0f7d3 100644 --- a/db/schema.ts +++ b/db/schema.ts @@ -86,6 +86,9 @@ export const taskStatusEnum = pgEnum("status", [ export const pipTask = pgTable("pip_task", { id: serial("id").primaryKey(), + rulerSurveyId: integer("ruler_survey_id").references( + () => rulerSurveyAnswers.id, + ), sprintSurveyId: integer("sprint_survey_id").references(() => sprintSurvey.id), finalSurveyId: integer("final_survey_id").references(() => finalSurvey.id), userId: uuid("user_id").references(() => user.id, { onDelete: "cascade" }), @@ -119,6 +122,9 @@ export const userResource = pgTable( resourceId: serial("resource_id").references(() => pipResource.id, { onDelete: "cascade", }), + rulerSurveyId: integer("ruler_survey_id").references( + () => rulerSurveyAnswers.id, + ), sprintSurveyId: integer("sprint_survey_id").references( () => sprintSurvey.id, ), @@ -153,7 +159,7 @@ export const rulerSurveyAnswers = pgTable( export const questionTypeEnum = pgEnum("type_question", [ "SPRINT_QUESTION", "COWORKER_QUESTION", - "COWORKER_COMMENT", + // "COWORKER_COMMENT", "FINAL_PROJECT_QUESTION", "FINAL_PROJECT_COMMENT", ]); From 19f71b2075723b2c64401cda2e87be50ee3bb4cc Mon Sep 17 00:00:00 2001 From: Eduardo de Valle Date: Wed, 5 Jun 2024 10:28:35 -0600 Subject: [PATCH 5/5] ESLint issues fixed --- db/schema.ts | 2 +- services/rag.ts | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/db/schema.ts b/db/schema.ts index dc0f7d3..d1b3f64 100644 --- a/db/schema.ts +++ b/db/schema.ts @@ -159,7 +159,7 @@ export const rulerSurveyAnswers = pgTable( export const questionTypeEnum = pgEnum("type_question", [ "SPRINT_QUESTION", "COWORKER_QUESTION", - // "COWORKER_COMMENT", + "COWORKER_COMMENT", "FINAL_PROJECT_QUESTION", "FINAL_PROJECT_COMMENT", ]); diff --git a/services/rag.ts b/services/rag.ts index a18bfe7..4e0c0b4 100644 --- a/services/rag.ts +++ b/services/rag.ts @@ -680,7 +680,11 @@ async function getQuestionsSkills( type: string, ): Promise { const questionsSkills: QuestionSkills = {}; - let questions: any[] = []; + type Question = { + questionId: number | null; + }; + + let questions: Question[] = []; if (type === "COWORKER_QUESTION") { questions = await db