Repository: electricitymaps/electricitymaps-contrib

Issue:
King Island: battery never seems to discharge 
I've been keeping an eye on AUS-TAS-KI since it was added to the map. Charging works fine, discharging doesn't show up.


Discussion:
batterie discharging 2020-Dec-16 between 3:30 and 3:45.
I don't see it on [ElectricityMap](https://www.electricitymap.org/zone/AUS-TAS-KI?wind=true).  Storing 161kW at 3:30 and the same at 3:45. (Assuming CET time zone due to your username.)


(My suspicion so far is that the issue lies with how ElectricityMap is handling data and not with the data source, so the King Island dashboard itself could very well have been showing the battery discharging during that time.)
You still can see it today:
at:
Carbon intensity in the last 24 hours
or:
Origin of electricity in the last 24 hours

just go with the mouse pointer to 3:30 or 3:45 pm on time aixle



Rainer 
As of right now (2:10 UTC December 17), the following non-zero "battery discharge" values are found in the 24 hour JSON history for King Island:

```
>>> [(r['stateDatetime'], r['production']['battery discharge']) for r in json['data'] if r['production']['battery discharge']]
[('2020-12-16T05:45:00.000Z', 0.338), ('2020-12-16T06:00:00.000Z', 0.239), ('2020-12-16T10:30:00.000Z', 0.147), ('2020-12-16T16:30:00.000Z', 0.752), ('2020-12-16T16:45:00.000Z', 0.65), ('2020-12-16T17:00:00.000Z', 0.646)]
```

However, I can't get them to display in EM graphs or the history view. This screenshot is from UTC-5, so 12:00 PM should be 17:00Z. Note the drop in origin of electricity chart around 16:30, 16:45, 17:00 that could indicate missing battery production:

![ki](https://user-images.githubusercontent.com/47415/102437096-f11ae900-3fe7-11eb-9686-4a38346549ad.png)

It looks like there might be some bugs/miscommunication in EM or the parser regarding showing battery discharge.

The KI parser and a few `co2eq_parameters.json` lines are the only hits for `battery discharge` in this repository: https://github.com/tmrowco/electricitymap-contrib/search?q=%22battery+discharge%22

It appears charging battery - the bar with colour #b76bcf - is defined as `'battery storage'`
https://github.com/tmrowco/electricitymap-contrib/blob/e3b1db3d685c9693b88cf678d4a2c6ecd5f10d0c/web/src/helpers/constants.js#L8

South Australia uses a different key still:

https://github.com/tmrowco/electricitymap-contrib/blob/52db4e03fac4ee5d85b59b08754899b4418bf37e/parsers/AU.py#L428

Per https://github.com/tmrowco/electricitymap-contrib/blob/e3b1db3d685c9693b88cf678d4a2c6ecd5f10d0c/web/src/helpers/constants.js#L31-L32 it looks like anything with `storage` will never be in PRODUCTION_MODES, while STORAGE_MODES will contain `battery`. I don't see `battery discharge` anywhere in EM frontend.

I'm not super familiar with EM frontend nor the closed source backend - can someone confirm what keys should be used?
The `'battery discharge'` in KI parser was changed in https://github.com/tmrowco/electricitymap-contrib/pull/2776 - was that perhaps wrong? Or backend was updated to require the "discharge" without also updating the frontend?
IIRC the King island parser had not gone live on ElectricityMap in the two days between the merging of #2456 and @FelixDQ changing `battery` to `battery discharge` in  #2776, so I don't know if it worked before that change. However, I don't think battery output has ever shown up on the map after the latter PR was merged.
Here we can see battery charging in a snapshot
![king-island-battery-discharging-2020-12-17 14-11-24](https://user-images.githubusercontent.com/28303688/102492874-97133580-4072-11eb-9aa3-d7bb4c84feab.png)


But the problem is the battery never _discharges_, it is never seen to supply energy to the grid
@corradio on Slack says:

>It should be obj.storage.battery, where obj is the returned dictionary
>Positive values are storage, negative are discharge
>Discharge should therefore not be in the production object
>Feel free to put me as reviewer if tou want to be sure!

Anyone want to put up a quick PR? I don't have a lot of free time today
@jarek @corradio
sorry, mistake in my last comment -corrected now-.
It really shows discharging -left of zero bar- in battery storage 

You still can see it today:
at:
Carbon intensity in the last 24 hours
or:
Origin of electricity in the last 24 hours

just go with the mouse pointer a little left on time line
> It really shows discharging -left of zero bar-

Left of zero bar is not discharging.

On EM website, left of 0 indicates the battery is charging. The grid has lots of energy and is supplying energy to the battery. Die Batterie lädt.

Right of 0 indicates the battery is discharging. The grid doesn't have enough energy, so battery is supplying energy to the grid. Die Batterie versorgt das Netz mit Energie.

![Screenshot_2020-12-17_09-57-55](https://user-images.githubusercontent.com/47415/102504144-7933d980-404e-11eb-9c03-093f841e3aef.png)

@jarek,
thanks for your comment.
Have other opinion. But not the point.
Right now the bar shows to the right. My opinion: charging.

In https://www.hydro.com.au/clean-energy/hybrid-energy-solutions/success-stories/king-island:
minus value -33 right now.

The graph of hydro shows energy going into battery.  It Also shows 0%. That i understand as charging.
Sometimes graph of hydro shows energy leaving battery and shows pos %. That i understand as discharging battery and giving energy to the red.

In EM pos value of 49kW. That i understand as charging there.

If the bar is changing between right and left. One is charging, the other is discharging.
So it shows charging and discharging.  -My opinion.-

Hello,

Just to clarify, when the bar is to the right, then it is supposed to mean
that the system is discharging (i.e. supplying electricity to the grid,
just like a normal production unit).
It might be that the direction is counterintuitive, but however at this
stage it seems to indicate that the data is improperly supplied to our
system.

Let's change the underlying data and then we can discuss the representation
in a separate issue?

Olivier

On Thu, Dec 17, 2020 at 4:36 PM strassburger <notifications@github.com>
wrote:

> @jarek <https://github.com/jarek>,
> thanks for your comment.
> Have other opinion. But not the point.
> Right now the bar shows to the right. My opinion: charging.
>
> In
> https://www.hydro.com.au/clean-energy/hybrid-energy-solutions/success-stories/king-island
> :
> minus value -33 right now.
>
> In EM pos value of 49kW
>
> If the bar is changing between right and left one is charging, the other
> is discharging.
>
> —
> You are receiving this because you were mentioned.
> Reply to this email directly, view it on GitHub
> <https://github.com/tmrowco/electricitymap-contrib/issues/2801#issuecomment-747514798>,
> or unsubscribe
> <https://github.com/notifications/unsubscribe-auth/AAMUIKB6VOXHCQ3IH6KBUJ3SVIQRBANCNFSM4TWDWAMA>
> .
>


-- 

Olivier Corradi

Founder, CEO

<https://www.linkedin.com/in/oliviercorradi> <https://twitter.com/corradio>

tmrow.com

I'll make a PR for this 

Resolving patch:
diff --git a/parsers/AUS_TAS_KI.py b/parsers/AUS_TAS_KI.py
--- a/parsers/AUS_TAS_KI.py
+++ b/parsers/AUS_TAS_KI.py
@@ -52,12 +52,10 @@ def parse_payload(logger, payload):
     return technologies_parsed, biodiesel_percent
 
 # Both keys battery and flywheel are negative when storing energy, and positive when feeding energy to the grid
-def format_storage_techs(technologies_parsed):
+def sum_storage_techs(technologies_parsed):
     storage_techs = technologies_parsed['battery']+technologies_parsed['flywheel']
-    battery_production = storage_techs if storage_techs > 0 else 0
-    battery_storage = storage_techs if storage_techs < 0 else 0
 
-    return battery_production, battery_storage
+    return storage_techs
 
 def fetch_production(zone_key='AUS-TAS-KI', session=None, target_datetime=None, logger: logging.Logger = logging.getLogger(__name__)):
 
@@ -66,12 +64,11 @@ def fetch_production(zone_key='AUS-TAS-KI', session=None, target_datetime=None,
       
     payload = SignalR("https://data.ajenti.com.au/live/signalr").get_value("TagHub", "Dashboard")
     technologies_parsed, biodiesel_percent = parse_payload(logger, payload)
-    battery_production, battery_storage = format_storage_techs(technologies_parsed)
+    storage_techs = sum_storage_techs(technologies_parsed)
     return {
       'zoneKey': zone_key,
       'datetime': arrow.now(tz='Australia/Currie').datetime,
       'production': {
-          'battery discharge': battery_production,
           'biomass': technologies_parsed['diesel']*biodiesel_percent/100,
           'coal': 0,
           'gas': 0,
@@ -84,9 +81,9 @@ def fetch_production(zone_key='AUS-TAS-KI', session=None, target_datetime=None,
           'unknown': 0
       },
       'storage': {
-          'battery': battery_storage*-1
+          'battery': storage_techs*-1 #Somewhat counterintuitively,to ElectricityMap positive means charging and negative means discharging
       },
-      'source': 'https://data.ajenti.com.au/KIREIP/index.html'
+      'source': 'https://www.hydro.com.au/clean-energy/hybrid-energy-solutions/success-stories/king-island' #Iframe: https://data.ajenti.com.au/KIREIP/index.html
     }
 
 if __name__ == '__main__':


Test patch: