Created
November 26, 2013 00:28
-
-
Save jasonblewis/7651396 to your computer and use it in GitHub Desktop.
how to get data into the dashing graph. using seconds from epoch is the trick.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Populate the graph with some random points | |
require 'tiny_tds' | |
require 'yaml' | |
config = YAML.load_file('lib/connection.yml') | |
client = TinyTds::Client.new(config["connection"]) | |
result = client.execute("USE " + config["database"]) | |
result.cancel | |
SCHEDULER.every '20s', :first_in => 1, allow_overlapping: false do |job| | |
result = client.execute("Set transaction isolation level read uncommitted; | |
select DATEDIFF(s, '1970-01-01 00:00:00',DATEADD(month,datediff(month,0,invoice_date),0) ) | |
month, round(sum(ship_line_pre_tax),0) as sales from so_order_and_ship_view | |
where invoice_date >= DATEADD(month,datediff(month,0,dateadd(m,-13,GETDATE())),0) and shipment_status in ('I','H') | |
group by DATEADD(month,datediff(month,0,invoice_date),0) | |
order by month") | |
saleshistory = result.each(:symbolize_keys => true) | |
result.cancel | |
saleshistory.each { |c| | |
c[:x]=c.delete :month | |
c[:y]=c.delete :sales | |
} | |
send_event('saleshistory', points: saleshistory) | |
# send_event('saleshistory', points: [{ x: -3100000, y: 195011 },{x: -2900000, y: 433345},{x: -2800000, y: 533345},{x: -2700000, y: 633345},{x: -2600000, y: 733345},{x: -2500000, y: 833345}]) | |
# send_event('saleshistory', points: [{ x: 1356998400, y: 195011}, | |
# { x: 1359676800, y: 433345}, | |
# { x: 1362096000, y: 533345}, | |
# { x: 1364774400, y: 633345}, | |
# { x: 1367366400, y: 733345}, | |
# { x: 1370044800, y: 833345}]) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment