effective_cpd 0.1.19 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fe768cdc3715d62c09b0c829d6823db4ce8587fd603244dceb4243976006bb02
4
- data.tar.gz: 0540bd3c67a6df4c5fbc2d612ccbc67f834ff46d96a605c2200ac8866f21dfbd
3
+ metadata.gz: 80e098e09ddea7dbc4d43707500e647e1795dd750b63f6e21ac44512a430fbcb
4
+ data.tar.gz: 72590ba94aa5535c8431afb6bcd4a4ef1b4a90be5f21f120914c94dbcfbe4cd0
5
5
  SHA512:
6
- metadata.gz: 00701f9319d26d59b192bf831d7072441661798a2202ba728cdf474b798fc9cfc5e3a013b5b725a45d58f6861192d48684acb6b3aec7508a7787d2e3608433c4
7
- data.tar.gz: a363248b7decc2a56fcc86d29748c3c29b97fe6ea256406a10f5a41af69064301158871851e8b3dbe2227e3bd40a8009e95a8f16601a4da8f629027d53e65470
6
+ metadata.gz: b3b459b4701245f5953e2ce0d01135dbc19e8d5587ba0a7e1b2e9de94897ae7c59e940b7bd8b3ad364e2bd1c8b78c617f83da2ffa075cb8e4fc19670d6b94f18
7
+ data.tar.gz: 238cc81c30a48006ca4e4886cdd654add4b322dd3bd612e5186e0b6fb15bb50a24639fa434639ca32d86506ef165a369ab22435f60d17c7a2e255f643975e42e
@@ -17,8 +17,14 @@ module Admin
17
17
  col :cpd_cycle, label: cpd_cycle_label.titleize
18
18
  col :user
19
19
  col :submitted_at, as: :date, label: 'Submitted'
20
- col :score
21
- col :carry_forward
20
+
21
+ col :score do |cpd_statement|
22
+ cpd_score(cpd_statement.score)
23
+ end
24
+
25
+ col :carry_forward do |cpd_statement|
26
+ cpd_score(cpd_statement.carry_forward)
27
+ end
22
28
 
23
29
  actions_col
24
30
  end
@@ -44,4 +44,9 @@ module EffectiveCpdHelper
44
44
  @effective_cpd_categories ||= Effective::CpdCategory.deep.sorted
45
45
  end
46
46
 
47
+ def cpd_score(value)
48
+ raise('expected a BigDecimal') unless value.nil? || value.kind_of?(BigDecimal)
49
+ ("%.#{2}f" % value.to_d)
50
+ end
51
+
47
52
  end
@@ -117,10 +117,12 @@ module Effective
117
117
  private
118
118
 
119
119
  def eval_equation(amount: nil, amount2: nil)
120
- return 0 if formula.blank?
120
+ return BigDecimal(0) if formula.blank?
121
121
 
122
122
  equation = formula.gsub('amount2', amount2.to_s).gsub('amount', amount.to_s)
123
- eval(equation).round.to_i
123
+
124
+ # Returns a BigDecimal
125
+ eval(equation).to_d
124
126
  end
125
127
 
126
128
  end
@@ -103,7 +103,7 @@ module Effective
103
103
  cpd_categories = special_rule.ruleables.select { |obj| obj.kind_of?(Effective::CpdCategory) }
104
104
 
105
105
  max_credits_per_cycle = special_rule.max_credits_per_cycle
106
- raise('expected max credits per cycle to be present') unless max_credits_per_cycle.to_i > 0
106
+ raise('expected max credits per cycle to be present') unless (max_credits_per_cycle || 0) > 0
107
107
 
108
108
  activities = statement.cpd_statement_activities.select { |sa| cpd_categories.include?(sa.cpd_category) }
109
109
 
@@ -97,17 +97,17 @@ module Effective
97
97
  required_by_cycle = cpd_cycle&.required_score
98
98
  required_by_user = user.cpd_statement_required_score(self) if user.respond_to?(:cpd_statement_required_score)
99
99
 
100
- [required_by_cycle.to_i, required_by_user.to_i].max
100
+ [required_by_cycle.to_d, required_by_user.to_d].max
101
101
  end
102
102
 
103
103
  def carry_forward
104
- cpd_statement_activities.sum { |activity| activity.carry_forward.to_i }
104
+ cpd_statement_activities.sum { |activity| activity.carry_forward || BigDecimal(0) }.to_d
105
105
  end
106
106
 
107
107
  # {category_id => 20, category_id => 15}
108
108
  def score_per_category
