Peponi.Maths is a package for Mathematics. Including contents are: 1. Coordinates - Cartesian (2D & 3D) - Cylindrical - Polar - Spherical 2. Numerical integrations - Trapezoidal - Midpoint - Simpson's rule (1/3 & 3/8) 3. Moving Averages - Simple moving average 4. Unit conversion - Angle - Angular speed - Area - Dry volume - Energy - Force - Length - Prefix - Pressure - Speed - Temperature - Volume - Weight 5. Windowing - Tumbling - Sliding - Hopping
$ dotnet add package Peponi.MathsPeponi.Maths is a package for Mathematics.
Including contents are:
1. Coordinates
- Cartesian (2D & 3D)
- Cylindrical
- Polar
- Spherical
2. Numerical integrations
- Trapezoidal
- Midpoint
- Simpson's rule (1/3 & 3/8)
3. Moving Averages
- Simple moving average
4. Unit conversion
- Angle
- Angular speed
- Area
- Dry volume
- Energy
- Force
- Length
- Prefix
- Pressure
- Speed
- Temperature
- Volume
- Weight
5. Windowing
- Tumbling
- Sliding
- Hopping
The MIT License (MIT)
Copyright (c) 2024 peponi
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
NuGet\Install-Package Peponi.Maths
Members
| Type | Name | Description |
|---|---|---|
| double | X | X axis value Raising PropertyChanged event |
| double | Y | Y axis value Raising PropertyChanged event |
| PropertyChangedEventHandler? | PropertyChanged | INotifyPropertyChanged support |
Methods
| Return type | Name | Description |
|---|---|---|
| CartesianCoordinate2D | CartesianCoordinate2D() | Default constructor |
| CartesianCoordinate2D | CartesianCoordinate2D(double, double) | Constructor |
| void | Deconstruct(out double, out double) | Deconstructor |
| double | GetDistanceFromOrigin() | Returns √(X2+Y2) |
| string | ToString() | Returns X, Y |
Example
using Peponi.Maths.Coordinates;
var coordinate = new(3, 4);
var (x, y) = coordinate;
Console.WriteLine(coordinate.GetDistanceFromOrigin());
Console.WriteLine(coordinate.ToString());
/* output:
5
3, 4
*/
Members
| Type | Name | Description |
|---|---|---|
| double | X | X axis value Raising PropertyChanged event |
| double | Y | Y axis value Raising PropertyChanged event |
| double | Z | Z axis value Raising PropertyChanged event |
| PropertyChangedEventHandler? | PropertyChanged | INotifyPropertyChanged support |
Methods
| Return type | Name | Description |
|---|---|---|
| CartesianCoordinate3D | CartesianCoordinate3D() | Default constructor |
| CartesianCoordinate3D | CartesianCoordinate3D(double, double, double) | Constructor |
| void | Deconstruct(out double, out double, out double) | Deconstructor |
| double | GetDistanceFromOrigin() | Returns √(X2+Y2+Z2) |
| string | ToString() | Returns X, Y, Z |
Example
using Peponi.Maths.Coordinates;
var coordinate = new(3, 4, 5);
var (x, y, z) = coordinate;
Console.WriteLine(coordinate.GetDistanceFromOrigin());
Console.WriteLine(coordinate.ToString());
/* output:
7.071068 ...
3, 4, 5
*/

Members
| Type | Name | Description |
|---|---|---|
| double | R | Radius Raising PropertyChanged event |
| double | Theta | Angle from axis Raising PropertyChanged event |
| double | Z | Z axis value Raising PropertyChanged event |
| PropertyChangedEventHandler? | PropertyChanged | INotifyPropertyChanged support |
Methods
| Return type | Name | Description |
|---|---|---|
| CylindricalCoordinate | CylindricalCoordinate() | Default constructor |
| CylindricalCoordinate | CylindricalCoordinate(double, double, double) | Constructor |
| void | Deconstruct(out double, out double, out double) | Deconstructor |
| double | GetDistanceFromOrigin() | Returns √(R2+Z2) |
| string | ToString() | Returns R, Theta, Z |
Example
using Peponi.Maths.Coordinates;
var coordinate = new(3, 4, 5);
var (r, theta, z) = coordinate;
Console.WriteLine(coordinate.GetDistanceFromOrigin());
Console.WriteLine(coordinate.ToString());
/* output:
5.830952 ...
3, 4, 5
*/

Members
| Type | Name | Description |
|---|---|---|
| double | R | Radius Raising PropertyChanged event |
| double | Theta | Angle from axis Raising PropertyChanged event |
| PropertyChangedEventHandler? | PropertyChanged | INotifyPropertyChanged support |
Methods
| Return type | Name | Description |
|---|---|---|
| PolarCoordinate | PolarCoordinate() | Default constructor |
| PolarCoordinate | PolarCoordinate(double, double) | Constructor |
| void | Deconstruct(out double, out double) | Deconstructor |
| double | GetDistanceFromOrigin() | Returns R |
| string | ToString() | Returns R, Theta |
Example
using Peponi.Maths.Coordinates;
var coordinate = new(3, 4);
var (r, theta) = coordinate;
Console.WriteLine(coordinate.GetDistanceFromOrigin());
Console.WriteLine(coordinate.ToString());
/* output:
3
3, 4
*/

Members
| Type | Name | Description |
|---|---|---|
| double | R | Radius Raising PropertyChanged event |
| double | Theta | Latitude Raising PropertyChanged event |
| double | Phi | Longitude Raising PropertyChanged event |
| PropertyChangedEventHandler? | PropertyChanged | INotifyPropertyChanged support |
Methods
| Return type | Name | Description |
|---|---|---|
| SphericalCoordinate | SphericalCoordinate() | Default constructor |
| SphericalCoordinate | SphericalCoordinate(double, double, double) | Constructor |
| void | Deconstruct(out double, out double, out double) | Deconstructor |
| double | GetDistanceFromOrigin() | Returns R |
| string | ToString() | Returns R, Theta, Phi |
Example
using Peponi.Maths.Coordinates;
var coordinate = new(3, 4, 5);
var (r, theta, phi) = coordinate;
Console.WriteLine(coordinate.GetDistanceFromOrigin());
Console.WriteLine(coordinate.ToString());
/* output:
3
3, 4, 5
*/

Methods
| Return type | Name | Description |
|---|---|---|
| double | Integrate<X, Y>(List<X>, List<Y>) | Integrate points Count of List<X> & List<Y> must me equal Count of List<X> must be odd |
| double | Integrate(Func<double, double>, double, double, int) | Integrate input function Low limit <= Upper limit Function must not be null |
Example
using Peponi.Maths.Integration;
/// List type
List<int> xs = new() { 1, 4, 7, 10, 13 };
List<double> ys = new() { 0, 1, -1, 4, 7 };
Console.WriteLine(Midpoint.Integrate(xs, ys));
/* output:
30
*/
using Peponi.Maths.Extensions;
using Peponi.Maths.Integration;
/// Function type
Console.WriteLine(Midpoint.Integrate(System.Math.Sin, 0, 17.2, 9).Round(6));
/* output:
1.262177
*/

Methods
| Return type | Name | Description |
|---|---|---|
| double | Integrate<X, Y>(List<X>, List<Y>) | Integrate points Count of List<X> & List<Y> must me equal Count of List<X> must be odd |
| double | Integrate(Func<double, double>, double, double, int) | Integrate input function Low limit <= Upper limit Function must not be null Interval count should be even |
Example
using Peponi.Maths.Integration;
/// List type
List<int> xs = new() { 1, 4, 7, 10, 13 };
List<double> ys = new() { 0, 1, -1, 4, 7 };
Console.WriteLine(Simpson1over3.Integrate(xs, ys));
/* output:
25
*/
using Peponi.Maths.Extensions;
using Peponi.Maths.Integration;
/// Function type
Console.WriteLine(Simpson1over3.Integrate(System.Math.Sin, 0, 17.2, 8).Round(6));
/* output:
1.341822
*/

Methods
| Return type | Name | Description |
|---|---|---|
| double | Integrate<X, Y>(List<X>, List<Y>) | Integrate points Count of List<X> & List<Y> must me equal Count of List<X> must be multiple of 3 |
| double | Integrate(Func<double, double>, double, double, int) | Integrate input function Low limit <= Upper limit Function must not be null Interval count should be multiple of 3 |
Example
using Peponi.Maths.Integration;
/// List type
List<int> xs = new() { 1, 4, 7, 10, 13, 16, 19 };
List<double> ys = new() { 0, 1, -1, 4, 7, -2, 5 };
Console.WriteLine(Simpson3over8.Integrate(xs, ys));
/* output:
31.5
*/
using Peponi.Maths.Extensions;
using Peponi.Maths.Integration;
/// Function type
Console.WriteLine(Simpson3over8.Integrate(System.Math.Sin, 0, 17.2, 9).Round(6));
/* output:
2.189858
*/

Methods
| Return type | Name | Description |
|---|---|---|
| double | Integrate<X, Y>(List<X>, List<Y>) | Integrate points Count of List<X> & List<Y> must me equal Count of List<X> should be over than 1 |
| double | Integrate(Func<double, double>, double, double, int) | Integrate input function Low limit <= Upper limit Function must not be null |
Example
using Peponi.Maths.Integration;
/// List type
List<int> xs = new() { 1, 4, 8, 12, 15, 20 };
List<double> ys = new() { 0, 1, -1, 4, 7, 5 };
Console.WriteLine(Trapezoidal.Integrate(xs, ys));
/* output:
54
*/
using Peponi.Maths.Extensions;
using Peponi.Maths.Integration;
/// Function type
Console.WriteLine(Trapezoidal.Integrate(System.Math.Sin, 0, 17.2, 8).Round(6));
/* output:
0.627166
*/

Methods
| Return type | Name | Description |
|---|---|---|
| SimpleMovingAverage | SimpleMovingAverage(uint) | Window size could not be 0 |
| T | Average(T) | Returns average value |
Example
using Peponi.Maths.MovingAverage;
SimpleMovingAverage<double> movingAverage = new(3);
for (int i = 1; i < 5; i++)
{
Console.WriteLine(movingAverage.Average(i));
}
/* output:
1
1.5
2
3
*/
using Peponi.Maths.Extensions;
using Peponi.Maths.UnitConversion;
Console.WriteLine(UnitConvert.Convert(1.234, AngleUnit.Degree, AngleUnit.Radian).Round(6));
/* output:
0.021537
*/
using Peponi.Maths.Extensions;
using Peponi.Maths.UnitConversion;
Console.WriteLine(UnitConvert.Convert(21.653, AngularSpeedUnit.RadianPerSecond, AngularSpeedUnit.RadianPerMinute).Round(6));
/* output:
1299.18
*/
using Peponi.Maths.Extensions;
using Peponi.Maths.UnitConversion;
Console.WriteLine(UnitConvert.Convert(21.653, AreaUnit.SquareMeter, AreaUnit.SquareFoot).Round(8));
/* output:
233.07095225
*/
using Peponi.Maths.Extensions;
using Peponi.Maths.UnitConversion;
Console.WriteLine(UnitConvert.Convert(21.653, DryVolumeUnit.Liter, DryVolumeUnit.Barrel).Round(6));
/* output:
0.187266
*/
using Peponi.Maths.Extensions;
using Peponi.Maths.UnitConversion;
Console.WriteLine(UnitConvert.Convert(21.653, EnergyUnit.Joule, EnergyUnit.WattHour).Round(6));
/* output:
0.006015
*/
using Peponi.Maths.Extensions;
using Peponi.Maths.UnitConversion;
Console.WriteLine(UnitConvert.Convert(21.653, ForceUnit.Newton, ForceUnit.KiloGramForce).Round(6));
/* output:
2.207992
*/
using Peponi.Maths.Extensions;
using Peponi.Maths.UnitConversion;
Console.WriteLine(UnitConvert.Convert(21.653, LengthUnit.Meter, LengthUnit.Mile).Round(6));
/* output:
0.013455
*/
using Peponi.Maths.UnitConversion;
Console.WriteLine(UnitConvert.Convert(21.653, PrefixUnit.None, PrefixUnit.Kilo));
/* output:
21.653E-3
*/
using Peponi.Maths.Extensions;
using Peponi.Maths.UnitConversion;
Console.WriteLine(UnitConvert.Convert(21.653, PressureUnit.Pascal, PressureUnit.Torr).Round(9));
/* output:
0.162410856
*/
using Peponi.Maths.Extensions;
using Peponi.Maths.UnitConversion;
Console.WriteLine(UnitConvert.Convert(21.653, SpeedUnit.MeterPerSecond, SpeedUnit.MilePerHour).Round(6));
/* output:
48.436382
*/
using Peponi.Maths.Extensions;
using Peponi.Maths.UnitConversion;
Console.WriteLine(UnitConvert.Convert(21.653, TemperatureUnit.Celsius, TemperatureUnit.Fahrenheit).Round(6));
/* output:
70.9754
*/
using Peponi.Maths.Extensions;
using Peponi.Maths.UnitConversion;
Console.WriteLine(UnitConvert.Convert(21.653, VolumeUnit.CubicMeter, VolumeUnit.CubicYard).Round(6));
/* output:
28.321055
*/
using Peponi.Maths.Extensions;
using Peponi.Maths.UnitConversion;
Console.WriteLine(UnitConvert.Convert(21.653, WeightUnit.KiloGram, WeightUnit.Pound).Round(6));
/* output:
47.736694
*/

Methods
| Return type | Name | Description |
|---|---|---|
| IEnumerable<IEnumerable<T>> | ToHoppingWindows(IEnumerable<T>, uint, uint) | Get windows for given parameters |
| Task<IEnumerable<IEnumerable<T>>> | ToHoppingWindowsAsync(IEnumerable<T>, uint, uint) | |
| IEnumerable<IEnumerable<T>> | ToHoppingWindows(IEnumerable<T>, uint, uint, uint) | |
| Task<IEnumerable<IEnumerable<T>>> | ToHoppingWindowsAsync(IEnumerable<T>, uint, uint, uint) | |
| IEnumerable<IEnumerable<T>> | ToHoppingWindows(IEnumerable<T>, uint, uint, uint, uint) | |
| Task<IEnumerable<IEnumerable<T>>> | ToHoppingWindowsAsync(IEnumerable<T>, uint, uint, uint, uint) | |
| IEnumerable<IEnumerable<V>> | ToHoppingWindows(IEnumerable<T>, uint, uint, Func<T, V>) | |
| Task<IEnumerable<IEnumerable<V>>> | ToHoppingWindowsAsync(IEnumerable<T>, uint, uint, Func<T, V>) | |
| IEnumerable<IEnumerable<V>> | ToHoppingWindows(IEnumerable<T>, uint, uint, uint, Func<T, V>) | |
| Task<IEnumerable<IEnumerable<V>>> | ToHoppingWindowsAsync(IEnumerable<T>, uint, uint, uint, Func<T, V>) | |
| IEnumerable<IEnumerable<V>> | ToHoppingWindows(IEnumerable<T>, uint, uint, uint, uint, Func<T, V>) | |
| Task<IEnumerable<IEnumerable<V>>> | ToHoppingWindowsAsync(IEnumerable<T>, uint, uint, uint, uint, Func<T, V>) | |
| IEnumerable<IEnumerable<DateTime>> | ToHoppingWindows(IEnumerable<DateTime>, DateTime, TimeSpan, TimeSpan) | |
| Task<IEnumerable<IEnumerable<DateTime>>> | ToHoppingWindowsAsync(IEnumerable<DateTime>, DateTime, TimeSpan, TimeSpan) | |
| IEnumerable<IEnumerable<DateTime>> | ToHoppingWindows(IEnumerable<DateTime>, DateTime, DateTime, TimeSpan, TimeSpan) | |
| Task<IEnumerable<IEnumerable<DateTime>>> | ToHoppingWindowsAsync(IEnumerable<DateTime>, DateTime, DateTime, TimeSpan, TimeSpan) | |
| IEnumerable<IEnumerable<V>> | ToHoppingWindows(IEnumerable<T>, DateTime, TimeSpan, TimeSpan, Func<T, DateTime>, Func<T, V>) | |
| Task<IEnumerable<IEnumerable<V>>> | ToHoppingWindowsAsync(IEnumerable<T>, DateTime, TimeSpan, TimeSpan, Func<T, DateTime>, Func<T, V>) | |
| IEnumerable<IEnumerable<V>> | ToHoppingWindows(IEnumerable<T>, DateTime, DateTime, TimeSpan, TimeSpan, Func<T, DateTime>, Func<T, V>) | |
| Task<IEnumerable<IEnumerable<V>>> | ToHoppingWindowsAsync(IEnumerable<T>, DateTime, DateTime, TimeSpan, TimeSpan, Func<T, DateTime>, Func<T, V>) |
Example
internal class DataClass
{
public DateTime Time;
public int Data;
public DataClass(int data)
{
Data = data;
}
public DataClass(DateTime time, int data)
{
Time = time;
Data = data;
}
}
using Peponi.Maths.Windowing;
List<int> datas = new();
for (int i = 0; i < 10; i++) datas.Add(i);
var result = HoppingWindows.ToHoppingWindows(datas, 1, 8, 5, 3);
foreach (var arr in result) Console.WriteLine(string.Join(", ", arr));
/* output:
1, 2, 3, 4, 5
4, 5, 6, 7, 8
*/
using Peponi.Maths.Windowing;
List<DataClass> datas = new();
for (int i = 0; i < 10; i++) datas.Add(new(i));
var result = HoppingWindows.ToHoppingWindows(datas, 1, 8, 5, 3, x => x.Data);
foreach (var arr in result) Console.WriteLine(string.Join(", ", arr));
/* output:
1, 2, 3, 4, 5
4, 5, 6, 7, 8
*/
using Peponi.Maths.Windowing;
List<DateTime> datas = new();
for (int i = 0; i < 10; i++) datas.Add(DateTime.Today + TimeSpan.FromSeconds(i));
var result = HoppingWindows.ToHoppingWindows(datas, DateTime.Today + TimeSpan.FromSeconds(1),
DateTime.Today + TimeSpan.FromSeconds(8), TimeSpan.FromSeconds(5), TimeSpan.FromSeconds(3));
foreach (var arr in result) Console.WriteLine(string.Join(", ", arr.Select(x => x.ToString("HH.mm.ss"))));
/* output:
00.00.01, 00.00.02, 00.00.03, 00.00.04, 00.00.05, 00.00.06
00.00.04, 00.00.05, 00.00.06, 00.00.07, 00.00.08
*/
using Peponi.Maths.Windowing;
List<DataClass> datas = new();
for (int i = 0; i < 10; i++) datas.Add(new(DateTime.Today + TimeSpan.FromSeconds(i) + TimeSpan.FromMilliseconds(i), i));
var result = SlidingWindows.ToSlidingWindows(datas, DateTime.Today + TimeSpan.FromSeconds(1),
DateTime.Today + TimeSpan.FromSeconds(8), TimeSpan.FromSeconds(5), x => x.Time, x => x.Data);
foreach (var arr in result) Console.WriteLine(string.Join(", ", arr));
/* output:
1, 2, 3, 4, 5
2, 3, 4, 5, 6
3, 4, 5, 6, 7
*/

Methods
| Return type | Name | Description |
|---|---|---|
| IEnumerable<IEnumerable<T>> | ToSlidingWindows(IEnumerable<T>, uint) | Get windows for given parameters |
| Task<IEnumerable<IEnumerable<T>>> | ToSlidingWindowsAsync(IEnumerable<T>, uint) | |
| IEnumerable<IEnumerable<T>> | ToSlidingWindows(IEnumerable<T>, uint, uint) | |
| Task<IEnumerable<IEnumerable<T>>> | ToSlidingWindowsAsync(IEnumerable<T>, uint, uint) | |
| IEnumerable<IEnumerable<T>> | ToSlidingWindows(IEnumerable<T>, uint, uint, uint) | |
| Task<IEnumerable<IEnumerable<T>>> | ToSlidingWindowsAsync(IEnumerable<T>, uint, uint, uint) | |
| IEnumerable<IEnumerable<V>> | ToSlidingWindows(IEnumerable<T>, uint, Func<T, V>) | |
| Task<IEnumerable<IEnumerable<V>>> | ToSlidingWindowsAsync(IEnumerable<T>, uint, Func<T, V>) | |
| IEnumerable<IEnumerable<V>> | ToSlidingWindows(IEnumerable<T>, uint, uint, Func<T, V>) | |
| Task<IEnumerable<IEnumerable<V>>> | ToSlidingWindowsAsync(IEnumerable<T>, uint, uint, Func<T, V>) | |
| IEnumerable<IEnumerable<V>> | ToSlidingWindows(IEnumerable<T>, uint, uint, uint, Func<T, V>) | |
| Task<IEnumerable<IEnumerable<V>>> | ToSlidingWindowsAsync(IEnumerable<T>, uint, uint, uint, Func<T, V>) | |
| IEnumerable<IEnumerable<DateTime>> | ToSlidingWindows(IEnumerable<DateTime>, DateTime, TimeSpan) | |
| Task<IEnumerable<IEnumerable<DateTime>>> | ToSlidingWindowsAsync(IEnumerable<DateTime>, DateTime, TimeSpan) | |
| IEnumerable<IEnumerable<DateTime>> | ToSlidingWindows(IEnumerable<DateTime>, DateTime, DateTime, TimeSpan) | |
| Task<IEnumerable<IEnumerable<DateTime>>> | ToSlidingWindowsAsync(IEnumerable<DateTime>, DateTime, DateTime, TimeSpan) | |
| IEnumerable<IEnumerable<V>> | ToSlidingWindows(IEnumerable<T>, DateTime, TimeSpan, Func<T, DateTime>, Func<T, V>) | |
| Task<IEnumerable<IEnumerable<V>>> | ToSlidingWindowsAsync(IEnumerable<T>, DateTime, TimeSpan, Func<T, DateTime>, Func<T, V>) | |
| IEnumerable<IEnumerable<V>> | ToSlidingWindows(IEnumerable<T>, DateTime, DateTime, TimeSpan, Func<T, DateTime>, Func<T, V>) | |
| Task<IEnumerable<IEnumerable<V>>> | ToSlidingWindowsAsync(IEnumerable<T>, DateTime, DateTime, TimeSpan, Func<T, DateTime>, Func<T, V>) |
Example
internal class DataClass
{
public DateTime Time;
public int Data;
public DataClass(int data)
{
Data = data;
}
public DataClass(DateTime time, int data)
{
Time = time;
Data = data;
}
}
using Peponi.Maths.Windowing;
List<int> datas = new();
for (int i = 0; i < 10; i++) datas.Add(i);
var result = SlidingWindows.ToSlidingWindows(datas, 2, 8, 5);
foreach (var arr in result) Console.WriteLine(string.Join(", ", arr));
/* output:
2, 3, 4, 5, 6
3, 4, 5, 6, 7
4, 5, 6, 7, 8
*/
using Peponi.Maths.Windowing;
List<DataClass> datas = new();
for (int i = 0; i < 10; i++) datas.Add(new(i));
var result = SlidingWindows.ToSlidingWindows(datas, 2, 8, 5, x => x.Data);
foreach (var arr in result) Console.WriteLine(string.Join(", ", arr));
/* output:
2, 3, 4, 5, 6
3, 4, 5, 6, 7
4, 5, 6, 7, 8
*/
using Peponi.Maths.Windowing;
List<DateTime> datas = new();
for (int i = 0; i < 10; i++) datas.Add(DateTime.Today + TimeSpan.FromSeconds(i));
var result = SlidingWindows.ToSlidingWindows(datas, DateTime.Today + TimeSpan.FromSeconds(1),
DateTime.Today + TimeSpan.FromSeconds(8), TimeSpan.FromSeconds(5));
foreach (var arr in result) Console.WriteLine(string.Join(", ", arr.Select(x => x.ToString("HH.mm.ss"))));
/* output:
00.00.01, 00.00.02, 00.00.03, 00.00.04, 00.00.05, 00.00.06
00.00.02, 00.00.03, 00.00.04, 00.00.05, 00.00.06, 00.00.07
00.00.03, 00.00.04, 00.00.05, 00.00.06, 00.00.07, 00.00.08
*/
using Peponi.Maths.Windowing;
List<DataClass> datas = new();
for (int i = 0; i < 10; i++) datas.Add(new(DateTime.Today + TimeSpan.FromSeconds(i) + TimeSpan.FromMilliseconds(i), i));
var result = SlidingWindows.ToSlidingWindows(datas, DateTime.Today + TimeSpan.FromSeconds(1),
DateTime.Today + TimeSpan.FromSeconds(8), TimeSpan.FromSeconds(5), x => x.Time, x => x.Data);
foreach (var arr in result) Console.WriteLine(string.Join(", ", arr));
/* output:
1, 2, 3, 4, 5
2, 3, 4, 5, 6
3, 4, 5, 6, 7
*/

