gcstats 1.0.3 → 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -9,9 +9,8 @@ Also available online as a web app: <http://gcstats.heroku.com/>
9
9
 
10
10
  ## Install ##
11
11
 
12
- To install, change directory to where you have extracted the gcstats source files and issue:
12
+ From [RubyGems.org](http://rubygems.org/gems/gcstats):
13
13
 
14
- gem build gcstats.gemspec
15
14
  gem install gcstats
16
15
 
17
16
  ## Use ##
@@ -23,8 +23,10 @@ if File.extname(in_fn) == '.zip'
23
23
  break
24
24
  end
25
25
  }
26
+ elsif in_fn == '-'
27
+ data = $stdin.read
26
28
  else
27
- data = (in_fn == '-') ? $stdin.read : File.read(in_fn)
29
+ data = File.read(in_fn)
28
30
  out_fn ||= File.basename(in_fn, File.extname(in_fn)) + '.html'
29
31
  end
30
32
 
@@ -45,5 +47,9 @@ if ARGV[1].nil? && caches[0] && caches[0].logs[0]
45
47
  out_fn += '.html'
46
48
  end
47
49
 
48
- open(out_fn, 'w') {|f| f.write(html) }
49
- puts "wrote #{out_fn}" if test(?s, out_fn)
50
+ if out_fn.nil?
51
+ print html
52
+ else
53
+ open(out_fn, 'w') {|f| f.write(html) }
54
+ puts "wrote #{out_fn}" if test(?s, out_fn)
55
+ end
@@ -42,20 +42,40 @@
42
42
  <tr>
43
43
  <th class="l">Oldest cache</th>
44
44
  <td>
45
- <a href="<%=h oldest_cache_found.url %>"><%=h oldest_cache_found.name %></a>
45
+ <%= link_to_cache oldest_cache_found %>
46
46
  (<%=h oldest_cache_found.published.strftime('%Y-%m-%d') %>)
47
47
  </td>
48
48
  </tr>
49
49
  <tr>
50
50
  <th class="l">Newest cache</th>
51
51
  <td>
52
- <a href="<%=h newest_cache_found.url %>"><%=h newest_cache_found.name %></a>
52
+ <%= link_to_cache newest_cache_found %>
53
53
  (<%=h newest_cache_found.published.strftime('%Y-%m-%d') %>)
54
54
  </td>
55
55
  </tr>
56
56
  </table>
57
57
  <%# }}} %>
58
58
 
59
+ <%# {{{ milestones %>
60
+ <table class="highlight">
61
+ <caption>Milestones</caption>
62
+ <tr>
63
+ <th>Milestone</th>
64
+ <th>Date</th>
65
+ <th>Days Passed</th>
66
+ <th>Cache</th>
67
+ </tr>
68
+ <% milestones.each_with_index {|milestone, i| %>
69
+ <tr>
70
+ <td><%= milestone[:milestone] %></td>
71
+ <td><%= milestone[:log].date.strftime('%Y-%m-%d') %></td>
72
+ <td class="r"><%= i == 0 ? '-' : (milestone[:log].date - milestones[i - 1][:log].date).to_i %>
73
+ <td><%= link_to_cache milestone[:cache] %></td>
74
+ </tr>
75
+ <% } %>
76
+ </table>
77
+ <%# }}} %>
78
+
59
79
  <%# {{{ finds by day of week %>
60
80
  <table class="highlight">
61
81
  <caption>Finds by Day of Week</caption>
@@ -107,16 +107,7 @@ module GCStats
107
107
 
108
108
  def find_dates
109
109
  @find_dates ||= begin
110
- dates = []
111
-
112
- logs.each {|log|
113
- if log.type.downcase == 'found it' or
114
- type.downcase == 'event cache' && log.type.downcase == 'attended'
115
- dates << log.date
116
- end
117
- }
118
-
119
- dates
110
+ logs.select {|log| log.found? }.map {|log| log.date }
120
111
  end
121
112
  end
122
113
  end
@@ -126,6 +117,10 @@ module GCStats
126
117
  @log_node = log_node
127
118
  end
128
119
 
120
+ def id
121
+ @id ||= @log_node.attributes['id'].to_i
122
+ end
123
+
129
124
  def date
130
125
  @date ||= Date.parse(@log_node.elements["#{NS}:date"].text)
131
126
  end
@@ -137,6 +132,10 @@ module GCStats
137
132
  def finder
138
133
  @finder ||= @log_node.elements["#{NS}:finder"].text
139
134
  end
135
+
136
+ def found?
137
+ ['found it', 'attended'].include?(self.type.downcase)
138
+ end
140
139
  end
141
140
  end
142
141
  end
@@ -188,6 +188,38 @@ module GCStats
188
188
  @newest_cache_found ||= @caches.sort {|a, b| a.published <=> b.published }.last
189
189
  end
190
190
 
191
+ def milestones
192
+ @milestones ||= begin
193
+ milestones = []
194
+ milestone = 1
195
+
196
+ logs = @caches.map {|cache|
197
+ cache.logs.map {|log| [cache, log] }
198
+ }.flatten(1).select {|cache, log|
199
+ log.found?
200
+ }.sort {|a, b|
201
+ a.last.id <=> b.last.id
202
+ }
203
+
204
+ while logs[milestone - 1]
205
+ milestones << {
206
+ :milestone => milestone,
207
+ :cache => logs[milestone - 1][0],
208
+ :log => logs[milestone - 1][1]
209
+ }
210
+
211
+ milestone += case milestone
212
+ when 1 then 49
213
+ when 2..99 then 50
214
+ when 100..499 then 100
215
+ else 500
216
+ end
217
+ end
218
+
219
+ milestones
220
+ end
221
+ end
222
+
191
223
  def geocacher_name
192
224
  @caches.first.logs.first.finder
193
225
  end
@@ -203,5 +235,9 @@ module GCStats
203
235
  def format_percent(value, total, precision = 1)
204
236
  '%.*f%%' % [precision, value / total.to_f * 100]
205
237
  end
238
+
239
+ def link_to_cache(cache)
240
+ %{<a href="#{h(cache.url)}">#{h(cache.name)}</a>}
241
+ end
206
242
  end
207
243
  end
@@ -1,3 +1,3 @@
1
1
  module GCStats
2
- VERSION = '1.0.3'
2
+ VERSION = '1.0.4'
3
3
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gcstats
3
3
  version: !ruby/object:Gem::Version
4
- hash: 17
4
+ hash: 31
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
8
  - 0
9
- - 3
10
- version: 1.0.3
9
+ - 4
10
+ version: 1.0.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Aggelos Orfanakos
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-05-24 00:00:00 +03:00
18
+ date: 2011-07-16 00:00:00 +03:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency