polyfemos.back.filewriter.FileWriter — polyfemos 0.3.29 documentation

# polyfemos.back.filewriter.FileWriter

class `polyfemos.back.filewriter.` `FileWriter`(bool_=False, fp_func=None, retroactive=False)

  Bases: `object`

  Parent class for state of health file writer classes

  Public Methods

  `__init__`(bool_=False, fp_func=None, retroactive=False)

    The attribute values are suitable for writing state of health csv files by default.

    `self._file_writing_func` is set to `write_csv()`.

    `self._create_line_func` is set to `create_csvline()`.

    Parameters

      - bool_ (bool) – If `False`, methods of this class do nothing, If `fp_func` is not callable, `bool_` is set to `False`

      - fp_func (func) – filepath function, e.g. FLAGs ‘sohtextfilepath’ ‘sohalertpath’ or ‘sohcsvpath’. See `_init_flags()` for more information.

      - retroactive (bool) – defines if the retroactive mode is used. See `_init_flags()` for more info.

  `append_and_write_data`(filename, *args)

    Additional arguments `args` are applied to the function `self._create_line_func`.

    Creates and immediately writes a new line to file `filename`.

    Parameters

      filename (str) –

  `append_data`(filename, *args)

    Additional arguments `args` are applied to the function `self._create_line_func`.

    Creates and appends a new line to file entry (`filename`) in `self._dict`.

    Parameters

      filename (str) –

  `append_line`(filename, line)

    If there is no file with a name `filename` in `self._dict`, header is added to the corersponding file entry in `self._dict`.

    Parameters

      - filename (str) –

      - line (list) – A line to be appended into the file (`filename`) entry in `self._dict`.

  `get_filename`(pathkwargs)

    Applies `pathkwargs` to `self._filepath_func` and returns the resulting filepath. If retroactive mode is used, ‘retro’ identifier is added to the filepath.

    Parameters

      pathkwargs (dict) – keyword arguments for `self._filepath_func`

    Return type

      str

    Returns

  `update_header`(header)
    Parameters

      header (str or list) – a new header applied to `self._header`

  `write_files`()

    Writes out every file in `self._dict` and deletes the data contained in it.