From 18c319f839ba51742ab53e3795dad40735d9a3e0 Mon Sep 17 00:00:00 2001 From: Marc Seeger Date: Wed, 13 Jan 2010 18:11:11 +0100 Subject: [PATCH] sorted filelist properly, minor performance tweak, less code in the view --- main.rb | 11 ++++++++--- views/category.erb | 15 ++++++--------- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/main.rb b/main.rb index 397bed5..8a79e2f 100644 --- a/main.rb +++ b/main.rb @@ -61,6 +61,8 @@ def insert_into_pstore(path_to_gpx) @file_list = Dir.glob("gpx/#{params[:foldername]}/*.gpx").sort.reverse files_to_insert = Array.new + + #detect new files @pstore.transaction(true) do @file_list.each do |item| if @pstore[params[:foldername]].nil? @@ -71,14 +73,14 @@ def insert_into_pstore(path_to_gpx) end #if end #do end #do - - + #insert new files files_to_insert.each do |gpxfile| insert_into_pstore(gpxfile) end - #update total stats + #update total stats and get file_list for view + @view_list = Array.new @stats = Hash.new @stats["total_distance"] = 0.0 @stats["total_duration"] = 0.0 @@ -86,9 +88,12 @@ def insert_into_pstore(path_to_gpx) @pstore[params[:foldername]].each do |gpxfile| @stats["total_distance"] += @pstore[gpxfile].distance @stats["total_duration"] += @pstore[gpxfile].duration + @view_list << @pstore[gpxfile] end unless @pstore[params[:foldername]].nil? end + @view_list.sort!{|item1, item2| item2.time_start <=> item1.time_start} + erb(:category) end diff --git a/views/category.erb b/views/category.erb index f4a3e67..0fa8132 100644 --- a/views/category.erb +++ b/views/category.erb @@ -26,18 +26,15 @@ Total distance: <%= (@stats["total_distance"] / 1000).round %> km, Total duratio - <% @pstore.transaction(true) do %> - <% @file_list.each_with_index do |f,index| %> + <% @view_list.each_with_index do |f,index| %> "> - - - - - + + + + + <% end %> - <% end %> -
filenamestarting timedurationdistanceavg speed
<%= f.split("/").last[0..-5] %><%= @pstore[f].time_start.strftime("%d.%h.%y%t-%t%H:%M") %><%= (@pstore[f].duration / 60).round %> min<%= @pstore[f].distance %> m<%= @pstore[f].speed_avg.to_s[/\d*\.\d\d/] %> km/h<%= f.filename.split("/").last[0..-5] %><%= f.time_start.strftime("%d.%h.%y%t-%t%H:%M") %><%= (f.duration / 60).round %> min<%= f.distance %> m<%= f.speed_avg.to_s[/\d*\.\d\d/] %> km/h