-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrace_base.rb
64 lines (48 loc) · 1.5 KB
/
race_base.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
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
require 'rubygems'
require 'data_mapper'
require 'dm-core'
require 'time'
require_relative 'runnerHelpers'
DataMapper.setup( :default, "sqlite3://#{File.dirname(__FILE__)}/race.db" )
class RaceEntry
include DataMapper::Resource
property :id, Serial, :key => true
property :age_group, String
property :gender, String
property :bib, String
property :name, String
property :chip_time, DateTime
property :official_time, DateTime
belongs_to :race, :required => false
def totalMinutes()
x = self.chip_time.strftime('%H').to_i * 60 + self.chip_time.strftime('%M').to_i
return x
end
def paceString()
seconds = self.chip_time.strftime('%H').to_i * 60 * 60 + self.chip_time.strftime('%M').to_i * 60 + self.chip_time.strftime('%S').to_i
paceSeconds = seconds.to_f / self.race.distance.to_f
minutes = (paceSeconds / 60).floor
secs = paceSeconds % 60
return "#{"%02d" % minutes}:#{"%02d" % secs}"
end
def totalSeconds()
self.chip_time.strftime('%H').to_i * 60 * 60 + self.chip_time.strftime('%M').to_i * 60 + self.chip_time.strftime('%S').to_i
end
def paceSeconds()
totalSeconds()/self.race.distance
end
def to_s
"#{@race_name};#{@gender};#{@age_group};#{@bib};#{@name};#{@chip_time};#{@official_time}"
end
end
class Race
include DataMapper::Resource
property :id, Serial, :key => true
property :race_name, String
property :distance, Decimal
property :date, DateTime
has n, :raceEntry
def to_s
"#{id};#{@race_name};#{@distance}"
end
end