Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 24 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,22 @@ Contains:
* Custom data series implementation
* Data I/O
* Helpers for Matrixes and Vectors
* Logger instance (_+ default ConsoleLogger implementation_)

## Code examples

> Read source data from file
### Read source data from file
```csharp
using ChaosSoft.Core.Data;

using ChaosSoft.Core.IO;

string fileName = "some_data.dat";
int linesToSkip = 2;
int linesToRead = 500;

// get source data from file
var data = new SourceData(fileName, linesToSkip, linesToRead);
IDataReader dataReader = new PlainTextFileReader(linesToSkip, linesToRead);
SourceData data = new SourceData(dataReader, linesToRead);

// assume file has two columns (1st - timestamp, 2nd - series)
int seriesColumn = 1;
Expand All @@ -39,7 +41,7 @@ data.SetTimeSeries(
var amplitude = data.TimeSeries.Amplitude.Y; //X property contains amplitude of X values (timestamp)
```

> Work with matrixes
### Work with matrixes
```csharp
using ChaosSoft.Core.DataUtils;

Expand All @@ -50,7 +52,7 @@ var matrix = Matrix.Create(3, 5, 5.3);
var column = Matrix.GetColumn(matrix, 2);
```

> Work with vectors
### Work with vectors
```csharp
using ChaosSoft.Core.DataUtils;

Expand All @@ -59,4 +61,21 @@ var vector = Vector.CreateUniform(5, -9, 3);

// find vector's Max absolute value
var maxAbs = Vector.MaxAbs(vector);
```

### Numbers formatting
By default numbers formatting is set to `"0.#######"` with `InvariantCulture`

```csharp
// To apply user formatting used by default (for example F2)
NumFormat.CurrentFormat = "F2";

// To apply culture used by default (for example en-US)
NumFormat.CurrentCulture = new CultureInfo("en-US");

// To reset formatting defaults
NumFormat.Reset();

// To set default precision (for example 11 decimal digits)
NumFormat.SetPrecision(11);
```
File renamed without changes.
4 changes: 3 additions & 1 deletion src/ChaosSoft.Core/ChaosSoft.Core.csproj
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net6.0;netstandard2.0</TargetFrameworks>
<TargetFrameworks>netstandard2.0</TargetFrameworks>
<LangVersion>10</LangVersion>
<NuspecProperties>version=$(Version)</NuspecProperties>
<EnableUnsafeBinaryFormatterSerialization>true</EnableUnsafeBinaryFormatterSerialization>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
Expand Down
7 changes: 2 additions & 5 deletions src/ChaosSoft.Core/ChaosSoft.Core.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<title>ChaosSoft.Core</title>
<authors>Vitaliy Dobriyan</authors>
<license type="expression">Apache-2.0</license>
<copyright>Copyright (c) Vitaliy Dobriyan 2023</copyright>
<copyright>Copyright (c) Vitaliy Dobriyan 2024</copyright>
<projectUrl>https://github.com/chaossoftware/core</projectUrl>
<repository type="git" url="https://github.com/chaossoftware/core.git"/>
<icon>images\icon.png</icon>
Expand All @@ -15,19 +15,16 @@
<description>
This package includes data and timeseries related objects and data specific IO operations, some math helpers.
</description>
<releaseNotes>First release: SourceData and DataSeries objects, date series specific IO operations, helpers for vectors and matrixes.</releaseNotes>
<releaseNotes>Rework of IO, added common interfaces, removed 3d and sound output classes, added logger</releaseNotes>
<tags>math io timeseries</tags>
<dependencies>
<group targetFramework="netstandard2.0"/>
<group targetFramework="net6.0"/>
</dependencies>
</metadata>
<files>
<file src="..\..\README.md" target="docs\" />
<file src="..\..\icon.png" target="images\" />
<file src="bin\Release\netstandard2.0\chaossoft.core.dll" target="lib\netstandard2.0" />
<file src="bin\Release\netstandard2.0\chaossoft.core.xml" target="lib\netstandard2.0" />
<file src="bin\Release\net6.0\chaossoft.core.dll" target="lib\net6.0" />
<file src="bin\Release\net6.0\chaossoft.core.xml" target="lib\net6.0" />
</files>
</package>
63 changes: 34 additions & 29 deletions src/ChaosSoft.Core/Data/DataPoint.cs
Original file line number Diff line number Diff line change
@@ -1,38 +1,43 @@
using ChaosSoft.Core.IO;
namespace ChaosSoft.Core.Data;

namespace ChaosSoft.Core.Data
/// <summary>
/// Represents 2D point object.
/// </summary>
public readonly struct DataPoint
{
/// <summary>
/// Represents 2D point object.
/// Initializes a new instance of the <see cref="DataPoint"/> class for specific X and Y coordinates.
/// </summary>
public readonly struct DataPoint
/// <param name="x">x coordinate</param>
/// <param name="y">y coordinate</param>
public DataPoint(double x, double y)
{
/// <summary>
/// Initializes a new instance of the <see cref="DataPoint"/> class for specific X and Y coordinates.
/// </summary>
/// <param name="x">x coordinate</param>
/// <param name="y">y coordinate</param>
public DataPoint(double x, double y)
{
X = x;
Y = y;
}
X = x;
Y = y;
}

/// <summary>
/// Gets X coordinate.
/// </summary>
public double X { get; }
/// <summary>
/// Gets X coordinate.
/// </summary>
public double X { get; }

/// <summary>
/// Gets Y coordinate.
/// </summary>
public double Y { get; }
/// <summary>
/// Gets Y coordinate.
/// </summary>
public double Y { get; }

/// <summary>
/// Gets string representation of the data point (G6 number format is used).
/// </summary>
/// <returns></returns>
public override string ToString() =>
$"[{Format.General(X)}, {Format.General(Y)}]";
}
/// <summary>
/// Gets string representation of the data point (<see cref="NumFormat.CurrentFormat"/> format is used).
/// </summary>
/// <returns>string representation</returns>
public override string ToString() =>
$"[{X.ToString(NumFormat.CurrentFormat)}, {Y.ToString(NumFormat.CurrentFormat)}]";

/// <summary>
/// Gets string representation of the data point with specified number format.
/// </summary>
/// <param name="format">number format to use</param>
/// <returns>string representation</returns>
public string ToString(string format) =>
$"[{X.ToString(format)}, {Y.ToString(format)}]";
}
Loading