Permalink
Browse files

La til statistikk

  • Loading branch information...
1 parent 18f2e11 commit e0e55c4a1b0cc89933d8f259bd426cfab3950947 Tallak Tveide committed Apr 10, 2013
Showing with 71 additions and 5 deletions.
  1. +7 −2 lista_spots_historikk.rb
  2. +64 −3 views/report.erb
View
@@ -22,7 +22,7 @@
{ id: 'bispen-fs',
tekst: 'Bispen (kite, freestyle)',
wind: 8..15,
- wind_dir: 'WSW'..'W' },
+ wind_dir: 'WSW'..'NW' },
{ id: 'huseby-fs',
tekst: 'Huseby (kite, freestyle)',
wind: 8..15,
@@ -119,7 +119,7 @@
}
WIND_DIRS = %w(S SSW SW WSW W WNW NW NNW N NNE NE ENE E ESE SE SSE)
-GURU = YAML::load_file(File.join(File.dirname(File.expand_path(__FILE__)), 'guru_data.yaml'))
+GURU ||= YAML::load_file(File.join(File.dirname(File.expand_path(__FILE__)), 'guru_data.yaml'))
def is_sunlight?(date, hours)
SUN_HOURS[date.match(/\d\d\.(\d\d)\.\d\d\d\d/)[1].to_i].member? hours
@@ -242,5 +242,10 @@ def wave_dir_ok?(spot, wave_dir)
{ date: guru_day[:date], results: results }
end
+ # some statistics
+ @total_days = @guru.size
+ @surfable_days = @guru.count {|r| r[:results].member? :good }
+ @totals = Hash[[:good, :bad, :rain, :cold, :dark, :not_weekend].map {|x| [x, @guru.map {|r| r[:results].count(x)}.reduce(&:+)] }]
+
erb :report
end
View
@@ -30,18 +30,79 @@
}
- table {
+ table.results {
border-collapse: collapse;
}
+
+ table.totals {
+ border-collapse: collapse;
+ border: 1px solid #999;
+ margin-bottom: 50px;
+ margin-above: 50px;
+ }
+
+ table.totals td {
+ width: 500px;
+ text-align: left;
+ border: 1px solid #999;
+ padding: 4px;
+ }
+
+ table.totals td:nth-child(3) {
+ width: 30px;
+ text-align: center;
+ }
+ table.totals td:first-child {
+ width: 300px;
+ text-align: left;
+ }
</style>
</head>
<body>
<% if @spot_navn.size < 2 %>
<h1>Mulige dager for <%= @spot_navn.first || '' %> </h1>
<% else %>
- <h1><%= @logikk_heading %>, gjelder for <%= @spot_navn.join ", " %> </h1>
+ <h1><%= @logikk_heading %></h1>
+ <ul>
+ <% @spot_navn.each do |n| %>
+ <li><%= n %></li>
+ <% end %>
+ </ul>
<% end %>
- <table>
+
+ <table class="totals">
+ <tr>
+ <td>Dager med minst en stjerne</td>
+ <td><%= @surfable_days %> dager av <%= @total_days %> mulige (<%= (@surfable_days * 100.0 / @total_days).to_i %>%)</td>
+ </tr>
+ <tr>
+ <td>Stjerner (mulige surfetidspunkt)</td>
+ <td><%= @totals[:good] %> stk av <%= @totals[:good] + @totals[:bad] %> mulige
+ (<%= (@totals[:good] * 100.0 / (@totals[:good] + @totals[:bad])).to_i %>%)</td>
+ <td>&#9733;</td>
+ </tr>
+ <tr>
+ <td>Kuldegrader</td>
+ <td><%= @totals[:cold] %> stk</td>
+ <td>&#10052;</td>
+ </tr>
+ <% if @totals[:rain] > 0 %>
+ <tr>
+ <td>Mye regnvær (2 mm per 3 timer)</td>
+ <td><%= @totals[:rain] %> stk</td>
+ <td>&#9748;</td>
+ </tr>
+ <% end %>
+ <% if @totals[:not_weekend] > 0 %>
+ <tr>
+ <td>I arbeidstiden (rød/ferie utelatt)</td>
+ <td><%= @totals[:not_weekend] %> stk</td>
+ <td>&#8986;</td>
+ </tr>
+ <% end %>
+ </table>
+
+ <table class="results">
<tr>
<% ([''] + @hours).each do |h| %>
<th><%= h %></th>

0 comments on commit e0e55c4

Please sign in to comment.