MCPcopy Create free account
hub / github.com/ElementsProject/lightning / get_median

Function get_median

plugins/currencyrate-plugin/src/oracle.rs:581–590  ·  view source on GitHub ↗
(source_results: Vec<SourceResult>)

Source from the content-addressed store, hash-verified

579}
580
581fn get_median(source_results: Vec<SourceResult>) -> f64 {
582 let mut prices: Vec<f64> = source_results.iter().map(|r| r.price).collect();
583 prices.sort_by(|a, b| a.partial_cmp(b).unwrap());
584 let mid = prices.len() / 2;
585 if prices.len() % 2 == 1 {
586 prices[mid]
587 } else {
588 f64::midpoint(prices[mid - 1], prices[mid])
589 }
590}

Callers 1

get_median_rateMethod · 0.85

Calls 3

midpointFunction · 0.85
mapMethod · 0.80
unwrapMethod · 0.45

Tested by

no test coverage detected