Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Backend] Update IAnalytics Model and All Relevant Routes #107

Open
samarth52 opened this issue Mar 27, 2024 · 0 comments
Open

[Backend] Update IAnalytics Model and All Relevant Routes #107

samarth52 opened this issue Mar 27, 2024 · 0 comments
Assignees

Comments

@samarth52
Copy link
Contributor

Context

With the change in the user flow of the app, we want a way to track if a user has completed a session on that day. Further, we now want to keep track of the past two sessions' metrics to be displayed in the app.

Requirements

The new model is as follows. I have listed the changes in parentheses beside the change:

  lastSessionsMetrics: {     (lastSessionMetrics -> lastSessionsMetrics)
    date: Date;
    math: {
      attempted: boolean;    (new)
      questionsAttempted: number;
      questionsCorrect: number;
      finalDifficultyScore: number;
      timePerQuestion: number;
    };
    trivia: {
      attempted: boolean;    (new)
      questionsAttempted: number;
      questionsCorrect: number;
      timePerQuestion: number;
    };
    reading: {
      attempted: boolean; // should be true even if the user attempts the section but skips without completing    (new)
      passagesRead: number;
      timePerPassage: number;
      wordsPerMinute: number;
      skipped: boolean;      (removed "questionsAnswered" and added this)
    };
    writing: {
      attempted: boolean; // should be true even if the user attempts the section but skips without completing    (new)
      questionsAnswered: number;
      timePerQuestion: number;
      skipped: boolean;      (new)
    };
  }[];    (now an array)

Update the IAnalytics type and Analytics model to reflect the above (remove all the parentheses while copying but keep the comment).

Subsequently, go through all the routes and MongoDB action functions that use or modify the analytics record, and make the appropriate changes to include and update these new metrics. Specifically, ensure the usage/modification of lastSessionsMetrics, skipped, and attempted are updated.

Now that lastSessionsMetrics is an array, we want it to keep track of only the last two sessions (the most recent one being at index 0).
The current user flow is that the user can complete a game only once per day. The user need not complete all games in sequence or at the same time. Thus, we should see if lastSessionsMetrics[0].date corresponds to the current day. If not, then move record 0 to record 1 and empty out record 0. You will need to do this check when the user logs in (/api/patient/auth/login), and in the /api/patient/analytics/record-* routes.

Further, delete /api/patient/analytics/record-session-complete. Instead do its job in the /api/patient/analytics/record-* routes if lastSessionsMetrics[0].*.attempted = true (* = all games).

Some specific changes to be made:

  1. In getAggregatedAnalytics function: the return value of lastSession.completed for Reading and Writing should be !res.lastSessionsMetrics[0].reading.skipped and !res.lastSessionsMetrics[0].writing.skipped resp.

  2. In /api/patient/auth/login, return:

{
    user: newUser,
    gameDetails: {
        active: analyticsRecord.active
        streak: analyticsRecord.streak,
        lastSessionsMetrics: analyticsRecord.lastSessionsMetrics,
    },
};
  1. In the modifyMath, modifyReading, modifyWriting, and modifyTrivia functions, ensure that the attempted (in all) and skipped (in reading and writing) fields are updated in MongoDB.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants