diff --git a/src/integrationUISP.py b/src/integrationUISP.py index dace05b5..af27988a 100644 --- a/src/integrationUISP.py +++ b/src/integrationUISP.py @@ -328,26 +328,25 @@ def findNodesBranchedOffPtMP(siteList, dataLinks, sites, rootSite, foundAirFiber parent = site['parent'] for link in dataLinks: if (link['to']['site'] is not None) and (link['to']['site']['identification'] is not None): - if ('identification' in link['to']['site']) and (link['to']['site']['identification'] is not None): - if ('identification' in link['from']['site']) and (link['from']['site']['identification'] is not None): - # Respect parent defined by topology and overrides - if link['from']['site']['identification']['id'] == trueParent: - if link['to']['site']['identification']['id'] == id: - if (link['from']['device']['overview']['wirelessMode'] == 'ap-ptmp') or (link['from']['device']['overview']['wirelessMode'] == 'ap'): - if 'overview' in link['to']['device']: - if ('downlinkCapacity' in link['to']['device']['overview']) and ('uplinkCapacity' in link['to']['device']['overview']): - if (link['to']['device']['overview']['downlinkCapacity'] is not None) and (link['to']['device']['overview']['uplinkCapacity'] is not None): - apID = link['from']['device']['identification']['id'] - # Capacity of the PtMP client radio feeding the PoP will be used as the site bandwidth limit - download = int(round(link['to']['device']['overview']['downlinkCapacity']/1000000)) - upload = int(round(link['to']['device']['overview']['uplinkCapacity']/1000000)) - nodeOffPtMP[id] = {'download': download, - 'upload': upload, - parent: apID - } - if usePtMPasParent: - site['parent'] = apID - print('Site ' + name + ' will use PtMP AP as parent.') + if ('identification' in link['to']['site']) and (link['to']['site']['identification'] is not None) and link['from'] is not None and link['from']['site'] is not None and link['from']['site']['identification'] is not None: + # Respect parent defined by topology and overrides + if link['from']['site']['identification']['id'] == trueParent: + if link['to']['site']['identification']['id'] == id: + if (link['from']['device']['overview']['wirelessMode'] == 'ap-ptmp') or (link['from']['device']['overview']['wirelessMode'] == 'ap'): + if 'overview' in link['to']['device']: + if ('downlinkCapacity' in link['to']['device']['overview']) and ('uplinkCapacity' in link['to']['device']['overview']): + if (link['to']['device']['overview']['downlinkCapacity'] is not None) and (link['to']['device']['overview']['uplinkCapacity'] is not None): + apID = link['from']['device']['identification']['id'] + # Capacity of the PtMP client radio feeding the PoP will be used as the site bandwidth limit + download = int(round(link['to']['device']['overview']['downlinkCapacity']/1000000)) + upload = int(round(link['to']['device']['overview']['uplinkCapacity']/1000000)) + nodeOffPtMP[id] = {'download': download, + 'upload': upload, + parent: apID + } + if usePtMPasParent: + site['parent'] = apID + print('Site ' + name + ' will use PtMP AP as parent.') return siteList, nodeOffPtMP def handleMultipleInternetNodes(sites, dataLinks, uispSite): diff --git a/src/rust/lqos_bus/src/bus/unix_socket_server.rs b/src/rust/lqos_bus/src/bus/unix_socket_server.rs index e209f67b..fcb93ab1 100644 --- a/src/rust/lqos_bus/src/bus/unix_socket_server.rs +++ b/src/rust/lqos_bus/src/bus/unix_socket_server.rs @@ -78,7 +78,7 @@ impl UnixSocketServer { } fn make_socket_public() -> Result<(), UnixSocketServerError> { - lqos_utils::run_success!( + let _ = lqos_utils::run_success!( "/bin/chmod", "-R", "a+rwx", diff --git a/src/rust/lts_client/src/collector/collation/min_max.rs b/src/rust/lts_client/src/collector/collation/min_max.rs index c46d1fc8..f2a5fd58 100644 --- a/src/rust/lts_client/src/collector/collation/min_max.rs +++ b/src/rust/lts_client/src/collector/collation/min_max.rs @@ -7,6 +7,21 @@ pub(crate) struct MinMaxAvg { pub(crate) avg: T, } +fn median(stats: &[T]) -> T +where + T: Bounded + Zero + std::ops::AddAssign + Copy + std::cmp::Ord + CheckedDiv + NumCast, +{ + let mut sorted = stats.to_vec(); + sorted.sort(); + let len = sorted.len(); + let mid = len / 2; + if len % 2 == 0 { + (sorted[mid] + sorted[mid - 1]).checked_div(&T::from(2).unwrap()).unwrap_or(T::zero()) + } else { + sorted[mid] + } +} + impl< T: Bounded + Zero @@ -20,17 +35,13 @@ impl< pub(crate) fn from_slice(stats: &[T]) -> Self { let mut min = T::max_value(); let mut max = T::min_value(); - let mut avg = T::zero(); stats.iter().for_each(|n| { - avg += *n; min = T::min(min, *n); max = T::max(max, *n); }); - let len = T::from(stats.len()).unwrap(); - avg = avg.checked_div(&len).unwrap_or(T::zero()); - Self { max, min, avg } + Self { max, min, avg: median(stats) } } }