gfspark 0.1.2 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -17,3 +17,4 @@ test/version_tmp
17
17
  tmp
18
18
  vendor/
19
19
  .gfspark
20
+ .ruby-version
data/README.md CHANGED
@@ -20,7 +20,8 @@ Or install it yourself as:
20
20
 
21
21
  ## ScreenShots
22
22
 
23
- <img src='https://github.com/yuroyoro/gfspark/raw/master/images/gfspark_screenshot.png' width='600'/>
23
+ <img src='https://github.com/yuroyoro/gfspark/raw/master/images/gfspark_screenshot1.png' width='600'/>
24
+ <img src='https://github.com/yuroyoro/gfspark/raw/master/images/gfspark_screenshot2.png' width='600'/>
24
25
 
25
26
  ## Usage
26
27
 
@@ -37,13 +38,14 @@ Or install it yourself as:
37
38
  --url=VALUE Your GrowthForecast URL
38
39
  -u, --user=USER
39
40
  -p, --pass=PASS
40
- -t=VALUE Range of Graph
41
+ -t, --type=VALUE Range of Graph
41
42
  --gmode=VALUE graph mode: gauge or subtract (default is gauge)
42
43
  --from=VALUE Start date of graph (2011/12/08 12:10:00) required if t=c or sc
43
44
  --to=VALUE End date of graph (2011/12/08 12:10:00) required if t=c or sc
44
45
  -h, --height=VALUE graph height (default 10
45
46
  -w, --width=VALUE graph width (default is deteced from $COLUMNS)
46
47
  -c, --color=VALUE Color of graph bar (black/red/green/yellow/blue/magenta/cyan/white)
48
+ -y, --y-axis-label=VALUE Show y axis labels (hide/show/simple: default is show)
47
49
  -n, --non-fullwidth-font Show bar symbol as fullwidth
48
50
  --sslnoverify don't verify SSL
49
51
  --sslcacert=v SSL CA CERT
@@ -61,7 +63,7 @@ Or install it yourself as:
61
63
  s8h : 8 Hours (1min avg)
62
64
  4h : 4 Hours (5min avg)
63
65
  s4h : 4 Hours (1min avg)
64
- h : Hour (5min avg),
66
+ h : Hour (5min avg)
65
67
  sh : Hour (1min avg)
66
68
  n : Half Day (5min avg)
67
69
  sn : Half Day (1min avg)
@@ -70,7 +72,7 @@ Or install it yourself as:
70
72
 
71
73
  gfspark does not supports "COMPLEX GRAPH".
72
74
  if graph output is broken, try `--non-fullwidth-font` option.
73
- For example, your Terminal font is "Rickty", then it'll be fix graph output problem.
75
+ For example, if your Terminal font is "Rickty", then it'll be fix graph output problem.
74
76
 
75
77
  ## Configuration
76
78
 
Binary file
Binary file
data/lib/gfspark/app.rb CHANGED
@@ -29,6 +29,14 @@ class Gfspark::App
29
29
  return
30
30
  end
31
31
 
32
+ @options[:t] ||= "d"
33
+ unless RANGES.keys.include?(@options[:t])
34
+ puts "Unknown graph range t=#{@options[:t]}"
35
+ @valid = false
36
+ return
37
+ end
38
+
39
+ @options[:y_axis_label] ||= "show"
32
40
  @valid = true
33
41
  detect_width_and_height!
34
42
  set_ssl_options!
@@ -64,7 +64,7 @@ module Gfspark::Config
64
64
  puts <<-MSG
65
65
 
66
66
  -t option detail:
67
- #{Gfspark::Graph::RANGE_DEFS.map{|k,v| sprintf(" %3s : %s", k, v)}.join("\n")}
67
+ #{Gfspark::Graph::RANGE_DEFS.map{|k,v,_| sprintf(" %3s : %s", k, v)}.join("\n")}
68
68
  MSG
69
69
  end
70
70
 
@@ -76,7 +76,7 @@ module Gfspark::Config
76
76
  def detect_width_and_height!
77
77
  @stty_height, @stty_width = `stty size`.split.map(&:to_i)
78
78
 
79
- width = ((@stty_width - 12) / 2).floor
79
+ width = ((@stty_width - 18) / 2).floor
80
80
  @options[:width] ||= width
81
81
  @width = @options[:width].to_i
82
82
  height = @options[:height].to_i
@@ -116,13 +116,14 @@ module Gfspark::Config
116
116
  opts.on("--url=VALUE", "Your GrowthForecast URL"){|v| @options[:url] = v}
117
117
  opts.on('-u=USER', '--user=USER'){|v| @options[:username] = v }
118
118
  opts.on('-p=PASS', '--pass=PASS'){|v| @options[:password] = v }
119
- opts.on("-t=VALUE", "Range of Graph"){|v| @options[:t] = v}
119
+ opts.on("-t=VALUE", "--type=VALUE", "Range of Graph"){|v| @options[:t] = v}
120
120
  opts.on("--gmode=VALUE", "graph mode: gauge or subtract (default is gauge)"){|v| @options[:gmode] = v}
121
121
  opts.on("--from=VALUE", "Start date of graph (2011/12/08 12:10:00) required if t=c or sc"){|v| @options[:from] = v}
122
122
  opts.on("--to=VALUE", "End date of graph (2011/12/08 12:10:00) required if t=c or sc"){|v| @options[:to] = v}
123
123
  opts.on("-h=VALUE", "--height=VALUE", "graph height (default 10"){|v| @options[:height] = v}
124
124
  opts.on("-w=VALUE", "--width=VALUE", "graph width (default is deteced from $COLUMNS)"){|v| @options[:width] = v}
125
125
  opts.on("-c=VALUE", "--color=VALUE", "Color of graph bar (#{COLORS.join("/")})"){|v| @options[:color] = v if COLORS.include?(v.to_sym)}
126
+ opts.on("-y=VALUE", "--y-axis-label=VALUE", "Show y axis labels (hide/show/simple: default is show)"){|v| @options[:y_axis_label] = v}
126
127
  opts.on("-n", "--non-fullwidth-font", "Show bar symbol as fullwidth"){ @options[:non_fullwidth_font] = true }
127
128
  opts.on("--sslnoverify", "don't verify SSL"){|v| @options[:sslNoVerify] = true}
128
129
  opts.on("--sslcacert=v", "SSL CA CERT"){|v| @options[:sslCaCert] = v}
data/lib/gfspark/graph.rb CHANGED
@@ -21,19 +21,33 @@ module Gfspark::Graph
21
21
  }
