Refactor: 1. add print into console data, 2. rewrite CLI parsing, 4. the output format csv has been reworked. 5. Add information to README. For addition create python code for plot csv data
This commit is contained in:
122
data/plot_flight_all.py
Normal file
122
data/plot_flight_all.py
Normal file
@@ -0,0 +1,122 @@
|
||||
import matplotlib.pyplot as plt
|
||||
from matplotlib import dates
|
||||
import pandas as pd
|
||||
from datetime import datetime
|
||||
import sys
|
||||
|
||||
font = 10
|
||||
print_width = 20
|
||||
print_height = 12
|
||||
width = 1
|
||||
plot_windows = 2
|
||||
channels = [1, 1, 1, 1, 1, 1]
|
||||
|
||||
xborders=False
|
||||
begin=0;
|
||||
end=0;
|
||||
|
||||
path = '/home/danila/Danila/work/MVN/Soft/asotr_csv/data/'
|
||||
fname = 'asotr01_data_T.csv'
|
||||
fname_pow = 'asotr01_data_P.csv'
|
||||
pict_name = path + "ASOTR1_flight_T_P_all"
|
||||
ox_dtime_format = '%d.%m.%Y %H:%M'
|
||||
|
||||
legend=['ch1', 'ch2', 'ch3', 'ch4', 'ch5', 'ch6', 'ch7']
|
||||
width=[1, 1, 1, 1, 1, 1]
|
||||
|
||||
marker = ['-', '-', '-', '-', '-', '-'];
|
||||
width_arr = [1, 0.5, 0.2, 0.1, 1, 1]
|
||||
|
||||
fname = [path + fname, path + fname_pow]
|
||||
|
||||
dateparse = lambda x: datetime.strptime(x, "%d.%m.%Y %H:%M:%S.%f")
|
||||
|
||||
data = [pd.read_csv(fname[0], sep=';', parse_dates=['timestamp'], date_parser=dateparse),
|
||||
pd.read_csv(fname[1], sep=';', parse_dates=['timestamp'], date_parser=dateparse)]
|
||||
|
||||
ch= [[], [], [], [], [], []]
|
||||
ch_signs = ["temp", "pow"]
|
||||
data_dict = {"temp": ch, "pow": ch, "time": []}
|
||||
data_dict["time"] = data[0]['timestamp']
|
||||
col=['ch1', 'ch2', 'ch3', 'ch4', 'ch5', 'ch6', 'ch7']
|
||||
|
||||
for j in range(2):
|
||||
for index, row, in data[j].iterrows():
|
||||
for i in range(6):
|
||||
ch[i].append(float(row[col[i]]))
|
||||
data_dict[ch_signs[j]] = ch
|
||||
ch= [[], [], [], [], [], []]
|
||||
|
||||
len_data = [len(data_dict['temp'][0]), len(data_dict['pow'][0])]
|
||||
len_ = min(len_data)
|
||||
|
||||
if xborders == False:
|
||||
begin = 0
|
||||
end = len_ - 1
|
||||
|
||||
if plot_windows == 1:
|
||||
fig, ax = plt.subplots(figsize=(print_width, print_height), dpi=200)
|
||||
|
||||
i = 0
|
||||
for elem in data_dict['temp']:
|
||||
if channels[i] == 1:
|
||||
plt.plot(data_dict['time'][begin:end], elem[begin:end], marker[i], linewidth=width[i], label=legend[i])
|
||||
i += 1
|
||||
|
||||
# ax.axvline(x = data['timestamp'][300], color='r', linestyle='-.', label="power=100")
|
||||
# ax.axvline(x = data['timestamp'][1500], color='b', linestyle='dotted', label="power=0")
|
||||
ax.tick_params(axis="both", width=1, labelsize=font)
|
||||
ax.grid(visible=True, linestyle = 'dotted')
|
||||
ax.set_ylabel('Температура, $^\circ$C', fontsize=font)
|
||||
ax.set_xlabel('Время', fontsize=font)
|
||||
ax.legend(fontsize=font)
|
||||
|
||||
date_formatter = dates.DateFormatter(ox_dtime_format)
|
||||
ax.xaxis.set_major_formatter(date_formatter)
|
||||
|
||||
plt.tight_layout()
|
||||
fig.savefig(pict_name)
|
||||
plt.show()
|
||||
|
||||
elif plot_windows == 2:
|
||||
|
||||
fig = plt.figure(figsize=(print_width, print_height), dpi=200)
|
||||
ax1 = fig.add_subplot(2, 1, 1)
|
||||
ax2 = fig.add_subplot(2, 1, 2, sharex=ax1)
|
||||
|
||||
i = 0
|
||||
for elem in data_dict['temp']:
|
||||
if channels[i] == 1:
|
||||
ax1.plot(data_dict['time'][begin:end], elem[begin:end], marker[i], linewidth=width[i], label=legend[i])
|
||||
i += 1
|
||||
|
||||
i = 0
|
||||
for elem in data_dict['pow']:
|
||||
if channels[i] == 1:
|
||||
ax2.plot(data_dict['time'][begin:end], elem[begin:end], marker[i], linewidth=width[i], label=legend[i])
|
||||
i += 1
|
||||
|
||||
# ax1.axvline(x = data['timestamp'][300], color='r', linestyle='-.', label="power=100")
|
||||
# ax.axvline(x = data['timestamp'][1500], color='b', linestyle='dotted', label="power=0")
|
||||
ax1.tick_params(axis="both", width=1, labelsize=font)
|
||||
ax1.grid(visible=True, linestyle = 'dotted')
|
||||
ax1.set_ylabel('Температура, $^\circ$C', fontsize=font)
|
||||
ax1.set_xlabel('Время', fontsize=font)
|
||||
ax1.legend(fontsize=font)
|
||||
|
||||
date_formatter = dates.DateFormatter('%d.%m.%Y %H')
|
||||
ax1.xaxis.set_major_formatter(date_formatter)
|
||||
|
||||
ax2.tick_params(axis="both", width=1, labelsize=font)
|
||||
ax2.grid(visible=True, linestyle = 'dotted')
|
||||
ax2.set_ylabel('Мощность, %', fontsize=font)
|
||||
ax2.set_xlabel('Время', fontsize=font)
|
||||
ax2.legend(fontsize=font)
|
||||
|
||||
date_formatter = dates.DateFormatter(ox_dtime_format)
|
||||
ax2.xaxis.set_major_formatter(date_formatter)
|
||||
|
||||
plt.tight_layout()
|
||||
fig.savefig(pict_name)
|
||||
plt.show()
|
||||
|
30
data/prepare_csv.sh
Executable file
30
data/prepare_csv.sh
Executable file
@@ -0,0 +1,30 @@
|
||||
#! /bin/bash
|
||||
|
||||
if [ $# != 2 ]
|
||||
then
|
||||
echo "error use $0. Right use this script: "
|
||||
echo "$0 path_to_file data_type (flight or KDI)"
|
||||
echo "example 1: $0 ./data/flight/30_12_2024/ASOTR_1_SOTR_T flight"
|
||||
else
|
||||
data_file=$1
|
||||
data_type=$2
|
||||
|
||||
if [ "$data_type" == "flight" ]
|
||||
then
|
||||
cat ${data_file}.csv | grep -Eo '[0-9]{2}\.[0-9]{2}\.[0-9]{4}' > file1
|
||||
cat ${data_file}.csv | grep -Eo [0-9]{2}:.* > file2
|
||||
|
||||
elif [ "$data_type" == "KDI" ]
|
||||
then
|
||||
cat ${data_file}.csv | grep -Eo [0-9]{2}.[0-9]{2}.[0-9]{4} > file1
|
||||
cat ${data_file}.csv | grep -Eo [0-9]{2}:.* > file2
|
||||
else
|
||||
echo "error argument of data_type: write \"flight\" or \"KDI\" in second argument"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
paste --delimiter=' ' file1 file2 > file.csv
|
||||
echo "timestamp;ch1;ch2;ch3;ch4;ch5;ch6" > ${data_file}_clear.csv
|
||||
cat file.csv >> ${data_file}_clear.csv
|
||||
rm file1 file2 file.csv
|
||||
fi
|
30
data/trash_prepare_csv.sh
Executable file
30
data/trash_prepare_csv.sh
Executable file
@@ -0,0 +1,30 @@
|
||||
#! /bin/bash
|
||||
|
||||
if [ $# != 2 ]
|
||||
then
|
||||
echo "error use $0. Right use this script: "
|
||||
echo "$0 path_to_file data_type (flight or KDI)"
|
||||
echo "example 1: $0 ./data/flight/30_12_2024/ASOTR_1_SOTR_T flight"
|
||||
else
|
||||
data_file=$1
|
||||
data_type=$2
|
||||
|
||||
if [ "$data_type" == "flight" ]
|
||||
then
|
||||
cat ${data_file}.csv | grep -Eo '[0-9]{2}\.[0-9]{2}\.[0-9]{4}' > file1
|
||||
cat ${data_file}.csv | grep -Eo [0-9]{2}:.* > file2
|
||||
|
||||
elif [ "$data_type" == "KDI" ]
|
||||
then
|
||||
cat ${data_file}.csv | grep -Eo [0-9]{2}.[0-9]{2}.[0-9]{4} > file1
|
||||
cat ${data_file}.csv | grep -Eo [0-9]{2}:.* > file2
|
||||
else
|
||||
echo "error argument of data_type: write \"flight\" or \"KDI\" in second argument"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
paste --delimiter=' ' file1 file2 > file.csv
|
||||
echo "timestamp;ch1;ch2;ch3;ch4;ch5;ch6" > ${data_file}_clear.csv
|
||||
cat file.csv >> ${data_file}_clear.csv
|
||||
rm file1 file2 file.csv
|
||||
fi
|
Reference in New Issue
Block a user