Skip to content
Snippets Groups Projects
challenge.md 6.01 KiB
Newer Older
  • Learn to ignore specific revisions
  • !!! info ""
    :construction: Section under Construction :construction:
    
    This section explain all the functionnalities in the challenge part
    
    ## Quiz
    
    
    A quiz includes 4 basic questions and one custom question.
    
    Rémi PAPIN's avatar
    Rémi PAPIN committed
    ### Basic Question
    
    
    Rémi PAPIN's avatar
    Rémi PAPIN committed
    All basics Questions are created in the quizEntity.json. We have to add :  
    - questionLabel => Label of the question  
    - Answers => An array of three answers  (answerLabel, isTrue)  
    - description => Explain the question  
    - source => Source of the explanaition  
    
    Rémi PAPIN's avatar
    Rémi PAPIN committed
    
    
    This questions and answers are in random order.
    
    
    Rémi PAPIN's avatar
    Rémi PAPIN committed
    In the question page the user have to select an answer and click validate. 
    
    Then, he sees the right answer and a modal with the explanation and the source. After this modal, he goes to the next question. 
    Depends on the answer, the question result state is set either correct or incorrect.
    
    If it is a right answer, the quiz result is incremented by one.
    
    Rémi PAPIN's avatar
    Rémi PAPIN committed
    
    ### Custom Question
    
    
    Rémi PAPIN's avatar
    Rémi PAPIN committed
    At the end of every quiz, we're creating a custom question. During the creation of the quiz, we have to add :  
    - type => data or calculation  
    - period => the period selected for the calcul  
    - timestep => the interval of the calcul (Day, Month, Year)  
    
    Rémi PAPIN's avatar
    Rémi PAPIN committed
    We get all this information to determine the custom question (All information are in the quizEntity.json). Depending of the question type, the system calcul a maximum or an average data. 
    Then, he generate two randoms answers following the right answer. 
    
    
    A user can stop during a quiz and picks up where he left off. To define where the user left off, we have to check if at least one of the question result status is unlocked.
    
    
    Once the custom question is answered, the quiz state is set to done. Then, the user sees his result and his earned stars. He can also retry or go back to the challenge page.
    
    ## Mission
    
    ## Duel
    
    
    Guilhem CARRON's avatar
    Guilhem CARRON committed
    ### On launch
    
    
      In order to find a valid reference period we search for a period which is defined by the duel duration.  
      We check the most recent period first if it's complete and then we go farther and farther in the time if the ones before got missing values.  
    
    Rémi PAPIN's avatar
    Rémi PAPIN committed
      We also define a threshold for a maximum old period (6 months for the moment determined in the code ==> hardcoding).
      If the thresold is reached and no valid period was found, we alert the user that he can't launch the duel and have to wait before he can retry this process.
    
    Guilhem CARRON's avatar
    Guilhem CARRON committed
    ### On going
    
    Guilhem CARRON's avatar
    Guilhem CARRON committed
    Every time the user go into the duel mode, we are checking if the duel is finished.
    if (actualDate - startDate) > duelDuration, the duel is done.
    
    Guilhem CARRON's avatar
    Guilhem CARRON committed
    ### On finish
    
    Guilhem CARRON's avatar
    Guilhem CARRON committed
    Once the state of the duel is set to DONE, we save the user result and determine if he wins (userComsumption < threshold of the reference period) or if he loses. Then the user sees his earned badge.
    
    Guilhem CARRON's avatar
    Guilhem CARRON committed
    ## Challenge data managment
    
    Guilhem CARRON's avatar
    Guilhem CARRON committed
    We handle data storage according to the following process :
    
    Guilhem CARRON's avatar
    Guilhem CARRON committed
    The folder /db contains all the JSON entities that are directly stored in the couchDB during the initialization process that is executed in the splash screen. They are stored under their related doctype.
    
    ## Initialization and Updating
    
    During the initialization process, we store a hash for each dataEntity that is likely to be changed or updated. The hash is stored in the userProfile.
    
    ```json
    [
      {
        "ecogestureHash": "",
        "challengeHash": "",
        "duelHash": "",
        "isFirstConnection": true,
        "haveSeenFavoriteModal": false,
        "haveSeenOldFluidModal": false,
        "haveSeenLastReport": true,
        "sendReportNotification": false,
        "monthlyReportDate": "0000-01-01T00:00:00.000Z"
      }
    ]
    ```
    
    This way, once the initialization is launched, we compare the hash we have in the current userProfile with the one generated from the entity located in /db folder, and if they are different we update the couchDB with the new data.
    
    ### dataEntity vs userData
    
    In the project, you'll see two versions for the same data. The dataEntity (quizEntity, challengeEntity, ...) is the data stored in the db folder and in the couchDB. These data are only edited in the couchDB when we update a challenge/quiz/duel or add a new one.
    
    The userData (userChallenge, userQuiz...) is created from the entity and extended with user's data, such as his progress, his consumption data, goals, fails etc.
    
    Using this 2 structures allows us to keep user's datas when we'll update the application, by editing just the entities.
    
    ## Challenges
    
    We can find the file challengeEntity.json in the /db folder. This file contains an array of challenges, and each of them includes relationships to duels, quiz, missions and actions.
    
    ### Relationships
    
    Relationships is a functionality made by cozy, they are built with the name of the relation, containing a "data" object, itself containing the id of the related item and its doctype "\_type". Using this allows us to reduce the size of the stored items and increase readability.
    
    You can see more on [cozy documentation](https://docs.cozy.io/en/cozy-doctypes/docs/io.cozy.apps.suggestions/#relationships).
    
    ```json
    "relationships": {
          "quiz": {
            "data": { "_id": "QUIZ001", "_type": "com.grandlyon.ecolyo.quiz" }
          },
          "duel": {
            "data": { "_id": "DUEL001", "_type": "com.grandlyon.ecolyo.duel" }
          }
        }
    ```
    
    ### UserData creation
    
    Once a user launch a challenge in the Ecolyo app, we create a userChallenge and store it in the couchDB under the doctype '**com.grandlyon.ecolyo.userchallenge'.** During this process, the objects related to the challenge (quiz, duel, mission, action) will be be converted to an user version which contains informations about the user progress, the fluids connected and so on. So we have now a userChallenge that contains a userQuiz, a userDuel, etc. instead of relations.
    
    To illustrate this, let's show the conversion of quizEntity to userQuiz :
    
    ```jsx
    DuelEntity {
      id: string
      title: string
      description: string
      duration: Duration
    }
    ```
    
    Becomes :
    
    ```jsx
    UserQuiz {
      id: string
      title: string
      description: string
    	duration: Duration
      threshold: number
      state: UserDuelState
      startDate: string | null
      fluidTypes: FluidType[]
      userConsumption: number
    }
    ```
    
    ### Data managment schema
    
    ![Data Scheme](/img/challengeFlow.png)