Note: You are viewing an old version of this page. View the 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)"