Skip to content
Snippets Groups Projects
dacc.md 7.33 KiB
Newer Older
  • Learn to ignore specific revisions
  • # DACC (Data Aggregator Cross Cozy)
    
    
    What is DACC ? A cozy blackbox where apps can send data in order to be anonymised and aggregate to provide usage stats.
    
    ## Infrastructure workflow
    
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
    We have two environments, a dev one and a production. Both of them look like the following schema :
    
    
    ![dacc](/img/architecture/dacc.png)
    
    
    On the development env, the 'cozy env' refers to our 'Alpha' VM.
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
    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 day randomly before **07:00AM**.
    
    ## Usage events
    
    
    This section explains how the application is tracking usage events. Here are the main step:
    
    - All events are stored during the use of the application in the doctype **com.grandlyon.ecolyo.usageevents**
    - A service is responsible of the aggregation of these events to create ANONYMIZED indicators. These indicators are then sent to a remote docType.
    
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
    | Title | Tech name | target | context | startDate | result | trigger | Cozy Dacc Name |
    
    | --- | --- | --- | --- | --- | --- | --- | --- |
    
    Guilhem CARRON's avatar
    Guilhem CARRON committed
    | Complétion d'un nouveau profile | ProfileSetEvent | --- | --- | --- | --- | Lors de l'affichage de la page de félicitation profileTypeFinished | navigation-action-daily |
    | Consultation du nouveau bilan mensuel | ReportFromEvent | --- | 'analysis' | --- | 1 | Lorsque l'utilisateur consulte sa page analyse quand la notification est activée | summary-subscription-monthly |
    
    Hugo SUBTIL's avatar
    Hugo SUBTIL committed
    ## Indicators
    
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
    !!! warning "note"
    
    Hugo SUBTIL's avatar
    Hugo SUBTIL committed
        All indicators are only sent if a user validate first version of CGU, the one containing dacc validation
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
    
    
    Hugo SUBTIL's avatar
    Hugo SUBTIL committed
    ### Monthly Indicators
    
    Hugo SUBTIL's avatar
    Hugo SUBTIL committed
    All monthly indicators call can be found after this comment on the code
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
    
    
    Hugo SUBTIL's avatar
    Hugo SUBTIL committed
    ```js
    // Monthly events
    ```
    
    Hugo SUBTIL's avatar
    Hugo SUBTIL committed
    | 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 consommation par type de fluide. Les paramètres différents sont le type de profil ainsi que le nombre de mois entre la première connexion de l'utilisateur et le moment où est remonté l'indicateur (seniority) |
    | summary-subscription-monthly | Tous les mois si un utilisateur a souscrit a la newsletter ou c'est désabonné | 1 si l’utilisateur est inscrit sinon 0 |
    
    Hugo SUBTIL's avatar
    Hugo SUBTIL committed
    | 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 |
    | 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é |
    
    Hugo SUBTIL's avatar
    Hugo SUBTIL committed
    ### Daily Indicators
    
    Hugo SUBTIL's avatar
    Hugo SUBTIL committed
    The daily process get all events of previous day and process them in the following indicators
    
    Hugo SUBTIL's avatar
    Hugo SUBTIL committed
    | Indicator | Trigger | value |
    | --- | --- | --- |
    | konnector-connected-daily | Tous les jours | La valeur est 1. Les valeurs sont catégorisées par type de fluide (electricity / electricity:water ...) |
    
    | summary-subscription-monthly | Tous les jours | 1 si l'utilisateur est revenu sur Ecolyo via le lien présent dans la newsletter |
    
    Hugo SUBTIL's avatar
    Hugo SUBTIL committed
    ## Information sending
    
    Hugo SUBTIL's avatar
    Hugo SUBTIL committed
    ### 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.
    
    Hugo SUBTIL's avatar
    Hugo SUBTIL committed
    The structure to send is the following :
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
    ```ts
    
    Hugo SUBTIL's avatar
    Hugo SUBTIL committed
      createdBy: string
      measureName: string
    
      startDate: string
    
    Hugo SUBTIL's avatar
    Hugo SUBTIL committed
      value: number | null
      group1?: object
      group2?: object
      group3?: object
    
    Hugo SUBTIL's avatar
    Hugo SUBTIL committed
    - *createdBy*: contains "ecolyo" value.
    
    Hugo SUBTIL's avatar
    Hugo SUBTIL committed
    - *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)
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
    - *mesureName*: contains one of the following value
    
    Hugo SUBTIL's avatar
    Hugo SUBTIL committed
      
    | ENUM | value |
    | --- | --- |
    | CONSUMPTION_VARIATION_MONTHLY   | consumption-variation-monthly |
    | FLUID_DATA_GRANULARITY    | fluid-data-granularity-monthly |
    
    | KONNECTOR_CONNECTED_PER_DAY   | konnector-connected-daily |
    
    Hugo SUBTIL's avatar
    Hugo SUBTIL committed
    | PROFILE_COUNT_MONTHLY    | profile-count-monthly |
    
    | SUMMARY_SUBSCRIPTION_MONTHLY  | summary-subscription-monthly |
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
    ### Environments
    
    Hugo NOUTS's avatar
    Hugo NOUTS committed
    There is two remote doctypes pointing to two different mode. `dacc-dev` is used on alpha.
    
    Hugo SUBTIL's avatar
    Hugo SUBTIL committed
    
    ```json
        "dacc": {
          "type": "cc.cozycloud.dacc",
          "verbs": ["ALL"]
        },
        "dacc-dev": {
          "type": "cc.cozycloud.dacc.dev",
          "verbs": ["ALL"]
        },
    ```
    
    Hugo SUBTIL's avatar
    Hugo SUBTIL committed
    ## How to local test ?
    
    Hugo SUBTIL's avatar
    Hugo SUBTIL committed
    First you need to modify the service in order to be able to see data in local :
    
    
    - Run a local server that will listen and log events.
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
    
    
    ```sh
    node srcipts/server.js
    ```
    
    - Edit dacc URL (line 67) to send requests to your local server at `http://localhost:8081`
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
    
    
    Hugo SUBTIL's avatar
    Hugo SUBTIL committed
    ```js
        await client
          .getStackClient()
          .fetchJSON(
            'POST',
    
    Hugo NOUTS's avatar
    Hugo NOUTS committed
            environments.isProduction()
    
              ? '/remote/cc.cozycloud.daccv_2'
              : 'http://localhost:8081',
    
    Hugo SUBTIL's avatar
    Hugo SUBTIL committed
            {
              data: JSON.stringify(indicator),
            }
          )
    ```
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
    
    
    - For **monthly indicators**, remove date protection (ligne 1100)
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
    
    
    Hugo SUBTIL's avatar
    Hugo SUBTIL committed
    ```js
      if (
        profile
        // &&
        // DateTime.local()
        //   .setZone('utc', {
        //     keepLocalTime: true,
        //   })
        //   .startOf('day').day === profile.monthlyAnalysisDate.day
      ) {
    ```
    
    - Generate usage events by navigating through the app
    
    You will be able to see previous events and freshly generated events in the db `com-grandlyon-ecolyo-usageevent`
    
    :warning: because the cron run every day before 7am, it will take events from the day before. So if you want to test specific usage, you will have to edit the `eventDate` of events you want to send.
    
    - Then you are finally ready to test ! Just run the following :
    
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
    *If aggregatorUsageEvents changed:*
    
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
    yarn build-dev:browser && yarn run cozy-konnector-dev -m ./manifest.webapp ./build/services/aggregatorUsageEvents/ecolyo.js
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
    
    
    *To save time, when running multiple times and if aggregatorUsageEvents didn't change, you don't have to build.*
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
    
    
    Hugo SUBTIL's avatar
    Hugo SUBTIL committed
    ```sh
    
    yarn run cozy-konnector-dev -m ./manifest.webapp ./build/services/aggregatorUsageEvents/ecolyo.js
    
    Hugo SUBTIL's avatar
    Hugo SUBTIL committed
    ```
    
    
    - You should see sent indicators in the logs of your local server
    
    Hugo SUBTIL's avatar
    Hugo SUBTIL committed
    
    ```json
    {
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
      "data": {"createdBy":"ecolyo","measureName":"connection-count-monthly","startDate":"2021-12-09","value":3}
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
      "data": {"createdBy":"ecolyo","measureName":"connection-count-monthly","startDate":"2021-12-09","value":3}
    
    Hugo SUBTIL's avatar
    Hugo SUBTIL committed
    }
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
    ## How to add new indicator ?
    
    You have to reach cozy and discuss with them about new indicators. They will implement it for `dacc-dev` and `dacc` and you will be able to test it on alpha env. Remember you will need **at least 5 data** of each type to see it in metabase.
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
    ## Visualisation
    
    All the data aggregated in the dacc can be visualized with a *Metabase* website hosted by [cozy](https://stats.cozycloud.cc/).
    
    ## Errors
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
    
    
    Rémi PAILHAREY's avatar
    Rémi PAILHAREY committed
    More here in [DJU](/ecolyo/functionalities/profile_type/#dju).
    
    
    If there is an authentication error, the api will returns an error in html format to cozy, so you'll get from cozy an error 502 as following, because cozy expects a json response :
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
    
    
    ```json
    {
      "status": "502",
      "title": "Bad Gateway",
      "detail": "the content-type for the response is not authorized",
      "source": {}
    }
    ```