Checking for incoming data

Question:

I have a csv file that receives data every second. Different calculations occur with this data in the class loop. After that, a signal is formed consisting of digits from -3 to 3, time, and an ordinal internal count.

Here is an example of a signal.

0,18:29:51,175

I run the algorithm like this

while True:
    Generic(60, 300, 40, 150)
    df = pd.read_csv('Datasets\RobotMath\table_OI.csv')
    df1 = pd.read_csv('Datasets\RobotMath\temp.csv')
    out = df.Time.tail(1) 
    out2 = df1.Time.tail(1)
    if out.item() != out2.item():
        method2()

df is a csv file that is constantly updated with data

df1 is a csv file that I already take in a loop and do calculations.

After that, I take the last values of these csvs and compare them. If they are not equal then give a signal

All the work of the algorithm implies that the data will come every second and we will always calculate the previous one and give a signal on it

But sometimes it happens that the data does not arrive for 30 seconds and I lose one signal, which can critically affect the entire system.

Is it possible to make a check in the while loop, something like if the data did not arrive for more than 2 seconds, make calculations for the last second and continue to wait for them?

Asked By: Serega

||

Answers:

to explain my comment, I have to write a small example.
the amount of df rows from previous loop can be saved in config.py file or temporary .txt or pickle file, – up to you

last_amount_of_rows  = 0 # for you to decide how to keep amount of df rows from the previous Loop.
while True:
    Generic(60, 300, 40, 150)
    df = pd.read_csv('Datasets\RobotMath\table_OI.csv')
    df1 = pd.read_csv('Datasets\RobotMath\temp.csv')

    new_amount_of_rows = df.shape[0] # it records amount of rows to the variable
    if new_amount_of_rows != last_amount_of_rows:
        out = df.Time.tail(1)
        out2 = df1.Time.tail(1)
        if out.item() != out2.item():
            method2()
            last_amount_of_rows = new_amount_of_rows # creating new value for last amount of rows
Answered By: NoobVB
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.