Ejemplo n.º 1
0
 def ls(self, **kwargs):
     self.session_controller = SessionController()
     print_format = kwargs.get('format', "table")
     download = kwargs.get('download', None)
     download_path = kwargs.get('download_path', None)
     sessions = self.session_controller.list(sort_key="created_at",
                                             sort_order="descending")
     header_list = [
         "id", "created at", "name", "selected", "tasks", "snapshots"
     ]
     item_dict_list = []
     for session_obj in sessions:
         snapshot_count = len(
             self.session_controller.dal.snapshot.query({
                 "session_id":
                 session_obj.id,
                 "model_id":
                 self.session_controller.model.id
             }))
         task_count = len(
             self.session_controller.dal.task.query({
                 "session_id":
                 session_obj.id,
                 "model_id":
                 self.session_controller.model.id
             }))
         item_dict_list.append({
             "id":
             session_obj.id,
             "created at":
             prettify_datetime(session_obj.created_at),
             "name":
             printable_object(session_obj.name),
             "selected":
             printable_object(session_obj.current),
             "tasks":
             printable_object(task_count),
             "snapshots":
             printable_object(snapshot_count)
         })
     if download:
         if not download_path:
             # download to current working directory with timestamp
             current_time = datetime.utcnow()
             epoch_time = datetime.utcfromtimestamp(0)
             current_time_unix_time_ms = (
                 current_time - epoch_time).total_seconds() * 1000.0
             download_path = os.path.join(
                 self.session_controller.home,
                 "session_ls_" + str(current_time_unix_time_ms))
         self.cli_helper.print_items(header_list,
                                     item_dict_list,
                                     print_format=print_format,
                                     output_path=download_path)
         return sessions
     self.cli_helper.print_items(header_list,
                                 item_dict_list,
                                 print_format=print_format)
     return sessions
Ejemplo n.º 2
0
 def ls(self, **kwargs):
     # Create controllers
     self.task_controller = TaskController()
     self.snapshot_controller = SnapshotController()
     session_id = kwargs.get('session_id',
                             self.task_controller.current_session.id)
     print_format = kwargs.get('format', "table")
     download = kwargs.get('download', None)
     download_path = kwargs.get('download_path', None)
     # Get all task meta information
     task_objs = self.task_controller.list(session_id,
                                           sort_key="created_at",
                                           sort_order="descending")
     header_list = [
         "id", "command", "status", "config", "results", "created at"
     ]
     item_dict_list = []
     run_obj_list = []
     for task_obj in task_objs:
         # Create a new Run Object from Task Object
         run_obj = RunObject(task_obj)
         task_results_printable = printable_object(str(run_obj.results))
         snapshot_config_printable = printable_object(str(run_obj.config))
         item_dict_list.append({
             "id":
             run_obj.id,
             "command":
             run_obj.command,
             "status":
             run_obj.status,
             "config":
             snapshot_config_printable,
             "results":
             task_results_printable,
             "created at":
             prettify_datetime(run_obj.created_at)
         })
         run_obj_list.append(run_obj)
     if download:
         if not download_path:
             # download to current working directory with timestamp
             current_time = datetime.utcnow()
             epoch_time = datetime.utcfromtimestamp(0)
             current_time_unix_time_ms = (
                 current_time - epoch_time).total_seconds() * 1000.0
             download_path = os.path.join(
                 os.getcwd(), "run_ls_" + str(current_time_unix_time_ms))
         self.cli_helper.print_items(header_list,
                                     item_dict_list,
                                     print_format=print_format,
                                     output_path=download_path)
         return task_objs
     self.cli_helper.print_items(header_list,
                                 item_dict_list,
                                 print_format=print_format)
     return run_obj_list
Ejemplo n.º 3
0
 def ls(self, **kwargs):
     self.task_controller = TaskController()
     session_id = kwargs.get('session_id',
                             self.task_controller.current_session.id)
     print_format = kwargs.get('format', "table")
     download = kwargs.get('download', None)
     download_path = kwargs.get('download_path', None)
     # Get all task meta information
     task_objs = self.task_controller.list(session_id,
                                           sort_key='created_at',
                                           sort_order='descending')
     header_list = [
         "id", "start time", "duration (s)", "command", "status", "results"
     ]
     item_dict_list = []
     for task_obj in task_objs:
         task_results_printable = printable_object(task_obj.results)
         item_dict_list.append({
             "id":
             task_obj.id,
             "command":
             printable_object(task_obj.command),
             "status":
             printable_object(task_obj.status),
             "results":
             task_results_printable,
             "start time":
             prettify_datetime(task_obj.start_time),
             "duration (s)":
             printable_object(task_obj.duration)
         })
     if download:
         if not download_path:
             # download to current working directory with timestamp
             current_time = datetime.utcnow()
             epoch_time = datetime.utcfromtimestamp(0)
             current_time_unix_time_ms = (
                 current_time - epoch_time).total_seconds() * 1000.0
             download_path = os.path.join(
                 self.task_controller.home,
                 "task_ls_" + str(current_time_unix_time_ms))
         self.cli_helper.print_items(header_list,
                                     item_dict_list,
                                     print_format=print_format,
                                     output_path=download_path)
         return task_objs
     self.cli_helper.print_items(header_list,
                                 item_dict_list,
                                 print_format=print_format)
     return task_objs
Ejemplo n.º 4
0
def model_experiments(model_name):
    model = base_controller.model.__dict__
    if model_name == model['name']:
        tasks = base_controller.dal.task.query({"model_id": model['id']})
        experiments = [Run(task) for task in tasks]
        for experiment in experiments:
            experiment.config_printable = printable_object(experiment.config)
            experiment.start_time_prettified = prettify_datetime(
                experiment.start_time)
            experiment.end_time_prettified = prettify_datetime(
                experiment.end_time)
            experiment.results_printable = printable_object(experiment.results)
    else:
        experiments = []
    return render_template("model_experiments.html",
                           user=user,
                           model=model,
                           experiments=experiments)