109
- @score_per_category ||= Hash.new(0).tap do |scores|
110
- cpd_statement_activities.each { |activity| scores[activity.cpd_category_id] += activity.score.to_i }
109
+ @score_per_category ||= Hash.new(BigDecimal(0)).tap do |scores|
110
+ cpd_statement_activities.each { |activity| scores[activity.cpd_category_id] += activity.score.to_d }
111
111
  end
112
112
  end
113
113
 
@@ -16,14 +16,14 @@ module Effective
16
16
  end
17
17
 
18
18
  effective_resource do
19
- amount :integer
20
- amount2 :integer
19
+ amount :decimal
20
+ amount2 :decimal
21
21
 
22
22
  description :text
23
23
 
24
- carry_over :integer # carry_over_from_last_cycle
25
- score :integer
26
- carry_forward :integer # carry_forward_to_next_cycle
24
+ carry_over :decimal # carry_over_from_last_cycle
25
+ score :decimal
26
+ carry_forward :decimal # carry_forward_to_next_cycle
27
27
 
28
28
  reduced_messages :text
29
29
 
@@ -35,7 +35,7 @@ module Effective
35
35
  scope :deep, -> { includes(:cpd_statement, :cpd_category, :cpd_activity, :original) }
36
36
  scope :sorted, -> { order(:id) }
37
37
 
38
- validates :original, presence: true, if: -> { carry_over.to_i > 0 }
38
+ validates :original, presence: true, if: -> { (carry_over || 0) > 0 }
39
39
  validates :description, presence: true
40
40
 
41
41
  validate(if: -> { new_record? && cpd_statement.present? }) do
@@ -17,7 +17,7 @@
17
17
 
18
18
  %tr
19
19
  %td
20
- %h4= last_3_scores.to_i
20
+ %h4= cpd_score(last_3_scores.to_d)
21
21
 
22
22
  %td #{cpd_credits_label} in last 3 #{cpd_cycles_label} (including this #{cpd_cycle_label})
23
23
 
@@ -24,12 +24,12 @@
24
24
  .col
25
25
  %strong= cpd_activity.amount_label
26
26
  %br
27
- = cpd_statement_activity.amount
27
+ = cpd_score(cpd_statement_activity.amount)
28
28
 
29
29
  - if cpd_activity.amount2_label.present?
30
30
  .col.text-center
31
31
  %strong= cpd_activity.amount2_label
32
- = cpd_statement_activity.amount2
32
+ = cpd_score(cpd_statement_activity.amount2)
33
33
 
34
34
  - if cpd_activity.amount_static?
35
35
  .col
@@ -43,14 +43,14 @@
43
43
  %strong= cpd_credits_label.titleize
44
44
  %br
45
45
  - if cpd_statement_activity.reduced_messages.present?
46
- %span{title: cpd_statement_activity.reduced_messages.values.join("\n\n")}= "#{cpd_statement_activity.score} *"
46
+ %span{title: cpd_statement_activity.reduced_messages.values.join("\n\n")}= "#{cpd_score(cpd_statement_activity.score)} *"
47
47
  - else
48
- = cpd_statement_activity.score.to_i
48
+ = cpd_score(cpd_statement_activity.score)
49
49
 
50
50
  .col.text-center
51
51
  %strong Carry
52
52
  %br
53
- = cpd_statement_activity.carry_forward.to_i
53
+ = cpd_score(cpd_statement_activity.carry_forward)
54
54
 
55
55
  - if cpd_statement_activity.files.present?
56
56
  %p
@@ -28,23 +28,23 @@
28
28
  %strong= cpd_credits_label.titleize
29
29
  %br
30
30
  - if f.object.reduced_messages.present?
31
- %span{title: f.object.reduced_messages.values.join("\n\n")}= "#{f.object.score} *"
31
+ %span{title: f.object.reduced_messages.values.join("\n\n")}= "#{cpd_score(f.object.score)} *"
32
32
  - else
33
- = f.object.score.to_i
33
+ = cpd_score(f.object.score)
34
34
 
35
35
  .col-2.text-center
36
36
  - if f.object.persisted?
37
37
  %strong Carry Forward
38
38
  %br
39
- = f.object.carry_forward.to_i
39
+ = cpd_score(f.object.carry_forward)
40
40
 
41
41
  .row
42
42
  .col
43
43
  - if activity.amount_label.present?
44
- = f.number_field :amount, label: activity.amount_label, required: true
44
+ = f.float_field :amount, label: activity.amount_label, required: true
45
45
 
46
46
  - if activity.amount2_label.present?
47
- = f.number_field :amount2, label: activity.amount2_label, required: true
47
+ = f.float_field :amount2, label: activity.amount2_label, required: true
48
48
 
49
49
  - if activity.amount_static?
50
50
  = f.hidden_field :amount, value: 1
@@ -12,7 +12,7 @@
12
12
  %h3
13
13
  #{category}
14
14
  %small
15
- = cpd_statement.score_per_category[category.id].to_i
15
+ = cpd_score(cpd_statement.score_per_category[category.id])
16
16
  - if rule.max_credits_per_cycle.present?
17
17
  = '/'
18
18
  = rule.max_credits_per_cycle
@@ -16,7 +16,7 @@
16
16
  %h3
17
17
  #{category}
18
18
  %small
19
- = cpd_statement.score_per_category[category.id].to_i
19
+ = cpd_score(cpd_statement.score_per_category[category.id])
20
20
  - if rule.max_credits_per_cycle.present?
21
21
  = '/'
22
22
  = rule.max_credits_per_cycle
@@ -41,12 +41,12 @@
41
41
 
42
42
  .col-2.score
43
43
  - if statement_activity.reduced_messages.present?
44
- %span{title: statement_activity.reduced_messages.values.join("\n\n")}= "#{statement_activity.score} *"
44
+ %span{title: statement_activity.reduced_messages.values.join("\n\n")}= "#{cpd_score(statement_activity.score)} *"
45
45
  - else
46
- = statement_activity.score.to_i
46
+ = cpd_score(statement_activity.score)
47
47
 
48
48
  .col-2.carry-forward
49
- = statement_activity.carry_forward.to_i
49
+ = cpd_score(statement_activity.carry_forward)
50
50
 
51
51
  .statement-activity-form.row{style: 'display: none;'}
52
52
  .col
@@ -59,6 +59,6 @@
59
59
  .col-8
60
60
  %h4 Total #{cpd_credits_label} in statement
61
61
  .col-2.score
62
- %h4= cpd_statement.score.to_i
62
+ %h4= cpd_score(cpd_statement.score)
63
63
  .col-2.carry-forward
64
- %h4= cpd_statement.carry_forward.to_i
64
+ %h4= cpd_score(cpd_statement.carry_forward)
@@ -19,14 +19,14 @@
19
19
 
20
20
  %tr
21
21
  %td
22
- %h4= resource.score.to_i
22
+ %h4= cpd_score(resource.score.to_d)
23
23
 
24
24
  %td
25
- #{cpd_credits_label} out of #{resource.required_score} required
25
+ #{cpd_credits_label} out of #{resource.required_score.to_i} required
26
26
 
27
27
  %tr
28
28
  %td
29
- %h4= last_3_scores.to_i
29
+ %h4= cpd_score(last_3_scores.to_d)
30
30
 
31
31
  %td #{cpd_credits_label} in last 3 #{cpd_cycles_label} (including this #{cpd_cycle_label})
32
32
 
@@ -24,8 +24,8 @@
24
24
 
25
25
  %tr
26
26
  %th Total #{cpd_credits_label.titleize}
27
- %td= cpd_statement.score
27
+ %td= cpd_score(cpd_statement.score)
28
28
 
29
29
  %tr
30
30
  %th Carry Forward
31
- %td= cpd_statement.carry_forward
31
+ %td= cpd_score(cpd_statement.carry_forward)
@@ -75,14 +75,14 @@ class CreateEffectiveCpd < ActiveRecord::Migration[6.0]
75
75
  t.references :cpd_category
76
76
  t.references :original
77
77
 
78
- t.integer :amount
79
- t.integer :amount2
78
+ t.decimal :amount, precision: 10, scale: 2
79
+ t.decimal :amount2, precision: 10, scale: 2
80
80
 
81
81
  t.text :description
82
82
 
83
- t.integer :carry_over
84
- t.integer :score
85
- t.integer :carry_forward
83
+ t.decimal :carry_over, precision: 10, scale: 2
84
+ t.decimal :score, precision: 10, scale: 2
85
+ t.decimal :carry_forward, precision: 10, scale: 2
86
86
 
87
87
  t.text :reduced_messages
88
88
 
@@ -98,7 +98,7 @@ class CreateEffectiveCpd < ActiveRecord::Migration[6.0]
98
98
 
99
99
  t.string :token
100
100
 
101
- t.integer :score
101
+ t.decimal :score, precision: 10, scale: 2
102
102
 
103
103
  t.boolean :confirm_read
104
104
  t.boolean :confirm_factual
@@ -1,3 +1,3 @@
1
1
  module EffectiveCpd
2
- VERSION = '0.1.19'
2
+ VERSION = '0.2.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: effective_cpd
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.19
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Code and Effect
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-11-17 00:00:00.000000000 Z
11
+ date: 2022-01-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails