On Thu, Apr 2, 2015 at 12:48 AM, Roberto Verzola <[email protected]> wrote: > > So the software we need has to do something like this: > - download the PDF or CSV Luzon file from WESM every 3-5 mins after the > hour > - add the target megawatts as a red horizontal line > - generate the jpeg/png graph. > - upload to server for mirroring/download by everyone else. > > > PS. A peaceful Holy Week to you Mr. fooler! Maybe your extraordinary > programming expertise can help in this activity. >
ok here is a bash script (also file attached) to make your holy week
more peaceful...
you need the following:
1) yum -y install curl
2) yum -y install gnuplot
$ cat -n wesm.sh
1 #!/bin/bash
2
3 #Target in MegaWatts
4 TARGET=4500
5
6 DATE=`date +%Y%m%d`
7 HOUR=`date +%H`
8 DATETITLE=`date +"%b %d, %Y"`
9 CSVFILE=$DATE$HOUR.csv
10 PNGFILE=$DATE$HOUR.png
11
12 curl -s
"http://www.wesm.ph/chart/export/luzon_dmd_csv_export.php?date=$DATE&hour=$HOUR"
| head -n 25 | tail -n 24 | awk -F ',' -v OFS=', ' -v "target=$TARGET"
'{print $1,target,$2,$3,$4,$5,$6,$7}' > $CSVFILE
13
14 gnuplot << EOF
15 set output "$PNGFILE"
16 set terminal png nocrop font small size 640,480
17 set xtics 1
18 set key outside center bottom Left reverse
19 set style data linespoints
20 set title "Luzon Market Demand (MW) - $DATETITLE"
21 set xlabel "HOURS"
22 set ylabel "MEGAWATT"
23 plot "$CSVFILE" using 1:2 title 'Target', "$CSVFILE" using 1:3
title 'Day Ahead Projection (DAP)', "$CSVFILE" using 1:4 title 'Hour
Ahead Projection (RTD)', "$CSVFILE" using 1:5 title 'Current Demand
(RTX)'
24 EOF
at line 4, change the TARGET to whatever megawatt your desired value....
at line 12, is the one fetching and reformatting the output and
inserted the "TARGET" value at column 2 for gnuplot to be able to
understand the format...
at line 14, gnuplot is the one creating the graph....
when you run that command.. it will create two files:
1) YYYYMMDDHH.csv
2) YYYYMMDDHH.png
where:
YYYY - year in 4 digits
MM - month in 2 digits
DD - day in 2 digits
HH - hour in 2 digits
change the file permission to executable (eg. chmod 700 wesm.sh) and
then run (eg. ./wesm.sh)
if you run on the next hour... it will create another set of two files
because of line 6 and 7...
if you want to automate the fetching... put it in cron job...
eg.
5 * * * * /path/to/wesm.sh
the above line it will fetch 5 minutes after an hour...
make sure you set your PATH and default folder properly in your cron
job to run curl and gnuplot properly or modify the script to have an
absolute path...
feel free to modify the script to suit your needs and feel free to
asks questions if you need further help as im pretty sure our experts
here in plug will be happy to assist you...
fooler.
wesm.sh
Description: Bourne shell script
_________________________________________________ Philippine Linux Users' Group (PLUG) Mailing List http://lists.linux.org.ph/mailman/listinfo/plug Searchable Archives: http://archives.free.net.ph

