Preprocessing real time analysis

mail@pastecode.io avatar
unknown
python
2 months ago
972 B
7
Indexable
Never
import pandas as pd

model_data = []


# preprocesses the data send from the java program for the ml model
def process_sensor_data(sensor_data_string, length_of_values):
    # Splits the data for usage
    sensor_data = sensor_data_string.split(',')
    # Pads the data to the longest sensor value data
    sensor_data += [0.0] * (length_of_values - len(sensor_data))
    # Names the columns of the data frame
    column_names = ['sensorname' if i == 0 else 'timestamp' if i == 1 else 'sensorvalues'
                    for i in range(length_of_values)]
    # Creates the dataframe with the split data and column names
    df = pd.DataFrame([sensor_data], columns=column_names)
    # Adds the dataframe to a list, so it gets stored outside of this func
    model_data.append(df)

    # Confirmation testing
    result = df.to_string(index=True)
    print(model_data)
    return result


process_sensor_data('accel,123123,9.9', 4)
process_sensor_data('accel,123123,9.9', 4)
Leave a Comment