Re: interview with howie severino
fooler mail <[email protected]> Tue, 7 Apr 2015 23:38:36 -0400
| Newsgroups | gmane.org.user-groups.linux.philippine |
|---|---|
| Message-ID | <CAKPk3KSy35o01NuvnWuO2y=bL=NJheEtNAYcbeDuSYNC--fUFQ@mail.gmail.com> |
hi obet,
been busy lately but here is your python script (see email attached
also) using matplotlib...
$ cat -n wesm.py
1 #!/bin/env python
2
3 from urllib2 import urlopen
4 from datetime import datetime, timedelta
5 from matplotlib import pyplot as plt
6
7 dem_target = 7000
8 lwap_target = 2000
9
10 today = datetime.today()
11 date = (today - timedelta(days=int(not
bool(today.hour)))).strftime('%Y%m%d')
12 hour = today.hour + 24 * int(not bool(today.hour))
13
14 url = urlopen('http://www.wesm.ph/chart/export/luzon_dmd_csv_export.php?date='
+ date + '&hour=' + str(hour).zfill(2))
15 luzon_str = url.read().replace('\n', ',' + str(dem_target) +
',' + str(lwap_target) + '\n').replace(' ','').splitlines()[1:25]
16
17 # HOUR, DEM_DAPEL, DEM_RTDEL, DEM_RTXEL, LWAP_DAPEL,
LWAP_RTDEL, LWAP_RTXEL, DEM_TARGET, LWAP_TARGET
18 luzon_data = [list(row) for row in zip(*[[float(column or
'nan') for column in row.split(',')] for row in luzon_str])]
19
20 plt.plot(luzon_data[0], luzon_data[7], 'r.-', label='Target')
21 plt.plot(luzon_data[0], luzon_data[1], 'y.-', label='Day Ahead
Projection (DAP)')
22 plt.plot(luzon_data[0], luzon_data[2], 'c.-', label='Hour
Ahead Projection (RTD)')
23 plt.plot(luzon_data[0], luzon_data[3], 'b.-', label='Current
Demand (RTX)')
24 plt.title('Luzon Market Demand - ' + today.strftime('%B %d,
%Y') + '\n' + 'Current Hour Demand: ' + str(luzon_data[3][hour - 2]) +
' MW' )
25 plt.xlabel('Hours')
26 plt.ylabel('MEGAWATTS')
27 plt.xticks(range(1,25))
28 plt.grid(linestyle=':')
29 plt.legend(loc='center', frameon=False, bbox_to_anchor=(0.5,
-0.2), fontsize='small')
30 plt.savefig(date + str(hour).zfill(2) + '.png', format='png',
bbox_inches='tight')
the bash script is not able to manage if hour is 24 as i forgot to
write an equation for that.. .but for python script... line 11 and 12
will take care of that... if hour is 24, it will adjust the date a day
before and set hour to 24..
line 15 reformat the csv format and added "dem_target" and
"lwap_target" found in line 7 and 8..
line 18 converted line 15 to a 2 dimensional array and the index
description of the first dimension is found at line 17.. the second
dimension is the value from hour 1 to 24...
fooler.
On Sun, Apr 5, 2015 at 11:37 PM, Roberto Verzola <[email protected]> wrote:
>> what i noticed with that url.. it just updated every hour... 5 minutes
>> after an hour is already good enough... that script is idempotent...
>> meaning if you run several times on the same hour.. it will give you
>> the same results....
>
>
> Yes, updates are hourly, but apparently not always at the same time.
> Sometimes 10 mins after the hour, you get an empty .csv file, rather
> than old data. Sometimes, it takes more than 15 min. before the next
> update is available. (Maybe they update manually???)
>
>
> _________________________________________________
> Philippine Linux Users' Group (PLUG) Mailing List
> http://lists.linux.org.ph/mailman/listinfo/plug
> Searchable Archives: http://archives.free.net.ph
_________________________________________________
Philippine Linux Users' Group (PLUG) Mailing List
http://lists.linux.org.ph/mailman/listinfo/plug
Searchable Archives: http://archives.free.net.ph
wesm.py
(application/octet-stream, 1.5 KB)
#!/bin/env python
from urllib2 import urlopen
from datetime import datetime, timedelta
from matplotlib import pyplot as plt
dem_target = 7000
lwap_target = 2000
today = datetime.today()
date = (today - timedelta(days=int(not bool(today.hour)))).strftime('%Y%m%d')
hour = today.hour + 24 * int(not bool(today.hour))
url = urlopen('http://www.wesm.ph/chart/export/luzon_dmd_csv_export.php?date=' + date + '&hour=' + str(hour).zfill(2))
luzon_str = url.read().replace('\n', ',' + str(dem_target) + ',' + str(lwap_target) + '\n').replace(' ','').splitlines()[1:25]
# HOUR, DEM_DAPEL, DEM_RTDEL, DEM_RTXEL, LWAP_DAPEL, LWAP_RTDEL, LWAP_RTXEL, DEM_TARGET, LWAP_TARGET
luzon_data = [list(row) for row in zip(*[[float(column or 'nan') for column in row.split(',')] for row in luzon_str])]
plt.plot(luzon_data[0], luzon_data[7], 'r.-', label='Target')
plt.plot(luzon_data[0], luzon_data[1], 'y.-', label='Day Ahead Projection (DAP)')
plt.plot(luzon_data[0], luzon_data[2], 'c.-', label='Hour Ahead Projection (RTD)')
plt.plot(luzon_data[0], luzon_data[3], 'b.-', label='Current Demand (RTX)')
plt.title('Luzon Market Demand - ' + today.strftime('%B %d, %Y') + '\n' + 'Current Hour Demand: ' + str(luzon_data[3][hour - 2]) + ' MW' )
plt.xlabel('Hours')
plt.ylabel('MEGAWATTS')
plt.xticks(range(1,25))
plt.grid(linestyle=':')
plt.legend(loc='center', frameon=False, bbox_to_anchor=(0.5, -0.2), fontsize='small')
plt.savefig(date + str(hour).zfill(2) + '.png', format='png', bbox_inches='tight')