tandemdrive / ocpi-tariffs

OCPI tariff calculations
Apache License 2.0
38 stars 9 forks source link

Time component with min_duration restriction does not seem to work #66

Closed james-siteclick closed 7 months ago

james-siteclick commented 7 months ago

I defined the tariff and CDR below. Based on my understanding of OCPI, the min_duration restriction below should mean I am charged after 3 hours, so for the last hour of my 4 hour session.

However the tool only shows a cost for FLAT and ENERGY.

Only if I change min_duration to 0 do I then receive a charge for TIME.

{
  "country_code": "NL",
  "party_id": "TDR",
  "id": "TDR1",
  "currency": "EUR",
  "elements": [
    {
      "restrictions": {
        "min_duration": 10800
      },
      "price_components": [
        {
          "type": "TIME",
          "price": 2,
          "vat": 20.0,
          "step_size": 900
        }
      ]
    },
    {
      "price_components": [
        {
          "type": "FLAT",
          "price": 0.50,
          "vat": 20.0,
          "step_size": 1
        },
        {
          "type": "ENERGY",
          "price": 0.25,
          "vat": 10.0,
          "step_size": 1
        }
      ]
    }
  ],
  "end_date_time": "2019-06-30T23:59:59Z",
  "last_updated": "2018-12-17T17:15:01Z"
}

And the following CDR:

{
  "country_code": "BE",
  "party_id": "BEC",
  "id": "12345",
  "start_date_time": "2015-06-29T13:00:00Z",
  "end_date_time": "2015-06-29T17:00:00Z",
  "cdr_token": {
    "uid": "012345678",
    "type": "RFID",
    "contract_id": "DE8ACC12E46L89"
  },
  "auth_method": "WHITELIST",
  "cdr_location": {
    "id": "LOC1",
    "name": "Gent Zuid",
    "address": "F.Rooseveltlaan 3A",
    "city": "Gent",
    "postal_code": "9000",
    "country": "BEL",
    "coordinates": {
      "latitude": "3.729944",
      "longitude": "51.047599"
    },
    "evse_uid": "3256",
    "evse_id": "BE*BEC*E041503003",
    "connector_id": "1",
    "connector_standard": "IEC_62196_T2",
    "connector_format": "SOCKET",
    "connector_power_type": "AC_1_PHASE"
  },
  "currency": "EUR",
  "tariffs": [],
  "charging_periods": [{
    "start_date_time": "2015-06-29T13:00:00Z",
    "dimensions": [{
      "type": "TIME",
      "volume": 4
    }, {
      "type": "ENERGY",
      "volume": 15.342
    }],
    "tariff_id": "12"
  }],
  "total_cost": {
    "excl_vat": 4.00,
    "incl_vat": 4.40
  },
  "total_energy": 15.342,
  "total_time": 1.973,
  "total_time_cost": {
    "excl_vat": 4.00,
    "incl_vat": 4.40
  },
  "last_updated": "2015-06-29T22:01:13Z"
}
remkop22 commented 7 months ago

Hi @james-siteclick, Thanks for checking out this tool!

You've run in to a strange aspect of the OCPI tariff module. Namely the producer of a CDR (normally a CPO) is responsible for creating at least distinct charging_periods for each period in the session where a different tariff element is active. The tool only tries to define a price for each charging period in the CDR. it cannot on it's own start subdividing charging periods into smaller pieces since it (usually) doesn't have enough information to accurately do this.

Since the only restriction in your tariff is min_duration, there should be at least a charging period before this restriction applies and when it actually applies. Then the tool will be able to evaluate the restrictions separately for each of those periods.

So in practice, with separate periods (I randomly distributed the energy component) it looks like this. Which should work as you expected, if it does or doesn't not please let me know!

{
  "charging_periods": [
    {
      "start_date_time": "2015-06-29T13:00:00Z",
      "dimensions": [
        {
          "type": "TIME",
          "volume": 3
        },
        {
          "type": "ENERGY",
          "volume": 12.342
        }
      ],
      "tariff_id": "12"
    },
    {
      "start_date_time": "2015-06-29T16:00:00Z",
      "dimensions": [
        {
          "type": "TIME",
          "volume": 1
        },
        {
          "type": "ENERGY",
          "volume": 3
        }
      ],
      "tariff_id": "12"
    }
  ]
}
remkop22 commented 7 months ago

Additionally It is on our roadmap to detect when a CDR is obviously not upholding this guarantee and show some warnings to the user.

james-siteclick commented 7 months ago

@remkop22 thanks so much for your quick reply, that makes complete sense now 👍

remkop22 commented 7 months ago

@james-siteclick No worries, I'll close the issue.