diff --git a/docs/ecolyo/functionalities/dacc.md b/docs/ecolyo/functionalities/dacc.md index 414194d81b01a99421e6c0a476907fb494d37567..e1a9b259bd983a6334d537625e7a4ec69944b474 100644 --- a/docs/ecolyo/functionalities/dacc.md +++ b/docs/ecolyo/functionalities/dacc.md @@ -14,6 +14,8 @@ On the developpement env, the 'cozy env' refers to our 'Alpha' VM. There is a service named `aggregatorUsageEvent`, running on a daily basis, sending pre-processed data to cozy. This service is responsible for parsing traced events store in database and send them to cozy. +The service is configured to run every night at **01:00AM**. + ## Usage events This section explains how the application is tracking usage events. Here are the main step: @@ -56,55 +58,154 @@ This section explains how the application is tracking usage events. Here are the | CGU | 'legalNotice' | Click sur la card de Legal Notice | | Autres | 'consumption' 'challenges' 'ecogestures' 'analysis' 'options' | Click dans la navbar | -## Functionnalities +## Indicators + +!!! warning "note" + All indicators are only sent if a user validate first version of CGU, the one containing dacc validation +### Monthly Indicators -The service will retrieve all new events by filter on the _aggregated_ flag to **false** and the event date before than today. -For each aggregator type we will defined the right calculation to apply to create the appropriate indicator: +All monthly indicators call can be found after this comment on the code +```js +// Monthly events +``` -- calculation of the session time indicator based on ConnectionEvent -- calculation of the konnectors connected per day based on the fluidStatus -- calculates if a user launched a duel just after earned 15 stars -- calculation of the period between 2 different challenges based on the ChallengeLaunchEvent -- calculation of the period between the first connection and the first challenge based on ChallengeLaunchEvent and ConnectionEvent -- calculation of an indicator based on a single event -- calculation of an aggregated indicator to sum an event type per days. +| Indicator | Trigger | value | +| --- | --- | --- | +| consumption-variation-monthly | Tous les mois si l'utilisateur a été connecté au moins une fois dans le mois | La variation de consomation par type de fluide. La paramètres différents sont le type de profile ainsi ue le nombre de mois d'anciennetée | +| summary-subscription-monthly | Tous les mois si un utilisateur a souscrit a la newsletter ou c'est désabonné | 1 si l'utilsteur est inscrit sinon 0 | +| fluid-data-granularity-monthly | Tous les mois sans condition | 1 si l'utilisateur possède de la donnée a la demi heure sur le mois. Sinon 0 | +| connection-count-monthly | Tous les mois si il y a eu au moins une connexion | Le nombre de jour unique de connexion | +| profile-count-monthly | Tous les mois si le profil a été complété au moins une fois | Le nombre de fois ou le profile a été complété | -Once the indicators is calculated we will: -1. post the indicator to the remote doctype -2. push the event used to calculate the indicator to a array, which will be used to identify all events taken into account during the process. +### Daily Indicators -At the end of the service, the service will change the _aggregated_ flag to **true** for all events present in the array. +The daily process get all events of previous day and process them in the following indicators -More technical information are available [here](/ecolyo/services/aggregator_usage_events.md) +| Indicator | Trigger | value | +| --- | --- | --- | +| connection-count-daily | Tous les jours | Nombre de connexion. Celle-ci sont catégorisé par type (mobile ou desktop) | +| konnector-event-daily | Tous les jours | Nombre d'essai. Ils sont catégorisé par type de connecteur, refresh/success et le status (error ou success) | +| konnector-connected-daily | Tous les jours | La valeur est 1. Les valeurs sont catégorisées par type de fluide (electricity / electricity:water ...) | +| navigation-count-daily | Tous les jours | nombre de page visualisé par type de page | +| challenge-launch-daily | Tous les jours | Nombre de défis lancés lors d'un challenge | +| session-duration | Tous les jours | Durée de la session en secondes | +| navigation-action-daily | Tous les jours | Nombre d'action sur une page donnée. Exemple sur la consomation on trace les changements de pas de temps sur chaque graph. | +| event-duration | Tous les jours | Durée entre deux événements: +1ere session et premier challenge / début de challenge et fin de challenge / début d'exploration et fin d'exploration / début d'action et fin d'action / début de duel et fin de duel | +| quiz-stars | Tous les jours | Nombre d'étoiles obtenu a la fin d'un quiz | -## Remote doctype +## Information sending -TODO: Rewrite +### Format All indicator are post to a remote doctype, which will allow the application to read a defined external API. This doctype is created by Cozy itself. -Here are the actual structure of this remote doctype: +The structure to send is the following : ``` { - source: string - name: string + createdBy: string + measureName: string startDate: string - endDate: string - value?: number - groups: { [key: string]: string } + value: number | null + group1?: object + group2?: object + group3?: object } ``` with: -- source: contains "ecolyo" value. -- name: contains the indicator type -- startDate and endDate: used to defined a period or if not relevant, it contains both the date of the events. -- value: contains aggreated value (example: number of page viewed on a day). -- groups: contains all other attribute useful for the indicator (example: context, target, result) +- *createdBy*: contains "ecolyo" value. +- *mesureName*: contains one of the following value + +| ENUM | value | +| --- | --- | +| CONNECTION_COUNT_DAILY | connection-count-daily | +| KONNECTOR_EVENT_DAILY | konnector-event-daily | +| KONNECTOR_CONNECTED_PER_DAY | konnector-connected-daily | +| NAVIGATION_COUNT_DAILY | navigation-count-daily | +| CHALLENGE_LAUNCH_EVENT_DAILY | challenge-launch-daily | +| CONSUMPTION_VARIATION_MONTHLY | consumption-variation-monthly | +| SESSION_DURATION | session-duration | +| NAVIGATION_ACTION_DAILY | navigation-action-daily | +| EVENT_DURATION | event-duration | +| QUIZ_STARS | quiz-stars | +| SUMMARY_SUBSCRIPTION_MONTHLY | summary-subscription-monthly | +| FLUID_DATA_GRANULARITY | fluid-data-granularity-monthly | +| CONNECTION_COUNT_MONTHLY | connection-count-monthly | +| PROFILE_COUNT_MONTHLY | profile-count-monthly | +- *startDate*: used to defined the start date of the indicator +- *value*: contains a value relevant to the defined indicator (example: number of page viewed on a day). +- *groups*: contains all attributes defining a indicator. Please refer to indicators definition (https://stats.cozycloud.cc/question#eyJkYXRhc2V0X3F1ZXJ5Ijp7ImRhdGFiYXNlIjo0LCJxdWVyeSI6eyJzb3VyY2UtdGFibGUiOjh9LCJ0eXBlIjoicXVlcnkifSwiZGlzcGxheSI6InRhYmxlIiwidmlzdWFsaXphdGlvbl9zZXR0aW5ncyI6e319) + +### Environnements + +There is two remote doctypes pointing to two differents mode. `dacc-dev` is used on alpha. + +```json + "dacc": { + "type": "cc.cozycloud.dacc", + "verbs": ["ALL"] + }, + "dacc-dev": { + "type": "cc.cozycloud.dacc.dev", + "verbs": ["ALL"] + }, +``` +## How to local test ? -## Indicators +First you need to modify the service in order to be able to see data in local : + + +- Modify dacc URL in order to see data (ligne 67) +```js + await client + .getStackClient() + .fetchJSON( + 'POST', + environementService.isProduction() + ? 'http://localhost:8081' + : '/remote/cc.cozycloud.dacc.dev', + { + data: JSON.stringify(indicator), + } + ) +``` +- Remove date protection if you want to test monthly indicators (ligne 1100) +```js + if ( + profile + // && + // DateTime.local() + // .setZone('utc', { + // keepLocalTime: true, + // }) + // .startOf('day').day === profile.monthlyAnalysisDate.day + ) { +``` -TODO \ No newline at end of file + +Then you need to launch a script that will simulate dacc api's. This terminal will listen to incoming request + +```sh +cd ./scripts +node server.js +``` + +Then you are finaly ready to test ! Just run the following : + +```sh +yarn build-dev:browser; yarn run cozy-konnector-dev -m .\manifest.webapp .\build\services\fluidsPrices\ecolyo.js +``` +You must see sent indicators in the previously open terminal + +```json +{ + data: '{"createdBy":"ecolyo","measureName":"connection-count-monthly","startDate":"2021-12-09","value":3}' +} +{ + data: '{"createdBy":"ecolyo","measureName":"connection-count-monthly","startDate":"2021-12-09","value":3}' +} +``` \ No newline at end of file