Skip to content

Commit

Permalink
Merge pull request #199 from wizelineacademy/final-survey-ruler-pcp
Browse files Browse the repository at this point in the history
Final survey ruler pcp
  • Loading branch information
EduardodeValle authored Jun 5, 2024
2 parents 995051e + 19f71b2 commit f36e808
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 4 deletions.
4 changes: 4 additions & 0 deletions app/(base)/profile/[id]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<main>
<ProfileBanner user={user} />
Expand Down
12 changes: 11 additions & 1 deletion db/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }),
Expand Down Expand Up @@ -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)
);
Expand All @@ -138,18 +146,20 @@ 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)
);

export const questionTypeEnum = pgEnum("type_question", [
"SPRINT_QUESTION",
"COWORKER_QUESTION",
// "COWORKER_COMMENT",
"COWORKER_COMMENT",
"FINAL_PROJECT_QUESTION",
"FINAL_PROJECT_COMMENT",
]);
Expand Down
31 changes: 28 additions & 3 deletions services/rag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
);
Expand Down Expand Up @@ -669,10 +680,14 @@ async function getQuestionsSkills(
type: string,
): Promise<QuestionSkills> {
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,
})
Expand All @@ -685,7 +700,7 @@ async function getQuestionsSkills(
),
);
} else if (type === "FINAL_PROJECT_QUESTION") {
const questions = await db
questions = await db
.select({
questionId: sprintSurveyQuestion.questionId,
})
Expand Down Expand Up @@ -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,
Expand All @@ -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)
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit f36e808

Please sign in to comment.