Skip to content

Commit

Permalink
chat session id and session id exported
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronshiel committed Sep 26, 2023
1 parent ef8940d commit ffb1ee4
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 30 deletions.
66 changes: 36 additions & 30 deletions client/src/lrs-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ The full terms of this copyright and license should always be found in the root
*/
import { Statement, Activity } from "@xapi/xapi";
import { UserQuestionGQL } from "lrs-api";
import { report } from "process";
// eslint-disable-next-line @typescript-eslint/no-var-requires
const dfd = require("danfojs");

Expand Down Expand Up @@ -459,6 +458,7 @@ export interface Report {
date: Array<string>;
userId: Array<string>;
chatSessionId: Array<string>;
sessionId: Array<string>;
dataSource: Array<string>;
topics: Array<string[]>;
}
Expand Down Expand Up @@ -514,6 +514,7 @@ export const reportToCsv = (reportEntries: ReportEntry[]): any => {
dataSource: effectiveEntries.map((entry) => entry.dataSource),
topics: effectiveEntries.map((entry) => entry.topics),
chatSessionId: effectiveEntries.map((entry) => entry.chatSessionId),
sessionId: effectiveEntries.map((entry) => entry.sessionId),
};
const dfReport = new dfd.DataFrame(report);

Expand All @@ -540,33 +541,38 @@ export const userQuestionsToCSV = (userQuestions: UserQuestionGQL[]): void => {
userQuestions.sort((a, b) =>
new Date(a.createdAt) > new Date(b.createdAt) ? -1 : 1
);

const report: UserQuestionReport = {
mentorId: userQuestions.map((uq) => uq.mentor._id),
mentorName: userQuestions.map((uq) => `"${uq.mentor.name}"`),
date: userQuestions.map(
(uq) =>
`"${new Date(uq.createdAt).toLocaleString("en-US", {
timeZone: "America/Los_Angeles",
})}"`
),
question: userQuestions.map((uq) => `"${uq.question}"`),
classifierQuestionMatch: userQuestions.map(
(uq) => `"${uq.classifierAnswer.question.question}"`
),
confidence: userQuestions.map((uq) => uq.confidence),
feedback: userQuestions.map((uq) => uq.feedback),
graderQuestionMatch: userQuestions.map(
(uq) => ` "${uq.graderAnswer ? uq.graderAnswer.question.question : "-"}"`
),
chatSessionId: userQuestions.map((uq) => uq.chatSessionId || ""),
};

const dfReport = new dfd.DataFrame(report);

dfd.toCSV(dfReport, {
fileName: `user-questions-report`,
download: true,
header: true,
});
try {
const report: UserQuestionReport = {
mentorId: userQuestions.map((uq) => uq.mentor?._id || ""),
mentorName: userQuestions.map((uq) => `"${uq.mentor?.name || ""}"`),
date: userQuestions.map(
(uq) =>
`"${new Date(uq.createdAt).toLocaleString("en-US", {
timeZone: "America/Los_Angeles",
})}"`
),
question: userQuestions.map((uq) => `"${uq.question}"`),
classifierQuestionMatch: userQuestions.map((uq) =>
uq.classifierAnswer
? `"${uq.classifierAnswer.question.question.trim()}"`
: "-"
),
confidence: userQuestions.map((uq) => uq.confidence),
feedback: userQuestions.map((uq) => uq.feedback),
graderQuestionMatch: userQuestions.map((uq) =>
uq.graderAnswer ? `"${uq.graderAnswer.question.question.trim()}"` : "-"
),
chatSessionId: userQuestions.map((uq) => uq.chatSessionId || ""),
};

const dfReport = new dfd.DataFrame(report);

dfd.toCSV(dfReport, {
fileName: `user-questions-report`,
download: true,
header: true,
});
} catch (err) {
console.log(err);
}
};
2 changes: 2 additions & 0 deletions client/src/pages/lrsreports.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,11 @@ function LRSReportsPage(): JSX.Element {
}
const userQuestions = await fetchUserQuestions(startDate, endDate);
if (!userQuestions) {
console.log("no user questions");
return;
}
if (!userQuestions.length) {
console.log("no user questions");
setNoReportAlert(true);
return;
}
Expand Down

0 comments on commit ffb1ee4

Please sign in to comment.