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 001e0a4..d1b3f64 100644 --- a/db/schema.ts +++ b/db/schema.ts @@ -86,7 +86,11 @@ 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" }), title: varchar("title", { length: 64 }), description: varchar("description", { length: 256 }), @@ -118,9 +122,13 @@ 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, ), + finalSurveyId: integer("final_survey_id").references(() => finalSurvey.id), }, // composite primary key on (userId, resourceId) ); @@ -138,10 +146,12 @@ 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" }), comment: text("comment"), + processed: boolean("processed").default(false), }, // composite primary key on (userId, rulerSurveyId) ); @@ -149,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 326c3fa..4e0c0b4 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, }); @@ -251,6 +255,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 +645,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 +680,14 @@ async function getQuestionsSkills( type: string, ): Promise { const questionsSkills: QuestionSkills = {}; - const questions: any[] = []; + type Question = { + questionId: number | null; + }; + + let questions: Question[] = []; if (type === "COWORKER_QUESTION") { - const questions = await db + questions = await db .select({ questionId: sprintSurveyQuestion.questionId, }) @@ -685,7 +700,7 @@ async function getQuestionsSkills( ), ); } else if (type === "FINAL_PROJECT_QUESTION") { - const questions = await db + questions = await db .select({ questionId: sprintSurveyQuestion.questionId, }) @@ -951,6 +966,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 +991,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 +1038,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) {