Documentation – my_tools.py

Utility functions for LiC processing, file signalling, state strings, CSV logging and system analysis.

← Back to Documentation Index

1. Paths and OS Detection

The my_tools.py module automatically selects the correct file paths depending on whether it runs under Linux or Windows. All signal files (S, U, R, H, Q, Sreq) are stored in a RAM disk.


# Linux:
"/home/host/FTP/ramdisk/S"

# Windows:
"C:\\home\\host\\FTP\\ramdisk\\S"

2. Creating Signal Files

create_file_to_send(what_file)

The function creates a signal file (S, U, R, H, Q). Steps:


create_file_to_send("S")

3. Processing Uresp.txt – LiC Values

DataFromUresp(historyU)

Reads voltage values for LiC1…LiC7 and stores them into the history deque structures. Values are extracted using a regular expression and then reversed so the newest is first:


LiC7, LiC6, ..., LiC1   # newest at index 0

After processing, the Uresp.txt file is removed.

4. Processing Sresp.txt – Status Strings

DataFromSresp(radio_vars)

Reads lines containing:

*1032101#

Resulting in an array:

[1,0,3,2,1,0,1]

update_radio_buttons_from_numbers()

Transfers 0/1/2/3 values into GUI radiobuttons.

5. Sreq and RUN Files

create_run_file(q)

Creates the R file to trigger a RUN cycle.

create_state_file(radio_vars)

Converts radiobutton states into a status string:

*1032101#

The result is written to Sreq.

6. CSV Logging

save_full_state_to_csv(historyU, radio_vars)

Saves one full data row into out_array.txt:


ROW;TIME;LiC7..LiC1;Sta7..Sta1

load_historyU_from_csv()

Reconstructs LiC history from the log file.

7. Computing LiC Averages

prumery_LiC7_6_5_4()

prumery_LiC3_2_1()

prumery_LiC47_13()

Example output:


{
 "LiC4": 3.6501,
 "LiC5": 3.6522,
 "LiC6": 3.6488,
 "LiC7": 3.6499
}

8. Limit Analysis

analyze_LiC_top7_6_5_4()

analyze_LiC_top3_2_1()

Returns e.g.:


{
 "min": 3.6488,
 "max": 3.6522,
 "avg": 3.6502,
 "over_limit_dolni": 0,
 "over_limit_horni": 3,
 "LiC_min": 6,
 "LiC_max": 5
}

9. Status Strings *XXXXXXX#

build_LiC_status()

Builds the status string:

*1032101#

parse_status_string(status_string)

Parses a string into an array:

[1,0,3,2,1,0,1]

10. Comparison and Conversions

convert_radio_to_status(values)


[4,1,2,3,1,4,1] β†’ [1,0,3,2,1,0,0]

compare_status_arrays(a1, a2)

Returns True or False depending on whether arrays match.