bpm_manager 0.9.0 → 0.9.1

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
  SHA1:
3
- metadata.gz: 308ea5ab2895ab6fe6fa2e2e70d2a4d95fe21ce1
4
- data.tar.gz: 18d0953554c19cabee67c145cedc8094df843ef2
3
+ metadata.gz: 2447f095243eadeb0cdb652f998b53887e402665
4
+ data.tar.gz: 902c7dd6e4e5bc891ba40cdb48cca5ce309c63a4
5
5
  SHA512:
6
- metadata.gz: 2b8434c185cd9614ba9fbc47e0eae5ad5f97582582f60c04b57b40de8e803002665cfbdc93f99107ec2f08fa67625d63690baa3f57b23f9ede0d7da2b36c6994
7
- data.tar.gz: eff3d64a09ae932b6a9f5ebe2b8cd74389743cc0f7489d6322741a37226679bc031b497ba245a81fd91835e132fb887b6798fc583d1c17d6f68bbbe53f4fb597
6
+ metadata.gz: 5796302fb793aa29dc042864ad1c46585251f059e8362f7cd1adc5c0bb4ab9dbd0f0d64d4390207a805ed9c38e5fd1b381961bdba9f628651e9b99d16ca513d0
7
+ data.tar.gz: 1c05c05830789c068b2a020f65f006a12318fbd9256cb55c1ba35b2b8a727d491965daaa436a2d8da1f6c1251b84a20df61fd1aade49fd6089c59e962569c1ed
@@ -122,6 +122,29 @@ module BpmManager
122
122
  RestClient.post(URI.encode(BpmManager.uri('/history/clear')), :headers => {:content_type => :json, :accept => :json})
123
123
  end
124
124
 
125
+ # Gets the SLA for a Process Instance
126
+ def self.get_task_sla(task_instance_id, process_sla_hours = 0, task_sla_hours = 0, warning_offset_percent = 20)
127
+ sla = OpenStruct.new
128
+ sla.task = OpenStruct.new
129
+ sla.process = OpenStruct.new
130
+ my_task = self.tasks_with_opts(:taskId => task_instance_id).first
131
+
132
+ unless my_task.nil?
133
+ else
134
+ # Calculates the process sla
135
+ sla.process.status = calculate_sla(my_task.process.start_on, process_sla_hours, warning_offset_percent)
136
+ sla.process.status_name = (calculate_sla(my_task.process.start_on, process_sla_hours, warning_offset_percent) == 0) ? 'ok' : (calculate_sla(my_task.process.start_on, process_sla_hours, warning_offset_percent) == 1 ? 'warning' : 'due')
137
+ sla.process.percent = calculate_sla_percent(my_task.process.start_on, process_sla_hours, warning_offset_percent)
138
+
139
+ # Calculates the task sla
140
+ sla.task.status = calculate_sla(my_task.task.created_on, task_sla_hours, warning_offset_percent)
141
+ sla.task.status_name = (calculate_sla(my_task.created_on, task_sla_hours, warning_offset_percent) == 0) ? 'ok' : (calculate_sla(my_task.created_on, task_sla_hours, warning_offset_percent) == 1 ? 'warning' : 'due')
142
+ sla.task.percent = calculate_sla_percent(my_task.created_on, task_sla_hours, warning_offset_percent)
143
+ end
144
+
145
+ return sla
146
+ end
147
+
125
148
  private
126
149
  def self.structure_task_data(input)
127
150
  tasks = []
@@ -158,5 +181,24 @@ module BpmManager
158
181
 
159
182
  return tasks
160
183
  end
184
+
185
+ def calculate_sla(start, sla_hours=0, offset=20)
186
+ unless sla_hours > 0
187
+ (start.to_f + ((sla_hours.to_f * 7*24*60*60))*((100-offset)/100)) <= Time.now.utc.to_f ? 0 : ((start.to_f + (sla_hours.to_f * 7*24*60*60) <= Time.now.utc.to_f) ? 1 : 2)
188
+ else
189
+ 0
190
+ end
191
+ end
192
+
193
+ def calculate_sla_percent(start, sla_hours=0, offset=20)
194
+ percent = OpenStruct.new
195
+ total = Time.now.utf.to_f - start.to_f
196
+
197
+ percent.green = sla_hours > 0 ? (start.to_f + ((sla_hours.to_f * 7*24*60*60)) * ((100-offset)/100)) / total * 100 : 100
198
+ percent.yellow = sla_hours > 0 ? (start.to_f + ((sla_hours.to_f * 7*24*60*60)) / total * 100) - green : 0
199
+ percent.red = sla_hours > 0 ? 100 - yellow - green : 0
200
+
201
+ return percent
202
+ end
161
203
  end
162
204
  end
@@ -1,3 +1,3 @@
1
1
  module BpmManager
2
- VERSION = "0.9.0"
2
+ VERSION = "0.9.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bpm_manager
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.0
4
+ version: 0.9.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ariel Presa