Differences between current version and predecessor to the previous major change of CyberLeo/Scraps/GoogleCharts.
Other diffs: Previous Revision, Previous Author
Newer page: | version 5 | Last edited on Thursday, 22 July 2010 8:22:18 | by CyberLeo | |
Older page: | version 3 | Last edited on Sunday, 4 July 2010 20:57:50 | by CyberLeo | Revert |
@@ -22,5 +22,46 @@
printf "http://chart.apis.google.com/chart?cht=lc&chs=1000x256&chd=e:"; src_data | head -n 768 | while read time rtt
do
int_to_ev $(( ${rtt} / 10 ))
done
+
+min_avg_max() {
+ while read min avg max; do echo "$(int_to_ev "${min}") $(int_to_ev "${avg}") $(int_to_ev "${max}")"; done | \
+ awk 'BEGIN{min="";avg="";max=""}{min=sprintf("%s%s", min, $1); avg=sprintf("%s%s", avg, $2); max=sprintf("%s%s", max, $3)}END{printf("%s,%s,%s", min, avg, max)}'
+}
+
+data() {
+ date="${1:-2010-07-17}"
+ sql="
+SELECT
+ STRFTIME('%Y-%m-%d %H:%M', DATETIME((( STRFTIME('%s', time) / 900 ) * 900 ), 'unixepoch')) AS tt,
+ CAST(MIN(rtt) AS INTEGER) / 100 AS min,
+ CAST(AVG(rtt) AS INTEGER) / 100 AS avg,
+ CAST(MAX(rtt) AS INTEGER) / 100 AS max
+FROM rtt
+WHERE time BETWEEN '${date} 00:00:00' AND '${date} 23:59:59'
+GROUP BY tt;
+"
+ sqlite3 data.db3 "${sql}" | sed -e 's/^[^|]*|//' | tr ' ' '_' | tr '|' ' '
+}
+
+echo "http://chart.apis.google.com/chart?cht=lc&chs=1000x256&chco=00FF00,0000FF,FF0000&chd=e:$(data "2010-07-16"| min_avg_max)"
+</code>
+
+<code brush="awk">
+#!/usr/bin/awk -f
+BEGIN {
+ ev_map="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-."
+}
+
+function int_to_ev(number) {
+ if (int(number) != number) return "__"
+ if ( number < 0 ) number = 0
+ if ( number > 4095 ) number = 4095
+ hob = int( number / 64 ) + 1
+ lob = int( number % 64 ) + 1
+ return sprintf("%s%s", substr(ev_map, hob, 1), substr(ev_map, lob, 1))
+}
+{
+ printf("%s", int_to_ev($1))
+}
</code>
current version
Convert integers to Extended Value format (bourne shell):
ev_map="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-." int_to_ev() { int="${1}" if [ ! "${int}" ] then printf "__" return fi [ "${int}" -lt 0 ] && int=0 [ "${int}" -gt 4095 ] && int=4095 hob=$(( ( ${int} / 64 ) + 1 )) lob=$(( ( ${int} % 64 ) + 1 )) printf "%s%s" "$(echo "${ev_map}" | cut -c${hob})" "$(echo "${ev_map}" | cut -c${lob})" } src_data() { cat link-20100704.log | awk -F'\t' '{ print $2 "\t" $1 }' } printf "http://chart.apis.google.com/chart?cht=lc&chs=1000x256&chd=e:"; src_data | head -n 768 | while read time rtt do int_to_ev $(( ${rtt} / 10 )) done min_avg_max() { while read min avg max; do echo "$(int_to_ev "${min}") $(int_to_ev "${avg}") $(int_to_ev "${max}")"; done | \ awk 'BEGIN{min="";avg="";max=""}{min=sprintf("%s%s", min, $1); avg=sprintf("%s%s", avg, $2); max=sprintf("%s%s", max, $3)}END{printf("%s,%s,%s", min, avg, max)}' } data() { date="${1:-2010-07-17}" sql=" SELECT STRFTIME('%Y-%m-%d %H:%M', DATETIME((( STRFTIME('%s', time) / 900 ) * 900 ), 'unixepoch')) AS tt, CAST(MIN(rtt) AS INTEGER) / 100 AS min, CAST(AVG(rtt) AS INTEGER) / 100 AS avg, CAST(MAX(rtt) AS INTEGER) / 100 AS max FROM rtt WHERE time BETWEEN '${date} 00:00:00' AND '${date} 23:59:59' GROUP BY tt; " sqlite3 data.db3 "${sql}" | sed -e 's/^[^|]*|//' | tr ' ' '_' | tr '|' ' ' } echo "http://chart.apis.google.com/chart?cht=lc&chs=1000x256&chco=00FF00,0000FF,FF0000&chd=e:$(data "2010-07-16"| min_avg_max)"
#!/usr/bin/awk -f BEGIN { ev_map="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-." } function int_to_ev(number) { if (int(number) != number) return "__" if ( number < 0 ) number = 0 if ( number > 4095 ) number = 4095 hob = int( number / 64 ) + 1 lob = int( number % 64 ) + 1 return sprintf("%s%s", substr(ev_map, hob, 1), substr(ev_map, lob, 1)) } { printf("%s", int_to_ev($1)) }