Skip to content

Commit 845ef80

Browse files
committed
Merge branch 'dev'
2 parents 6506688 + d6d635b commit 845ef80

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+1049
-59
lines changed

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -222,3 +222,7 @@ _Pvt_Extensions
222222
/demos/gfoidl.DataCompression.Demos.DeadBand/data/coolant-temp_compressed.csv
223223
/demos/gfoidl.DataCompression.Demos.DeadBand.Stats/data/coolant-temp.png
224224
/demos/gfoidl.DataCompression.Demos.DeadBand.Stats/data/error.png
225+
/demos/gfoidl.DataCompression.Demos.SwingingDoor/data/coolant-temp.png
226+
/demos/gfoidl.DataCompression.Demos.SwingingDoor/data/coolant-temp_compressed.csv
227+
/demos/gfoidl.DataCompression.Demos.SwingingDoor.Stats/data/error.png
228+
/demos/gfoidl.DataCompression.Demos.SwingingDoor.Stats/data/*.csv

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@
77
## Algorithms
88

99
* [Dead band](./doc/DeadBand.md)
10+
* [Swinging Door](./doc/SwingingDoor.md)
1011

demos/gfoidl.DataCompression.Demos.DeadBand/data/coolant-temp.plt

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@ set key bottom right
1313
#set datafile separator ";"
1414

1515
# replot is also possible for the second plot
16-
plot 'coolant-temp.csv' with linespoints title 'raw', \
17-
'coolant-temp_compressed.csv' with linespoints title 'compressed'
16+
plot 'coolant-temp.csv' with linespoints title 'raw', \
17+
'coolant-temp_compressed.csv' with linespoints title 'compressed'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
#define INTERPOLATE
2+
3+
using System;
4+
using System.Collections.Generic;
5+
using System.Diagnostics;
6+
using System.IO;
7+
using System.Linq;
8+
using static System.FormattableString;
9+
10+
namespace gfoidl.DataCompression.Demos.SwingingDoor.Stats
11+
{
12+
static class Program
13+
{
14+
static void Main()
15+
{
16+
Directory.CreateDirectory(Path.Combine(Directory.GetCurrentDirectory(), "data"));
17+
Environment.CurrentDirectory = Path.Combine(Directory.GetCurrentDirectory(), "data");
18+
19+
var data = CreateData().ToList();
20+
var compressed = data.SwingingDoorCompression(0.1).ToList();
21+
var reconstructed = Reconstruct(data, compressed).ToList();
22+
23+
new DataPointSerializer().Write("compressed.csv", compressed, header: ("x", "y"));
24+
25+
Console.WriteLine($"{"Data items:",-18}{data.Count,4}");
26+
Console.WriteLine($"{"Compressed items:",-18}{compressed.Count,4}");
27+
28+
using (StreamWriter sw = File.CreateText("result.csv"))
29+
{
30+
sw.WriteLine("# x\traw\tcompressed\terror");
31+
32+
for (int i = 0; i < data.Count; ++i)
33+
sw.WriteLine(Invariant($"{data[i].X}\t{data[i].Y}\t{reconstructed[i].Y}\t{data[i].Y - reconstructed[i].Y}"));
34+
}
35+
36+
GnuPlot();
37+
ShowChart();
38+
}
39+
//---------------------------------------------------------------------
40+
private static IEnumerable<DataPoint> CreateData()
41+
{
42+
var rnd = new Random();
43+
44+
for (int i = 0; i < 1_000; ++i)
45+
{
46+
double x = i * 1e-2;
47+
double y = 10 * Math.Log((10 - x) + 2.5) + (rnd.NextDouble() * 0.2 - 0.1) + 5 * Math.Cos((10 - x) / 10 * Math.PI);
48+
49+
yield return (x, y);
50+
}
51+
}
52+
//---------------------------------------------------------------------
53+
private static IEnumerable<DataPoint> Reconstruct(IEnumerable<DataPoint> raw, IEnumerable<DataPoint> compressed)
54+
{
55+
var compressedEnum = compressed.GetEnumerator();
56+
var rawEnum = raw.GetEnumerator();
57+
58+
#if INTERPOLATE
59+
double x = default;
60+
#endif
61+
double y = default;
62+
63+
while (compressedEnum.MoveNext() && rawEnum.MoveNext())
64+
{
65+
yield return compressedEnum.Current;
66+
x = compressedEnum.Current.X;
67+
y = compressedEnum.Current.Y;
68+
69+
if (!compressedEnum.MoveNext()) yield break;
70+
71+
#if INTERPOLATE
72+
double k = (compressedEnum.Current.Y - y) / (compressedEnum.Current.X - x);
73+
#endif
74+
75+
while (rawEnum.MoveNext() && rawEnum.Current.X < compressedEnum.Current.X)
76+
#if INTERPOLATE
77+
yield return (rawEnum.Current.X, y + k * (rawEnum.Current.X - x));
78+
#else
79+
yield return (rawEnum.Current.X, y);
80+
#endif
81+
yield return compressedEnum.Current;
82+
}
83+
}
84+
//---------------------------------------------------------------------
85+
private static void GnuPlot()
86+
{
87+
var gnuPlot = new Process();
88+
//gnuPlot.StartInfo.WorkingDirectory = Path.Combine(Directory.GetCurrentDirectory(), "data");
89+
gnuPlot.StartInfo.FileName = "gnuplot";
90+
gnuPlot.StartInfo.Arguments = "error.plt";
91+
gnuPlot.Start();
92+
gnuPlot.WaitForExit();
93+
}
94+
//---------------------------------------------------------------------
95+
private static void ShowChart()
96+
{
97+
var png = new Process();
98+
png.StartInfo.UseShellExecute = true; // defaults to false in .net Core
99+
png.StartInfo.FileName = "error.png";
100+
png.Start();
101+
}
102+
}
103+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
reset
2+
3+
set term pngcairo size 1200,1000 enhanced
4+
set output 'error.png'
5+
6+
set multiplot layout 4, 1 title "Error for dead band compression\n"
7+
8+
unset title
9+
set grid
10+
set key top right
11+
12+
set ytics 10.0
13+
plot 'result.csv' using 1:2 with lines title 'raw'
14+
plot 'compressed.csv' with dots title 'compressed'
15+
plot 'result.csv' using 1:3 with lines title 'compressed reconstructed'
16+
17+
#set xlabel 'x'
18+
set ytics 0.2
19+
set yrange [-0.3:0.3]
20+
plot 'result.csv' using 1:4 with lines title 'error'
21+
22+
unset multiplot
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>netcoreapp2.0</TargetFramework>
6+
<LangVersion>latest</LangVersion>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<ProjectReference Include="..\..\source\gfoidl.DataCompression\gfoidl.DataCompression.csproj" />
11+
</ItemGroup>
12+
13+
<ItemGroup>
14+
<None Update="data\error.plt" CopyToOutputDirectory="PreserveNewest" />
15+
</ItemGroup>
16+
17+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Diagnostics;
4+
using System.IO;
5+
6+
namespace gfoidl.DataCompression.Demos.SwingingDoor
7+
{
8+
static class Program
9+
{
10+
static void Main()
11+
{
12+
Environment.CurrentDirectory = Path.Combine(Directory.GetCurrentDirectory(), "data");
13+
14+
var dataPointReader = new DataPointSerializer();
15+
16+
IEnumerable<DataPoint> compressed = dataPointReader
17+
.Read("coolant-temp.csv")
18+
.SwingingDoorCompression(1.5);
19+
20+
dataPointReader.Write("coolant-temp_compressed.csv", compressed, header: ("Oh", "Temp"));
21+
22+
GnuPlot();
23+
ShowChart();
24+
}
25+
//---------------------------------------------------------------------
26+
private static void GnuPlot()
27+
{
28+
var gnuPlot = new Process();
29+
//gnuPlot.StartInfo.WorkingDirectory = Path.Combine(Directory.GetCurrentDirectory(), "data");
30+
gnuPlot.StartInfo.FileName = "gnuplot";
31+
gnuPlot.StartInfo.Arguments = "coolant-temp.plt";
32+
gnuPlot.Start();
33+
gnuPlot.WaitForExit();
34+
}
35+
//---------------------------------------------------------------------
36+
private static void ShowChart()
37+
{
38+
var png = new Process();
39+
png.StartInfo.UseShellExecute = true; // defaults to false in .net Core
40+
png.StartInfo.FileName = "coolant-temp.png";
41+
png.Start();
42+
}
43+
}
44+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
# Oh Temp [°C]
2+
27830 86
3+
28332 85
4+
28641 85
5+
29135 85
6+
29749 83
7+
29940 84
8+
30743 83
9+
31266 80
10+
31384 80
11+
31943 84
12+
32039 84
13+
32728 87
14+
32775 85
15+
33415 86
16+
34157 87
17+
34351 88
18+
34610 86
19+
35291 86
20+
36061 82
21+
36584 82
22+
36630 82
23+
37305 82
24+
37398 82
25+
38103 83
26+
38643 83
27+
38886 82
28+
38930 82
29+
39570 82
30+
40249 83
31+
40747 83
32+
40890 89
33+
41671 87
34+
42343 86
35+
42530 88
36+
42812 86
37+
42831 88
38+
42973 88
39+
43158 89
40+
43828 86
41+
44287 86
42+
44618 86
43+
45048 83
44+
45188 86
45+
46145 86
46+
46817 85
47+
46970 86
48+
47127 86
49+
47315 86
50+
48153 84
51+
48154 81
52+
48851 82
53+
48868 81
54+
49181 83
55+
49681 85
56+
50196 83
57+
50197 83
58+
50976 85
59+
51310 85
60+
51693 85
61+
52126 81
62+
52939 80
63+
52985 80
64+
53746 80
65+
54178 80
66+
54345 80
67+
54849 80
68+
55109 79
69+
55250 79
70+
55762 79
71+
56238 79
72+
56523 79
73+
56993 84
74+
57278 84
75+
57618 83
76+
57730 83
77+
57849 84
78+
58013 83
79+
58348 86
80+
58755 85
81+
59395 82
82+
60167 79
83+
60333 79
84+
60667 78
85+
60862 78
86+
61313 76
87+
61640 78
88+
62236 78
89+
62712 71
90+
62733 78
91+
62877 79
92+
63065 80
93+
63701 82
94+
63960 82
95+
64373 81
96+
65032 84
97+
65613 79
98+
65633 83
99+
65951 81
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
reset
2+
3+
#set terminal dumb
4+
set term pngcairo size 800,600 enhanced
5+
set output 'coolant-temp.png'
6+
7+
set grid
8+
set title 'Coolant temp over Oh'
9+
set xlabel 'Oh'
10+
set ylabel 'temp [°C]'
11+
set key bottom right
12+
13+
#set datafile separator ";"
14+
15+
# replot is also possible for the second plot
16+
plot 'coolant-temp.csv' with linespoints title 'raw', \
17+
'coolant-temp_compressed.csv' with linespoints title 'compressed'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>netcoreapp2.0</TargetFramework>
6+
</PropertyGroup>
7+
8+
<ItemGroup>
9+
<ProjectReference Include="..\..\source\gfoidl.DataCompression\gfoidl.DataCompression.csproj" />
10+
</ItemGroup>
11+
12+
<ItemGroup>
13+
<None Update="data\*" CopyToOutputDirectory="PreserveNewest" />
14+
</ItemGroup>
15+
16+
</Project>

0 commit comments

Comments
 (0)