-
Notifications
You must be signed in to change notification settings - Fork 0
/
target_kpi_calculator.rb
88 lines (67 loc) · 2.53 KB
/
target_kpi_calculator.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
class TargetKPICalculator
def initialize(bizlog_context, biztarget_context, date)
@bizlog_context = bizlog_context
@biztarget_context = biztarget_context
@date = date
end
def daily_target
@biztarget_context.fetch(date)
return @biztarget_context.sum_target
end
def daily_ratio
@bizlog_context.fetch(date)
value = @bizlog_context.sum_value
@biztarget_context.fetch(date)
target = @biztarget_context.sum_target
return nil if value == nil || target == nil || target == 0
return value * 1.0 / target
end
def monthly_target
@biztarget_context.fetch(Date.new(@date.year, @date.month, 1), Date.new(@date.year, @date.month, -1))
return @biztarget_context.sum_target
end
def monthly_ratio
@bizlog_context.fetch(Date.new(@date.year, @date.month, 1), @date)
value = @bizlog_context.sum_value
@biztarget_context.fetch(Date.new(@date.year, @date.month, 1), Date.new(@date.year, @date.month, -1))
target = @biztarget_context.sum_target
return nil if value == nil || target == nil || target == 0
return value * 1.0 / target
end
def weekly_target
@biztarget_context.fetch(@date.last_monday, (@date+7).last_monday)
return @biztarget_context.sum_target
end
def weekly_ratio
@bizlog_context.fetch(@date.last_monday, @date)
value = @bizlog_context.sum_value
@biztarget_context.fetch(@date.last_monday, (@date+7).last_monday)
target = @biztarget_context.sum_target
return nil if value == nil || target == nil || target == 0
return value * 1.0 / target
end
def monthly_BVA
@bizlog_context.fetch(Date.new(@date.year, @date.month, 1), @date)
value = @bizlog_context.sum_value
@biztarget_context.fetch(Date.new(@date.year, @date.month, 1), Date.new(@date.year, @date.month, -1))
target = @biztarget_context.sum_target
return nil if value == nil || target == nil || target == 0
return value - target
end
def weekly_BVA
@bizlog_context.fetch(@date.last_monday, @date)
value = @bizlog_context.sum_value
@biztarget_context.fetch(@date.last_monday, (@date+7).last_monday)
target = @biztarget_context.sum_target
return nil if value == nil || target == nil || target == 0
return value - target
end
def daily_BVA
@bizlog_context.fetch(date)
value = @bizlog_context.sum_value
@biztarget_context.fetch(date)
target = @biztarget_context.sum_target
return nil if value == nil || target == nil || target == 0
return value - target
end
end