public
Fork of evanfarrar/opensprints
Description: Bringing GoldSprints to the masses.
Homepage: http://www.opensprints.com/
Clone URL: git://github.com/toothrot/opensprints.git
  - set finish times in race presenter before we draw them
  - fix tournament recording
  - make mock arduino act more like real sensor data
  - main can be run directoy if you have shoes in your path
toothrot (author)
Sat Aug 02 22:24:24 -0700 2008
commit  3160db80a92ea61eeeb0fbe1d0a0cc4d4ab818da
tree    38a9678b87648b99fcc3a202ed844b5f0aee11fc
parent  1c8fe7057993c0d8cfa23025266d17def2fcf07c
...
94
95
96
97
98
 
 
 
 
 
99
100
101
102
103
104
105
106
 
107
108
109
...
94
95
96
 
 
97
98
99
100
101
102
103
104
105
 
106
107
 
108
109
110
111
0
@@ -94,16 +94,18 @@ class RacePresenter
0
         @shoes_instance.span(@blue.name,{:stroke => "#00F"}),
0
         {:top => 300, :align => 'center'})
0
 
0
- if @sensor.values[:red_finish] && @sensor.values[:blue_finish]#@race.complete?
0
- @shoes_instance.title "#{@race.winner.name.upcase} WINS!!!\n", :align => "center",
0
+ @red.finish_time = @sensor.values[:red_finish]
0
+ @blue.finish_time = @sensor.values[:blue_finish]
0
+
0
+ if @race.complete?
0
+ @shoes_instance.title "#{@race.winner.name.upcase} WINS!!!\n", :align => "center",
0
          :top => 380, :width => 800, :stroke => @shoes_instance.ivory
0
         @shoes_instance.title "#{@red.name}: #{@sensor.values[:red_finish]/1000.0}s, #{@blue.name}: #{@sensor.values[:blue_finish]/1000.0}s", :stroke => @shoes_instance.ivory,
0
           :align => 'center', :top => 450, :width => 800
0
 
0
- @red.finish_time = @sensor.values[:finish_time]
0
         @sensor.stop
0
         @continue = false
0
- @shoes_instance.owner.tournament_record(@sensor.values)
0
+ @shoes_instance.owner.tournament_record(@race)
0
         @shoes_instance.owner.post_race
0
       end
0
     end
...
1
2
3
 
4
5
6
...
12
13
14
15
16
 
 
 
 
 
 
 
 
 
 
 
 
 
17
18
 
19
20
21
 
22
23
24
...
27
28
29
30
 
31
32
33
 
34
35
36
37
 
 
 
 
38
39
40
41
42
43
44
 
45
 
 
 
 
 
46
47
48
...
1
2
 
3
4
5
6
...
12
13
14
 
 
15
16
17
18
19
20
21
22
23
24
25
26
27
28
 
29
30
 
 
31
32
33
34
...
37
38
39
 
40
41
42
 
43
44
45
 
 
46
47
48
49
50
51
52
53
54
55
 
56
57
58
59
60
61
62
63
64
65
0
@@ -1,6 +1,6 @@
0
 #Arduino: a sensor written for the arduino open source hardware.
0
 class Sensor
0
- attr_accessor :queue
0
+ #attr_accessor :queue
0
   def initialize(queue, filename=nil)
0
     @queue = queue
0
   end
0
@@ -12,13 +12,23 @@ class Sensor
0
       t = 0
0
       f = []
0
       sleep 5
0
- 2000.times {|i| f << "#{rand(2)+1}: #{i}"}
0
- [1,2].sort_by{rand}.each {|i| f << "#{i}f: #{1+rand(1000)}"}
0
+ racer_1 = 0
0
+ racer_2 = 0
0
+
0
+ until racer_1 >= 2000 && racer_2 >= 2000
0
+ if (rand(2) == 1 && racer_1 < 2000)
0
+ f << "1: #{racer_1 += rand(35)}"
0
+ else
0
+ f << "2: #{racer_2 += rand(35)}"
0
+ end
0
+ end
0
+ wins = ["1f: #{racer_1}", "2f: #{racer_2}"]
0
+ (racer_1 >= racer_2) ? f.concat(wins) : f.concat(wins.reverse)
0
+
0
       t_start = Time.now.to_f
0
- while true do
0
+ until !Thread.current["red_finish"].nil? && !Thread.current["blue_finish"].nil? do
0
         l = f.shift
0
- sleeptime = l.split[1].to_f/1000.0 - (Time.now.to_f - t_start)
0
- sleep sleeptime if sleeptime > 0
0
+ sleep (rand(50))/1000.0
0
 
0
         if l =~ /1:/
0
           Thread.current["red"] = l.gsub(/1: /,'').to_i
0
@@ -27,22 +37,29 @@ class Sensor
0
           Thread.current["blue"] = l.gsub(/2: /,'').to_i
0
         end
0
         if l =~ /1f:/
0
- Thread.current["red_finish"] = l.gsub(/1f: /,'').to_i
0
+ Thread.current["red_finish"] = (Time.now.to_f - t_start).to_i
0
         end
0
         if l =~ /2f:/
0
- Thread.current["blue_finish"] = l.gsub(/2f: /,'').to_i
0
+ Thread.current["blue_finish"] = (Time.now.to_f - t_start).to_i
0
         end
0
 
0
- @queue << l
0
- puts l
0
+ if l
0
+ @queue << l
0
+ puts l
0
+ end
0
       end
0
     end
0
     self
0
   end
0
 
0
   def values
0
- {:red => @t["red"], :blue => @t["blue"],
0
+ @values ||= {:red => 1, :blue => 1,
0
      :red_finish => @t["red_finish"], :blue_finish => @t["blue_finish"]}
0
+ if @t["red"] || @t["blue"] #something not nil?
0
+ @values = {:red => @t["red"], :blue => @t["blue"],
0
+ :red_finish => @t["red_finish"], :blue_finish => @t["blue_finish"]}
0
+ end
0
+ @values
0
   end
0
 
0
   def stop
0
main.rb 100644 →
...
 
1
2
3
...
1
2
3
4
0
@@ -1,3 +1,4 @@
0
+#!/usr/bin/env shoes
0
 require 'yaml'
0
 
0
 begin

Comments

    No one has commented yet.