View previous topic :: View next topic |
Author |
Message |
jonfr Veteran
Joined: 20 Jul 2003 Posts: 1008 Location: Denmark
|
Posted: Sat Mar 01, 2008 8:21 pm Post subject: How to run Ploticus to make plots [help needed] |
|
|
I am trying to setup an script that can count earthquakes for me. At first round I did try to use mrtg, but with no luck at all. I got pointed in the direction of Ploticus as it was pointed out that it might be better fit for what I am trying to do.
However, I have no idea how to set it up or how to configure it so that I can make the plots I need. Help is most welcomed with thanks in advance.
A users that was/is helping me did make this script.
Code: | #!/bin/bash
URL="http://hraun.vedur.is/ja/englishweb/eqlist.html"
YDATE=`date -d yesterday +%Y-%m-%d`
YQUAKES="quakes.${YDATE}"
lynx -dump ${URL} | grep ${YDATE} | sed 's/ .*\[[0-9][0-9]\]//g' | awk -F' ' '{print $1, $2, $6}' > ${YQUAKES}
exit 0 |
|
|
Back to top |
|
|
Wormo Retired Dev
Joined: 29 Nov 2004 Posts: 526 Location: SB County California
|
|
Back to top |
|
|
jonfr Veteran
Joined: 20 Jul 2003 Posts: 1008 Location: Denmark
|
Posted: Sat Mar 01, 2008 10:12 pm Post subject: |
|
|
I would need something like this. Something that can show me date, month, year differences in activate. Along with what sizes of earthquakes are most common during that time. The vbars example 4 would be nice for size of the earthquakes for instance while lines example 5 would do nice for the numbers of earthquakes.
I am new at this and I can't find a good documentation on this to work with.
Thanks for the help. |
|
Back to top |
|
|
Wormo Retired Dev
Joined: 29 Nov 2004 Posts: 526 Location: SB County California
|
Posted: Sat Mar 01, 2008 10:51 pm Post subject: |
|
|
Ok, let's start with the first type of graph.
Input: a file with the format generated by your script
Output: a histogram with earthquake magnitude along the x-axis, and y-axis shows how frequently earthquakes of each size occurred during the time period covered by your input file
Is that right? |
|
Back to top |
|
|
jonfr Veteran
Joined: 20 Jul 2003 Posts: 1008 Location: Denmark
|
Posted: Sat Mar 01, 2008 11:10 pm Post subject: |
|
|
Yes, that would be correct. I need to be able to track earthquake swarms and see how often they are and when they peak (both size and numbers of earthquakes) and start to slow down. But I also need to track the numbers of earthquakes over the day, unrelated to size. Too see how the day and the weeks develop in terms of how many earthquakes there are happening over the day, week, month and the year. |
|
Back to top |
|
|
Wormo Retired Dev
Joined: 29 Nov 2004 Posts: 526 Location: SB County California
|
Posted: Sun Mar 02, 2008 7:14 am Post subject: |
|
|
Ok so I translated the commas in the data file to periods with 'tr' (this program doesn't like European style decimals),
then used 'pl' command to make a histogram from it:
Code: |
lynx -dump ${URL} | grep ${YDATE} | sed 's/ .*\[[0-9][0-9]\]//g' |
awk -F' ' '{print $1, $2, $6}' | tr ',' '.' > ${YQUAKES}
pl -prefab dist x=3 bisize=0.2 barwidth=0.1 ygrid=yes \
title="Histogram of quake magnitudes" -ps -o ${YQUAKES}.ps data=${YQUAKES}
|
How is that for a start |
|
Back to top |
|
|
jonfr Veteran
Joined: 20 Jul 2003 Posts: 1008 Location: Denmark
|
Posted: Sun Mar 02, 2008 2:10 pm Post subject: |
|
|
This looks great, thanks. Now I just have to figure out how to make it run in cron. Maybe by creating sh file to run from. But where does the image file goes ?
This also teaches me how to work with this program. |
|
Back to top |
|
|
Wormo Retired Dev
Joined: 29 Nov 2004 Posts: 526 Location: SB County California
|
Posted: Sun Mar 02, 2008 7:01 pm Post subject: |
|
|
In my example, I just appended .ps to the data file name that you had generated earlier in the script
Code: |
-ps -o ${YQUAKES}.ps
|
Also note ploticus can output svg instead of postscript if you want,
Code: |
-svg -o ${YQUAKES}.svg
|
|
|
Back to top |
|
|
jonfr Veteran
Joined: 20 Jul 2003 Posts: 1008 Location: Denmark
|
Posted: Sun Mar 02, 2008 7:15 pm Post subject: |
|
|
I did try to run this as a sh script. But I got this error messages.
Code: | ./imo.earthquake.sh
Usage: grep [OPTION]... PATTERN [FILE]...
Try `grep --help' for more information.
./imo.earthquake.sh: line 4: ${YQUAKES}: ambiguous redirect
Error: either 'data' or 'inlinedata' must be specified.
|
I also prefer png files if possible and to be able to run this from cron so I can make a new image every 5 min. Thanks a lot for your help. As I am new to scripting and I have no idea what to do at this moment. |
|
Back to top |
|
|
Wormo Retired Dev
Joined: 29 Nov 2004 Posts: 526 Location: SB County California
|
Posted: Sun Mar 02, 2008 9:26 pm Post subject: |
|
|
I was unclear before... I was showing the part of your script that I had modified; you still need to keep the top part.
Here is the whole thing, including creation of a .png file since that's what you prefer:
Code: |
#!/bin/bash
URL="http://hraun.vedur.is/ja/englishweb/eqlist.html"
YDATE=`date -d yesterday +%Y-%m-%d`
YQUAKES="quakes.${YDATE}"
# date time magnitude
lynx -dump ${URL} | grep ${YDATE} | sed 's/ .*\[[0-9][0-9]\]//g' |
awk -F' ' '{print $1, $2, $6}' | tr ',' '.' > ${YQUAKES}
pl -prefab dist x=3 bisize=0.2 barwidth=0.1 ygrid=yes \
title="Histogram of quake magnitudes" -svg -o ${YQUAKES}.svg data=${YQUAKES}
convert ${YQUAKES}.svg ${YQUAKES}.png
exit 0
|
You will need imagemagick package compiled with svg useflag enabled to get 'convert' utility for this.
You can run this script from cron every 5 minutes if you want to, but most of the graphs will be pretty redundant; wouldn't you rather run it daily at about the same time each day? |
|
Back to top |
|
|
jonfr Veteran
Joined: 20 Jul 2003 Posts: 1008 Location: Denmark
|
Posted: Sun Mar 02, 2008 11:01 pm Post subject: |
|
|
Thanks.
The reason why want to run it every 5 min is the fact from time to time there are earthquakes swarms what make 10 to 30 earthquakes pr hour, sometimes more and sometimes less. This way it is easy to keep track of them and too see how they are progressing. I am also looking for an plot to see how many earthquakes there are on hourly basic not based on size.
Can I change ${YQUAKES}.svg to quakeplot.svg so that the name is static and not day on day basic. (Found it).
I also wonder what I need to show the change pr hour.
Here is my attempt to make an script that can tell me how many earthquakes pr hour there are. It crashes and doesn't work, so I guess that I am doing some really wrong.
Code: | #!/bin/bash
URL="http://hraun.vedur.is/ja/englishweb/eqlist.html"
YDATE=`date -d yesterday +%Y-%m-%d`
YQUAKES="quakes.time"
# date time magnitude
lynx -dump ${URL} | grep ${YDATE} | sed 's/ .*\[[0-9][0-9]\]//g' |
awk -F' ' '{print $1, $2, $6}' | tr ',' '.' > ${YQUAKES}
pl -prefab chron data=data16 x=3 tab=hour datefmt=yyyy-mm-dd xinc="1 day" \
barwidth=line stubfmt=YYYYmm unittype=datetime timefld=2 \
title="Histogram of quakes hour" -svg -o ${YQUAKES}.svg data=${YQUAKES}
convert ${YQUAKES}.svg ${YQUAKES}.png
exit 0
|
To clear up what I am trying to, here is the closest thing I want to do. Except that I want count size, number and how many there are over 1 hour period over two days. In one plot or many isn't an issue for me. I also need to learn how to do this so I can write my own scripts, but I am bad at bash.
Last edited by jonfr on Mon Mar 03, 2008 12:31 am; edited 1 time in total |
|
Back to top |
|
|
jonfr Veteran
Joined: 20 Jul 2003 Posts: 1008 Location: Denmark
|
Posted: Sun Mar 02, 2008 11:57 pm Post subject: |
|
|
I also got an interesting problem with the plot when there are over 200 earthquakes in the list like there are at the moment. When that is the case, I get just two bars, one big and one really small if I change yesterday to today. |
|
Back to top |
|
|
Wormo Retired Dev
Joined: 29 Nov 2004 Posts: 526 Location: SB County California
|
Posted: Wed Mar 12, 2008 4:56 am Post subject: |
|
|
Sorry to take a while to get back to you... have you got a working script for earthquakes/hour yet, or should I give a whack at fixing what you posted earlier? |
|
Back to top |
|
|
jonfr Veteran
Joined: 20 Jul 2003 Posts: 1008 Location: Denmark
|
Posted: Wed Mar 12, 2008 8:35 pm Post subject: |
|
|
I haven't figured out how to make an daily script with ploticus, to figure out the size. But I did manage to get daily count script up and running. It can be seen here. That uses mrtg. But the attempt to make an daily script results in failure, with everything collecting in one place on the plot. |
|
Back to top |
|
|
|