[ARVADOS] updated: a0fc519db4f3664366c356d21a8478495f2ae78b

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


Summary of changes:
 .../app/helpers/pipeline_instances_helper.rb       | 100 ++++++++++-----------
 .../pipeline_instances_controller_test.rb          |  40 +++++++++
 apps/workbench/test/unit/determine_time_test.rb    |   8 --
 3 files changed, 90 insertions(+), 58 deletions(-)
 create mode 100644 apps/workbench/test/controllers/pipeline_instances_controller_test.rb
 delete mode 100644 apps/workbench/test/unit/determine_time_test.rb

       via  a0fc519db4f3664366c356d21a8478495f2ae78b (commit)
      from  08b9ee71323c22fb04c183b09991ca3e6db712fd (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 a0fc519db4f3664366c356d21a8478495f2ae78b
Author: Peter Amstutz <peter.amstutz at curoverse.com>
Date:   Thu Sep 11 11:57:12 2014 -0400

    3187: Tested and fixed and time calculation algorithm.

diff --git a/apps/workbench/app/helpers/pipeline_instances_helper.rb b/apps/workbench/app/helpers/pipeline_instances_helper.rb
index 2db463c..a17f125 100644
--- a/apps/workbench/app/helpers/pipeline_instances_helper.rb
+++ b/apps/workbench/app/helpers/pipeline_instances_helper.rb
@@ -22,6 +22,56 @@ module PipelineInstancesHelper
     pj
   end
 
+  def merge_range timestamps, started_at, finished_at
+    timestamps.each_index do |i|
+      if started_at
+        if started_at >= timestamps[i][0] and finished_at <= timestamps[i][1]
+          # 'j' started and ended during 'i'
+          return timestamps
+        end
+
+        if started_at < timestamps[i][0] and finished_at >= timestamps[i][0] and finished_at <= timestamps[i][1]
+          # 'j' started before 'i' and finished during 'i'
+          # re-merge range between when 'j' started and 'i' finished
+          finished_at = timestamps[i][1]
+          timestamps.delete_at i
+          return merge_range timestamps, started_at, finished_at
+        end
+
+        if started_at >= timestamps[i][0] and started_at <= timestamps[i][1]
+          # 'j' started during 'i' and finished sometime after
+          # move end time of 'i' back
+          # re-merge range between when 'i' started and 'j' finished
+          started_at = timestamps[i][0]
+          timestamps.delete_at i
+          return merge_range timestamps, started_at, finished_at
+        end
+
+        if finished_at < timestamps[i][0]
+          # 'j' finished before 'i' started, so insert before 'i'
+          timestamps.insert i, [started_at, finished_at]
+          return timestamps
+        end
+      end
+    end
+
+    timestamps << [started_at, finished_at]
+  end
+
+  def determine_wallclock_runtime jobs
+    puts "Begin #{jobs}"
+    timestamps = []
+    jobs.each do |j|
+      insert_at = 0
+      started_at = j[:started_at]
+      finished_at = (if j[:finished_at] then j[:finished_at] else Time.now end)
+      if started_at
+        timestamps = merge_range timestamps, started_at, finished_at
+      end
+    end
+    timestamps.map { |t| t[1] - t[0] }.reduce(:+)
+  end
+
   protected
 
   def pipeline_jobs_newschool object
@@ -186,54 +236,4 @@ module PipelineInstancesHelper
     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/controllers/pipeline_instances_controller_test.rb b/apps/workbench/test/controllers/pipeline_instances_controller_test.rb
new file mode 100644
index 0000000..d9f915b
--- /dev/null
+++ b/apps/workbench/test/controllers/pipeline_instances_controller_test.rb
@@ -0,0 +1,40 @@
+require 'test_helper'
+
+class PipelineInstancesControllerTest < ActionController::TestCase
+  include PipelineInstancesHelper
+
+  test "one" do
+    r = [{started_at: 1, finished_at: 3}]
+    assert_equal 2, determine_wallclock_runtime(r)
+
+    r = [{started_at: 1, finished_at: 5}]
+    assert_equal 4, determine_wallclock_runtime(r)
+
+    r = [{started_at: 1, finished_at: 2}, {started_at: 3, finished_at: 5}]
+    assert_equal 3, determine_wallclock_runtime(r)
+
+    r = [{started_at: 3, finished_at: 5}, {started_at: 1, finished_at: 2}]
+    assert_equal 3, determine_wallclock_runtime(r)
+
+    r = [{started_at: 3, finished_at: 5}, {started_at: 1, finished_at: 2},
+         {started_at: 2, finished_at: 4}]
+    assert_equal 4, determine_wallclock_runtime(r)
+
+    r = [{started_at: 1, finished_at: 5}, {started_at: 2, finished_at: 3}]
+    assert_equal 4, determine_wallclock_runtime(r)
+
+    r = [{started_at: 3, finished_at: 5}, {started_at: 1, finished_at: 4}]
+    assert_equal 4, determine_wallclock_runtime(r)
+
+    r = [{started_at: 1, finished_at: 4}, {started_at: 3, finished_at: 5}]
+    assert_equal 4, determine_wallclock_runtime(r)
+
+    r = [{started_at: 1, finished_at: 4}, {started_at: 3, finished_at: 5},
+         {started_at: 5, finished_at: 8}]
+    assert_equal 7, determine_wallclock_runtime(r)
+
+    r = [{started_at: 1, finished_at: 4}, {started_at: 3, finished_at: 5},
+         {started_at: 6, finished_at: 8}]
+    assert_equal 6, determine_wallclock_runtime(r)
+  end
+end
diff --git a/apps/workbench/test/unit/determine_time_test.rb b/apps/workbench/test/unit/determine_time_test.rb
deleted file mode 100644
index 1243221..0000000
--- a/apps/workbench/test/unit/determine_time_test.rb
+++ /dev/null
@@ -1,8 +0,0 @@
-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