add exception processing into plot_flight_borders functional
This commit is contained in:
@@ -3,7 +3,7 @@ from matplotlib import dates
|
||||
import argparse
|
||||
import sys
|
||||
from importlib import reload
|
||||
sys.path.append('/home/danila/Danila/work/MVN/Soft/PID/python/')
|
||||
sys.path.append('./')
|
||||
import asotr
|
||||
reload(asotr)
|
||||
import pandas as pd
|
||||
@@ -16,18 +16,16 @@ def convert_to_str(lst):
|
||||
res += f"_{idx + 1}"
|
||||
return res
|
||||
|
||||
def plot_asotr_borders(ch, asotr_kit, begin, end, font=14, cmd=0):
|
||||
def plot_asotr_borders(path_with_data, ch, asotr_kit, begin, end, font=14, cmd=0, show_flag=False):
|
||||
print_width = 20
|
||||
print_height = 12
|
||||
width = 1
|
||||
plot_windows = 2
|
||||
|
||||
channels = list(map(int, ch))
|
||||
|
||||
pict_name = (f'./reports/ASOTR{asotr_kit}_flight_T_P_{convert_to_str(channels)}_{begin[0:5].replace(".", "")}_{end[0:5].replace(".", "")}_{end[6:]}.png')
|
||||
|
||||
plot_task = {"temp": 1, "temp_set": 1, "pow": 1}
|
||||
|
||||
ox_dtime_format = "%d.%m.%Y"
|
||||
|
||||
legend = [
|
||||
@@ -46,10 +44,12 @@ def plot_asotr_borders(ch, asotr_kit, begin, end, font=14, cmd=0):
|
||||
width_arr = [1, 0.5, 0.2, 0.1, 1, 1]
|
||||
|
||||
# get from files and prepare data
|
||||
path = "/home/danila/Danila/work/MVN/Soft/asotr_csv/data/"
|
||||
start_date = begin + " 00:00:00" # Начальная граница
|
||||
end_date = end + " 23:59:59" # Конечная граница
|
||||
data, data_dict = asotr.get_data(path, asotr_kit, start_date, end_date, 'minutes')
|
||||
start_date = begin + " 00:00:00"
|
||||
end_date = end + " 23:59:59"
|
||||
try:
|
||||
data, data_dict = asotr.get_data(path_with_data, asotr_kit, start_date, end_date, 'minutes')
|
||||
except Exception as e:
|
||||
return
|
||||
|
||||
if plot_windows == 1:
|
||||
fig, ax = plt.subplots(figsize=(print_width, print_height), dpi=200)
|
||||
@@ -82,10 +82,14 @@ def plot_asotr_borders(ch, asotr_kit, begin, end, font=14, cmd=0):
|
||||
ax1 = fig.add_subplot(2, 1, 1)
|
||||
ax2 = fig.add_subplot(2, 1, 2, sharex=ax1)
|
||||
|
||||
|
||||
if cmd == '1':
|
||||
cmd_human = pd.read_csv('./flight_cmd_human.txt',
|
||||
fname = './flight_cmd_human.txt'
|
||||
try:
|
||||
cmd_human = pd.read_csv('./flight_cmd_human.txt',
|
||||
delimiter=';', names=['timestamp', 'cmd'])
|
||||
except Exception as e:
|
||||
print(f'Error parsing file: {e}')
|
||||
return
|
||||
|
||||
for i, row in cmd_human.iterrows():
|
||||
if i > 20:
|
||||
@@ -97,7 +101,7 @@ def plot_asotr_borders(ch, asotr_kit, begin, end, font=14, cmd=0):
|
||||
linestyle='-.')
|
||||
ax1.text(data_dict['time_temp'][idx], 30, row['cmd'],
|
||||
rotation=45, va='bottom', fontsize=font)
|
||||
|
||||
|
||||
if plot_task["temp"] == 1:
|
||||
for i in range(len(channels)):
|
||||
if channels[i] == 1:
|
||||
@@ -149,11 +153,14 @@ def plot_asotr_borders(ch, asotr_kit, begin, end, font=14, cmd=0):
|
||||
fig.suptitle(title, fontsize=font)
|
||||
plt.tight_layout()
|
||||
fig.savefig(pict_name)
|
||||
plt.show()
|
||||
if show_flag == True:
|
||||
plt.show()
|
||||
|
||||
if __name__ == '__main__':
|
||||
argparser = argparse.ArgumentParser("plot_flight_borders.py")
|
||||
|
||||
argparser.add_argument('-s', '--source', required=True,
|
||||
help='type path with asotr csv data')
|
||||
argparser.add_argument('-c', '--channel', required=True,
|
||||
help='type channel (example: 000011)')
|
||||
argparser.add_argument('-a', '--asotr', required=True,
|
||||
@@ -166,7 +173,9 @@ if __name__ == '__main__':
|
||||
help='type font size (from 1 to 30)')
|
||||
argparser.add_argument('-d', '--cmd', required=False,
|
||||
help='type display commands flag (0/1)')
|
||||
argparser.add_argument('-p', '--plot', required=False,
|
||||
help='display data in plot flag (0/1)')
|
||||
args = argparser.parse_args()
|
||||
|
||||
plot_asotr_borders(args.channel, args.asotr, args.begin, args.end,
|
||||
args.font, args.cmd)
|
||||
plot_asotr_borders(args.source, args.channel, args.asotr, args.begin, args.end,
|
||||
args.font, args.cmd, args.plot)
|
||||
|
||||
Reference in New Issue
Block a user