Ejemplo n.º 5
0
 def ls(self, **kwargs):
     self.environment_controller = EnvironmentController()
     print_format = kwargs.get('format', "table")
     download = kwargs.get('download', None)
     download_path = kwargs.get('download_path', None)
     environment_objs = self.environment_controller.list()
     header_list = ["id", "created at", "name", "description"]
     item_dict_list = []
     for environment_obj in environment_objs:
         environment_obj_name = printable_object(environment_obj.name)
         environment_obj_description = printable_object(
             environment_obj.description)
         item_dict_list.append({
             "id":
             environment_obj.id,
             "created at":
             prettify_datetime(environment_obj.created_at),
             "name":
             environment_obj_name,
             "description":
             environment_obj_description
         })
     if download:
         if not download_path:
             # download to current working directory with timestamp
             current_time = datetime.utcnow()
             epoch_time = datetime.utcfromtimestamp(0)
             current_time_unix_time_ms = (
                 current_time - epoch_time).total_seconds() * 1000.0
             download_path = os.path.join(
                 self.environment_controller.home,
                 "environment_ls_" + str(current_time_unix_time_ms))
         self.cli_helper.print_items(header_list,
                                     item_dict_list,
                                     print_format=print_format,
                                     output_path=download_path)
         return environment_objs
     self.cli_helper.print_items(header_list,
                                 item_dict_list,
                                 print_format=print_format)
     return environment_objs
Ejemplo n.º 6
0
 def to_dictionary(self, stringify=False):
     attr_dict = self.__dict__
     pruned_attr_dict = {
         attr: val
         for attr, val in attr_dict.items()
         if not callable(getattr(self, attr)) and not attr.startswith("__")
     }
     if stringify:
         for key in ["config", "stats", "message", "label"]:
             pruned_attr_dict[key] = printable_object(pruned_attr_dict[key])
         for key in ["created_at", "updated_at"]:
             pruned_attr_dict[key] = prettify_datetime(
                 pruned_attr_dict[key])
     return pruned_attr_dict
Ejemplo n.º 7
0
 def ls(self, **kwargs):
     self.snapshot_controller = SnapshotController()
     detailed_info = kwargs.get('details', None)
     show_all = kwargs.get('show_all', None)
     print_format = kwargs.get('format', "table")
     download = kwargs.get('download', None)
     download_path = kwargs.get('download_path', None)
     current_snapshot_obj = self.snapshot_controller.current_snapshot()
     current_snapshot_id = current_snapshot_obj.id if current_snapshot_obj else None
     if show_all:
         snapshot_objs = self.snapshot_controller.list(
             sort_key="created_at", sort_order="descending")
     else:
         snapshot_objs = self.snapshot_controller.list(
             visible=True, sort_key="created_at", sort_order="descending")
     item_dict_list = []
     if detailed_info:
         header_list = [
             "id", "created at", "config", "stats", "message", "label",
             "code id", "environment id", "file collection id"
         ]
         for snapshot_obj in snapshot_objs:
             snapshot_config_printable = printable_object(
                 snapshot_obj.config)
             snapshot_stats_printable = printable_object(snapshot_obj.stats)
             snapshot_message = printable_object(snapshot_obj.message)
             snapshot_label = printable_object(snapshot_obj.label)
             printable_snapshot_id = snapshot_obj.id if current_snapshot_id is not None and \
                                                        snapshot_obj.id != current_snapshot_id\
                 else "(current) " + snapshot_obj.id
             item_dict_list.append({
                 "id": printable_snapshot_id,
                 "created at": prettify_datetime(snapshot_obj.created_at),
                 "config": snapshot_config_printable,
                 "stats": snapshot_stats_printable,
                 "message": snapshot_message,
                 "label": snapshot_label,
                 "code id": snapshot_obj.code_id,
                 "environment id": snapshot_obj.environment_id,
                 "file collection id": snapshot_obj.file_collection_id
             })
     else:
         header_list = [
             "id", "created at", "config", "stats", "message", "label"
         ]
         for snapshot_obj in snapshot_objs:
             snapshot_config_printable = printable_object(
                 snapshot_obj.config)
             snapshot_stats_printable = printable_object(snapshot_obj.stats)
             snapshot_message = printable_object(snapshot_obj.message)
             snapshot_label = printable_object(snapshot_obj.label)
             printable_snapshot_id = snapshot_obj.id if current_snapshot_id is not None and \
                                                        snapshot_obj.id != current_snapshot_id \
                 else "(current) " + snapshot_obj.id
             item_dict_list.append({
                 "id": printable_snapshot_id,
                 "created at": prettify_datetime(snapshot_obj.created_at),
                 "config": snapshot_config_printable,
                 "stats": snapshot_stats_printable,
                 "message": snapshot_message,
                 "label": snapshot_label,
             })
     if download:
         if not download_path:
             # download to current working directory with timestamp
             current_time = datetime.utcnow()
             epoch_time = datetime.utcfromtimestamp(0)
             current_time_unix_time_ms = (
                 current_time - epoch_time).total_seconds() * 1000.0
             download_path = os.path.join(
                 self.snapshot_controller.home,
                 "snapshot_ls_" + str(current_time_unix_time_ms))
         self.cli_helper.print_items(
             header_list,
             item_dict_list,
             print_format=print_format,
             output_path=download_path)
         return snapshot_objs
     self.cli_helper.print_items(
         header_list, item_dict_list, print_format=print_format)
     return snapshot_objs