Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Progress

  • Loading branch information...
commit 66c8d1773c9bf69006ed2f6416f81c357b0f11f8 1 parent 1fcaa6b
Polar Humenn authored
3  Gemfile
@@ -26,6 +26,9 @@ gem "carrierwave"
26 26 gem "mm-carrierwave"
27 27 gem "libarchive" # requires apt-get install libarchive-dev
28 28 gem "zipruby"
  29 +gem "statsample"
  30 +gem "statistics2"
  31 +gem "clbustos-rtf" #, "~> 0.4.2"
29 32 gem "delayed_job"
30 33 gem "delayed_job_mongo_mapper", :git => "git://github.com/polar/delayed_job_mongo_mapper.git"
31 34 gem "daemons"
104 Gemfile.lock
@@ -56,9 +56,9 @@ GEM
56 56 addressable (2.2.7)
57 57 arel (3.0.2)
58 58 bcrypt-ruby (3.0.1)
59   - bson (1.6.0)
60   - bson_ext (1.6.0)
61   - bson (= 1.6.0)
  59 + bson (1.6.1)
  60 + bson_ext (1.6.1)
  61 + bson (~> 1.6.1)
62 62 builder (3.0.0)
63 63 cancan (1.6.7)
64 64 cantango (0.9.4.7)
@@ -74,10 +74,12 @@ GEM
74 74 rack-test (>= 0.5.4)
75 75 selenium-webdriver (~> 2.0)
76 76 xpath (~> 0.1.4)
77   - carrierwave (0.5.8)
78   - activesupport (~> 3.0)
  77 + carrierwave (0.6.1)
  78 + activemodel (>= 3.2.0)
  79 + activesupport (>= 3.2.0)
79 80 childprocess (0.3.1)
80 81 ffi (~> 1.0.6)
  82 + clbustos-rtf (0.5.0)
81 83 coffee-rails (3.2.2)
82 84 coffee-script (>= 2.2.0)
83 85 railties (~> 3.2.0)
@@ -96,8 +98,8 @@ GEM
96 98 cucumber (>= 1.1.8)
97 99 nokogiri (>= 1.5.0)
98 100 daemons (1.1.8)
99   - database_cleaner (0.7.1)
100   - delayed_job (3.0.1)
  101 + database_cleaner (0.7.2)
  102 + delayed_job (3.0.2)
101 103 activesupport (~> 3.0)
102 104 devise (2.0.4)
103 105 bcrypt-ruby (~> 3.0)
@@ -105,17 +107,20 @@ GEM
105 107 railties (~> 3.1)
106 108 warden (~> 1.1.1)
107 109 diff-lcs (1.1.3)
  110 + dirty-memoize (0.0.4)
  111 + distribution (0.7.0)
108 112 erubis (2.7.0)
109 113 execjs (1.3.0)
110 114 multi_json (~> 1.0)
111   - factory_girl (2.6.0)
112   - activesupport (>= 2.3.9)
113   - factory_girl_rails (1.7.0)
114   - factory_girl (~> 2.6.0)
  115 + extendmatrix (0.3.1)
  116 + factory_girl (3.0.0)
  117 + activesupport (>= 3.0.0)
  118 + factory_girl_rails (3.0.0)
  119 + factory_girl (~> 3.0.0)
115 120 railties (>= 3.0.0)
116 121 fastercsv (1.5.4)
117 122 ffi (1.0.11)
118   - gherkin (2.9.0)
  123 + gherkin (2.9.3)
119 124 json (>= 1.4.6)
120 125 hashie (1.2.0)
121 126 hike (1.2.1)
@@ -125,32 +130,34 @@ GEM
125 130 jquery-rails (2.0.1)
126 131 railties (>= 3.2.0, < 5.0)
127 132 thor (~> 0.14)
128   - json (1.6.5)
129   - launchy (2.0.5)
  133 + json (1.6.6)
  134 + launchy (2.1.0)
130 135 addressable (~> 2.2.6)
131 136 libarchive (0.1.2)
132   - mail (2.4.1)
  137 + mail (2.4.4)
133 138 i18n (>= 0.4.0)
134 139 mime-types (~> 1.16)
135 140 treetop (~> 1.4.8)
136   - mime-types (1.17.2)
  141 + mime-types (1.18)
  142 + minimization (0.2.1)
  143 + text-table (~> 1.2)
137 144 mm-carrierwave (0.0.2)
138 145 carrierwave (~> 0.5)
139 146 mongo_mapper (~> 0.9)
140   - mongo (1.6.0)
141   - bson (= 1.6.0)
142   - mongo_mapper (0.11.0)
  147 + mongo (1.6.1)
  148 + bson (~> 1.6.1)
  149 + mongo_mapper (0.11.1)
143 150 activemodel (~> 3.0)
144 151 activesupport (~> 3.0)
145 152 plucky (~> 0.4.0)
146   - multi_json (1.1.0)
147   - nokogiri (1.5.0)
148   - orm_adapter (0.0.6)
  153 + multi_json (1.2.0)
  154 + nokogiri (1.5.2)
  155 + orm_adapter (0.0.7)
149 156 plucky (0.4.4)
150 157 mongo (~> 1.5)
151 158 polyglot (0.3.3)
152 159 rack (1.4.1)
153   - rack-cache (1.1)
  160 + rack-cache (1.2)
154 161 rack (>= 0.4)
155 162 rack-ssl (1.3.2)
156 163 rack
@@ -174,22 +181,28 @@ GEM
174 181 rake (0.9.2.2)
175 182 rdoc (3.12)
176 183 json (~> 1.4)
177   - rspec (2.8.0)
178   - rspec-core (~> 2.8.0)
179   - rspec-expectations (~> 2.8.0)
180   - rspec-mocks (~> 2.8.0)
181   - rspec-core (2.8.0)
182   - rspec-expectations (2.8.0)
183   - diff-lcs (~> 1.1.2)
184   - rspec-mocks (2.8.0)
185   - rspec-rails (2.8.1)
  184 + reportbuilder (1.1.0)
  185 + rtf (~> 0.1)
  186 + rserve-client (0.2.5)
  187 + rspec (2.9.0)
  188 + rspec-core (~> 2.9.0)
  189 + rspec-expectations (~> 2.9.0)
  190 + rspec-mocks (~> 2.9.0)
  191 + rspec-core (2.9.0)
  192 + rspec-expectations (2.9.0)
  193 + diff-lcs (~> 1.1.3)
  194 + rspec-mocks (2.9.0)
  195 + rspec-rails (2.9.0)
186 196 actionpack (>= 3.0)
187 197 activesupport (>= 3.0)
188 198 railties (>= 3.0)
189   - rspec (~> 2.8.0)
  199 + rspec (~> 2.9.0)
  200 + rtf (0.3.3)
  201 + ruby-ole (1.2.11.3)
  202 + rubyvis (0.2.2)
190 203 rubyzip (0.9.6.1)
191 204 sass (3.1.15)
192   - sass-rails (3.2.4)
  205 + sass-rails (3.2.5)
193 206 railties (~> 3.2.0)
194 207 sass (>= 3.1.10)
195 208 tilt (~> 1.3)
@@ -198,10 +211,25 @@ GEM
198 211 ffi (~> 1.0)
199 212 multi_json (~> 1.0)
200 213 rubyzip
  214 + spreadsheet (0.6.8)
  215 + ruby-ole (>= 1.0)
201 216 sprockets (2.1.2)
202 217 hike (~> 1.2)
203 218 rack (~> 1.0)
204 219 tilt (~> 1.1, != 1.3.0)
  220 + statistics2 (0.54)
  221 + statsample (0.16.0)
  222 + dirty-memoize (~> 0.0)
  223 + extendmatrix (~> 0.3.1)
  224 + fastercsv
  225 + minimization (~> 0.2.0)
  226 + reportbuilder (~> 1.0)
  227 + rserve-client (~> 0.2.5)
  228 + rubyvis (~> 0.2.2)
  229 + spreadsheet (~> 0.6.0)
  230 + statsample-bivariate-extension (> 0)
  231 + statsample-bivariate-extension (1.1.0)
  232 + distribution (~> 0.6)
