Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 52 lines (42 sloc) 1.105 kb
72dbfe97 »
2009-04-04 update require paths
1 require 'sinatra'
2 require 'sequel'
ad4273bd »
2008-08-24 point class
3
34ef7b32 »
2008-08-24 post dynamic points
4 module Points
5 def self.data
2e964d97 »
2008-08-26 use sequel orm
6 @@data ||= make
7 end
8
9 def self.make
35d08254 »
2008-09-15 use database_url
10 db = Sequel.connect(ENV['DATABASE_URL'] || 'sqlite://rifgraf.db')
cf2f59f8 »
2008-08-31 connect to production db via env vars
11 make_table(db)
c78b9f6f »
2008-08-31 catch table already exists error
12 db[:points]
cf2f59f8 »
2008-08-31 connect to production db via env vars
13 end
14
15 def self.make_table(db)
2e964d97 »
2008-08-26 use sequel orm
16 db.create_table :points do
17 varchar :graph, :size => 32
18 varchar :value, :size => 32
0306d762 »
2008-09-14 rename date -> timestamp
19 timestamp :timestamp
2e964d97 »
2008-08-26 use sequel orm
20 end
332c5ec3 »
2008-09-14 Revert "don't rescue error on make table"
21 rescue Sequel::DatabaseError
22 # assume table already exists
34ef7b32 »
2008-08-24 post dynamic points
23 end
24 end
8c665ccd »
2008-08-24 init
25
df655f43 »
2008-09-09 about page (not quite finished)
26 get '/' do
27 erb :about
28 end
29
82516eca »
2008-08-25 bucket points by graph
30 get '/graphs/:id' do
e1185388 »
2008-09-16 404 when accessing a graph with no points
31 throw :halt, [ 404, "No such graph" ] unless Points.data.filter(:graph => params[:id]).count > 0
294d5e53 »
2008-08-31 switch to amstock
32 erb :graph, :locals => { :id => params[:id] }
8c665ccd »
2008-08-24 init
33 end
34
294d5e53 »
2008-08-31 switch to amstock
35 get '/graphs/:id/amstock_settings.xml' do
36 erb :amstock_settings, :locals => { :id => params[:id] }
37 end
38
39 get '/graphs/:id/data.csv' do
0306d762 »
2008-09-14 rename date -> timestamp
40 erb :data, :locals => { :points => Points.data.filter(:graph => params[:id]).reverse_order(:timestamp) }
34ef7b32 »
2008-08-24 post dynamic points
41 end
42
82516eca »
2008-08-25 bucket points by graph
43 post '/graphs/:id' do
0306d762 »
2008-09-14 rename date -> timestamp
44 Points.data << { :graph => params[:id], :timestamp => (params[:timestamp] || Time.now), :value => params[:value] }
34ef7b32 »
2008-08-24 post dynamic points
45 "ok"
8c665ccd »
2008-08-24 init
46 end
05b6bb9d »
2008-08-31 delete a graph
47
48 delete '/graphs/:id' do
f46cad44 »
2008-09-17 delete filtered to just current graph (thanks François Beausoleil)
49 Points.data.filter(:graph => params[:id]).delete
05b6bb9d »
2008-08-31 delete a graph
50 "ok"
51 end
Something went wrong with that request. Please try again.