MattJeanes / TeslaMateAgile

Integration to automatically fill in prices for charge data captured by TeslaMate for smart energy providers
MIT License
76 stars 9 forks source link

Some Crashing Entries #30

Closed brombomb closed 1 year ago

brombomb commented 1 year ago

Found some entries from the logs that are causing FAIL errors.

Here's the log:

fail: TeslaMateAgile.PriceHelper[0]
      Failed to calculate charging cost / energy for charging process 415
      System.InvalidOperationException: Sequence contains no elements
         at System.Linq.ThrowHelper.ThrowNoElementsException()
         at System.Linq.Enumerable.Average(IEnumerable`1 source)
         at TeslaMateAgile.PriceHelper.DeterminePhases(IEnumerable`1 charges) in /src/TeslaMateAgile/Helpers/PriceHelper.cs:line 141
         at TeslaMateAgile.PriceHelper.CalculateChargeCost(IEnumerable`1 charges) in /src/TeslaMateAgile/Helpers/PriceHelper.cs:line 91
         at TeslaMateAgile.PriceHelper.Update() in /src/TeslaMateAgile/Helpers/PriceHelper.cs:line 64
info: TeslaMateAgile.PriceHelper[0]
      Calculating cost for charges 01/15/2022 05:13:21 UTC - 01/15/2022 05:13:28 UTC
fail: TeslaMateAgile.PriceHelper[0]
      Failed to calculate charging cost / energy for charging process 416
      System.InvalidOperationException: Sequence contains no elements
         at System.Linq.ThrowHelper.ThrowNoElementsException()
         at System.Linq.Enumerable.Average(IEnumerable`1 source)
         at TeslaMateAgile.PriceHelper.DeterminePhases(IEnumerable`1 charges) in /src/TeslaMateAgile/Helpers/PriceHelper.cs:line 141
         at TeslaMateAgile.PriceHelper.CalculateChargeCost(IEnumerable`1 charges) in /src/TeslaMateAgile/Helpers/PriceHelper.cs:line 91
         at TeslaMateAgile.PriceHelper.Update() in /src/TeslaMateAgile/Helpers/PriceHelper.cs:line 64
info: TeslaMateAgile.PriceHelper[0]
      Calculating cost for charges 03/14/2022 02:04:18 UTC - 03/14/2022 02:04:26 UTC
fail: TeslaMateAgile.PriceHelper[0]
      Failed to calculate charging cost / energy for charging process 465
      System.InvalidOperationException: Sequence contains no elements
         at System.Linq.ThrowHelper.ThrowNoElementsException()
         at System.Linq.Enumerable.Average[TSource](IEnumerable`1 source, Func`2 selector)
         at TeslaMateAgile.PriceHelper.DeterminePhases(IEnumerable`1 charges) in /src/TeslaMateAgile/Helpers/PriceHelper.cs:line 145
         at TeslaMateAgile.PriceHelper.CalculateChargeCost(IEnumerable`1 charges) in /src/TeslaMateAgile/Helpers/PriceHelper.cs:line 91
         at TeslaMateAgile.PriceHelper.Update() in /src/TeslaMateAgile/Helpers/PriceHelper.cs:line 64

and here's some sample data (zip of a CSV and SQL insert statements) charging_processes_202207192202.zip

MattJeanes commented 1 year ago

Hi @brombomb thanks for the error logs and zip very useful!

It seems that your charge was very very short so much so that there wasn't actually any records in the database where the charger current and voltage was recorded.

Would you mind sending me over the relevant data from the charges table as well as the charging_processes table? As a CSV would be perfect if you don't mind! Then I can see exactly what happened and add some code to at least prevent it throwing an error in this scenario.

To workaround this issue, you can manually set the cost for the charge to 0 in the database to stop TeslaMateAgile from trying to calculate it.

brombomb commented 1 year ago

Here is a list of all the charges associated with the charging processes from the zip/csv above. Not all of these were errors but I included them because I couldn't tell at a glance what the common issue/thread was. If you need more data I'm happy to supply more rows.

charges_202207232048.csv

MattJeanes commented 1 year ago

Thanks very much - I've taken one of your examples and added it as a test case to re-create your error and added extra safeguards around the code in this area.

This is now released as v1.9.1 if you'd like to give it a go! Let me know if it solves your problem and then we can close this off 🙂

brombomb commented 1 year ago

Looks good to me. No more errors in my logs! Thanks for the quick fix.

MattJeanes commented 1 year ago

Awesome! Thanks for trying it out 🙂