[autotest] Add time segmented filter on job table on View Host page.
Modified the frontend to provide a start time and an end time with
datetime pickers. The place holder values are set to midnight "today".
Please note that the place holder values are not default values.
They are equivalent to empty strings, but exist to avoid making users
have to fill in all six segments (year, month, day, hour, minute, am/pm).
On the rpc side, added start_time and end_time parameters to
get_host_queue_entries, get_num_host_queue_entries,
get_host_queue_entries_and_special_tasks,
and get_num_host_queue_entries_and_special_tasks.
A helper function inject_start_end_time_to_dict is used to inject start_time
and end_time to filter_datas.
BUG=chromium:362240
TEST=ran afe, passed rpc_interface_unittest and frontend_unittest
DEPLOY=afe, apache
Change-Id: I44d59124cc104cf55d2ac3838be983286e270195
Reviewed-on: https://chromium-review.googlesource.com/209389
Tested-by: Jiaxi Luo <jiaxiluo@chromium.org>
Reviewed-by: Simran Basi <sbasi@chromium.org>
Commit-Queue: Jiaxi Luo <jiaxiluo@chromium.org>
diff --git a/frontend/afe/rpc_utils.py b/frontend/afe/rpc_utils.py
index 6cb369b..bccc23d 100644
--- a/frontend/afe/rpc_utils.py
+++ b/frontend/afe/rpc_utils.py
@@ -878,3 +878,40 @@
return global_config.global_config.get_config_value('AUTOTEST_WEB',
'wmatrix_url',
default='')
+
+
+def inject_times_to_filter(start_time_key=None, end_time_key=None,
+ start_time_value=None, end_time_value=None,
+ **filter_data):
+ """Inject the key value pairs of start and end time if provided.
+
+ @param start_time_key: A string represents the filter key of start_time.
+ @param end_time_key: A string represents the filter key of end_time.
+ @param start_time_value: Start_time value.
+ @param end_time_value: End_time value.
+
+ @returns the injected filter_data.
+ """
+ if start_time_value:
+ filter_data[start_time_key] = start_time_value
+ if end_time_value:
+ filter_data[end_time_key] = end_time_value
+ return filter_data
+
+
+def inject_times_to_hqe_special_tasks_filters(filter_data_common,
+ start_time, end_time):
+ """Inject start and end time to hqe and special tasks filters.
+
+ @param filter_data_common: Common filter for hqe and special tasks.
+ @param start_time_key: A string represents the filter key of start_time.
+ @param end_time_key: A string represents the filter key of end_time.
+
+ @returns a pair of hqe and special tasks filters.
+ """
+ filter_data_special_tasks = filter_data_common.copy()
+ return (inject_times_to_filter('started_on__gte', 'started_on__lte',
+ start_time, end_time, **filter_data_common),
+ inject_times_to_filter('time_started__gte', 'time_started__lte',
+ start_time, end_time,
+ **filter_data_special_tasks))
\ No newline at end of file