Repository: incubator-airflow
Updated Branches:
  refs/heads/master 949479cf7 -> ea2904610


[AIRFLOW-225] Better units for task duration graph

Right now the job duration window defaults to hours, which for short lived tasks
results in numbers out to five decimals. This patch adjusts the scale of the 
Y-axis
in accordance with the maximum value of the durations to be shown.


Project: http://git-wip-us.apache.org/repos/asf/incubator-airflow/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-airflow/commit/11411652
Tree: http://git-wip-us.apache.org/repos/asf/incubator-airflow/tree/11411652
Diff: http://git-wip-us.apache.org/repos/asf/incubator-airflow/diff/11411652

Branch: refs/heads/master
Commit: 1141165271b0e1546ca231bf8aa412793dc38201
Parents: 8aa7160
Author: Kengo Seki <[email protected]>
Authored: Wed Jun 15 04:19:02 2016 +0000
Committer: Kengo Seki <[email protected]>
Committed: Wed Jun 15 04:19:02 2016 +0000

----------------------------------------------------------------------
 airflow/www/views.py | 21 +++++++++++++++++++--
 1 file changed, 19 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-airflow/blob/11411652/airflow/www/views.py
----------------------------------------------------------------------
diff --git a/airflow/www/views.py b/airflow/www/views.py
index b468bc1..fc6819b 100644
--- a/airflow/www/views.py
+++ b/airflow/www/views.py
@@ -1477,6 +1477,7 @@ class Airflow(BaseView):
                 include_downstream=False)
 
         all_data = []
+        max_duration = 0
         for task in dag.tasks:
             data = []
             for ti in task.get_task_instances(session, start_date=min_date,
@@ -1484,11 +1485,27 @@ class Airflow(BaseView):
                 if ti.duration:
                     data.append([
                         ti.execution_date.isoformat(),
-                        float(ti.duration) / (60*60)
+                        ti.duration
                     ])
+                    if max_duration < ti.duration:
+                        max_duration = ti.duration
             if data:
                 all_data.append({'data': data, 'name': task.task_id})
 
+        def divide_durations(all_data, denom):
+            for data in all_data:
+                for d in data['data']:
+                    d[1] /= denom
+
+        if 60*60 < max_duration:
+            unit = 'hours'
+            divide_durations(all_data, float(60*60))
+        elif 60 < max_duration:
+            unit = 'minutes'
+            divide_durations(all_data, 60.0)
+        else:
+            unit = 'seconds'
+
         tis = dag.get_task_instances(
                 session, start_date=min_date, end_date=base_date)
         dates = sorted(list({ti.execution_date for ti in tis}))
@@ -1503,7 +1520,7 @@ class Airflow(BaseView):
             'airflow/chart.html',
             dag=dag,
             data=json.dumps(all_data),
-            chart_options={'yAxis': {'title': {'text': 'hours'}}},
+            chart_options={'yAxis': {'title': {'text': unit}}},
             height="700px",
             demo_mode=conf.getboolean('webserver', 'demo_mode'),
             root=root,

Reply via email to