Advertisement
devinteske

mmreclaim2gaph

Feb 9th, 2017
1,491
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Awk 1.66 KB | None | 0 0
  1. #!/usr/bin/awk -f
  2. BEGIN {
  3.     u = "[[:upper:]]"
  4.     l = "[[:lower:]]"
  5.     d = "[[:digit:]]"
  6.     # w   m  day        t  tz    y
  7.     # Wed Feb  8 12:02:50 PST 2017
  8.     w = m = u l l
  9.     day = "(" d "|" d d ")"
  10.     t = "[0-2]" d ":[0-5]" d ":[0-5]" d
  11.     tz = "[[:alnum:]+-]+"
  12.     y = d d d d
  13.     # Wed Feb  8 12:02:50 PST 2017
  14.     s = "[[:space:]]+"
  15.     date = w s m s day s t s tz s y
  16.     months = "Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec"
  17.     for (n = split(months, x) + 1; --n;) month[x[n]] = n - 1
  18. }
  19. function dump() {
  20.     if (!totals) return
  21.     totals = 0
  22.  
  23.     split(ft, tf, /:/)
  24.     hour = tf[1]
  25.     minute = tf[2]
  26.     second = tf[3]
  27.    
  28.     e = sprintf("gTime(%4u, %2u, %2u, %2u, %2u, %2u)",
  29.         fy, month[fm], fd, hour, minute, second)
  30.     reclaim_data = reclaim_data sprintf("\t\t\t[%s, %u],\n", e, reclaims)
  31.     freed_data = freed_data sprintf("\t\t\t[%s, %u],\n", e, freed)
  32. }
  33. $0 ~ "^" date "$" {
  34.     dump()
  35.  
  36.     # w   m    d t        tz  y
  37.     # Wed Feb  8 12:02:50 PST 2017
  38.     split(curdate = $0, f, s)
  39.     fw = f[1]
  40.     fm = f[2]
  41.     fd = f[3]
  42.     ft = f[4]
  43.     ftz = f[5]
  44.     fy = f[6]
  45.  
  46.     next
  47. }
  48. $1 == "Totals" {
  49.     totals = 1
  50.     reclaims = $5
  51.     freed = $7
  52. }
  53. END {
  54.     dump()
  55.  
  56.     print "\t{"
  57.     print "\t\tid: 'reclaims',"
  58.     print "\t\ttype: 'spline',"
  59.     print "\t\tname: 'Reclaims',"
  60.     print "\t\tzIndex: 5,"
  61.     print "\t\taddToNavigator: true,"
  62.     print "\t\tcolor: colors[0],"
  63.     printf "\t\tdata: [\n%s\t\t], // data\n", reclaim_data
  64.     print "\t}, // reclaims"
  65.  
  66.     print "\t{"
  67.     print "\t\tid: 'freed',"
  68.     print "\t\ttype: 'spline',"
  69.     print "\t\tname: 'Freed',"
  70.     print "\t\tzIndex: 4,"
  71.     print "\t\taddToNavigator: true,"
  72.     print "\t\tcolor: colors[1],"
  73.     printf "\t\tdata: [\n%s\t\t], // data\n", freed_data
  74.     print "\t}, // freed"
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement