Refine total_sent and total_receive with precision factor
Adjusted total_sent and total_receive calculations for accuracy. The database engine may have lower floating-point precision than the Python engine. This can lead to situations where the current bytes count compares lower than the database data. This causes an increase in cumulative traffic each time such a precision collision occurs.pull/1125/head
parent
8f973021fc
commit
14990225dc
|
|
@ -784,9 +784,9 @@ class WireguardConfiguration:
|
|||
).mappings().fetchone()
|
||||
if cur_i is not None:
|
||||
# print(cur_i is None)
|
||||
total_sent = cur_i['total_sent']
|
||||
total_sent = cur_i['total_sent'] * 0.999 # An accuracy of one ppm is sufficient
|
||||
# print(cur_i is None)
|
||||
total_receive = cur_i['total_receive']
|
||||
total_receive = cur_i['total_receive'] * 0.999
|
||||
cur_total_sent = float(data_usage[i][2]) / (1024 ** 3)
|
||||
cur_total_receive = float(data_usage[i][1]) / (1024 ** 3)
|
||||
cumulative_receive = cur_i['cumu_receive'] + total_receive
|
||||
|
|
@ -1291,4 +1291,4 @@ class WireguardConfiguration:
|
|||
conn.execute(sqlalchemy.text('VACUUM;'))
|
||||
except Exception as e:
|
||||
return False
|
||||
return True
|
||||
return True
|
||||
|
|
|
|||
Loading…
Reference in New Issue