Shopify / dashing

The exceptionally handsome dashboard framework in Ruby and Coffeescript.
http://shopify.github.com/dashing/
MIT License
10.98k stars 1.18k forks source link

history not reused #185

Open jaisingh opened 11 years ago

jaisingh commented 11 years ago

currently using dashing (1.2.0) , the history.yml is generated but not reused on restart of sinatra. The file is read in but never transmitted or appended to which leads to the next event in send_events overwriting that particular key and history starting over again.

Also the data stored in settings.history['key'] cannot be json decoded by ruby and is not usable by the job.

Data as encoded in history.yml file:

1.9.3-p448 :002 > s = YAML.load_file('history.yml')
 => {"na_ccu_graph"=>"data: {\"in_match_ccu\":[{\"x\":1376159050,\"y\":179},{\"x\":1376159111,\"y\":197}],\"total_ccu\":[{\"x\":1376159050,\"y\":183},{\"x\":1376159111,\"y\":200}],\"id\":\"na_ccu_graph\",\"updatedAt\":1376159117}\n\n", "eu_ccu_graph"=>"data: {\"in_match_ccu\":[{\"x\":1376159053,\"y\":131},{\"x\":1376159114,\"y\":121}],\"total_ccu\":[{\"x\":1376159053,\"y\":134},{\"x\":1376159114,\"y\":122}],\"id\":\"eu_ccu_graph\",\"updatedAt\":1376159117}\n\n", "na_error_meter"=>"data: {\"current\":\"5270\",\"last\":\"5213\",\"id\":\"na_error_meter\",\"updatedAt\":1376159117}\n\n", "eu_error_meter"=>"data: {\"current\":\"480\",\"last\":\"479\",\"id\":\"eu_error_meter\",\"updatedAt\":1376159117}\n\n", "widget_id"=>"data: {\"id\":\"widget_id\",\"updatedAt\":1376159103}\n\n"} 

Class of key:

1.9.3-p448 :006 > s['na_error_meter'].class
 => String

JSON parse error:

1.9.3-p448 :009 > JSON.parse(s['na_error_meter'])
JSON::ParserError: 746: unexpected token at 'data: {"current":"5270","last":"5213","id":"na_error_meter","updatedAt":1376159117}
pal commented 10 years ago

You need to remove the leading identifier (in this case data:) that prepends the JSON string.

Try: JSON.parse(s['na_error_meter'].sub(/^[\w:]*/,""))

Or, if you feel quesy about not removing the space as well: JSON.parse(s['na_error_meter'].sub(/^[\w\s:]*/,""))