{"id":32,"date":"2007-10-07T22:01:26","date_gmt":"2007-10-08T02:01:26","guid":{"rendered":"http:\/\/ryepup.unwashedmeme.com\/blog\/2007\/10\/07\/graphing-my-fuel-efficiency-with-lisp-and-vecto\/"},"modified":"2007-10-08T01:18:05","modified_gmt":"2007-10-08T05:18:05","slug":"graphing-my-fuel-efficiency-with-lisp-and-vecto","status":"publish","type":"post","link":"http:\/\/ryepup.unwashedmeme.com\/blog\/2007\/10\/07\/graphing-my-fuel-efficiency-with-lisp-and-vecto\/","title":{"rendered":"Graphing my fuel efficiency with lisp and Vecto"},"content":{"rendered":"<p>Gonna try to be quick about this, as there&#8217;s chicken on the grill.  I took a break from Team Fortress 2 to play some more with <a href=\"http:\/\/www.xach.com\/lisp\/vecto\/\">Vecto<\/a>, another fine library from Xach.  I started another post about last weekend&#8217;s lisp playing, but this one got finished first.<\/p>\n<p>I&#8217;ve been tracking my fuel efficiency for a few weeks, noting the date, gallons purchased, price per gallon, and miles since last refill.  You can&#8217;t control what you don&#8217;t measure.  I had a ruby script keeping up with these as YAML and then giving me some handy stats, but I&#8217;m trying to gain some levels in lisp, so I decided to fire up slime and make some graphs.<\/p>\n<p>The graph isn&#8217;t pretty, but here&#8217;s my miles per gallon:<\/p>\n<p><a href=\"http:\/\/ryepup.unwashedmeme.com\/blog\/wp-content\/uploads\/2007\/10\/graph.png\" title=\"graph.png\"><img decoding=\"async\" src=\"http:\/\/ryepup.unwashedmeme.com\/blog\/wp-content\/uploads\/2007\/10\/graph.thumbnail.png\" alt=\"graph.png\" \/><\/a><\/p>\n<p>As usual, I pulled up my favorite <a href=\"http:\/\/www.gigamonkeys.com\/book\/\">lisp tutorial<\/a> and <a href=\"irc:\/\/freenode.net\/lisp\">#lisp<\/a>, and after a few hours, I had a graph.  Given my logging fetish, I imagine I&#8217;ll be growing the graphing capabilities in the future.<\/p>\n<p>Right now, the implementation is a little weird.  I have an class for a fuel entry, and then convert the date to a <a href=\"http:\/\/www.lisp.org\/HyperSpec\/Body\/glo_u.html#universal_time\">universal-time<\/a> using <a href=\"http:\/\/www.cliki.net\/net-telent-date\">net.telent.date<\/a>.  Then in my graphing function I use the universal time for the x values, and any number of functions for the y values (defaulting to #&#8217;mpg-of).  In order to get the graph to take up most of the canvas, I then normalize the x and y values, so the minimum is 0 and the maximum is 1, and then scale the number to fit the canvas size before drawing.<\/p>\n<p>I still consider myself a lisp beginner, and there are some bits I&#8217;m sure could be more efficient, but it works for now.  Those interested in the code can get it here: <a href=\"http:\/\/ryepup.unwashedmeme.com\/files\/fuelman.tar.gz\" title=\"fuelman.tar.gz\">fuelman.tar.gz<\/a>, and any feedback in comments is much appreciated.<\/p>\n<p><strong>Update<\/strong>: Played with it a lot more, simplified my normalization crap a lot using loop instead of mapcar, and pulled it into a couple of objects: graph, graph-series, and fuel-graph-series.\u00c2\u00a0 Also linked the source above as a proper .tar.gz file, after reading <a href=\"http:\/\/wordpress.org\/support\/topic\/119972\">how to do that in wordpress<\/a>.\u00c2\u00a0 The aesthetics are still terrible, but it&#8217;s getting there:<\/p>\n<p><a href=\"http:\/\/ryepup.unwashedmeme.com\/blog\/wp-content\/uploads\/2007\/10\/graph1.png\" title=\"graph1.png\"><img decoding=\"async\" src=\"http:\/\/ryepup.unwashedmeme.com\/blog\/wp-content\/uploads\/2007\/10\/graph1.thumbnail.png\" alt=\"graph1.png\" \/><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Gonna try to be quick about this, as there&#8217;s chicken on the grill. I took a break from Team Fortress 2 to play some more with Vecto, another fine library from Xach. I started another post about last weekend&#8217;s lisp playing, but this one got finished first. I&#8217;ve been tracking my fuel efficiency for a [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,15,8,16],"tags":[],"class_list":["post-32","post","type-post","status-publish","format-standard","hentry","category-code-snippet","category-lisp","category-open-source","category-vecto"],"_links":{"self":[{"href":"http:\/\/ryepup.unwashedmeme.com\/blog\/wp-json\/wp\/v2\/posts\/32","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/ryepup.unwashedmeme.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/ryepup.unwashedmeme.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/ryepup.unwashedmeme.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/ryepup.unwashedmeme.com\/blog\/wp-json\/wp\/v2\/comments?post=32"}],"version-history":[{"count":0,"href":"http:\/\/ryepup.unwashedmeme.com\/blog\/wp-json\/wp\/v2\/posts\/32\/revisions"}],"wp:attachment":[{"href":"http:\/\/ryepup.unwashedmeme.com\/blog\/wp-json\/wp\/v2\/media?parent=32"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/ryepup.unwashedmeme.com\/blog\/wp-json\/wp\/v2\/categories?post=32"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/ryepup.unwashedmeme.com\/blog\/wp-json\/wp\/v2\/tags?post=32"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}