Skip to content
Snippets Groups Projects
Commit a701fca4 authored by Rémi PAPIN's avatar Rémi PAPIN
Browse files

Merge branch 'master' of...

parents 2f8ec68a e3de9bda
No related branches found
No related tags found
No related merge requests found
Pipeline #9969 passed
......@@ -14,7 +14,8 @@ All basics Questions are created in the quizEntity.json. We have to add :
- source => Source of the explanaition
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 explaination and the source. After this modal, he goes to the next question.
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.
### Custom Question
......@@ -25,6 +26,7 @@ At the end of every quiz, we're creating a custom question. During the creation
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.
## Mission
## Duel
......
......@@ -10,12 +10,12 @@ You should also check Cozy's official documentations for konnectors :
## Enedis Konnector
The Oauth protocol does not take place in the konnector code, therefore it is also important to take a look at the [proxy](../proxy/description.md) to fully understand all the interactions that will be told below.
The Oauth protocol does not take place in the konnector code, therefore it is also important to take a look at the [proxy](../../proxy/description.md) to fully understand all the interactions that will be told below.
All the actions performed by the stack are targetted from pre-registered paramaters, here is the list of all parameters needed by the stack to perform the Oauth protocol and allow the konnector to fetch data.
On its first launch, following the Oauth Client Connect authentification.
- The cozy stack calls the **authentification_endpoint** and start the oauth protocol, see [proxy doc](../proxy/description.md).
- The cozy stack calls the **authentification_endpoint** and start the oauth protocol, see [proxy doc](../../proxy/description.md).
- The account has now an access_token and an id_token from the oauth call
!!! info ""
......@@ -32,8 +32,70 @@ This token holds several meta datas, including the pce_id (id of user's meter) t
## Enedis API
API Url for Production : [https://gw.prd.api.enedis.fr](https://gw.prd.api.enedis.fr)
API url for Development : [https://gw.hml.api.enedis.fr](https://gw.hml.api.enedis.fr)
Enpoints :
Once you've finished the OAuth protocol and have a valid token, you can go fetch the data. Currently we use the two following endpoints in Ecolyo:
- /v4/metering_data/consumption_load_curve
- /v4/metering_data/daily_consumption
Method : **GET**
Route : **/v4/metering_data/consumption_load_curve**
Method : **GET**
Route : **/v4/metering_data/daily_consumption**
```json
"params":
{
"usage_point_id": <your-usage-point-id>,
"start": "YYYY-MM-DD",
"end": "YYYY-MM-DD",
}
```
```json
"headers":
{
"Accept": "application/json",
"Authorization": "Bearer xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
}
```
For more information about Datahub-Enedis API, checkout the [Datahub documentation](https://datahub-enedis.fr/data-connect/documentation/metering-data-v4/).
### Konnector Methods
| Method | Description |
| ----------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| start | Init Function |
| getDailyData | Retrieve data from the API. Format: `{ value: "Wh", "date": "YYYY-MM-DD" }`" |
| startLoadDataProcess | Check if history is loaded. If not, call several time the api to retrieve 1 month of history for load data. If yes only call once the api |
| launchLoadDataProcess | Launch process to handle load data |
| getLoadData | Retrieve data from the API. Format: `{ value: "W", "date": "YYYY-MM-DD hh:mm:ss" }` |
| processData | Parse data. Remove existing data from DB using hydrateAndFilter, store filtered data and return the list of filtered data |
| agregateMonthAndYearData | Agregate data from daily data to monthly and yearly data |
| agregateHourlyData | Agregate data from load data (every 30 min) to Hourly data |
| storeData | Save data in the right doctype db and prevent duplicated keys |
| formateData | Format data for DB storage and remove bad data |
| buildAgregatedData | Retrieve and remove old data for a specific doctype and return an array of agregated data |
| buildDataFromKey | Format an entry for DB storage using key and value. For year doctype: key = "YYYY". For month doctype: key = "YYYY-MM" |
| isHistoryLoaded | Function checking if the history is loaded |
| resetInProgressAggregatedData | Function handling special case.The temporary aggregated data need to be remove in order for the most recent one te be saved. Ex for com.grandlyon.enedis.year : `{ load: 76.712, year: 2020, ... }` need to be replace by `{ load: 82.212, year: 2020, ... }` after enedis data reprocess |
## Troubleshooting when asking for refresh token
When a token expires, the konnector will encounter an error when fetching user data, leading to a refresh token request.
Since refresh token requests restart the Konnector, it was decided to add the ```usage_point_id``` into the start fields when asking for a refresh token (see line 97).
!!! info "restart to refresh token"
Line 85: ```await cozyClient.fetchJSON(
'POST',
`/accounts/enedisgrandlyon/${accountId}/refresh`
)```
Line 97: ```fields.usage_point_id = usage_point_id```
Line 98: ```return start(fields, cozyParameters, false)```
In fact the usage_point_id still remains in the account collection, but on restart, the konnector loses ```this._account``` context leading to an error when searching for usage_point_id in account.
\ No newline at end of file
!!! info ""
:construction: Section under Construction :construction:
:construction: Section under Construction :construction:
This konnector fetches consumptions measures from Grdf Adict API. This is an Oauth Konnector, meaning the authentification performed to access all data is made following an Oauth2 protocol.
You can clone the project [here](https://forge.grandlyon.com/web-et-numerique/llle_project/grdf-adict-konnector).
......@@ -10,7 +10,7 @@ You should also check Cozy's official documentations for konnectors :
## Grdf Adict Konnector
The Oauth protocol does not take place in the konnector code, therefore it is also important to take a look at the [proxy](../proxy/description.md) to fully understand all the interactions that will be told below.
The Oauth protocol does not take place in the konnector code, therefore it is also important to take a look at the [proxy](../../proxy/description.md) to fully understand all the interactions that will be told below.
All the actions performed by the stack are targetted from pre-registered paramaters, here is the list of all parameters needed by the stack to perform the Oauth protocol and allow the konnector to fetch data.
......@@ -18,28 +18,27 @@ All the actions performed by the stack are targetted from pre-registered paramat
On its first launch, following the Oauth Client Connect authentification.
- The cozy stack calls the **authentification_endpoint** and start the oauth protocol, see [proxy doc](../proxy/description.md).
- The cozy stack calls the **authentification_endpoint** and start the oauth protocol, see [proxy doc](../../proxy/description.md).
- The account has now an access_token and an id_token from the oauth call
!!! info ""
id_token is only given when requesting the token endpoint in *authorization_code* grant_type.
This token holds several meta datas, including the pce_id (id of user's meter) that will be needed further to fetch user's datas.
- Konnector starts, fails to find a pce_id in database on first launch therefore decodes the id_token to store the pce_id in db (see [addData](https://docs.cozy.io/en/cozy-konnector-libs/api/#adddata_1)).
id_token is only given when requesting the token endpoint in _authorization_code_ grant_type.
This token holds several meta datas, including the pce_id (id of user's meter) that will be needed further to fetch user's datas.
- Konnector starts, fails to find a pce_id in database on first launch therefore decodes the id_token to store the pce_id in db (see [addData](https://docs.cozy.io/en/cozy-konnector-libs/api/#adddata_1)).
- Konnector restarts, this time knowing a pce_id, it fails to fetch datas because the access_token from oauth call has a reduced scope (only scoping for meta data requests).
- Konnector launches a refresh call, the proxy knows to answer it with a *client_credentials* grant_type call to grdf /access_token.
- Konnector launches a refresh call, the proxy knows to answer it with a _client_credentials_ grant_type call to grdf /access_token.
- Konnector restarts with everyting needed in database to fetch datas and store them in couchdb.
- Further jobs will not need to change scope again and will only ask for refresh tokens.
### Flow summarized
![Konnector flow](/img/flowgrdf.jpeg)
!!! info "to do"
:construction: Request PCE's frequency :construction:
Grdf owns different type of meters, some are read twice a year (every six months therefore called 6M), others are 1M or 1D
:construction: Request PCE's frequency :construction:
Grdf owns different type of meters, some are read twice a year (every six months therefore called 6M), others are 1M or 1D
## Launch on standalone
......@@ -51,9 +50,9 @@ Build the konnector with `yarn build`.
### Install on easy-cozy (development purposes)
```sudo docker cp /home/easy-cozy/fun/grdf-konnector/build/ $container_id:/tmp/grdf-oauth```
`sudo docker cp /home/easy-cozy/fun/grdf-konnector/build/ $container_id:/tmp/grdf-oauth`
```sudo docker-compose exec cozy ./cozy konnectors install grdf-oauth --domain "$alphaDomain" file:///tmp/grdf-oauth $container_id ```
`sudo docker-compose exec cozy ./cozy konnectors install grdf-oauth --domain "$alphaDomain" file:///tmp/grdf-oauth $container_id `
### Install on production
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment