[ARVADOS] updated: 08b9ee71323c22fb04c183b09991ca3e6db712fd

git at public.curoverse.com git at public.curoverse.com
Thu Sep 11 08:57:59 EDT 2014


Summary of changes:
 .../app/helpers/pipeline_instances_helper.rb       | 51 ++++++++++++++++++++++
 apps/workbench/test/unit/determine_time_test.rb    |  8 ++++
 2 files changed, 59 insertions(+)
 create mode 100644 apps/workbench/test/unit/determine_time_test.rb

       via  08b9ee71323c22fb04c183b09991ca3e6db712fd (commit)
      from  aadca3ff41a12a7a52a2a072696564b90537b9b3 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.


commit 08b9ee71323c22fb04c183b09991ca3e6db712fd
Author: Peter Amstutz <peter.amstutz at curoverse.com>
Date:   Thu Sep 11 08:57:55 2014 -0400

    3187: Added algorithm to calculate wall clock run time from a set of overlapping ranges (i.e. concurrent jobs).

diff --git a/apps/workbench/app/helpers/pipeline_instances_helper.rb b/apps/workbench/app/helpers/pipeline_instances_helper.rb
index d2b3a85..2db463c 100644
--- a/apps/workbench/app/helpers/pipeline_instances_helper.rb
+++ b/apps/workbench/app/helpers/pipeline_instances_helper.rb
@@ -185,4 +185,55 @@ module PipelineInstancesHelper
     end
     s
   end
+
+  def determine_wallclock_runtime jobs
+    timestamps = []
+    jobs.each do |j|
+      insert_at = 0
+      timestamps.each_index do |i|
+        if started_at = j[:started_at]
+          finished_at = (if j[:finished_at] then j[:finished_at] else Time.now end)
+
+          if started_at >= timestamps[i][0] and finished_at <= timestamps[i][1]
+            # 'j' started and ended during 'i'
+            insert_at = -1
+            break
+          end
+
+          if started_at < timestamps[i][0] and finished_at >= timestamps[i][0] and finished_at <= timestamps[i][1]
+            # 'j' started before 'i' and ended during 'i'
+            # move start time of 'i' back
+            timestamps[i][0] = started_at
+            insert_at = -1
+            break
+          end
+
+          if started_at >= timestamps[i][0] and started_at <= timestamps[i][1]
+            # 'j' started during 'i'
+            # move end time of 'i' back
+            timestamps[i][1] = finished_at
+            insert_at = -1
+            break
+          end
+
+          if finished_at < timestamps[i][0]
+            # 'j' finished before 'i' started, so insert before 'i'
+            insert_at = i
+            break
+          end
+
+          if started_at > timestamps[i][1]
+            # 'j' started after 'i' finished, so insert after 'i'
+            insert_at = i
+            break
+          end
+
+        end
+      end
+      if insert_at > -1
+        timestamps.insert insert_at, [started_at, finished_at]
+      end
+    end
+    timestamps.map { |t| t[1] - t[0] }.reduce(:+)
+  end
 end
diff --git a/apps/workbench/test/unit/determine_time_test.rb b/apps/workbench/test/unit/determine_time_test.rb
new file mode 100644
index 0000000..1243221
--- /dev/null
+++ b/apps/workbench/test/unit/determine_time_test.rb
@@ -0,0 +1,8 @@
+require 'test_helper'
+
+class DetermineTimeTest < ActiveSupport::TestCase
+  test "one" do
+    r1 = [{started_at: 1, finished_at: 3}]
+    assert_equal 2, determine_wallclock_runtime(r1)
+  end
+end

-----------------------------------------------------------------------


hooks/post-receive
-- 




More information about the arvados-commits mailing list