Repository: electricitymaps/electricitymaps-contrib

Issue:
Data for Bolivia
I found hourly production for Bolivia [here](http://www.cndc.bo/media/archivos/graf/gene_hora/gweb_despdia_genera.php). I'll write a parser if nobody is on it!

The installed capacities are declined [here](http://www.cndc.bo/agentes/generacion.php). It's divided in 3 types:
- hydraulic (483.22 MW)
- wind (27 MW)
- thermal (1344.55 MW)

It seems that thermal includes plants consuming gas, oil or biomass. Should I put this overall section as unknown?


Discussion:
Good job finding that!

Looks like data for the chart ultimately comes from http://www.cndc.bo/media/archivos/graf/gene_hora/despacho_diario.php?fechag=2017-08-08 which should be alright to parse

The data breakdown is a bit underwhelming, hydro is the only clear one. If we go by the capabilities you've linked, we can probably assume the "intermittent" is wind. Looking through production archive for August 2017, intermittent production has come somewhat close to the specified capacity of 27 MW, but never exceeded it, I saw 18.8 at most.

Watch out because I've seen the intermittent production report -0.01, which breaks data importers (I saw this in data for 2017-08-03). Force the value to be at least 0.
http://global-climatescope.org/en/country/bolivia/#/details says installed thermal capacity is mostly gas, with no coal and very limited oil/diesel, however there is about 25% of "other fossil fuels". Probably safest to report the thermal generation as "unknown" when better breakdown is not available.
@igorarduin Nice work on finding this.  I've been looking at that site and there looks to be detailed programmed generation for the day ahead http://www.cndc.bo/media/archivos/boletindiario/precmp_090817.htm under Programación de la Operación  as well as a detailed report on previous days generation http://www.cndc.bo/media/archivos/boletindiario/dcdr_070817.htm under Resultados de la Operación. 

Since both of those have breakdown by plant maybe we can incorporate it somehow to help provide breakdown of the thermal generation.  Regardless both look like useful datasets to scrape for future reference.
Maybe we could try to do a breakdown for each generation unit?

![image](https://user-images.githubusercontent.com/1655848/29516752-f4a1563c-8671-11e7-8a65-9fbf82650364.png)

But won't we need the real time breakdown then? Hourly data are only available for the following variables: "Gen. Prevista", "Gen. Real", "Termo", "Hidro" and "Intermitentes"
My bad, I though we had access to the breakdown in real time. My screenshot was only capacities..
Do we access to exchanges? If we don't, I think we can close this issue and perhaps open one very specific for exchanges.
Nothing on exchanges as far as I know. I realised I did a mistake in my code for the generation forecast function. I am fixing it now and then maybe we could close the issue? Or should I open another one?
Just write "Fixes #671" in your pull request, and as soon as the PR gets merged, this issue will automatically be closed.

Resolving patch:
diff --git a/parsers/BO.py b/parsers/BO.py
--- a/parsers/BO.py
+++ b/parsers/BO.py
@@ -104,7 +104,7 @@ def fetch_production(country_code='BO', session=None):
     return data
     
 
-def fetch_hourly_generation_forecast(country_code, obj, hour, date):          
+def fetch_hourly_generation_forecast(country_code, obj, hour, date):
     #output frame
     data = {
         'countryCode': country_code,
@@ -112,50 +112,37 @@ def fetch_hourly_generation_forecast(country_code, obj, hour, date):
         'source': 'cndc.bo',
     }
     
-    #Fill datetime variable
-    data['datetime'] = arrow.get(date, 'YYYY-MM-DD').replace(tzinfo=tz_bo, hour=hour).datetime   
-    #Datetime are recorded from hour 1 to 24 in the web service
-    if hour == 0:
-        hour = 24
-    #Fill production types
+    #Fill forecasted value
     data['value'] = obj['Gen.Prevista'][obj.hour == hour].iloc[0]
     
+    #Fill datetime variable - changing format if midnight (datetime are recorded from hour 1 to 24 in the webservice)
+    if hour == 24:
+        hour = 0
+        date = arrow.get(date, 'YYYY-MM-DD').shift(days=+1).format('YYYY-MM-DD')
+    data['datetime'] = arrow.get(date, 'YYYY-MM-DD').replace(tzinfo=tz_bo, hour=hour).datetime   
+    
     return data
 
 
 def fetch_generation_forecast(country_code = 'BO', session=None):
-	
     #Define actual and last day (for midnight data)
-    now = arrow.now(tz=tz_bo)
-    formatted_date = now.format('YYYY-MM-DD')
-    past_formatted_date = arrow.get(formatted_date, 'YYYY-MM-DD').shift(days=-1).format('YYYY-MM-DD')
-
-    #Define output frame    
-    actual_hour = now.hour
-    data = [dict() for h in range(actual_hour+1)]
+    formatted_date = arrow.now(tz=tz_bo).format('YYYY-MM-DD')
+    
+    #Define output frame
+    data = [dict() for h in range(24)]
 
     #initial path for url to request
     url_init = 'http://www.cndc.bo/media/archivos/graf/gene_hora/despacho_diario.php?fechag=' 
+    url = url_init + formatted_date
     
-    #Start with data for midnight
-    url = url_init + past_formatted_date
     #Request and rearange in DF
     r = session or requests.session()
     response = r.get(url)
     obj = webparser(response)
-    data_temp = fetch_hourly_generation_forecast(country_code, obj, 0, formatted_date)
-    data[0] = data_temp
     
-    #Fill data for the other hours until actual hour
-    if actual_hour>1:
-        url = url_init + formatted_date
-        #Request and rearange in DF
-        r = session or requests.session()
-        response = r.get(url)
-        obj = webparser(response)
-        for h in range(1, actual_hour+1):
-            data_temp = fetch_hourly_generation_forecast(country_code, obj, h, formatted_date)
-            data[h] = data_temp
+    for h in range(1,25):
+        data_temp = fetch_hourly_generation_forecast('BO', obj, h, formatted_date)
+        data[h-1] = data_temp
 
     return data
 


Test patch: