WIP: AddGui #1
@ -4,7 +4,8 @@ public static class KMeans
|
|||||||
{
|
{
|
||||||
private const int MaxLoops = 30;
|
private const int MaxLoops = 30;
|
||||||
|
|
||||||
public static void KMeansCalculation(IReadOnlyCollection<Point> points, int k, out IReadOnlyCollection<Point> centroids)
|
public static void KMeansCalculation(IReadOnlyCollection<Point> points, int k,
|
||||||
|
out IReadOnlyCollection<Point> centroids)
|
||||||
{
|
{
|
||||||
centroids = InitializeRandomCentroids(points, k).ToArray();
|
centroids = InitializeRandomCentroids(points, k).ToArray();
|
||||||
|
|
||||||
@ -64,10 +65,8 @@ public static class KMeans
|
|||||||
|
|
||||||
private static IEnumerable<Point> InitializeRandomCentroids(IReadOnlyCollection<Point> points, int k)
|
private static IEnumerable<Point> InitializeRandomCentroids(IReadOnlyCollection<Point> points, int k)
|
||||||
{
|
{
|
||||||
var minX = points.Min(p => p.X);
|
var (minX, maxX) = (points.Min(p => p.X), points.Max(p => p.X));
|
||||||
var maxX = points.Max(p => p.X);
|
var (minY, maxY) = (points.Min(p => p.Y), points.Max(p => p.Y));
|
||||||
var minY = points.Min(p => p.Y);
|
|
||||||
var maxY = points.Max(p => p.Y);
|
|
||||||
var rnd = new Random();
|
var rnd = new Random();
|
||||||
|
|
||||||
for (var i = 0; i < k; i++)
|
for (var i = 0; i < k; i++)
|
||||||
|
@ -3,5 +3,8 @@
|
|||||||
x:Class="KMeansGui.App">
|
x:Class="KMeansGui.App">
|
||||||
<Application.Styles>
|
<Application.Styles>
|
||||||
<FluentTheme Mode="Light"/>
|
<FluentTheme Mode="Light"/>
|
||||||
|
|
||||||
|
<!-- Add the line below to get OxyPlot UI theme applied. -->
|
||||||
|
<StyleInclude Source="resm:OxyPlot.Avalonia.Themes.Default.xaml?assembly=OxyPlot.Avalonia"/>
|
||||||
</Application.Styles>
|
</Application.Styles>
|
||||||
</Application>
|
</Application>
|
@ -1,25 +1,29 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<OutputType>WinExe</OutputType>
|
<OutputType>WinExe</OutputType>
|
||||||
<TargetFramework>net5.0</TargetFramework>
|
<TargetFramework>net6.0</TargetFramework>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Remove=".gitignore" />
|
<None Remove=".gitignore" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Avalonia" Version="0.10.11" />
|
<PackageReference Include="Avalonia" Version="0.10.11" />
|
||||||
<PackageReference Include="Avalonia.Desktop" Version="0.10.11" />
|
<PackageReference Include="Avalonia.Desktop" Version="0.10.11" />
|
||||||
<!--Condition below is needed to remove Avalonia.Diagnostics package from build output in Release configuration.-->
|
<!--Condition below is needed to remove Avalonia.Diagnostics package from build output in Release configuration.-->
|
||||||
<PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="0.10.11" />
|
<PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="0.10.11" />
|
||||||
<PackageReference Include="MvvmGen" Version="1.1.2" />
|
<PackageReference Include="MvvmGen" Version="1.1.2" />
|
||||||
</ItemGroup>
|
<PackageReference Include="OxyPlot.Avalonia" Version="2.1.0-Preview1" />
|
||||||
<ItemGroup>
|
</ItemGroup>
|
||||||
<Folder Include="Shell\" />
|
<ItemGroup>
|
||||||
</ItemGroup>
|
<Folder Include="Shell\" />
|
||||||
<ItemGroup>
|
</ItemGroup>
|
||||||
<Compile Update="ShellView.axaml.cs">
|
<ItemGroup>
|
||||||
<DependentUpon>ShellView.axaml</DependentUpon>
|
<Compile Update="ShellView.axaml.cs">
|
||||||
</Compile>
|
<DependentUpon>ShellView.axaml</DependentUpon>
|
||||||
</ItemGroup>
|
</Compile>
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\KMeansBase\KMeansBase.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
|
@ -2,14 +2,29 @@
|
|||||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
xmlns:kMeansGui="clr-namespace:KMeansGui" x:Name="LayoutRoot"
|
xmlns:kMeansGui="clr-namespace:KMeansGui"
|
||||||
|
xmlns:avalonia="http://oxyplot.org/avalonia"
|
||||||
|
x:Name="LayoutRoot"
|
||||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||||
x:Class="KMeansGui.ShellView"
|
x:Class="KMeansGui.ShellView"
|
||||||
Title="KMeansGui">
|
Title="KMeansGui">
|
||||||
<Window.DataContext>
|
<Window.DataContext>
|
||||||
<kMeansGui:ShellViewModel />
|
<kMeansGui:ShellViewModel />
|
||||||
</Window.DataContext>
|
</Window.DataContext>
|
||||||
<Grid RowDefinitions="*,*" ColumnDefinitions="*,*">
|
<Grid ColumnDefinitions="*,*">
|
||||||
<Button Command="{Binding OpenCsvFileAsync}" CommandParameter="{Binding ElementName=LayoutRoot}" >Load CSV file</Button>
|
<StackPanel Grid.Row="0" Grid.Column="0" Spacing="10">
|
||||||
</Grid>
|
<Button HorizontalAlignment="Stretch" Command="{Binding OpenCsvFileAsync}"
|
||||||
|
CommandParameter="{Binding ElementName=LayoutRoot}">
|
||||||
|
Load CSV file
|
||||||
|
</Button>
|
||||||
|
<TextBox UseFloatingWatermark="True" Watermark="Hello" Text="{Binding CountOfCentroids}"></TextBox>
|
||||||
|
</StackPanel>
|
||||||
|
<avalonia:Plot Height="150" Grid.Column="1"
|
||||||
|
PlotMargins="50 0 0 0"
|
||||||
|
PlotAreaBorderColor="#999999">
|
||||||
|
<avalonia:Plot.Series>
|
||||||
|
<avalonia:ScatterSeries Items="{Binding Points}" />
|
||||||
|
</avalonia:Plot.Series>
|
||||||
|
</avalonia:Plot>
|
||||||
|
</Grid>
|
||||||
</Window>
|
</Window>
|
@ -1,4 +1,5 @@
|
|||||||
using System.Threading.Tasks;
|
using System.Collections.Generic;
|
||||||
|
using System.Threading.Tasks;
|
||||||
using Avalonia.Controls;
|
using Avalonia.Controls;
|
||||||
using MvvmGen;
|
using MvvmGen;
|
||||||
|
|
||||||
@ -7,13 +8,21 @@ namespace KMeansGui
|
|||||||
[ViewModel]
|
[ViewModel]
|
||||||
public partial class ShellViewModel
|
public partial class ShellViewModel
|
||||||
{
|
{
|
||||||
|
[Property] private int _countOfCentroids;
|
||||||
|
[Property] private List<KMeansBase.Point> _points;
|
||||||
|
|
||||||
public async Task OpenCsvFileAsync(object parent)
|
public async Task OpenCsvFileAsync(object parent)
|
||||||
{
|
{
|
||||||
if (parent is Window window)
|
if (parent is Window window)
|
||||||
{
|
{
|
||||||
|
var fileDialogFilter = new FileDialogFilter();
|
||||||
|
fileDialogFilter.Extensions.Add("csv");
|
||||||
|
fileDialogFilter.Name = "comma separated file";
|
||||||
var fileDialog = new OpenFileDialog();
|
var fileDialog = new OpenFileDialog();
|
||||||
|
fileDialog.AllowMultiple = false;
|
||||||
|
|
||||||
|
fileDialog.Filters.Add(fileDialogFilter);
|
||||||
|
fileDialog.Title = "Select a csv file.";
|
||||||
var result = await fileDialog.ShowAsync(window);
|
var result = await fileDialog.ShowAsync(window);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user