Aggiunta importazione da file .txt
This commit is contained in:
parent
b472765d5f
commit
0dfeb02c83
3 changed files with 43 additions and 10 deletions
BIN
Quattro.odg
Normal file
BIN
Quattro.odg
Normal file
Binary file not shown.
BIN
Quattro.pdf
Normal file
BIN
Quattro.pdf
Normal file
Binary file not shown.
|
@ -26,7 +26,7 @@ column_indexes = { # columns indexes that we want to import: None means try
|
|||
}
|
||||
|
||||
|
||||
def load_a_file(path: Path) ->list[Measure]:
|
||||
def load_a_xlsx_file(path: Path) -> list[Measure]:
|
||||
"""Returns a sorted list of Measures()"""
|
||||
discharge = []
|
||||
wb_obj = load_workbook(path)
|
||||
|
@ -61,6 +61,33 @@ def load_a_file(path: Path) ->list[Measure]:
|
|||
return discharge
|
||||
|
||||
|
||||
def load_a_txt_file(path: Path) -> list[Measure]:
|
||||
"""Returns a sorted list of Measures()"""
|
||||
|
||||
# 1742542808 Ch 101 4.6694100e-03 VDC 1742542808 Ch 102 3.6288222e+00 VDC
|
||||
# 1742542838 Ch 101 4.6651780e-03 VDC 1742542838 Ch 102 3.6315371e+00 VDC
|
||||
# 0 1 2 3 4 5 6 7 8 9
|
||||
discharge = []
|
||||
with open(path, 'r') as fin:
|
||||
for raw_line in fin:
|
||||
if len(raw_line) < 10: # arbitrario per rimuovere linee sicuramente sbagliate
|
||||
continue
|
||||
fields = raw_line.strip().strip('\n').split()
|
||||
if len(fields) < 10:
|
||||
continue # remove malformed lines
|
||||
ts = int(fields[0])
|
||||
v = float(fields[8])
|
||||
i = float(fields[3])
|
||||
if None not in (ts, v, i):
|
||||
i /= 0.010007
|
||||
measure = Measure(ts=ts, v=v, i=i)
|
||||
# print(measure)
|
||||
discharge.append(measure)
|
||||
|
||||
discharge.sort(key=lambda x: x.ts)
|
||||
return discharge
|
||||
|
||||
|
||||
def compute_discharge(measures: list[Measure], initial_capacity: float = 0.0) -> list[DischargePoint]:
|
||||
discharge_sequence = []
|
||||
last_m = None
|
||||
|
@ -106,19 +133,19 @@ def show_a_discharge(discharge: list[DischargePoint], title='Title'):
|
|||
vbatt.append(dp.v)
|
||||
ibatt.append(dp.i * 1000.0)
|
||||
caps.append(dp.c * 1000.0)
|
||||
ax.plot(mins, vbatt, color='g', lw=3, alpha=0.5, label='V_Batt')
|
||||
axr.plot(mins, caps, color='b', lw=3, alpha=0.5, label='Capacity')
|
||||
axr.plot(mins, ibatt, color='r', lw=3, alpha=0.5, label='Current')
|
||||
ax.plot(mins, vbatt, color='g', lw=3, alpha=0.5, label='Battery Voltage')
|
||||
axr.plot(mins, caps, color='b', lw=3, alpha=0.5, label='Accumulated Capacity')
|
||||
axr.plot(mins, ibatt, color='r', lw=3, alpha=0.5, label='Charging Current')
|
||||
ax.set_xlim(0, None)
|
||||
ax.set_ylim(3.0, 4.3)
|
||||
axr.set_ylim(0, 1100)
|
||||
axr.set_ylim(0, 930.0)
|
||||
axr.set_ylabel('Capacity [mAh] / Current [mA]')
|
||||
ax.set_xlabel('time [minutes')
|
||||
ax.set_xlabel('time [minutes]')
|
||||
ax.set_ylabel('Cell Voltage [V]')
|
||||
ax.set_title(title)
|
||||
axr.legend(loc='center right')
|
||||
ax.legend(loc='upper left')
|
||||
txt = f'End Capacity: {caps[-1]:.1f} mAh'
|
||||
txt = f'Total Capacity: {caps[-1]:.1f} mAh'
|
||||
print(txt)
|
||||
axr.text(mins[-1], caps[-1] - 150, txt, ha='right', fontsize=10, bbox={'facecolor': 'cyan', 'alpha': 0.7, 'pad': 5})
|
||||
# fig.tight_layout()
|
||||
|
@ -128,9 +155,15 @@ def show_a_discharge(discharge: list[DischargePoint], title='Title'):
|
|||
|
||||
if __name__ == '__main__':
|
||||
for f in source_file_folder.iterdir():
|
||||
if f.is_file() and f.suffix.lower() == '.xlsx':
|
||||
if f.is_file():
|
||||
if f.suffix.lower() == '.xlsx':
|
||||
print(f)
|
||||
measured_data = load_a_file(f)
|
||||
measured_data = load_a_xlsx_file(f)
|
||||
elif f.suffix.lower() == '.txt':
|
||||
print(f)
|
||||
measured_data = load_a_txt_file(f)
|
||||
else:
|
||||
continue
|
||||
discharge = compute_discharge(measured_data)
|
||||
show_a_discharge(discharge, title=f.stem.replace(' ', '_'))
|
||||
# break
|
||||
|
|
Loading…
Add table
Reference in a new issue