205 233 stringex (1.3.2)
206 234 sugar-high (0.6.3)
207 235 activesupport (>= 3.0.1)
@@ -209,13 +237,14 @@ GEM
209 237 activesupport (>= 3.0.1)
210 238 i18n
211 239 term-ansicolor (1.0.7)
  240 + text-table (1.2.2)
212 241 thor (0.14.6)
213 242 tilt (1.3.3)
214 243 treetop (1.4.10)
215 244 polyglot
216 245 polyglot (>= 0.3.1)
217   - tzinfo (0.3.31)
218   - uglifier (1.2.3)
  246 + tzinfo (0.3.32)
  247 + uglifier (1.2.4)
219 248 execjs (>= 0.3.0)
220 249 multi_json (>= 1.0.2)
221 250 warden (1.1.1)
@@ -233,6 +262,7 @@ DEPENDENCIES
233 262 cantango_editor!
234 263 capybara (>= 1.1.2)
235 264 carrierwave
  265 + clbustos-rtf
236 266 coffee-rails (~> 3.2.2)
237 267 cucumber-rails (>= 1.2.1)
238 268 daemons
@@ -252,6 +282,8 @@ DEPENDENCIES
252 282 rails (= 3.2.1)
253 283 rspec-rails (>= 2.8.1)
254 284 sass-rails (~> 3.2.4)
  285 + statistics2
  286 + statsample
