Skip to content

dcs.data.processing

DataGathering

A class to handle data gathering from the PLC and export to files.

This class provides functionality for collecting data during PLC operations and exporting it to JSON and CSV formats for analysis and storage.

Attributes:

Name Type Description
_DATA str

The absolute path of the data directory.

_JSON_DIR str

The absolute path of the json directory.

_CSV_DIR str

The absolute path of the csv directory.

filename str

Base filename for data export files.

Example

gatherer = DataGathering("experiment_01") data = {"timestamp": "2024-01-01", "value": 42.5} gatherer.write_dict_to_json(data) gatherer.write_dict_to_csv([data], ["timestamp", "value"])

__init__(filename)

Initialize data gathering with specified filename.

Parameters:

Name Type Description Default
filename str

Base filename for exported data files.

required

write_dict_to_csv(data, header)

Export list of dictionaries to CSV file.

Writes the provided data list to a CSV file in the configured CSV directory with the specified filename and header.

Parameters:

Name Type Description Default
data list

List of dictionaries containing row data.

required
header list

List of column headers for the CSV file.

required
Example

gatherer = DataGathering("sensor_log") data = [{"time": "10:00", "temp": 25.3}, {"time": "10:01", "temp": 25.5}] header = ["time", "temp"] gatherer.write_dict_to_csv(data, header)

write_dict_to_json(data)

Export dictionary data to JSON file.

Writes the provided dictionary to a JSON file in the configured JSON directory with the specified filename.

Parameters:

Name Type Description Default
data dict

Data dictionary to export to JSON.

required
Example

gatherer = DataGathering("test_data") data = {"sensor_1": 25.3, "sensor_2": 42.1} gatherer.write_dict_to_json(data)

DataHandler

Legacy DataHandler class - DEPRECATED.

This class is maintained for backwards compatibility but should not be used in new code. Use ConfigManager from dcs.infrastructure.config_manager instead.

Example

OLD (deprecated):

from dcs.data.processing import DataHandler handler = DataHandler()

from dcs.infrastructure.config_manager import ConfigManager config = ConfigManager() config.load_plc_config()

__init__()

Initialize legacy DataHandler.

__str__()

String representation of DataHandler.

data_object_decoder(obj) staticmethod

Decode JSON object to DataParam.