Skip to content
Snippets Groups Projects
challenge.md 12.88 KiB

This section explain all the functionalities in the challenge part

Quiz

A quiz includes 4 basic questions and one custom question.

Process

Questions and answers are generated in random order.

At the begining of the quiz, the user have to select an answer and click validate.

Then, he sees the right answer and a modal with the explanation. After this modal, he goes to the next question.

Depending on the answer, the question result state is set either to correct or incorrect. If it is a right answer, the quiz result is incremented by one.

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.

Basic Question

All basics Questions are created in the quizEntity.json. We have to add :

Field Description
questionLabel Label of the question
answers Array of 3 answers (answerLabel, isTrue)
description Explains the question
source Source of the explanation

Custom Question

At the end of every quiz, we're creating a custom question. Here are the fields used to create a custom question

Field Type Description
type CustomQuestionType Type of custom qusetion: DATE or MAXLOAD or AVERAGE.
timeStep TimeStep Time step of the result value (DAY / WEEK / MONTH / YEAR). For MAXLOAD or AVERAGE type, it represents daily / weekly / monthly / yearly average.
interval TimeStep Interval in which the data will be searched (DAY / WEEK / MONTH / YEAR)
period CustomPeriod Case day / month / year:
Use to define a specific period for the interval { day? / month? / year? }.
Case weekday:
Only usable with AVERAGE type and DAY timestep: Allow to specify a weekday on which average is made. If used with another type, period will not be taken into account.
If not assigned the period will be the last interval (example: last week)
singleFluid boolean Indicate if all connected fluid should be taken into account.
If set to true only the first connected fluid will be taken into account in this order: electricity, gas, water. #unit and #fluid in the question label will be replace by the unit and the name of the fluid
result UserQuizState Indicate the state of the custom question (UNLOCKED, CORRECT, UNCORRECT)

Calculation of custom question is done by combination of all parameters:

Type DATE

  • If period is empty.

    Retrieve the date of day/month/year (define by timeStep) from the last week, month, year (define by interval), if there is no data in this interval, then it will go back to a previous interval, up to a maximum of 6 months

example: What day did I consumme the most on the last week ?
type = CustomQuestionType.DATA
timeStep = TimeStep.DAY
interval = TimeStep.WEEK
period = {}
singleFluid = false
example: What day did I consumme the most #fluid in #unit on the last week ?
type = CustomQuestionType.DATA
timeStep = TimeStep.DAY
interval = TimeStep.WEEK
period = {}
singleFluid = true
  • If period is not empty

    Retrieve the date of day/month/year (define by timeStep) from a week, month, year (define by interval) of period

example: What month did I consumme the most on year 2020 ?
type = CustomQuestionType.DATA
timeStep = TimeStep.MONTH
interval = TimeStep.YEAR
period = { year: 2020 }
singleFluid = false

Type MAXLOAD

  • If period is empty

Retrieve the maxload value of day/month/year (define by timeStep) from the last week, month, year (define by interval).

example: Which is your daily max consumption on the last week ?
type = CustomQuestionType.MAXLOAD
timeStep = TimeStep.DAY
interval = TimeStep.WEEK
period = {}
singleFluid = false
  • If period is not empty

Retrieve the maxload value of day/month/year (define by timeStep) from a week, month, year (define by interval) of period

example: Which is your daily max consumption on january 2020 ?
type = CustomQuestionType.MAXLOAD
timeStep = TimeStep.DAY
interval = TimeStep.MONTH
period = { month: 1, year: 2020 }
singleFluid = false

Type AVERAGE

  • If period is empty

Retrieve the average of day/month/year (define by timeStep) from the last week, month, year (define by interval).

example: Which is your daily average consumption on last week ?
type = CustomQuestionType.AVERAGE
timeStep = TimeStep.DAY
interval = TimeStep.WEEK
period = {}
singleFluid = false
  • If period is not empty

Retrieve the average of day/month/year (define by timeStep) from a week, month, year (define by interval) of period

example: Which is your daily average consumption on january 2020 ?
type = CustomQuestionType.AVERAGE
timeStep = TimeStep.DAY
interval = TimeStep.MONTH
period = { month: 1, year: 2020 }
singleFluid = false
  • If period is weekday

Retrieve the average of the weekday from a week, month, year (define by interval).

example: Which is your daily average consumption on wednesdays of last month?
type = CustomQuestionType.AVERAGE
timeStep = TimeStep.DAY
interval = TimeStep.MONTH
period = { weekday: 3 }
singleFluid = false