Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Series.SampleInto method C# example in .NET 8 #568

Open
Pinkisagit opened this issue Oct 14, 2024 · 0 comments
Open

Series.SampleInto method C# example in .NET 8 #568

Pinkisagit opened this issue Oct 14, 2024 · 0 comments

Comments

@Pinkisagit
Copy link

I've noticed that documentation for C# lacks an example for Series.SampleInto method in .NET 8.
Here is an example that uses FuncConvert.FromFunc to convert Func to F#. I think this is somewhat different from older versions of F#/.NET.

This code produces 90 samples every 1 seconds and then sub-samples them every 30 seconds using mean aggregation.

SeriesBuilder<DateTime, double?> data = new SeriesBuilder<DateTime, double?>();
DateTime date = DateTime.UtcNow;
for (int i = 0; i < 90; i++)
{
    data.Add(date, Random.Shared.Next(5, 10));
    date = date.AddSeconds(1);
}
var fsharp = FuncConvert.FromFunc<Series<DateTime, double?>, object>(x => x.Mean());
Func<DateTime, FSharpFunc<Series<DateTime, double?>, object>> avg = date => fsharp;
var samples = data.Series.SampleInto(TimeSpan.FromSeconds(30), Direction.Forward, avg);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant