using System.Diagnostics; using System.Drawing; using System.Globalization; namespace kMeans; public static class Program { private const string Coordinates = "coordinates.csv"; private const string PlotOut = "plot.png"; private const int K = 3; private static void Main() { Console.WriteLine("k-Means-Algorithmus"); var points = ParseCsv(Coordinates); PlotDiagram(points); } private static IReadOnlyList ParseCsv(string path) { var sw = Stopwatch.StartNew(); var result = new List(); var lines = File.ReadLines(path); foreach (var line in lines) { var current = line.Split(','); if (!double.TryParse(current[0], NumberStyles.Any, CultureInfo.InvariantCulture, out var x)) continue; if (!double.TryParse(current[1], NumberStyles.Any, CultureInfo.InvariantCulture, out var y)) continue; var point = new Point(x, y); result.Add(point); } sw.Stop(); Console.WriteLine($"[{nameof(ParseCsv)}] Elapsed: {sw.ElapsedMilliseconds}ms"); return result; } private static void PlotDiagram(IReadOnlyList points) { var sw = Stopwatch.StartNew(); var plot = new ScottPlot.Plot(); plot.AddScatterPoints(points.Select(p => p.X).ToArray(), points.Select(p => p.Y).ToArray()); plot.SaveFig(PlotOut); sw.Stop(); Process.Start(new ProcessStartInfo(PlotOut) { UseShellExecute = true }); Console.WriteLine($"[{nameof(PlotDiagram)}] Elapsed: {sw.ElapsedMilliseconds}ms"); } private record Point(double X, double Y, Color? Color = default, bool Mean = false); }