``collection`` ================================== .. py:module:: optimeed.core.collection Module Contents --------------- Classes ~~~~~~~ .. autoapisummary:: optimeed.core.collection.SingleObjectSaveLoad optimeed.core.collection.DataStruct_Interface optimeed.core.collection.ListDataStruct_Interface optimeed.core.collection.AutosaveStruct optimeed.core.collection.ListDataStruct optimeed.core.collection.Performance_ListDataStruct Attributes ~~~~~~~~~~ .. autoapisummary:: optimeed.core.collection.theLock .. py:class:: SingleObjectSaveLoad .. py:method:: load(filename) :staticmethod: .. py:method:: save(theObject, filename) :staticmethod: .. py:class:: DataStruct_Interface .. py:method:: save(filename) :abstractmethod: Save the datastructure to filename .. py:method:: clone(filename) :abstractmethod: Clone the datastructure to a new location .. py:method:: load(filename, **kwargs) :staticmethod: :abstractmethod: Load the datastructure from filename .. py:method:: get_extension() :staticmethod: File extension used for datastructure .. py:method:: __str__() Return str(self). .. py:class:: ListDataStruct_Interface Bases: :py:obj:`DataStruct_Interface` .. py:method:: add_data(data_in) :abstractmethod: .. py:method:: get_data_at_index(index) :abstractmethod: .. py:method:: get_data_generator() :abstractmethod: .. py:method:: delete_points_at_indices(indices) :abstractmethod: Delete several elements from the Collection :param indices: list of indices to delete .. py:method:: get_nbr_elements() :abstractmethod: :return: the number of elements contained inside the structure .. py:method:: extract_collection_from_indices(theIndices) :abstractmethod: Extract data from the collection at specific indices, and return it as new collection :param theIndices: :return: A new collection .. py:method:: _jsondata_to_obj(item, theClass=None) :staticmethod: .. py:method:: get_list_attributes(attributeName) Get the value of attributeName of all the data in the Collection :param attributeName: string (name of the attribute to get) :return: list .. py:class:: AutosaveStruct(dataStruct, filename='', change_filename_if_exists=True) Structure that provides automated save of DataStructures .. py:method:: __str__() Return str(self). .. py:method:: get_filename() Get set filename .. py:method:: set_filename(filename, change_filename_if_exists) :param filename: Filename to set :param change_filename_if_exists: If already exists, create a new filename .. py:method:: stop_autosave() Stop autosave .. py:method:: start_autosave(timer_autosave, safe_save=True) Start autosave .. py:method:: save(safe_save=True) Save .. py:method:: get_datastruct() Return :class:'~DataStruct_Interface' .. py:method:: __getstate__() .. py:method:: __setstate__(state) .. py:class:: ListDataStruct(compress_save=False) Bases: :py:obj:`ListDataStruct_Interface` .. py:attribute:: _DATA_STR :value: 'data' .. py:attribute:: _COMPRESS_SAVE_STR :value: 'module_tree' .. py:method:: __len__() .. py:method:: get_length() .. py:method:: clone(filename) Clone the datastructure to a new location .. py:method:: save(filename) Save data using json format. The data to be saved are automatically detected, see :meth:`~optimeed.core.myjson.obj_to_json` .. py:method:: extract_collection_from_indices(indices) Extract data from the collection at specific indices, and return it as new collection .. py:method:: _format_str_save() Save data using json format. The data to be saved are automatically detected, see :meth:`~optimeed.core.myjson.obj_to_json` .. py:method:: _format_data_lines() .. py:method:: _get_json_module_tree() .. py:method:: load(filename, theClass=None) :staticmethod: Load the file filename. :param filename: file to load :param theClass: optional. Can be used to fix unpickling errors. :return: self-like object .. py:method:: add_data(data_in) Add a data to the list .. py:method:: get_data() Get full list of datas .. py:method:: get_data_generator() Get a generator to all the data stored .. py:method:: get_data_at_index(index) .. py:method:: set_data(theData) Set full list of datas .. py:method:: set_data_at_index(data_in, index) Replace data at specific index .. py:method:: extract_collection_from_attribute(attributeName) Convenience class to create a sub-collection from an attribute of all the items. :param attributeName: Name of the attribute to extract :return: ListDataStruct .. py:method:: reset_data() .. py:method:: delete_points_at_indices(indices) Delete several elements from the Collection :param indices: list of indices to delete .. py:method:: merge(collection) Merge a collection with the current collection :param collection: :class:`~optimeed.core.Collection.Collection` to merge .. py:method:: get_nbr_elements() :return: the number of elements contained inside the structure .. py:data:: theLock .. py:class:: Performance_ListDataStruct(stack_size=500) Bases: :py:obj:`ListDataStruct_Interface` .. py:attribute:: _NBR_ELEMENTS :value: 'nbr_elements' .. py:attribute:: _STACK_SIZE :value: 'stack_size' .. py:attribute:: _COMPRESS_SAVE_STR :value: 'module_tree' .. py:method:: _initialize(filename) .. py:method:: _get_subfolder_path(main_filename) :staticmethod: .. py:method:: _get_list_from_file(filenumber) .. py:method:: _get_path_from_filenumber(main_filename, filenumber) :staticmethod: .. py:method:: split_list(numb_in_list, stack_size, thing_to_hash) :staticmethod: .. py:method:: extract_collection_from_indices(indices) Extract data from the collection at specific indices, and return it as new collection .. py:method:: clone(filename) Clone the datastructure to a new location .. py:method:: _get_str_mainfile() .. py:method:: get_total_nbr_elements(count_unsaved=True) .. py:method:: add_data(theData) Add data to the collection .. py:method:: add_json_data(theStr) Add already deserialized data to the collection .. py:method:: _save_moduletree(theDict) .. py:method:: _map_index_to_file(index) .. py:method:: _get_json_str_at_index(index, refresh_cache=False) Internal method to return the json string at index .. py:method:: get_attribute_value_at_index_fast(attribute, index) Experimental method to extract the value of an attribute without converting the string to an object. It is based on regex search, and will fail if the element is the last in string. :param attribute: attribute to search :param index: index of the element in collection :return: .. py:method:: reorder(permutations) Reorder collection accordingly to permutations. E.G, permutations [0,2,1] with collection elems [0,3,2] => collection elems = [0,2,3] :param permutations: :return: / .. py:method:: get_data_at_index(index, ignore_attributes=None, none_if_error=False) Same as parent, with additional kwargs :param index: :param ignore_attributes: ignore attributes to deserialize (list) :param none_if_error: :return: .. py:method:: save(filename) Save the datastructure to filename .. py:method:: load(filename, **kwargs) :staticmethod: Load the datastructure from filename .. py:method:: load_as_listdatastruct(filename, **kwargs) :staticmethod: Return :class:`ListDataStruct`. Serializes all objects of collection .. py:method:: get_data_generator(**kwargs) .. py:method:: get_nbr_elements() :return: the number of elements contained inside the structure .. py:method:: set_data_at_index(data_in, index) Replace data at specific index .. py:method:: set_data_at_indices(data_list, indices) Replace datas at specific indices :param data_list: list of objects to set to the collection, at specific indices :param indices: list of indices :return: .. py:method:: delete_points_at_indices(indices) Delete several elements from the Collection :param indices: list of indices to delete