Class: GRI::Cgraph
Constant Summary collapse
- TERMS =
{'sh'=>['Hour', 3600], 's8h'=>['8Hours', 8*3600], 'd'=>['Day', 24*3600], 'w'=>['Week', 7*24*3600], 'm'=>['Month', 31*24*3600], 'y'=>['Year', 366*24*3600]}
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(options = {}) ⇒ Cgraph
constructor
A new instance of Cgraph.
Constructor Details
#initialize(options = {}) ⇒ Cgraph
Returns a new instance of Cgraph.
10 11 12 |
# File 'lib/gri/cgraph.rb', line 10 def initialize ={} @options = end |
Instance Method Details
#call(env) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/gri/cgraph.rb', line 14 def call env req = Rack::Request.new env service_name, section_name, graph_name = Cast.parse_path_info env begin cast_dir = @options[:dir] gra_dir = "#{cast_dir}/#{service_name}" params = GParams.new params['r'] = "#{section_name}_num_#{graph_name}" params['z'] = 'gf' t = req.params['t'] || 'd' params['title'] = TERMS[t].first gr = Graph.new :dirs=>[gra_dir] etime = Time.now.to_i stime = etime - TERMS[t][1] img = gr.graph stime, etime, params [200, {'Content-type' => 'image/png'}, [img]] rescue [500, {}, []] end end |