Skip to content

dcs.utils.data_processing

DataProcessing

Data collection and processing utility class.

Handles data export to JSON and CSV formats with timestamped filenames.

data_dict property

Get the current data dictionary.

Returns:

Name Type Description
dict dict

The stored data dictionary.

__init__(filename, data=None)

Initialize with filename and optional data.

Parameters:

Name Type Description Default
filename str

Base filename for exported files.

required
data dict

Initial data dictionary. Defaults to None.

None

__is_file_existed(filepath)

Check if file already exists.

Parameters:

Name Type Description Default
filepath str

Path to the file to check.

required

Returns:

Name Type Description
bool bool

True if file exists, False otherwise.

update_data(new_data)

Update the data dictionary.

Parameters:

Name Type Description Default
new_data dict

New data dictionary to store.

required

write_dict_to_csv(header)

Export data dictionary to CSV file.

Parameters:

Name Type Description Default
header list

List of column headers for the CSV file.

required

Raises:

Type Description
Exception

If the file already exists.

write_dict_to_json()

Export data dictionary to JSON file.

Creates a JSON file in the json directory with auto-numbered filename if the original filename already exists.