This repository has been archived by the owner on Dec 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
calc.rb
152 lines (129 loc) · 3.88 KB
/
calc.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
require 'data.rb'
def to_seconds(time)
return time.scan(/(\d*)h(\d*)m(\d*)s/).collect { |h, min, s| s.to_i + (min.to_i*60)+(h.to_i*60*60)}.first
end
def common_cost(line,opt)
sum = 0
countries = line.map{ |l| l['country'] }.uniq
countries.each{ |country|
mobile_and_phone = line.select { |l|
(l['type']=='mobile'|| l['type']=='phone') && l['country']==country
}.map{ |l|{'s'=>to_seconds(l['time']),'#'=>l['#']}
}.inject({'s'=>0,'#'=>0}){ |s, l|
{'s'=>s['s']+l['s'],'#'=>s['#']+l['#']}
}
sum += mobile_and_phone['#']*opt[country]["opening"]
sum += (mobile_and_phone['s']/60.0)*opt[country]["minute"]
sms = line.select { |l|
l['type']=='sms' && l['country']==country
}.map{ |l| l['#'] }.inject(:+)
sms ||= 0
sum += sms*opt[country]["sms"]
mms = line.select { |l|
l['type']=='mms' && l['country']==country
}.map{ |l| l['#'] }.inject(:+)
mms ||= 0
sum += mms*opt[country]["mms"]
}
return sum
end
def ext_common_cost(line,opt)
sum = 0
countries = line.map{ |l| l['country'] }.uniq
countries.each{ |country|
mobile = line.select { |l|
(l['type']=='mobile') && l['country']==country
}.map{ |l|{'s'=>to_seconds(l['time']),'#'=>l['#']}
}.inject({'s'=>0,'#'=>0}){ |s, l|
{'s'=>s['s']+l['s'],'#'=>s['#']+l['#']}
}
sum += mobile['#']*opt[country]["opening"]
sum += (mobile['s']/60.0)*opt[country]["minute"]
sms = line.select { |l|
l['type']=='sms' && l['country']==country
}.map{ |l| l['#'] }.inject(:+)
sms ||= 0
sum += sms*opt[country]["sms"]
mms = line.select { |l|
l['type']=='mms' && l['country']==country
}.map{ |l| l['#'] }.inject(:+)
mms ||= 0
sum += mms*opt[country]["mms"]
}
return sum
end
@@telia_gr_cost={'opening'=>0.36,'minute'=>3.96,'sms'=>1.5,'mms'=>1.99}
def cost_telia_prata_pa(line)
return 98.0+common_cost(line,{
'sv'=>{'opening'=>0.79,'minute'=>0.29,'sms'=>0.29,'mms'=>1.99},
'gr'=>@@telia_gr_cost,
})
end
def cost_telia_till_vanner(line)
return 98.0+common_cost(line,{
'sv'=>{'opening'=>0.69,'minute'=>0.69,'sms'=>0.69,'mms'=>1.99},
'gr'=>@@telia_gr_cost,
})
end
def cost_comviq_smart_69(line)
return common_cost(line, {
'sv'=>{'opening'=>0.99,'minute'=>0.19,'sms'=>0.69,'mms'=>0.69},
'gr'=>{'opening'=>0.99,'minute'=>3.45,'sms'=>0.69,'mms'=>80}
}) + 3.0*5.0*4.5
end
def cost_comviq_smart_169(line)
return common_cost(line, {
'sv'=>{'opening'=>0.99,'minute'=>0.19,'sms'=>0.0,'mms'=>0.69},
'gr'=>{'opening'=>0.99,'minute'=>3.45,'sms'=>0.69,'mms'=>80}
})
end
def halebob(line)
return 149.0+common_cost(line,{
'sv'=>{'opening'=>0.69,'minute'=>0.19,'sms'=>0.0,'mms'=>1.99},
'gr'=>{'opening'=>0.36,'minute'=>3.47,'sms'=>1.5,'mms'=>80},
})
end
def tre_pott499(line)
return common_cost(line,{
'sv'=>{'opening'=>0.69,'minute'=>0.69,'sms'=>0.69,'mms'=>1.69},
'gr'=>{'opening'=>0.69,'minute'=>4.95,'sms'=>1.69,'mms'=>80}
})
#{
# 'mobile'=>{
# 'sv'=>{
# 'tre'=>{'opening'=>0.69,'minute'=>0.19,'sms'=>0.69,'mms'=>1.69},
# 'other'=>{'opening'=>0.69,'minute'=>0.69,'sms'=>0.69,'mms'=>1.69}
# },
# 'gr'=>{'other'=>{'opening'=>0.69,'minute'=>4.95,'sms'=>2,'mms'=>80}},
# },
# 'phone'=>{
# 'sv'=>{'opening'=>0.69,'minute'=>0.69},
# 'gr'=>{'opening'=>0.69,'minute'=>4.95},
# }
# })
end
samtal = Samtal.new().get
p "cost_telia_prata_pa"
samtal.each{ |k,v|
p "#{k} = #{cost_telia_prata_pa(v)}"
}
p "cost_telia_till_vanner"
samtal.each{ |k,v|
p "#{k} = #{cost_telia_till_vanner(v)}"
}
p "cost_comviq_smart_69"
samtal.each{ |k,v|
p "#{k} = #{cost_comviq_smart_69(v)}"
}
p "cost_comviq_smart_169"
samtal.each{ |k,v|
p "#{k} = #{cost_comviq_smart_169(v)}"
}
p "halebob"
samtal.each{ |k,v|
p "#{k} = #{halebob(v)}"
}
p "tre_pott499"
samtal.each{ |k,v|
p "#{k} = #{tre_pott499(v)}"
}