Methods
| Return type | Name | Description |
|---|---|---|
| IEnumerable<IEnumerable<T>> | ToTumblingWindows(IEnumerable<T>, uint) | Get windows for given parameters |
| Task<IEnumerable<IEnumerable<T>>> | ToTumblingWindowsAsync(IEnumerable<T>, uint) | |
| IEnumerable<IEnumerable<T>> | ToTumblingWindows(IEnumerable<T>, uint, uint) | |
| Task<IEnumerable<IEnumerable<T>>> | ToTumblingWindowsAsync(IEnumerable<T>, uint, uint) | |
| IEnumerable<IEnumerable<T>> | ToTumblingWindows(IEnumerable<T>, uint, uint, uint) | |
| Task<IEnumerable<IEnumerable<T>>> | ToTumblingWindowsAsync(IEnumerable<T>, uint, uint, uint) | |
| IEnumerable<IEnumerable<V>> | ToTumblingWindows(IEnumerable<T>, uint, Func<T, V>) | |
| Task<IEnumerable<IEnumerable<V>>> | ToTumblingWindowsAsync(IEnumerable<T>, uint, Func<T, V>) | |
| IEnumerable<IEnumerable<V>> | ToTumblingWindows(IEnumerable<T>, uint, uint, Func<T, V>) | |
| Task<IEnumerable<IEnumerable<V>>> | ToTumblingWindowsAsync(IEnumerable<T>, uint, uint, Func<T, V>) | |
| IEnumerable<IEnumerable<V>> | ToTumblingWindows(IEnumerable<T>, uint, uint, uint, Func<T, V>) | |
| Task<IEnumerable<IEnumerable<V>>> | ToTumblingWindowsAsync(IEnumerable<T>, uint, uint, uint, Func<T, V>) | |
| IEnumerable<IEnumerable<DateTime>> | ToTumblingWindows(IEnumerable<DateTime>, DateTime, TimeSpan) | |
| Task<IEnumerable<IEnumerable<DateTime>>> | ToTumblingWindowsAsync(IEnumerable<DateTime>, DateTime, TimeSpan) | |
| IEnumerable<IEnumerable<DateTime>> | ToTumblingWindows(IEnumerable<DateTime>, DateTime, DateTime, TimeSpan) | |
| Task<IEnumerable<IEnumerable<DateTime>>> | ToTumblingWindowsAsync(IEnumerable<DateTime>, DateTime, DateTime, TimeSpan) | |
| IEnumerable<IEnumerable<V>> | ToTumblingWindows(IEnumerable<T>, DateTime, TimeSpan, Func<T, DateTime>, Func<T, V>) | |
| Task<IEnumerable<IEnumerable<V>>> | ToTumblingWindowsAsync(IEnumerable<T>, DateTime, TimeSpan, Func<T, DateTime>, Func<T, V>) | |
| IEnumerable<IEnumerable<V>> | ToTumblingWindows(IEnumerable<T>, DateTime, DateTime, TimeSpan, Func<T, DateTime>, Func<T, V>) | |
| Task<IEnumerable<IEnumerable<V>>> | ToTumblingWindowsAsync(IEnumerable<T>, DateTime, DateTime, TimeSpan, Func<T, DateTime>, Func<T, V>) |
Example
internal class DataClass
{
public DateTime Time;
public int Data;
public DataClass(int data)
{
Data = data;
}
public DataClass(DateTime time, int data)
{
Time = time;
Data = data;
}
}
using Peponi.Maths.Windowing;
List<int> datas = new();
for (int i = 0; i < 10; i++) datas.Add(i);
var result = TumblingWindows.ToTumblingWindows(datas, 2, 8, 5);
foreach (var arr in result) Console.WriteLine(string.Join(", ", arr));
/* output:
2, 3, 4, 5, 6
7, 8
*/
using Peponi.Maths.Windowing;
List<DataClass> datas = new();
for (int i = 0; i < 10; i++) datas.Add(new(i));
var result = TumblingWindows.ToTumblingWindows(datas, 3, 8, 5, x => x.Data);
foreach (var arr in result) Console.WriteLine(string.Join(", ", arr));
/* output:
3, 4, 5, 6, 7
8
*/
using Peponi.Maths.Windowing;
List<DataClass> datas = new();
for (int i = 0; i < 10; i++) datas.Add(new(DateTime.Today + TimeSpan.FromSeconds(i), i));
var result = TumblingWindows.ToTumblingWindows(datas, DateTime.Today, TimeSpan.FromSeconds(5), x => x.Time, x => x.Data);
foreach (var arr in result) Console.WriteLine(string.Join(", ", arr));
/* output:
0, 1, 2, 3, 4, 5
5, 6, 7, 8, 9
*/
using Peponi.Maths.Windowing;
List<DataClass> datas = new();
for (int i = 0; i < 10; i++) datas.Add(new(DateTime.Today + TimeSpan.FromSeconds(i) + TimeSpan.FromMilliseconds(i), i));
var result = TumblingWindows.ToTumblingWindows(datas, DateTime.Today + TimeSpan.FromSeconds(1),
DateTime.Today + TimeSpan.FromSeconds(8), TimeSpan.FromSeconds(5),
x => x.Time, x => x.Data);
foreach (var arr in result) Console.WriteLine(string.Join(", ", arr));
/* output:
1, 2, 3, 4, 5
6, 7
*/