EVerest / libocpp

C++ implementation of the Open Charge Point Protocol
Apache License 2.0
99 stars 48 forks source link

1.6 Smart Charging Calculate Composite Schedule #609

Closed folkengine closed 2 months ago

folkengine commented 6 months ago

OCPP Version

OCPP1.6

Describe the bug

When attempting to determine the Composite Schedule in 1.6, if a Profile's chargingSchedulePeriod begins after the start of the requested time range, even if it is within the time range, the Profile's chargingSchedulePeriod won't be applied.

To Reproduce

For example, given these two Profiles:

{
  "chargingProfileId": 1,
  "chargingProfileKind": "Absolute",
  "chargingProfilePurpose": "TxDefaultProfile",
  "chargingSchedule": {
    "chargingRateUnit": "W",
    "chargingSchedulePeriod": [
      {
        "limit": 2000.0,
        "numberPhases": 1,
        "startPeriod": 0
      }
    ],
    "duration": 1080,
    "minChargingRate": 0.0,
    "startSchedule": "2024-01-17T18:00:00.000Z"
  },
  "recurrencyKind": "Daily",
  "stackLevel": 1
}
{
    "chargingProfileId": 100,
    "chargingProfileKind": "Recurring",
    "chargingProfilePurpose": "TxDefaultProfile",
    "chargingSchedule": {
        "chargingRateUnit": "W",
        "chargingSchedulePeriod": [
            {
                "limit": 11000.0,
                "numberPhases": 3,
                "startPeriod": 0
            },
            {
                "limit": 6000.0,
                "numberPhases": 3,
                "startPeriod": 28800
            },
            {
                "limit": 12000.0,
                "numberPhases": 3,
                "startPeriod": 72000
            }
        ],
        "duration": 86400,
        "minChargingRate": 0.0,
        "startSchedule": "2023-01-17T17:00:00.000Z"
    },
    "recurrencyKind": "Daily",
    "stackLevel": 0
}

If you set the start of the time range to 18:01:00 the generated Composite Schedule will include the time range that started at 18:00:00:

{
    "chargingRateUnit": "W",
    "chargingSchedulePeriod": [
        {
            "limit": 2000.0,
            "numberPhases": 1,
            "stackLevel": 1,
            "startPeriod": 0
        },
        {
            "limit": 11000.0,
            "numberPhases": 3,
            "stackLevel": 0,
            "startPeriod": 1020
        }
    ],
    "duration": 21540
}

The breakdown is:

Start Time> 2024-01-17T18:01:00.000Z
            period #1 {limit: 2000 numberPhases:1 stackLevel:1} starts 0 Seconds in
            period #2 {limit: 11000 numberPhases:3 stackLevel:0} starts 17 Minutes in
            period #2 ends after 5 Hours 59 Minutes

However, if the time range starts one second before the Profile's chargingSchedulePeriod, even though the Profile's period is within the time range requested, it will not be applied:

{
    "chargingRateUnit": "W",
    "chargingSchedulePeriod": [
        {
            "limit": 11000.0,
            "numberPhases": 3,
            "stackLevel": 0,
            "startPeriod": 0
        }
    ],
    "duration": 21601
}
Start Time> 2024-01-17T17:59:59.000Z
            period #1 {limit: 11000 numberPhases:3 stackLevel:0} starts 0 Seconds in
            period #1 ends after 6 Hours 1 Seconds 

This image will show a graphical breakdown of the data:

CompositeSchedule

Anything else?

liboccp PR #606 has tests that include both examples shown above.

folkengine commented 6 months ago

bugfix/composite-schedule-calculation is a branch that is working on this issue.

No longer needed. Fixed in #619

Pietfried commented 4 months ago

This should be fixed with a rework of the composite schedule calcuation: https://github.com/EVerest/libocpp/pull/619

folkengine commented 2 months ago

This should be fixed with a rework of the composite schedule calcuation: #619

Confirmed. #745 will include tests used to verify.