def get_functions_by_name(harness, name): """ Returns all the functions by name, if it exists, otherwise returns False """ collection = get_function_collection(harness) argument = db_utils.make_single_field_argument("name", name) cursor = db_utils.mongo_find_records(collection, argument=argument, named_tuple=False) return db_utils.unload_cursor(cursor)
def get_current_structures(database): """Returns all the structures that haven't been removed. """ collection = get_structure_collection(database) argument = db_utils.make_single_field_argument("remove_date", None) cursor = db_utils.mongo_find_records(collection, argument=argument) return db_utils.unload_cursor(cursor)
def get_all_harnesses(): """Returns all the harness objects as a list as they currently exist in the program storage. """ collection = get_harness_collection() cursor = db_utils.mongo_find_records(collection, named_tuple=False) return db_utils.unload_cursor(cursor)
def get_removed_functions(harness): """Returns functions that have been removed from the specified harness. Optionally can return all records (including older) if current_only is set to False. """ collection = get_function_collection(harness) argument = db_utils.make_single_field_argument("status", "removed") cursor = db_utils.mongo_find_records(collection, argument=argument, named_tuple=False) return db_utils.unload_cursor(cursor)
def get_all_stations_by_program(program): """Returns all the stations that are within the given program. """ collection = get_station_collection() argument = db_utils.make_single_field_argument("program", program) cursor = db_utils.mongo_find_records(collection, argument=argument, named_tuple=False) return db_utils.unload_cursor(cursor)
def get_components_by_name(database, name): """ Returns all the components by name, if it exists, otherwise returns False """ collection = get_component_collection(database) argument = db_utils.make_single_field_argument('name', name) cursor = db_utils.mongo_find_records(collection, argument=argument, named_tuple=False) return db_utils.unload_cursor(cursor)
def get_all_current_functions(harness): """Returns all functions that are current (no removal date) in the current harness. """ collection = get_function_collection(harness) argument = db_utils.make_single_field_argument("remove_date", None) cursor = db_utils.mongo_find_records(collection, argument=argument, named_tuple=False) return db_utils.unload_cursor(cursor)
def get_all_workflows(harness, current_only=False): """ Returns all workflows as a list of workflow dictionary objects. Optionally can specify current_only to retrieve only the most current record for each workflow. """ collection = get_workflow_collection(harness) cursor = db_utils.mongo_find_records(collection, named_tuple=False) return db_utils.unload_cursor(cursor)
def get_all_components(database, current_only=False): """ Returns all components as a list of component dictionary objects. Optionally can specify current_only to retrieve only the most current record for each component. """ collection = get_component_collection(database) cursor = db_utils.mongo_find_records(collection, named_tuple=False) return db_utils.unload_cursor(cursor)
def get_all_current_components(database): """Returns all components that are current (no removal date) in the current database. """ collection = get_component_collection(database) argument = db_utils.make_single_field_argument('remove_date', None) cursor = db_utils.mongo_find_records(collection, argument=argument, named_tuple=False) return db_utils.unload_cursor(cursor)
def get_removed_components(database): """Returns components that have been removed from the specified database. Optionally can return all records (including older) if current_only is set to False. """ collection = get_component_collection(database) argument = db_utils.make_single_field_argument('status', 'removed') cursor = db_utils.mongo_find_records(collection, argument=argument, named_tuple=False) return db_utils.unload_cursor(cursor)
def get_function_by_id(harness, function_id): """Returns the function by the given id. """ collection = get_function_collection(harness) argument = db_utils.make_single_field_argument("_id", function_id) cursor = db_utils.mongo_find_records(collection, argument=argument, named_tuple=False) function_list = db_utils.unload_cursor(cursor) try: return function_list[0] except IndexError: return None
def get_record_by_id(database, collection, record_id): """Returns the record for the given id. """ collection = get_record_collection(database, collection) argument = db_utils.make_single_field_argument("_id", record_id) cursor = db_utils.mongo_find_records(collection, argument=argument) record_list = db_utils.unload_cursor(cursor) try: return record_list[0] except IndexError: return None
def get_component_by_id(database, component_id): """Returns the component by the given id. """ collection = get_component_collection(database) argument = db_utils.make_single_field_argument('_id', component_id) cursor = db_utils.mongo_find_records(collection, argument=argument, named_tuple=False) component_list = db_utils.unload_cursor(cursor) try: return component_list[0] except IndexError: return None
def get_workflow_by_id(harness, workflow_id): """Returns the workflow by the given id. """ collection = get_workflow_collection(harness) argument = db_utils.make_single_field_argument('_id', workflow_id) cursor = db_utils.mongo_find_records(collection, argument=argument, named_tuple=False) workflow_list = db_utils.unload_cursor(cursor) try: return workflow_list[0] except IndexError: return None
def get_harness_by_name(harness_name): """Returns the harness object with the matching passed name. """ collection = get_harness_collection() argument = db_utils.make_single_field_argument("name", harness_name) cursor = db_utils.mongo_find_records(collection, argument=argument, named_tuple=False) harness_list = db_utils.unload_cursor(cursor) try: return harness_list[0] except: return None
def get_enabled_functions(harness, current_only=True): """Returns the enabled functions for the specified harness. Optionally can return all records (including older) if current_only is set to False. """ collection = get_function_collection(harness) arguments = [] if current_only: arguments.append(db_utils.make_single_field_argument("remove_date", None)) arguments.append(db_utils.make_single_field_argument("status", "enabled")) argument = utils.merge_list_of_dicts(arguments) cursor = db_utils.mongo_find_records(collection, argument=argument, named_tuple=False) function_list = db_utils.unload_cursor(cursor) return function_list
def get_functions_for_component(harness, component, current=True): """Returns functions for the given component for the given harness. Optional parameter allows user to return current or all functions. """ collection = get_function_collection(harness) arguments = [] if current: arguments.append(db_utils.make_single_field_argument("remove_date", None)) arguments.append(db_utils.make_single_field_argument("component", component)) argument = utils.merge_list_of_dicts(arguments) cursor = db_utils.mongo_find_records(collection, argument=argument, named_tuple=False) function_list = db_utils.unload_cursor(cursor) return function_list
def get_all_templates_by_structure_name(database, structure_name): """Returns all templates in storage for the given structure name. """ collection = get_template_collection(database) arguments = [] arguments.append(db_utils.make_single_field_argument('structure', structure_name)) argument = utils.merge_list_of_dicts(arguments) cursor = db_utils.mongo_find_records(collection, argument=argument) template_list = db_utils.unload_cursor(cursor) try: return template_list except IndexError: return None
def replace_function_by_id(harness, function_id, function): """Replaces the current function with the new function. Returns the new function. """ collection = get_function_collection(harness) argument = db_utils.make_single_field_argument("_id", function_id) cursor = db_utils.mongo_replace_one(collection, function, argument) if cursor.matched_count == 1: cursor = db_utils.mongo_find_records(collection, argument=argument, named_tuple=False) function_list = db_utils.unload_cursor(cursor) try: return function_list[0] except IndexError: return None
def get_disabled_components(database, current_only=True): """Returns the disabled components for the specified database. Optionally can return all records (including older) if current_only is set to False. """ collection = get_component_collection(database) arguments = [] if current_only: arguments.append(db_utils.make_single_field_argument('remove_date', None)) arguments.append(db_utils.make_single_field_argument('status', 'disabled')) argument = utils.merge_list_of_dicts(arguments) cursor = db_utils.mongo_find_records(collection, argument=argument, named_tuple=False) component_list = db_utils.unload_cursor(cursor) return component_list
def get_program_stations_by_geoindex(program, longitude, latitude, max_count=0, max_distance=None): """Returns stations for the given program. Uses a max count or max distance to search from the given location. """ collection = get_station_collection() arguments = [] arguments.append(db_utils.make_single_field_argument("program", program)) arguments.append(db_utils.make_spatial_near_argument("location.point", longitude, latitude, max_distance)) argument = utils.merge_list_of_dicts(arguments) cursor = db_utils.mongo_find_records(collection, argument=argument, named_tuple=False).limit(max_count) return db_utils.unload_cursor(cursor)
def get_program_stations_within_polygon(program, polygon, max_count=0): """Returns stations for a given program that are within a given polygon, for example a country or state. The polygon must be a GeoJSON geometry. """ collection = get_station_collection() arguments = [] arguments.append(db_utils.make_single_field_argument("program", program)) arguments.append(db_utils.make_spatial_within_argument("location.point", polygon.coordinates, polygon.type)) argument = utils.merge_list_of_dicts(arguments) cursor = db_utils.mongo_find_records(collection, argument=argument, named_tuple=False).limit(max_count) return db_utils.unload_cursor(cursor)
def replace_workflow_by_id(harness, workflow_id, workflow): """Replaces the current workflow with the new workflow. Returns the new workflow. """ collection = get_workflow_collection(harness) argument = db_utils.make_single_field_argument('_id', workflow_id) cursor = db_utils.mongo_replace_one(collection, workflow, argument) if cursor.matched_count == 1: cursor = db_utils.mongo_find_records(collection, argument=argument, named_tuple=False) workflow_list = db_utils.unload_cursor(cursor) try: return workflow_list[0] except IndexError: return None
def get_structure_by_id(database, structure_id): """Returns the current profile by name. """ collection = get_structure_collection(database) arguments = [] arguments.append(db_utils.make_single_field_argument('_id', structure_id)) arguments.append(db_utils.make_single_field_argument('remove_date', None)) argument = utils.merge_list_of_dicts(arguments) cursor = db_utils.mongo_find_records(collection, argument=argument) structure_list = db_utils.unload_cursor(cursor) try: return structure_list[0] except IndexError: return None
def get_template_by_id(database, template_id): """Returns the template by id. """ collection = get_template_collection(database) template_id = db_utils.ensure_objectid(template_id) arguments = [] arguments.append(db_utils.make_single_field_argument('_id', template_id)) argument = utils.merge_list_of_dicts(arguments) cursor = db_utils.mongo_find_records(collection, argument=argument) template_list = db_utils.unload_cursor(cursor) try: return template_list[0] except IndexError: return None
def get_translator_by_id(database, translator_id): """Returns the current translator by id. """ collection = get_translator_collection(database) arguments = [] arguments.append(db_utils.make_single_field_argument('_id', translator_id)) arguments.append(db_utils.make_single_field_argument('remove_date', None)) argument = utils.merge_list_of_dicts(arguments) cursor = db_utils.mongo_find_records(collection, argument=argument) translator_list = db_utils.unload_cursor(cursor) try: return translator_list[0] except IndexError: return None
def replace_component_by_id(database, component_id, component): """Replaces the current component with the new component. Returns the new component. """ collection = get_component_collection(database) argument = db_utils.make_single_field_argument('_id', component_id) cursor = db_utils.mongo_replace_one(collection, component, argument) if cursor.matched_count == 1: cursor = db_utils.mongo_find_records(collection, argument=argument, named_tuple=False) component_list = db_utils.unload_cursor(cursor) try: return component_list[0] except IndexError: return None
def get_current_function_by_name(harness, name): """Returns the current function by name. """ collection = get_function_collection(harness) arguments = [] arguments.append(db_utils.make_single_field_argument("name", name)) arguments.append(db_utils.make_single_field_argument("remove_date", None)) argument = utils.merge_list_of_dicts(arguments) cursor = db_utils.mongo_find_records(collection, argument=argument, named_tuple=False) function_list = db_utils.unload_cursor(cursor) try: return function_list[0] except IndexError: return None
def get_current_component_by_name(database, name): """Returns the current component by name. """ collection = get_component_collection(database) arguments = [] arguments.append(db_utils.make_single_field_argument('name', name)) arguments.append(db_utils.make_single_field_argument('remove_date', None)) argument = utils.merge_list_of_dicts(arguments) cursor = db_utils.mongo_find_records(collection, argument=argument, named_tuple=False) component_list = db_utils.unload_cursor(cursor) try: return component_list[0] except IndexError: return None