Advertisement
Guest User

Code to generate graphic of Mefi favoriting data

a guest
Dec 2nd, 2011
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.44 KB | None | 0 0
  1. #!/bin/sh
  2. # extract postid and datestamp (in secs since epoch)
  3. sed 1,2d postdata_mefi.txt \
  4. |awk -F '\t' '$1 ~ /^980..$/ {print $1,$3}' \
  5. |while read postid datestamp; do
  6. echo $postid $(date -d "$datestamp" +%s);
  7. done \
  8. |sort -k1b,1 \
  9. >posts
  10. sed 1,2d favoritesdata.txt \
  11. |awk -F '\t' '$4 == 2 && $6 ~ /^980..$/ {print $6,$7}' \
  12. |while read postid datestamp; do
  13. echo $postid $(date -d "$datestamp" +%s);
  14. done \
  15. |sort -k1b,1 \
  16. >favs
  17.  
  18. # convert fav timestamps to time-since-post, first 24 hours only,
  19. # bin into 30-minute bins
  20. join -j1 posts favs \
  21. |awk '{print $1, int(($3-$2)/(30*60))}' \
  22. |sort -k1b,1 -k2 -n \
  23. |uniq -c \
  24. |awk '$3 < 48 {printf "%d:%02d %d\n",$2,$3,$1}' \
  25. |sort -k1b,1 \
  26. >x
  27. # add zero lines
  28. seq 98000 98099 \
  29. |while read n; do seq -f "$n:%02.0f" 0 47; done \
  30. |join -j1 -a1 - x \
  31. |awk '$2 == "" {$2=0} {print}' \
  32. >data
  33.  
  34. # make graphs
  35. seq 98000 98099 |while read n; do
  36. echo $n >&2
  37. (cat <<EOF
  38. %!PS-Adobe-3.0 EPSF-3.0
  39. %%BoundingBox: 0 0 49 49
  40. 1 setlinewidth
  41. 0.5 0.5 translate
  42. gsave
  43. 0 0 0 setrgbcolor
  44. 1 1 translate
  45. /bar { exch 0 moveto 0 exch rlineto stroke } def
  46. EOF
  47. grep "^$n:" data |sed -e 's,^.*:,,' -e 's,$, bar,'
  48. cat <<EOF
  49. grestore
  50. 0.5 0.5 0.5 setrgbcolor
  51. 0 0 moveto 0 48 lineto 48 48 lineto 48 0 lineto closepath stroke
  52. %%EOF
  53. EOF
  54. ) |convert eps:- $n.png
  55. done
  56. montage -geometry +1+1 980*.png montage.png
  57.  
  58.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement