> ## Documentation Index
> Fetch the complete documentation index at: https://docs.datanumia.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Comparison of consumptions between two periods.

> This API is used to get consumption comparisons between two periods : selected period and reference period.
Selected period is the period that needs to be compared.
Reference period is the period to which the selected period is compared to.




## OpenAPI

````yaml /api-reference/comparison.yaml get /sites/{site-id}/consumptions-self-comparison
openapi: 3.0.3
info:
  title: Comparison lifecycle
  version: '1.0'
servers:
  - url: https://api.home.datanumia.com/api/v1
security: []
paths:
  /sites/{site-id}/consumptions-self-comparison:
    get:
      summary: Comparison of consumptions between two periods.
      description: >
        This API is used to get consumption comparisons between two periods :
        selected period and reference period.

        Selected period is the period that needs to be compared.

        Reference period is the period to which the selected period is compared
        to.
      operationId: getComparisons
      parameters:
        - name: site-id
          in: path
          description: Site identifier
          required: true
          schema:
            type: string
        - name: fluid
          in: query
          description: Energy type.
          required: true
          schema:
            type: string
            enum:
              - ELEC
        - name: strategy
          in: query
          description: >
            Represents the strategy used for the comparison.

            Two options are available : SHORTEST_DAY_MONTH, SAME_DAYS.

            SHORTEST_DAY_MONTH is used to truncate the longest period with the
            length of the shortest one.

            SAME_DAYS is used to compared same days and months between to
            period.
          required: true
          schema:
            type: string
            enum:
              - SHORTEST_PERIOD_LENGTH
              - SAME_DAYS_MONTH
        - name: selectedPeriodBeginTs
          in: query
          description: >
            Represents selected period begin date (yyyy-MM-dd'T'HH:mm:ss'Z or
            yyyy-MM-dd'T'HH:mm:ss.SSS'Z)
          required: true
          schema:
            type: string
            format: date-time
        - name: selectedPeriodEndTs
          in: query
          description: >
            Represents selected period end date (yyyy-MM-dd'T'HH:mm:ss'Z or
            yyyy-MM-dd'T'HH:mm:ss.SSS'Z)
          required: true
          schema:
            type: string
            format: date-time
        - name: referencePeriodBeginTs
          in: query
          description: >
            Represents the reference period begin date (yyyy-MM-dd'T'HH:mm:ss'Z
            or yyyy-MM-dd'T'HH:mm:ss.SSS'Z)
          required: true
          schema:
            type: string
            format: date-time
        - name: referencePeriodEndTs
          in: query
          description: >
            Represents the reference period end date (yyyy-MM-dd'T'HH:mm:ss'Z or
            yyyy-MM-dd'T'HH:mm:ss.SSS'Z)
          required: true
          schema:
            type: string
            format: date-time
      responses:
        '200':
          description: OK
          content:
            '*/*':
              schema:
                $ref: '#/components/schemas/ConsumptionComparisonResponse'
        '400':
          description: >
            Functional error. Possible values: 

            <table><tr><td><b>ErrorCode</b></td><td><b>ErrorDescription</b></td></tr>

            <tr><td>PARAM_MANDATORY</td><td>The parameter fluid is
            mandatory</td></tr>

            <tr><td>PARAM_MANDATORY</td><td>The parameter step is
            mandatory</td></tr>

            <tr><td>PARAM_MANDATORY</td><td>The parameter beginTs1 is
            mandatory</td></tr>

            <tr><td>PARAM_MANDATORY</td><td>The parameter endTs1 is
            mandatory</td></tr>

            <tr><td>PARAM_MANDATORY</td><td>The parameter beginTs2 is
            mandatory</td></tr>

            <tr><td>PARAM_MANDATORY</td><td>The parameter endTs2 is
            mandatory</td></tr>

            <tr><td>INVALID_DATE_FORMAT</td><td>The parameter beginTs1 is not
            valid. It must be a Zone date format</td></tr></tr>

            <tr><td>INVALID_DATE_FORMAT</td><td>The parameter endTs1 is not
            valid. It must be a Zone date format</td></tr></tr>

            <tr><td>INVALID_DATE_FORMAT</td><td>The parameter beginTs2 is not
            valid. It must be a Zone date format</td></tr></tr>

            <tr><td>INVALID_DATE_FORMAT</td><td>The parameter endTs2 is not
            valid. It must be a Zone date format</td></tr></tr>

            <tr><td>INVALID_STEP_FORMAT</td><td>The parameter step is not valid.
            It must be an ISO Period format PnYnMnD</td></tr></tr>

            </table>
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ProblemDetail'
        '401':
          description: unauthorized
          content: {}
        '404':
          description: Functional error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ProblemDetail'
        '500':
          description: unexpected error
          content: {}
components:
  schemas:
    ConsumptionComparisonResponse:
      type: object
      properties:
        units:
          $ref: '#/components/schemas/Units'
        comparisons:
          type: array
          description: List of compared periods.
          items:
            $ref: '#/components/schemas/Comparison'
    ProblemDetail:
      required:
        - type
        - status
      properties:
        type:
          type: string
        title:
          type: string
          description: The problem title
        status:
          type: integer
          description: The problem status
        detail:
          type: string
          description: The problem detail
        instance:
          type: string
          description: The problem instance. By default, the request path
        properties:
          type: object
          description: A generic map of properties
      description: Representation for an RFC 7807 problem detail
    Units:
      type: object
      description: Units used in body response.
      properties:
        cost:
          type: string
          description: Cost unit.
          example: EUR
        energyMeter:
          type: string
          description: Energy unit.
          example: KWH
    Comparison:
      type: object
      description: Comparison between selected period and reference period.
      properties:
        selectedPeriod:
          $ref: '#/components/schemas/ComparisonPeriod'
          description: >-
            Key information about selected period like cost, energy consumption
            and error flags.
        referencePeriod:
          $ref: '#/components/schemas/ComparisonPeriod'
          description: >-
            Key information about reference period like cost, energy consumption
            and error flags.
        weatherImpactMessageCode:
          type: string
          description: Code of the weather impact message to display.
          example: COLDER_WEATHER_HIGHER_CONSO
        differenceRate:
          $ref: '#/components/schemas/DifferenceRate'
    ComparisonPeriod:
      type: object
      properties:
        period:
          $ref: '#/components/schemas/Period'
        cost:
          $ref: '#/components/schemas/Cost'
        energyMeter:
          $ref: '#/components/schemas/EnergyMeter'
        errorFlags:
          type: array
          description: >
            Indicates error cause encountered during consumption calculation.

            BAD_INDEX_INFORMATION_OR_CONTRACT_CHANGE_MISSING: We have incoherent
            information in the contracts or indexes associated to the site.

            ABERRANT_CONSUMPTION: The calculated consumption is above the
            aberrancy threshold
          items:
            type: string
          example:
            - ABERRANT_CONSUMPTION
            - BAD_INDEX_INFORMATION_OR_CONTRACT_CHANGE_MISSING
    DifferenceRate:
      type: object
      description: Difference rates between selected and reference periods.
      properties:
        cost:
          $ref: '#/components/schemas/Cost'
        energyMeter:
          $ref: '#/components/schemas/EnergyMeter'
    Period:
      type: object
      description: Period begin date and end date.
      properties:
        startTime:
          type: string
          description: Period starting date.
          format: date-time
          example: '2024-01-01T00:00:00+01:00'
        endTime:
          type: string
          description: Period ending date.
          format: date-time
          example: '2024-01-31T00:00:00+01:00'
    Cost:
      type: object
      description: Period consumption cost (cost unit define by Units object above).
      properties:
        total:
          type: number
          description: Period cost value.
          example: 285.6546
    EnergyMeter:
      type: object
      description: Period energy (energy unit define by Units object above).
      properties:
        total:
          type: number
          description: Period energy value.
          example: 1613.622

````