255 287 stringex
256 288 uglifier (>= 1.2.3)
257 289 zipruby
4 app/assets/javascripts/OpenLayers-2.11/lib/OpenLayers/Marker/Box.js
@@ -81,7 +81,7 @@ OpenLayers.Marker.Box = OpenLayers.Class(OpenLayers.Marker, {
81 81 * sz - {<OpenLayers.Size>}
82 82 *
83 83 * Returns:
84   - * {DOMElement} A new DOM Image with this marker�s icon set at the
  84 + * {DOMElement} A new DOM Image with this marker�s icon set at the
85 85 * location passed-in
86 86 */
87 87 draw: function(px, sz) {
@@ -92,7 +92,7 @@ OpenLayers.Marker.Box = OpenLayers.Class(OpenLayers.Marker, {
92 92 /**
93 93 * Method: onScreen
94 94 *
95   - * Rreturn:
  95 + * Return:
96 96 * {Boolean} Whether or not the marker is currently visible on screen.
97 97 */
98 98 onScreen:function() {
42 app/assets/stylesheets/scrollable-vertical.css.erb
... ... @@ -0,0 +1,42 @@
  1 + /* root element for scrollable */
  2 + .vertical {
  3 +
  4 + /* required settings */
  5 + position:relative;
  6 + overflow:hidden;
  7 +
  8 + /* vertical scrollers have typically larger height than width */
  9 + border-top:1px solid #ddd;
  10 + }
  11 +
  12 + /* root element for scrollable items */
  13 + .items {
  14 + }
  15 +
  16 + /* single scrollable item */
  17 + .item {
  18 + }
  19 +
  20 + /* the action buttons above the scrollable */
  21 + .scroll_actions {
  22 + position:relative;
  23 + }
  24 +
  25 + .scroll_actions a {
  26 + font-size:11px;
  27 + cursor:pointer;
  28 + color:#666;
  29 + }
  30 +
  31 + .scroll_actions a:hover {
  32 + text-decoration:underline;
  33 + color:#000;
  34 + }
  35 +
  36 + .disabled {
  37 + visibility:hidden;
  38 + }
  39 +
  40 + .next {
  41 + float:right;
  42 + }
12 app/controllers/masters/municipalities/simulate/webmap_controller.rb
@@ -76,7 +76,7 @@ def curloc
76 76 respond_to do |format|
77 77 format.html { render :nothing, :status => 403 } #forbidden
78 78 format.json {
79   - render :json => getJourneyLocationJSON(@vehicile_journey, @journey_location)
  79 + render :json => getJourneyLocationJSON(@vehicle_journey, @journey_location)
80 80 }
81 81 format.text {
82 82 if @vehicle_journey == nil
@@ -113,7 +113,7 @@ def getRouteSpec(route)
113 113 end
114 114
115 115 def getRouteSpecText(route)
116   - "#{route.name.tr(",", "_")},#{route.persistentid},R,#{route.version}"
  116 + "#{route.name.tr(",", "_")},#{route.id.to_s},R,#{route.version}"
117 117 end
118 118
119 119 def getJourneySpec(journey, route)
@@ -127,7 +127,7 @@ def getJourneySpec(journey, route)
127 127 end
128 128
129 129 def getJourneySpecText(journey, route)
130   - "#{journey.display_name.tr(",", "_")},#{journey.persistentid},V,#{route.persistentid},#{route.version}"
  130 + "#{journey.display_name.tr(",", "_")},#{journey.id.to_s},V,#{route.id.to_s},#{route.version}"
131 131 end
132 132
133 133
@@ -144,7 +144,7 @@ def getDefinitionJSON(route_journey)
144 144 def getRouteDefinitionJSON(route)
145 145 box = route.theBox # [[nw_lon,nw_lat],[se_lon,se_lat]]
146 146 data = { }
147   - data[:_id] = "#{route.persistentid}"
  147 + data[:_id] = "#{route.id.to_s}"
148 148 data[:_type] = 'route'
149 149 data[:_name] = "#{route.display_name}"
150 150 data[:_code] = "#{route.code}"
@@ -160,7 +160,7 @@ def getRouteDefinitionJSON(route)
160 160 def getJourneyDefinitionJSON(journey)
161 161 box = journey.journey_pattern.theBox # [[nw_lon,nw_lat],[se_lon,se_lat]]
162 162 data = { }
163   - data[:_id] = "#{journey.persistentid}"
  163 + data[:_id] = "#{journey.id.to_s}"
164 164 data[:_type] = 'journey'
165 165 data[:_name] = "#{journey.display_name}"
166 166 data[:_code] = "#{journey.service.route.code}"
@@ -235,7 +235,7 @@ def getRouteGeoJSON(route)
235 235
236 236 def getJourneyLocationJSON(journey, journey_location)
237 237 data = { }
238   - data[:id] ="#{journey.persistentid}"
  238 + data[:id] ="#{journey.id.to_s}"
239 239 data[:type] = 'journey'
240 240 data[:name] ="#{journey.display_name}"
241 241 data[:code] ="#{journey.service.route.code}"
12 app/controllers/masters/municipalities/simulate_controller.rb
@@ -49,11 +49,15 @@ def start
49 49 end
50 50 begin
51 51 @clock = Time.parse(@date.strftime("%Y-%m-%d") + " " + @time.strftime("%H:%M %Z"))
52   - rescue ArgumentError
  52 + @status = "WTF?"
  53 + rescue Exception => boom
53 54 @status = "Cannot parse time"
54 55 return
  56 + ensure
  57 + @status = "GODMAN"
55 58 end
56 59
  60 +
57 61 @job = SimulateJob.first(options)
58 62 if @job
59 63 if @job.is_processing?
@@ -67,7 +71,7 @@ def start
67 71 end
68 72 @job.save!
69 73 VehicleJourney.delay.simulate_all(10, @clock, options)
70   - @status = "Simulation for #{@municipality.name} is started"
  74 + @status = "Simulation for #{@municipality.name} has been started."
71 75 end
72 76
73 77 def stop
@@ -119,10 +123,6 @@ def partial_status
119 123 end
120 124
121 125 def api
122   - @municipality = Municipality.where(:master_id => @master.id, :id => params[:id]).first
123   - if (@municipality.nil?)
124   - throw "Not Found"
125   - end
126 126 authorize!(:read, @municipality)
127 127 @api = {
128 128 :majorVersion => 1,
1  app/controllers/masters_controller.rb
@@ -20,7 +20,6 @@ def show
20 20 if @master.nil?
21 21 raise "Not found"
22 22 end
23   - authorize!(:read, @master)
24 23 end
25 24
26 25 def new
21 app/models/journey_location.rb
@@ -2,8 +2,20 @@ class JourneyLocation
2 2 include MongoMapper::Document
3 3
4 4 # Coordinates are { :lat => float, :lon => float }
5   - key :coordinates, Hash
6   - key :last_coordinates, Hash
  5 + # Coordinates are [ lon, lat ]
  6 + key :coordinates, Array
  7 + key :direction, Float
  8 + key :distance, Float
  9 + key :timediff, Integer
  10 + key :reported_time, Time
  11 + key :recorded_time, Time
  12 +
  13 + key :last_coordinates, Array
  14 + key :last_direction, Float
  15 + key :last_distance, Float
  16 + key :last_timediff, Integer
  17 + key :last_reported_time, Integer
  18 +
7 19
8 20 belongs_to :vehicle_journey
9 21 belongs_to :service
@@ -14,7 +26,10 @@ class JourneyLocation
14 26 validates_presence_of :service
15 27 validates_presence_of :route
16 28
17   - attr_accessible :route, :service, :vehicle_journey
  29 + attr_accessible :route, :service, :vehicle_journey,
  30 + :vehicle_journey_id, :service_id, :route_id,
  31 + :coordinates, :direction, :timediff, :reported_time, :recorded_time,
  32 + :last_coordinates, :last_direction, :last_timediff, :last_reported_time
18 33
19 34 before_save :cache_fields
20 35
2  app/models/simulate_job.rb
@@ -36,7 +36,7 @@ def reinitialize()
36 36 end
37 37
38 38 def is_processing?
39   - return "Stopped" != processing_status
  39 + return ! ["Stopped"].include?(processing_status)
40 40 end
41 41
42 42 def set_processing_status(status)
9 app/models/vehicle_journey.rb
@@ -299,7 +299,7 @@ def figure_location(distance, tm_last, tm_now, tm_start)
299 299
300 300 #Look for ReportedJourneyLocation
301 301 rjls = ReportedJourneyLocation.find(:all,
302   - :conditions => {:vehicle_journey_id => self},
  302 + :conditions => {:vehicle_journey_id => self.id},
303 303 :order => "reported_time, recorded_time")
304 304 if (rjls == nil)
305 305 return estimate
@@ -391,6 +391,7 @@ def simulate(interval, logger = VehicleJourney.logger, clock = Time)
391 391 while (distance < target_distance) do
392 392 ans = figure_location(distance, tm_last, tm_now, tm_start)
393 393 if (ans != nil)
  394 + logger.info "VehicleJourney '#{self.name}' answer #{ans.inspect}"
394 395 if journey_location == nil
395 396 create_journey_location(:service => service, :route => service.route)
396 397 else
@@ -463,9 +464,9 @@ def run
463 464 logger.info "Starting Journey #{journey.id} #{journey.name}"
464 465 thread = Thread.new do
465 466 begin
466   - journey.simulate(time_interval, clock, logger)
  467 + journey.simulate(time_interval, logger, clock)
467 468 logger.info "Journey ended normally #{journey.id} #{journey.name}"
468   - rescue Error => boom
  469 + rescue Exception => boom
469 470 logger.info "Stopping Journey #{journey.id} #{journey.name} on #{boom}"
470 471 ensure
471 472 logger.info "Removing Journey #{journey.id} #{journey.name}"
@@ -489,7 +490,9 @@ def self.simulate_all(time_interval, time = Time.now, options = {})
489 490 logger = job
490 491 logger.info "Starting Simulation for #{options.inspect}."
491 492 begin
  493 + job.sim_time = time
492 494 job.processing_started_at = Time.now
  495 + job.processing_completed_at = nil
493 496 job.set_processing_status!("Running")
494 497 JourneyLocation.where(options).all.each {|x| x.delete() }
495 498 syslogger.info "Deleted all JourneyLocations"
26 app/views/masters/municipalities/simulate/map.html.erb
@@ -9,7 +9,7 @@
9 9 $(function() {
10 10 // Clear log on Start Simulation
11 11 $("#start").click(function(ev) {
12   - $('#processing_log').html("");
  12 + $('#processing_log .items').html("");
13 13 this.disabled=true;
14 14 $('#start_status').html("");
15 15 });
@@ -26,9 +26,9 @@
26 26 "?log="+log,
27 27 dataType: "json",
28 28 success: function(data) {
29   - if (data) {
  29 + if (data != null) {
30 30 $.each(data['logs'], function(i, item) {
31   - $('#processing_log').append('<div>'+item+'</div>');
  31 + $('#processing_log .items').append('<div class="item">'+item+'</div>');
32 32 });
33 33 if (data['completed_at']) {
34 34 $('#completed_at').html(data['completed_at']);
@@ -41,8 +41,8 @@
41 41 }
42 42 if (data['status']) {
43 43 $('#status').html(data['status']);
44   - $("#start")[0].disabled=data['status'] != "Stopped";
45   - $("#stop")[0].disabled=data['status'] == "Stopped";
  44 + $("#start")[0].disabled = data['status'] != "Stopped";
  45 + $("#stop")[0].disabled = data['status'] == "Stopped" || data['status'] == "StopRequested" || data['status'] == "Stopping";
46 46 }
47 47 } else {
48 48 $('#processing_log').html("");
@@ -69,7 +69,7 @@
69 69 $(function() {
70 70 $("body").layout({ applyDefaultStyles: true });
71 71 // initialize scrollable with mousewheel support
72   - $("#routesView").scrollable({ vertical: true, mousewheel: true, keyboard : true, easing: "swing" });
  72 + $(".scrollable").scrollable({ vertical: true, mousewheel: true, keyboard : true, easing: "swing" });
73 73 var scroll = $("#routesView").data("scrollable");
74 74 var api = new BusPassAPI( { loginUrl : '<%= api_master_municipality_simulate_path(@municipality, :master_id => @master.id) %>' });
75 75 view = new BusPass.ActivePlanController( {
@@ -167,7 +167,7 @@
167 167 <div class="row">
168 168 <div class="span4">
169 169 </div>
170   - <div class="span2">
  170 + <div class="span2 scroll_actions">
171 171 <a class="prev">&laquo; Up</a>
172 172 </div>
173 173 </div>
@@ -182,7 +182,7 @@
182 182 <div class="row">
183 183 <div class="span4">
184 184 </div>
185   - <div class="span2">
  185 + <div class="span2 scroll_actions">
186 186 <a class="next">Down &raquo;</a>
187 187 </div>
188 188 </div>
@@ -230,10 +230,16 @@
230 230 "" if @job %></div></td>
231 231 </table>
232 232 <h3>Simulation Log</h3>
233   - <div id="processing_log">
  233 + <div class="scroll_actions">
  234 + <a class="previous">&laquo; Older</a>
  235 + <a class="next">Newer &raquo;</a>
  236 + </div>
  237 + <div id="processing_log" class="scrollable vertical">
  238 + <div class="items">
234 239 <% for i in @job.processing_log %>
235   - <div><%= i %></div>
  240 + <div class="item"><%= i %></div>
236 241 <% end if @job%>
  242 + </div>
237 243 </div>
238 244 </div>
239 245 </div>

0 comments on commit 66c8d17

Please sign in to comment.
Something went wrong with that request. Please try again.