Skip to content

Commit

Permalink
sorted filelist properly, minor performance tweak, less code in the view
Browse files Browse the repository at this point in the history
  • Loading branch information
rb2k committed Jan 13, 2010
1 parent 11a17f4 commit 18c319f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
11 changes: 8 additions & 3 deletions main.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand All @@ -71,24 +73,27 @@ 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
@pstore.transaction do
@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

Expand Down
15 changes: 6 additions & 9 deletions views/category.erb
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,15 @@ Total distance: <%= (@stats["total_distance"] / 1000).round %> km, Total duratio

<table id="tracktable" border="0">
<th>filename</th><th>starting time</th><th>duration</th><th>distance</th><th>avg speed</th>
<% @pstore.transaction(true) do %>
<% @file_list.each_with_index do |f,index| %>
<% @view_list.each_with_index do |f,index| %>
<tr class="<%= if index.even? then "even";else "odd";end%>">
<td><a href="/details/<%= f %>"><%= f.split("/").last[0..-5] %></a></td>
<td><%= @pstore[f].time_start.strftime("%d.%h.%y%t-%t%H:%M") %></td>
<td><%= (@pstore[f].duration / 60).round %> min</td>
<td><%= @pstore[f].distance %> m</td>
<td><%= @pstore[f].speed_avg.to_s[/\d*\.\d\d/] %> km/h</td>
<td><a href="/details/<%= f.filename %>"><%= f.filename.split("/").last[0..-5] %></a></td>
<td><%= f.time_start.strftime("%d.%h.%y%t-%t%H:%M") %></td>
<td><%= (f.duration / 60).round %> min</td>
<td><%= f.distance %> m</td>
<td><%= f.speed_avg.to_s[/\d*\.\d\d/] %> km/h</td>
</tr>
<% end %>
<% end %>

</table>
</div>
</html>
Expand Down

0 comments on commit 18c319f

Please sign in to comment.