-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(kubegraph): implement generic fake dist generator
- Loading branch information
Showing
8 changed files
with
77 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
use kubegraph_api::connector::fake::NetworkConnectorFakeDataValueType; | ||
use polars::{error::PolarsError, series::Series}; | ||
use rand::Rng; | ||
use rand_distr::Distribution; | ||
|
||
pub(super) struct GenericDistModel<D, R> { | ||
pub(super) count: usize, | ||
pub(super) dist: D, | ||
pub(super) rng: R, | ||
pub(super) value_type: NetworkConnectorFakeDataValueType, | ||
} | ||
|
||
impl<'a, D, R> super::DataGenerator<'a> for GenericDistModel<D, R> | ||
where | ||
D: Distribution<f64>, | ||
R: Rng, | ||
{ | ||
type Args = (); | ||
type Error = PolarsError; | ||
type Output = Series; | ||
|
||
fn generate( | ||
self, | ||
(): <Self as super::DataGenerator<'a>>::Args, | ||
) -> Result<<Self as super::DataGenerator<'a>>::Output, <Self as super::DataGenerator<'a>>::Error> | ||
{ | ||
let Self { | ||
count, | ||
dist, | ||
rng, | ||
value_type, | ||
} = self; | ||
|
||
Series::from_iter(rng.sample_iter::<f64, _>(dist).take(count)).cast(&value_type.into()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters