mirror of
https://github.com/DJ2LS/FreeDATA
synced 2024-05-14 10:04:33 +02:00
adjusted stats
This commit is contained in:
parent
9706260933
commit
fd9fb81fa2
|
@ -104,7 +104,7 @@ class ARQSession():
|
|||
action_name = self.STATE_TRANSITION[self.state][frame_type]
|
||||
received_data, type_byte = getattr(self, action_name)(frame)
|
||||
if isinstance(received_data, bytearray) and isinstance(type_byte, int):
|
||||
self.arq_data_type_handler.dispatch(type_byte, received_data, self.calculate_session_statistics())
|
||||
self.arq_data_type_handler.dispatch(type_byte, received_data, self.update_histograms(len(received_data), len(received_data)))
|
||||
return
|
||||
|
||||
self.log(f"Ignoring unknown transition from state {self.state.name} with frame {frame['frame_type']}")
|
||||
|
@ -121,15 +121,15 @@ class ARQSession():
|
|||
|
||||
return self.session_ended - self.session_started
|
||||
|
||||
def calculate_session_statistics(self):
|
||||
def calculate_session_statistics(self, confirmed_bytes, total_bytes):
|
||||
duration = self.calculate_session_duration()
|
||||
total_bytes = self.total_length
|
||||
#total_bytes = self.total_length
|
||||
# self.total_length
|
||||
duration_in_minutes = duration / 60 # Convert duration from seconds to minutes
|
||||
|
||||
# Calculate bytes per minute
|
||||
if duration_in_minutes > 0:
|
||||
bytes_per_minute = int(total_bytes / duration_in_minutes)
|
||||
bytes_per_minute = int(confirmed_bytes / duration_in_minutes)
|
||||
else:
|
||||
bytes_per_minute = 0
|
||||
|
||||
|
@ -147,11 +147,12 @@ class ARQSession():
|
|||
'bpm_histogram': bpm_histogram_dict,
|
||||
}
|
||||
|
||||
def update_histograms(self):
|
||||
stats = self.calculate_session_statistics()
|
||||
def update_histograms(self, confirmed_bytes, total_bytes):
|
||||
stats = self.calculate_session_statistics(confirmed_bytes, total_bytes)
|
||||
self.snr_histogram.append(self.snr)
|
||||
self.bpm_histogram.append(stats['bytes_per_minute'])
|
||||
self.time_histogram.append(datetime.datetime.now().isoformat())
|
||||
return stats
|
||||
|
||||
def get_appropriate_speed_level(self, snr):
|
||||
# Start with the lowest speed level as default
|
||||
|
|
|
@ -151,14 +151,14 @@ class ARQSessionIRS(arq_session.ARQSession):
|
|||
self.received_bytes += len(data_part)
|
||||
self.log(f"Received {self.received_bytes}/{self.total_length} bytes")
|
||||
self.event_manager.send_arq_session_progress(
|
||||
False, self.id, self.dxcall, self.received_bytes, self.total_length, self.state.name, self.calculate_session_statistics())
|
||||
False, self.id, self.dxcall, self.received_bytes, self.total_length, self.state.name, self.calculate_session_statistics(self.received_bytes, self.total_length))
|
||||
|
||||
return True
|
||||
|
||||
def receive_data(self, burst_frame):
|
||||
self.process_incoming_data(burst_frame)
|
||||
# update statistics
|
||||
self.update_histograms()
|
||||
self.update_histograms(self.received_bytes, self.total_length)
|
||||
|
||||
if not self.all_data_received():
|
||||
self.calibrate_speed_settings(burst_frame=burst_frame)
|
||||
|
@ -189,7 +189,7 @@ class ARQSessionIRS(arq_session.ARQSession):
|
|||
self.session_ended = time.time()
|
||||
self.set_state(IRS_State.ENDED)
|
||||
self.event_manager.send_arq_session_finished(
|
||||
False, self.id, self.dxcall, True, self.state.name, data=self.received_data, statistics=self.calculate_session_statistics())
|
||||
False, self.id, self.dxcall, True, self.state.name, data=self.received_data, statistics=self.calculate_session_statistics(self.received_bytes, self.total_length))
|
||||
|
||||
return self.received_data, self.type_byte
|
||||
else:
|
||||
|
@ -256,7 +256,7 @@ class ARQSessionIRS(arq_session.ARQSession):
|
|||
self.set_state(IRS_State.ABORTED)
|
||||
self.states.setARQ(False)
|
||||
self.event_manager.send_arq_session_finished(
|
||||
False, self.id, self.dxcall, False, self.state.name, statistics=self.calculate_session_statistics())
|
||||
False, self.id, self.dxcall, False, self.state.name, statistics=self.calculate_session_statistics(self.received_bytes, self.total_length))
|
||||
return None, None
|
||||
|
||||
def transmission_failed(self, irs_frame=None):
|
||||
|
@ -264,6 +264,6 @@ class ARQSessionIRS(arq_session.ARQSession):
|
|||
self.session_ended = time.time()
|
||||
self.set_state(IRS_State.FAILED)
|
||||
self.log(f"Transmission failed!")
|
||||
self.event_manager.send_arq_session_finished(True, self.id, self.dxcall,False, self.state.name, statistics=self.calculate_session_statistics())
|
||||
self.event_manager.send_arq_session_finished(True, self.id, self.dxcall,False, self.state.name, statistics=self.calculate_session_statistics(self.received_bytes, self.total_length))
|
||||
self.states.setARQ(False)
|
||||
return None, None
|
||||
|
|
|
@ -150,14 +150,14 @@ class ARQSessionISS(arq_session.ARQSession):
|
|||
|
||||
def send_data(self, irs_frame):
|
||||
# update statistics
|
||||
self.update_histograms()
|
||||
self.update_histograms(self.confirmed_bytes, self.total_length)
|
||||
|
||||
self.update_speed_level(irs_frame)
|
||||
if 'offset' in irs_frame:
|
||||
self.confirmed_bytes = irs_frame['offset']
|
||||
self.log(f"IRS confirmed {self.confirmed_bytes}/{self.total_length} bytes")
|
||||
self.event_manager.send_arq_session_progress(
|
||||
True, self.id, self.dxcall, self.confirmed_bytes, self.total_length, self.state.name, statistics=self.calculate_session_statistics())
|
||||
True, self.id, self.dxcall, self.confirmed_bytes, self.total_length, self.state.name, statistics=self.calculate_session_statistics(self.confirmed_bytes, self.total_length))
|
||||
|
||||
# check if we received an abort flag
|
||||
if irs_frame["flag"]["ABORT"]:
|
||||
|
@ -190,8 +190,8 @@ class ARQSessionISS(arq_session.ARQSession):
|
|||
self.session_ended = time.time()
|
||||
self.set_state(ISS_State.ENDED)
|
||||
self.log(f"All data transfered! flag_final={irs_frame['flag']['FINAL']}, flag_checksum={irs_frame['flag']['CHECKSUM']}")
|
||||
self.event_manager.send_arq_session_finished(True, self.id, self.dxcall,True, self.state.name, statistics=self.calculate_session_statistics())
|
||||
self.arq_data_type_handler.transmitted(self.type_byte, self.data, self.calculate_session_statistics())
|
||||
self.event_manager.send_arq_session_finished(True, self.id, self.dxcall,True, self.state.name, statistics=self.calculate_session_statistics(self.confirmed_bytes, self.total_length))
|
||||
self.arq_data_type_handler.transmitted(self.type_byte, self.data, self.calculate_session_statistics(self.confirmed_bytes, self.total_length))
|
||||
self.state_manager.remove_arq_iss_session(self.id)
|
||||
self.states.setARQ(False)
|
||||
return None, None
|
||||
|
@ -201,10 +201,10 @@ class ARQSessionISS(arq_session.ARQSession):
|
|||
self.session_ended = time.time()
|
||||
self.set_state(ISS_State.FAILED)
|
||||
self.log(f"Transmission failed!")
|
||||
self.event_manager.send_arq_session_finished(True, self.id, self.dxcall,False, self.state.name, statistics=self.calculate_session_statistics())
|
||||
self.event_manager.send_arq_session_finished(True, self.id, self.dxcall,False, self.state.name, statistics=self.calculate_session_statistics(self.confirmed_bytes, self.total_length))
|
||||
self.states.setARQ(False)
|
||||
|
||||
self.arq_data_type_handler.failed(self.type_byte, self.data, self.calculate_session_statistics())
|
||||
self.arq_data_type_handler.failed(self.type_byte, self.data, self.calculate_session_statistics(self.confirmed_bytes, self.total_length))
|
||||
return None, None
|
||||
|
||||
def abort_transmission(self, irs_frame=None):
|
||||
|
@ -213,7 +213,7 @@ class ARQSessionISS(arq_session.ARQSession):
|
|||
self.set_state(ISS_State.ABORTING)
|
||||
|
||||
self.event_manager.send_arq_session_finished(
|
||||
True, self.id, self.dxcall, False, self.state.name, statistics=self.calculate_session_statistics())
|
||||
True, self.id, self.dxcall, False, self.state.name, statistics=self.calculate_session_statistics(self.confirmed_bytes, self.total_length))
|
||||
|
||||
# break actual retries
|
||||
self.event_frame_received.set()
|
||||
|
@ -233,7 +233,7 @@ class ARQSessionISS(arq_session.ARQSession):
|
|||
self.event_frame_received.set()
|
||||
|
||||
self.event_manager.send_arq_session_finished(
|
||||
True, self.id, self.dxcall, False, self.state.name, statistics=self.calculate_session_statistics())
|
||||
True, self.id, self.dxcall, False, self.state.name, statistics=self.calculate_session_statistics(self.confirmed_bytes, self.total_length))
|
||||
self.state_manager.remove_arq_iss_session(self.id)
|
||||
self.states.setARQ(False)
|
||||
return None, None
|
||||
|
|
Loading…
Reference in a new issue