parser: percentiles fixed

This commit is contained in:
k
2024-07-12 19:06:52 +02:00
parent 6c7bd2a63a
commit dcf605aa69
2 changed files with 16 additions and 14 deletions

View File

@@ -731,10 +731,13 @@ where
let min_percentile_date = chrono::NaiveDate::from_ymd_opt(2012, 1, 1).unwrap();
let min_percentile_wdate = WNaiveDate::wrap(min_percentile_date);
let nan = T::from(f32::NAN).unwrap();
let two = T::from(2.0).unwrap();
dates.iter().cloned().try_for_each(|date| {
if date < min_percentile_wdate {
map_and_percentiles.iter_mut().for_each(|(map, _)| {
(*map).insert(date, T::from(f32::NAN).unwrap());
(*map).insert(date, nan);
});
return ControlFlow::Continue::<()>(());
}
@@ -800,13 +803,12 @@ where
}
let value = {
if vec.is_empty() {
T::default()
if len < 2 {
nan
} else {
let index = (len - 1) as f32 * *percentile;
let fract = index.fract();
let fract_t = T::from(fract).unwrap();
if fract != 0.0 {
(vec.get(index.ceil() as usize)
@@ -815,7 +817,6 @@ where
panic!()
})
.0
* fract_t
+ vec
.get(index.floor() as usize)
.unwrap_or_else(|| {
@@ -829,7 +830,7 @@ where
panic!()
})
.0)
* T::from(1.0 - fract).unwrap()
/ two
} else {
vec.get(index.floor() as usize)
.unwrap_or_else(|| {
@@ -845,7 +846,7 @@ where
});
} else {
map_and_percentiles.iter_mut().for_each(|(map, _)| {
(*map).insert(date, T::default());
(*map).insert(date, nan);
});
}

View File

@@ -719,6 +719,9 @@ where
let min_percentile_height = 160_000;
let nan = T::from(f32::NAN).unwrap();
let two = T::from(2.0).unwrap();
if min_percentile_height % HEIGHT_MAP_CHUNK_SIZE != 0 {
panic!("Should be 0");
}
@@ -726,7 +729,7 @@ where
heights.iter().cloned().try_for_each(|height| {
if height < min_percentile_height {
map_and_percentiles.iter_mut().for_each(|(map, _)| {
(*map).insert(height, T::from(f32::NAN).unwrap());
(*map).insert(height, nan);
});
return ControlFlow::Continue::<()>(());
}
@@ -784,13 +787,12 @@ where
}
let value = {
if vec.is_empty() {
T::default()
if len < 2 {
nan
} else {
let index = (len - 1) as f32 * *percentile;
let fract = index.fract();
let fract_t = T::from(fract).unwrap();
if fract != 0.0 {
(vec.get(index.ceil() as usize)
@@ -806,7 +808,6 @@ where
panic!()
})
.0
* fract_t
+ vec
.get(index.floor() as usize)
.unwrap_or_else(|| {
@@ -819,7 +820,7 @@ where
panic!()
})
.0)
* T::from(1.0 - fract).unwrap()
/ two
} else {
vec.get(index as usize).unwrap().0
}
@@ -830,7 +831,7 @@ where
});
} else {
map_and_percentiles.iter_mut().for_each(|(map, _)| {
(*map).insert(height, T::default());
(*map).insert(height, nan);
});
}