22
22
  end
23
23
 
24
+ def seconds_to_label(sec)
25
+ t = Time.at(sec).utc
26
+ d, h, m, s = t.day.pred, t.hour, t.min, t.sec
27
+ res = ""
28
+ res += "#{d}day" unless d.zero?
29
+ res += "#{h}h" unless h.zero? && (d.zero? || (m.zero? && s.zero?))
30
+ res += "#{m}min" unless m.zero? && ((d.zero? && h.zero?) || s.zero?)
31
+ res += "#{s}sec" unless s.zero?
32
+ return res
33
+ end
34
+
24
35
  def render(json, summary, url = nil)
25
- rows = json['rows']
26
- max = rows.flatten.compact.max
36
+ rows = json['rows']
37
+ step = json['step'].to_i
38
+ max = rows.flatten.compact.max
27
39
  max_val = (max / 8).ceil * 8
28
- unit = max_val / (@height * 8).to_f
40
+ unit = max_val / (@height * 8).to_f
29
41
 
30
- s = Time.at(json["start_timestamp"].to_i).strftime("%Y-%m-%d %H:%M:%S")
31
- e = Time.at(json["end_timestamp"].to_i).strftime("%Y-%m-%d %H:%M:%S")
42
+ start_timestamp = json["start_timestamp"].to_i
43
+ end_timestamp = json["end_timestamp"].to_i
44
+ s = Time.at(start_timestamp).localtime.strftime("%Y-%m-%d %H:%M:%S")
45
+ e = Time.at(end_timestamp ).localtime.strftime("%Y-%m-%d %H:%M:%S")
32
46
 
33
47
  puts " #{blue(json["column_names"].first)}"
34
48
  puts " #{yellow(url)}"
35
49
  puts ""
36
- puts " #{period_title} #{s} - #{e}"
50
+ puts " #{period_title} #{s} - #{e} step: /#{seconds_to_label(step)}"
37
51
  puts ""
38
52
 
39
53
  result = []
@@ -45,15 +59,51 @@ module Gfspark::Graph
45
59
  if color = @options[:color]
46
60
  line = Term::ANSIColor.send(color, line)
47
61
  end
48
- result << "#{sprintf("%10s", label)} | #{line} |"
62
+ result << "#{sprintf("%10s", label)} |#{line}|"
49
63
  end
50
64
  puts result.join("\n")
65
+
66
+ render_y_axis_labels(rows, start_timestamp, step)
67
+
51
68
  puts ""
52
69
 
53
70
  sums = summary.first.last
54
71
  puts " #{sprintf("cur: %.1f ave: %.1f max: %.1f min %.1f", *sums)}"
55
72
  end
56
73
 
74
+ def render_y_axis_labels(rows, start_timestamp, step)
75
+ y_axis_labels = rows.length.times.select{|n| n % 4 == 0}. map{|n|
76
+ t = Time.at(start_timestamp + (n * step)).localtime
77
+ sprintf("%-8s", to_axis_label(t))
78
+ }.join
79
+ y_axis_arrows= rows.length.times.select{|n| n % 4 == 0}. map{|n|
80
+ " / "
81
+ }.join
82
+
83
+ case @options[:y_axis_label]
84
+ when "show"
85
+ puts sprintf("%10s%s", "", y_axis_arrows)
86
+ puts sprintf("%10s%s", "", y_axis_labels)
87
+ when "simple"
88
+ puts sprintf("%10s%s", "", y_axis_labels)
89
+ end
90
+ end
91
+
92
+ def axis_unit
93
+ @axis_unit ||= RANGE_DEFS.find{|_| _.first == @options[:t]}.last
94
+ end
95
+
96
+ def to_axis_label(t)
97
+ case axis_unit
98
+ when :min then t.strftime("%M")
99
+ when :hour then t.strftime("%H:%M")
100
+ when :day then t.strftime("%d")
101
+ when :week then t.strftime("%a")
102
+ when :month then t.strftime("%m")
103
+ else t.strftime("%H:%M")
104
+ end
105
+ end
106
+
57
107
  def period_title
58
108
  case @options[:t]
59
109
  when "c", "sc" then sprintf("%s to %s", @options[:from], @options[:to])
@@ -62,25 +112,26 @@ module Gfspark::Graph
62
112
  end
63
113
 
64
114
  RANGE_DEFS = [
65
- ["y" , 'Year (1day avg)'],
66
- ["m" , 'Month (2hour avg)'],
67
- ["w" , 'Week (30min avg)'],
68
- ["3d" , '3 Days (5min avg)'],
69
- ["s3d" , '3 Days (5min avg)'],
70
- ["d" , 'Day (5min avg)'],
71
- ["sd" , 'Day (1min avg)' ],
72
- ["8h" , '8 Hours (5min avg)'],
73
- ["s8h" , '8 Hours (1min avg)' ],
74
- ["4h" , '4 Hours (5min avg)'],
75
- ["s4h" , '4 Hours (1min avg)' ],
76
- ["h" , 'Hour (5min avg), '],
77
- ["sh" , 'Hour (1min avg)' ],
78
- ["n" , 'Half Day (5min avg)'],
79
- ["sn" , 'Half Day (1min avg)'],
80
- ["c" , "Custom (5min avg)"],
81
- ["sc" , "Custom (1min avg)"]
115
+ # option, label, y-axis unit
116
+ ["y" , 'Year (1day avg)' , :month],
117
+ ["m" , 'Month (2hour avg)' , :day ],
118
+ ["w" , 'Week (30min avg)' , :week ],
119
+ ["3d" , '3 Days (5min avg)' , :hour ],
120
+ ["s3d" , '3 Days (5min avg)' , :hour ],
121
+ ["d" , 'Day (5min avg)' , :hour ],
122
+ ["sd" , 'Day (1min avg)' , :hour ],
123
+ ["8h" , '8 Hours (5min avg)' , :hour ],
124
+ ["s8h" , '8 Hours (1min avg)' , :hour ],
125
+ ["4h" , '4 Hours (5min avg)' , :hour ],
126
+ ["s4h" , '4 Hours (1min avg)' , :hour ],
127
+ ["h" , 'Hour (5min avg)' , :min ],
128
+ ["sh" , 'Hour (1min avg)' , :min ],
129
+ ["n" , 'Half Day (5min avg)' , :hour ],
130
+ ["sn" , 'Half Day (1min avg)' , :hour ],
131
+ ["c" , "Custom (5min avg)" , :min ],
132
+ ["sc" , "Custom (1min avg)" , :min ]
82
133
  ]
83
- RANGES = Hash[*RANGE_DEFS.flatten]
134
+ RANGES = Hash[*RANGE_DEFS.map{|k,v,_| [k,v]}.flatten]
84
135
 
85
136
  def range_arg?(t)
86
137
  RANGES.keys.include? t
@@ -1,4 +1,4 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  module Gfspark
3
- VERSION = "0.1.2"
3
+ VERSION = "0.2.0"
4
4
  end
metadata CHANGED
@@ -1,75 +1,57 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: gfspark
3
- version: !ruby/object:Gem::Version
4
- hash: 31
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
5
  prerelease:
6
- segments:
7
- - 0
8
- - 1
9
- - 2
10
- version: 0.1.2
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Tomohito Ozaki
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2013-05-29 00:00:00 +09:00
19
- default_executable:
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
22
- prerelease: false
12
+ date: 2013-05-30 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
23
15
  name: json
24
- type: :runtime
25
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: &70140268416000 !ruby/object:Gem::Requirement
26
17
  none: false
27
- requirements:
28
- - - ">="
29
- - !ruby/object:Gem::Version
30
- hash: 3
31
- segments:
32
- - 0
33
- version: "0"
34
- version_requirements: *id001
35
- - !ruby/object:Gem::Dependency
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
36
23
  prerelease: false
24
+ version_requirements: *70140268416000
25
+ - !ruby/object:Gem::Dependency
37
26
  name: term-ansicolor
38
- type: :runtime
39
- requirement: &id002 !ruby/object:Gem::Requirement
27
+ requirement: &70140268415440 !ruby/object:Gem::Requirement
40
28
  none: false
41
- requirements:
42
- - - ">="
43
- - !ruby/object:Gem::Version
44
- hash: 3
45
- segments:
46
- - 0
47
- version: "0"
48
- version_requirements: *id002
49
- - !ruby/object:Gem::Dependency
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
50
34
  prerelease: false
35
+ version_requirements: *70140268415440
36
+ - !ruby/object:Gem::Dependency
51
37
  name: rake
52
- type: :development
53
- requirement: &id003 !ruby/object:Gem::Requirement
38
+ requirement: &70140268414960 !ruby/object:Gem::Requirement
54
39
  none: false
55
- requirements:
56
- - - ">="
57
- - !ruby/object:Gem::Version
58
- hash: 3
59
- segments:
60
- - 0
61
- version: "0"
62
- version_requirements: *id003
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *70140268414960
63
47
  description: GrowthForecast on Terminal
64
- email:
48
+ email:
65
49
  - ozaki@yuroyoro.com
66
- executables:
50
+ executables:
67
51
  - gfspark
68
52
  extensions: []
69
-
70
53
  extra_rdoc_files: []
71
-
72
- files:
54
+ files:
73
55
  - .gitignore
74
56
  - Gemfile
75
57
  - LICENSE.txt
@@ -78,45 +60,36 @@ files:
78
60
  - bin/gfspark
79
61
  - gfspark.gemspec
80
62
  - images/gfspark_screenshot.png
63
+ - images/gfspark_screenshot1.png
64
+ - images/gfspark_screenshot2.png
81
65
  - lib/gfspark.rb
82
66
  - lib/gfspark/app.rb
83
67
  - lib/gfspark/config.rb
84
68
  - lib/gfspark/connection.rb
85
69
  - lib/gfspark/graph.rb
86
70
  - lib/gfspark/version.rb
87
- has_rdoc: true
88
71
  homepage: http://yuroyoro.github.io/gfspark/
89
72
  licenses: []
90
-
91
73
  post_install_message:
92
74
  rdoc_options: []
93
-
94
- require_paths:
75
+ require_paths:
95
76
  - lib
96
- required_ruby_version: !ruby/object:Gem::Requirement
77
+ required_ruby_version: !ruby/object:Gem::Requirement
97
78
  none: false
98
- requirements:
99
- - - ">="
100
- - !ruby/object:Gem::Version
101
- hash: 3
102
- segments:
103
- - 0
104
- version: "0"
105
- required_rubygems_version: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ! '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ required_rubygems_version: !ruby/object:Gem::Requirement
106
84
  none: false
107
- requirements:
108
- - - ">="
109
- - !ruby/object:Gem::Version
110
- hash: 3
111
- segments:
112
- - 0
113
- version: "0"
85
+ requirements:
86
+ - - ! '>='
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
114
89
  requirements: []
115
-
116
90
  rubyforge_project:
117
- rubygems_version: 1.5.2
91
+ rubygems_version: 1.8.10
118
92
  signing_key:
119
93
  specification_version: 3
120
94
  summary: GrowthForecast Graph viewer on Terminal
121
95
  test_files: []
122
-