-
Notifications
You must be signed in to change notification settings - Fork 2
/
generate.rb
53 lines (48 loc) · 1.14 KB
/
generate.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
#!/usr/bin/env ruby
require 'csv'
# current as of February 2017
fare_types = {
"pub_aircon" => {
"fare" => 12.00,
"firstkm" => 5,
"perkm" => 2.2,
"limit" => 60
},
"pub_ordinary" => {
"fare" => 10.00,
"firstkm" => 5,
"perkm" => 1.85,
"limit" => 60
},
"puj" => {
"fare" => 8.00,
"firstkm" => 4,
"perkm" => 1.5,
"limit" => 50
}
}
def round(original)
"%.2f" % ((original*4).round/4.0)
end
def if_override(original, type, dist, name)
value = original
value = type['override'][dist][name] if type['override'] && type['override'][dist] && type['override'][dist][name]
value
end
fare_types.each do |key, type|
CSV.open(key+'.csv', 'wb') do |csv|
csv << ['distance', 'regular', 'discounted']
type['limit'].times do |x|
dist = x+1
fare = type['fare']
if dist > type['firstkm']
fare += type['perkm'] * (dist - type['firstkm'])
end
discounted = round(fare*0.8)
fare = round(fare)
discounted = if_override(discounted, type, dist, 'discounted')
fare = if_override(fare, type, dist, 'fare')
csv << [dist, fare, discounted]
end
end
end