mirror of
https://github.com/ikoHSE/KDZ1.git
synced 2024-11-27 14:33:15 +03:00
Initial commit
This commit is contained in:
commit
5e9743ba70
BIN
.vs/Frequencies/v15/.suo
Normal file
BIN
.vs/Frequencies/v15/.suo
Normal file
Binary file not shown.
0
.vs/Frequencies/v15/Server/sqlite3/db.lock
Normal file
0
.vs/Frequencies/v15/Server/sqlite3/db.lock
Normal file
BIN
.vs/Frequencies/v15/Server/sqlite3/storage.ide
Normal file
BIN
.vs/Frequencies/v15/Server/sqlite3/storage.ide
Normal file
Binary file not shown.
24
Frequencies.sln
Normal file
24
Frequencies.sln
Normal file
@ -0,0 +1,24 @@
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 15
|
||||
VisualStudioVersion = 15.0.27004.2009
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Frequencies", "Frequencies\Frequencies.csproj", "{013D9794-3BF4-425A-A60F-D06CD6A97976}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|x86 = Debug|x86
|
||||
Release|x86 = Release|x86
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{013D9794-3BF4-425A-A60F-D06CD6A97976}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||
{013D9794-3BF4-425A-A60F-D06CD6A97976}.Debug|x86.Build.0 = Debug|Any CPU
|
||||
{013D9794-3BF4-425A-A60F-D06CD6A97976}.Release|x86.ActiveCfg = Release|x86
|
||||
{013D9794-3BF4-425A-A60F-D06CD6A97976}.Release|x86.Build.0 = Release|x86
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {E3FF2AD0-694C-4469-999C-98F20916F872}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
19
Frequencies.userprefs
Normal file
19
Frequencies.userprefs
Normal file
@ -0,0 +1,19 @@
|
||||
<Properties StartupConfiguration="{013D9794-3BF4-425A-A60F-D06CD6A97976}|Default">
|
||||
<MonoDevelop.Ide.Workbench ActiveDocument="Frequencies/MainForm.cs">
|
||||
<Files>
|
||||
<File FileName="Frequencies/FIleReader.cs" Line="54" Column="1" />
|
||||
<File FileName="Frequencies/Histogram.cs" Line="1" Column="1" />
|
||||
<File FileName="Frequencies/FileChooser.cs" Line="1" Column="1" />
|
||||
<File FileName="Frequencies/Main.cs" Line="16" Column="26" />
|
||||
<File FileName="Frequencies/LoadingView.cs" Line="1" Column="1" />
|
||||
<File FileName="Frequencies/MainForm.cs" Line="6" Column="18" />
|
||||
</Files>
|
||||
</MonoDevelop.Ide.Workbench>
|
||||
<MonoDevelop.Ide.Workspace ActiveConfiguration="Debug|x86" />
|
||||
<MonoDevelop.Ide.ItemProperties.Frequencies PreferredExecutionTarget="MonoDevelop.Default" />
|
||||
<MonoDevelop.Ide.DebuggingService.Breakpoints>
|
||||
<BreakpointStore />
|
||||
</MonoDevelop.Ide.DebuggingService.Breakpoints>
|
||||
<MonoDevelop.Ide.DebuggingService.PinnedWatches />
|
||||
<MultiItemStartupConfigurations />
|
||||
</Properties>
|
60
Frequencies/ClassDiagram1.cd
Normal file
60
Frequencies/ClassDiagram1.cd
Normal file
@ -0,0 +1,60 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<ClassDiagram MajorVersion="1" MinorVersion="1">
|
||||
<Class Name="Frequencies.FileChooser">
|
||||
<Position X="2.5" Y="2.75" Width="1.5" />
|
||||
<TypeIdentifier>
|
||||
<HashCode>AAAAAABAAAAAAAAAAAAAAAAAECAQAAAIAAAAAAAAAAI=</HashCode>
|
||||
<FileName>FileChooser.cs</FileName>
|
||||
</TypeIdentifier>
|
||||
</Class>
|
||||
<Class Name="Frequencies.FileReader">
|
||||
<Position X="0.75" Y="5" Width="1.5" />
|
||||
<TypeIdentifier>
|
||||
<HashCode>AAAgAAAAAAAAAAAABAAAAAAkAAAAAAAAAAgAAAAAAAA=</HashCode>
|
||||
<FileName>FIleReader.cs</FileName>
|
||||
</TypeIdentifier>
|
||||
</Class>
|
||||
<Class Name="Frequencies.Histogram">
|
||||
<Position X="4.5" Y="2.75" Width="1.5" />
|
||||
<TypeIdentifier>
|
||||
<HashCode>AAAgAAEQAAAAAQAAAAAACQQAAAAAADAAAICEAkQBASA=</HashCode>
|
||||
<FileName>Histogram.cs</FileName>
|
||||
</TypeIdentifier>
|
||||
</Class>
|
||||
<Class Name="Frequencies.LoadingView">
|
||||
<Position X="4.5" Y="0.5" Width="1.5" />
|
||||
<TypeIdentifier>
|
||||
<HashCode>AAAAAAAAAAAAABAAAAAAAAAAAAAAAAAIAAAAAAAAAAA=</HashCode>
|
||||
<FileName>LoadingView.cs</FileName>
|
||||
</TypeIdentifier>
|
||||
</Class>
|
||||
<Class Name="Frequencies.Program">
|
||||
<Position X="0.75" Y="0.5" Width="1.5" />
|
||||
<TypeIdentifier>
|
||||
<HashCode>AQAAAAAAAAAAAAAAQAAAAAAAAACgAAAAAAAABAAQAAA=</HashCode>
|
||||
<FileName>Main.cs</FileName>
|
||||
</TypeIdentifier>
|
||||
</Class>
|
||||
<Class Name="Frequencies.MainForm">
|
||||
<Position X="0.75" Y="3" Width="1.5" />
|
||||
<TypeIdentifier>
|
||||
<HashCode>AAAAAAAAAAAAAhAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=</HashCode>
|
||||
<FileName>MainForm.cs</FileName>
|
||||
</TypeIdentifier>
|
||||
</Class>
|
||||
<Class Name="View">
|
||||
<Position X="2.5" Y="0.5" Width="1.5" />
|
||||
<TypeIdentifier>
|
||||
<HashCode>AAAAAAAAAAAAAAAAAAAEAAAAAAAAACAIAAAAAAAAAAA=</HashCode>
|
||||
<FileName>MainForm.cs</FileName>
|
||||
</TypeIdentifier>
|
||||
</Class>
|
||||
<Class Name="Frequencies.ResultPresenter">
|
||||
<Position X="6.25" Y="0.5" Width="1.5" />
|
||||
<TypeIdentifier>
|
||||
<HashCode>AAAAEgArAAoABQBACAAAAAAAIQAIQAAJgAABgAIAAQA=</HashCode>
|
||||
<FileName>ResultPresenter.cs</FileName>
|
||||
</TypeIdentifier>
|
||||
</Class>
|
||||
<Font Name="Segoe UI" Size="9" />
|
||||
</ClassDiagram>
|
67
Frequencies/FIleReader.cs
Normal file
67
Frequencies/FIleReader.cs
Normal file
@ -0,0 +1,67 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace Frequencies {
|
||||
public class FileReader {
|
||||
private Dictionary<String, int> recorded = new Dictionary<String, int>();
|
||||
|
||||
public KeyValuePair<String, int>[] result {
|
||||
get => recorded.OrderBy((arg) => arg.Value).Where(x => x.Value > 1).Reverse().ToArray();
|
||||
}
|
||||
|
||||
public void Read(string file, Encoding encoding, int pollInterval = 30) {
|
||||
recorded.Clear();
|
||||
if (File.Exists(file)) {
|
||||
var reader = new StreamReader(file, encoding);
|
||||
char c;
|
||||
List<char> soFar = new List<char>();
|
||||
var i = 0;
|
||||
while ((Int16) (c = (char) reader.Read()) != -1) {
|
||||
//Console.WriteLine(c);
|
||||
if (Char.IsLetter(c) || c == '-' || c == '\'') {
|
||||
soFar.Add(Char.ToLower(c));
|
||||
} else {
|
||||
if (soFar.Count > 0) {
|
||||
i += 1;
|
||||
var st = new String(soFar.ToArray());
|
||||
if (!recorded.Keys.Contains(st)) {
|
||||
recorded[st] = 0;
|
||||
}
|
||||
|
||||
recorded[st] += 1;
|
||||
|
||||
soFar.Clear();
|
||||
|
||||
if (i >= pollInterval) {
|
||||
i = 0;
|
||||
poll?.Invoke();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
if (soFar.Count > 0) {
|
||||
i += 1;
|
||||
var st = new String(soFar.ToArray());
|
||||
if (!recorded.Keys.Contains(st)) {
|
||||
recorded[st] = 0;
|
||||
}
|
||||
|
||||
recorded[st] += 1;
|
||||
}
|
||||
finished?.Invoke();
|
||||
}
|
||||
}
|
||||
public void Read(string file, Encoding encoding, Action<KeyValuePair<String, int>[]> completion) {
|
||||
finished += () => {
|
||||
completion(this.result);
|
||||
};
|
||||
this.Read(file, encoding);
|
||||
}
|
||||
public event Action poll;
|
||||
public event Action finished;
|
||||
}
|
||||
}
|
68
Frequencies/FileChooser.cs
Normal file
68
Frequencies/FileChooser.cs
Normal file
@ -0,0 +1,68 @@
|
||||
using System;
|
||||
using System.Windows.Forms;
|
||||
using System.Drawing;
|
||||
using System.Text;
|
||||
namespace Frequencies {
|
||||
public class FileChooser: View {
|
||||
|
||||
private ComboBox encodingChooser = new ComboBox() {
|
||||
FlatStyle = FlatStyle.System
|
||||
};
|
||||
private Button button = new Button() {
|
||||
FlatStyle = FlatStyle.System
|
||||
};
|
||||
private OpenFileDialog fileDialog = new OpenFileDialog();
|
||||
|
||||
public FileChooser() {
|
||||
controls.Add(encodingChooser);
|
||||
encodingChooser.DropDownStyle = ComboBoxStyle.DropDownList;
|
||||
encodingChooser.Items.Add("UTF-8");
|
||||
encodingChooser.Items.Add("UTF-16");
|
||||
encodingChooser.Items.Add("Windows-1251");
|
||||
encodingChooser.SelectedIndex = 0;
|
||||
encodingChooser.Width = 210;
|
||||
encodingChooser.Font = new Font(new FontFamily("Segoe UI"), 21, FontStyle.Regular);
|
||||
|
||||
button.Font = new Font(new FontFamily("Segoe UI"), 34, FontStyle.Regular);
|
||||
controls.Add(button);
|
||||
button.Text = "Select file";
|
||||
button.AutoSize = true;
|
||||
|
||||
button.Click += (_, __) => {
|
||||
var result = fileDialog.ShowDialog();
|
||||
if (fileDialog.FileName != null && result == DialogResult.OK) {
|
||||
didSelectFile?.Invoke(fileDialog.FileName, GetEncoding());
|
||||
}
|
||||
};
|
||||
|
||||
fileDialog.Filter = "Text files (*.txt)|*.txt";
|
||||
fileDialog.InitialDirectory = "c:\\" ;
|
||||
fileDialog.FilterIndex = 0;
|
||||
}
|
||||
|
||||
private Encoding GetEncoding() {
|
||||
switch (encodingChooser.SelectedIndex) {
|
||||
case 0:
|
||||
return Encoding.UTF8;
|
||||
case 1:
|
||||
return Encoding.Unicode;
|
||||
case 2:
|
||||
return Encoding.GetEncoding("windows-1251");
|
||||
default:
|
||||
throw new Exception("Something has gone horribly wrong.");
|
||||
}
|
||||
}
|
||||
|
||||
public override void Layout(Size rect) {
|
||||
encodingChooser.Left = rect.Width/2 - encodingChooser.Width/2;
|
||||
encodingChooser.Top = (int)(rect.Height * 0.23);
|
||||
|
||||
button.Left = rect.Width/2 - button.Width/2;
|
||||
button.Top = encodingChooser.Bottom + 55;
|
||||
}
|
||||
|
||||
public event Action<string, Encoding> didSelectFile;
|
||||
|
||||
}
|
||||
}
|
||||
|
59
Frequencies/Frequencies.csproj
Normal file
59
Frequencies/Frequencies.csproj
Normal file
@ -0,0 +1,59 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{013D9794-3BF4-425A-A60F-D06CD6A97976}</ProjectGuid>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<RootNamespace>Frequencies</RootNamespace>
|
||||
<AssemblyName>Frequencies</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.7</TargetFrameworkVersion>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release</OutputPath>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<PlatformTarget>x86</PlatformTarget>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug</OutputPath>
|
||||
<DefineConstants>DEBUG;</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<PlatformTarget>anycpu</PlatformTarget>
|
||||
<CustomCommands>
|
||||
<CustomCommands>
|
||||
<Command>
|
||||
<type>BeforeBuild</type>
|
||||
<command>../../clean.fish ${TargetDir}</command>
|
||||
</Command>
|
||||
</CustomCommands>
|
||||
</CustomCommands>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Main.cs" />
|
||||
<Compile Include="FileChooser.cs" />
|
||||
<Compile Include="MainForm.cs">
|
||||
<SubType>Form</SubType>
|
||||
</Compile>
|
||||
<Compile Include="FIleReader.cs" />
|
||||
<Compile Include="ResultPresenter.cs" />
|
||||
<Compile Include="LoadingView.cs" />
|
||||
<Compile Include="Histogram.cs">
|
||||
<SubType>Component</SubType>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System.Windows.Forms" />
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Drawing" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="ClassDiagram1.cd" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
8
Frequencies/Frequencies.csproj.user
Normal file
8
Frequencies/Frequencies.csproj.user
Normal file
@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup Condition=" '$(RunConfiguration)' == 'Default' ">
|
||||
<StartAction>Program</StartAction>
|
||||
<StartProgram>..\..\runWin10.fish</StartProgram>
|
||||
<StartArguments>${TargetPath}</StartArguments>
|
||||
</PropertyGroup>
|
||||
</Project>
|
18
Frequencies/Frequencies.sln
Normal file
18
Frequencies/Frequencies.sln
Normal file
@ -0,0 +1,18 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 2012
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Frequencies", "Frequencies.csproj", "{013D9794-3BF4-425A-A60F-D06CD6A97976}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|x86 = Debug|x86
|
||||
Release|x86 = Release|x86
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{013D9794-3BF4-425A-A60F-D06CD6A97976}.Release|x86.ActiveCfg = Release|x86
|
||||
{013D9794-3BF4-425A-A60F-D06CD6A97976}.Release|x86.Build.0 = Release|x86
|
||||
{013D9794-3BF4-425A-A60F-D06CD6A97976}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{013D9794-3BF4-425A-A60F-D06CD6A97976}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
EndGlobalSection
|
||||
EndGlobal
|
19
Frequencies/Frequencies.userprefs
Normal file
19
Frequencies/Frequencies.userprefs
Normal file
@ -0,0 +1,19 @@
|
||||
<Properties StartupConfiguration="{013D9794-3BF4-425A-A60F-D06CD6A97976}|Default">
|
||||
<MonoDevelop.Ide.Workbench ActiveDocument="MainForm.cs">
|
||||
<Files>
|
||||
<File FileName="MainForm.cs" Line="22" Column="32" />
|
||||
<File FileName="Main.cs" Line="28" Column="43" />
|
||||
<File FileName="ResultPresenter.cs" Line="30" Column="53" />
|
||||
<File FileName="FIleReader.cs" Line="18" Column="84" />
|
||||
<File FileName="FileChooser.cs" Line="23" Column="60" />
|
||||
<File FileName="LoadingView.cs" Line="29" Column="92" />
|
||||
</Files>
|
||||
</MonoDevelop.Ide.Workbench>
|
||||
<MonoDevelop.Ide.Workspace ActiveConfiguration="Debug" />
|
||||
<MonoDevelop.Ide.ItemProperties.Frequencies PreferredExecutionTarget="MonoDevelop.Default" />
|
||||
<MonoDevelop.Ide.DebuggingService.Breakpoints>
|
||||
<BreakpointStore />
|
||||
</MonoDevelop.Ide.DebuggingService.Breakpoints>
|
||||
<MonoDevelop.Ide.DebuggingService.PinnedWatches />
|
||||
<MultiItemStartupConfigurations />
|
||||
</Properties>
|
121
Frequencies/Histogram.cs
Normal file
121
Frequencies/Histogram.cs
Normal file
@ -0,0 +1,121 @@
|
||||
using System;
|
||||
using System.Windows.Forms;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
namespace Frequencies {
|
||||
public class Histogram: PictureBox {
|
||||
public Histogram() {
|
||||
Paint += PaintRects;
|
||||
}
|
||||
|
||||
private KeyValuePair<string, int>[] _values;
|
||||
private ListView.SelectedIndexCollection _selectedIndices;
|
||||
private Color _mainColor = Color.FromArgb(230, 230, 230); //Color.LightGray;
|
||||
private Color _selectedColor = Color.FromArgb(200, 200, 200); //Color.DimGray;
|
||||
private int _count = 0;
|
||||
|
||||
public int Count {
|
||||
get => _count;
|
||||
set {
|
||||
_count = value;
|
||||
Invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
public Color MainColor {
|
||||
get => _mainColor;
|
||||
set {
|
||||
_mainColor = value;
|
||||
Invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
public Color SelectedColor {
|
||||
get => _selectedColor;
|
||||
set {
|
||||
_selectedColor = value;
|
||||
Invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
public ListView.SelectedIndexCollection SelectedIndices {
|
||||
get => _selectedIndices;
|
||||
set {
|
||||
_selectedIndices = value;
|
||||
Invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
public KeyValuePair<string, int>[] values {
|
||||
get => _values;
|
||||
set {
|
||||
_values = value;
|
||||
Invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static int minPadding = 8;
|
||||
private static int minWidth = 10;
|
||||
private Font wordFont = new Font(new FontFamily("Segoe UI"), 21, FontStyle.Bold);
|
||||
private Font numFont = new Font(new FontFamily("Segoe UI"), 8, FontStyle.Bold);
|
||||
private static Color wordColor = Color.Black;
|
||||
private static Color numColor = Color.Black;
|
||||
private static int numberPadding = 1;
|
||||
private int heightBuffer = 21;
|
||||
private void PaintRects(object _, PaintEventArgs e) {
|
||||
if (values.Length > 0) {
|
||||
var g = e.Graphics;
|
||||
var mainBrush = new SolidBrush(MainColor);
|
||||
var selectedBrush = new SolidBrush(SelectedColor);
|
||||
var wordBrush = new SolidBrush(wordColor);
|
||||
var numBrush = new SolidBrush(numColor);
|
||||
var min = Math.Min(Count, values.Length);
|
||||
var k = (double)(Height - heightBuffer) / (double)values.First().Value;
|
||||
var currentX = minPadding;
|
||||
var numberWidth = ResultPresenter.WidthFor(values.First().Value, numFont, g);
|
||||
var i = 0;
|
||||
foreach (var el in values.Take(Count)) {
|
||||
|
||||
g.ResetTransform();
|
||||
|
||||
var word = el.Key;
|
||||
var descent = wordFont.FontFamily.GetCellDescent(wordFont.Style);
|
||||
var lineHeight = wordFont.FontFamily.GetLineSpacing(wordFont.Style);
|
||||
var actualDescent = wordFont.Height * descent / lineHeight;
|
||||
var actualWordWidth = wordFont.Height - actualDescent;
|
||||
|
||||
var barHeight = (int) (el.Value * k);
|
||||
|
||||
var actualWidth = Math.Max(actualWordWidth + numberPadding, minWidth) + numberWidth;
|
||||
var rect = new Rectangle(new Point(currentX, Height - barHeight), new Size(actualWidth, barHeight));
|
||||
if (SelectedIndices == null) {
|
||||
g.FillRectangle(mainBrush, rect);
|
||||
} else {
|
||||
g.FillRectangle(SelectedIndices.Contains(i) ? selectedBrush : mainBrush, rect);
|
||||
}
|
||||
|
||||
|
||||
g.TranslateTransform(currentX, Height - barHeight);
|
||||
|
||||
var numString = $"{el.Value}";
|
||||
var numSize = g.MeasureString(numString, numFont);
|
||||
g.DrawString(numString, numFont, numBrush, new PointF(actualWordWidth + numberPadding + (numberWidth - numSize.Width), -numSize.Height));
|
||||
|
||||
var wordSize = g.MeasureString(el.Key, wordFont);
|
||||
var wordHeight = wordSize.Width;
|
||||
var actualWordHeight = Math.Max(wordHeight, barHeight);
|
||||
|
||||
g.RotateTransform(90);
|
||||
g.DrawString(el.Key, wordFont, wordBrush, new PointF(barHeight - actualWordHeight, -actualWordWidth));
|
||||
|
||||
currentX += actualWidth + minPadding;
|
||||
i += 1;
|
||||
}
|
||||
Width = currentX;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
21
Frequencies/LoadingView.cs
Normal file
21
Frequencies/LoadingView.cs
Normal file
@ -0,0 +1,21 @@
|
||||
using System.Windows.Forms;
|
||||
using System.Drawing;
|
||||
namespace Frequencies {
|
||||
public class LoadingView: View {
|
||||
|
||||
private Label label = new Label();
|
||||
|
||||
public LoadingView() {
|
||||
label.Font = new Font("Segoe UI", 55, FontStyle.Regular);
|
||||
controls.Add(label);
|
||||
label.ForeColor = Color.LightGray;
|
||||
label.AutoSize = true;
|
||||
label.Text = "Loading...";
|
||||
}
|
||||
|
||||
public override void Layout(System.Drawing.Size rect) {
|
||||
label.Left = rect.Width/2 - label.Width/2;
|
||||
label.Top = rect.Height/2 - label.Height/2 - (int)((double)(rect.Height) * 0.07);
|
||||
}
|
||||
}
|
||||
}
|
50
Frequencies/Main.cs
Normal file
50
Frequencies/Main.cs
Normal file
@ -0,0 +1,50 @@
|
||||
using System;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace Frequencies {
|
||||
public static class Program {
|
||||
static MainForm form;
|
||||
static FileReader reader;
|
||||
static FileChooser fileChooser;
|
||||
static ResultPresenter presenter;
|
||||
static LoadingView loading;
|
||||
[STAThread]
|
||||
public static void Main() {
|
||||
Application.EnableVisualStyles();
|
||||
Application.SetCompatibleTextRenderingDefault(false);
|
||||
|
||||
form = new MainForm();
|
||||
reader = new FileReader();
|
||||
fileChooser = new FileChooser();
|
||||
presenter = new ResultPresenter();
|
||||
loading = new LoadingView();
|
||||
|
||||
form.Present(fileChooser);
|
||||
|
||||
reader.finished += () => {
|
||||
var result = reader.result;
|
||||
if (result.Length == 0) {
|
||||
form.Present(fileChooser);
|
||||
form.Refresh();
|
||||
MessageBox.Show("There appear to be no words that show up more than once in your file...");
|
||||
} else {
|
||||
|
||||
presenter.Consume(reader.result);
|
||||
form.Present(presenter);
|
||||
form.Refresh();
|
||||
}
|
||||
};
|
||||
presenter.DidClickBackButton += () => {
|
||||
form.Present(fileChooser);
|
||||
presenter.Reset();
|
||||
};
|
||||
fileChooser.didSelectFile += (file, encoding) => {
|
||||
form.Present(loading);
|
||||
form.Refresh();
|
||||
reader.Read(file, encoding);
|
||||
};
|
||||
|
||||
Application.Run(form);
|
||||
}
|
||||
}
|
||||
}
|
41
Frequencies/MainForm.cs
Normal file
41
Frequencies/MainForm.cs
Normal file
@ -0,0 +1,41 @@
|
||||
using System.Windows.Forms;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
|
||||
namespace Frequencies {
|
||||
public class MainForm: Form {
|
||||
|
||||
public MainForm(): base() {
|
||||
Text = "Frequencies";
|
||||
MinimumSize = new System.Drawing.Size(750, 500);
|
||||
DoubleBuffered = true;
|
||||
Layout += (_, __) => {
|
||||
currentView?.Layout(ClientSize);
|
||||
};
|
||||
BackColor = Color.White;
|
||||
}
|
||||
|
||||
private View currentView;
|
||||
|
||||
public void Present(View view) {
|
||||
currentView = view;
|
||||
Controls.Clear();
|
||||
Controls.AddRange(view.controlsArray);
|
||||
Invalidate();
|
||||
Refresh();
|
||||
}
|
||||
}
|
||||
|
||||
abstract public class View {
|
||||
protected List<Control> controls = new List<Control>();
|
||||
public Control[] controlsArray {
|
||||
get {
|
||||
return controls.ToArray();
|
||||
}
|
||||
}
|
||||
|
||||
abstract public void Layout(Size rect);
|
||||
}
|
||||
}
|
||||
|
||||
|
156
Frequencies/ResultPresenter.cs
Normal file
156
Frequencies/ResultPresenter.cs
Normal file
@ -0,0 +1,156 @@
|
||||
using System;
|
||||
using System.Windows.Forms;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
namespace Frequencies {
|
||||
public class ResultPresenter: View {
|
||||
|
||||
private static Font numberFont = new Font("Segoe UI", 13, FontStyle.Regular);
|
||||
private static Color numberColor = Color.Black;
|
||||
private static Font wordFont = new Font("Segoe UI", 13, FontStyle.Bold);
|
||||
private static Color wordColor = Color.Black;
|
||||
private static int paddingBetweenElements = 8;
|
||||
private static int minListWidth = 144;
|
||||
private static int backButtonWidth = 233;
|
||||
private static int backButtonHeight = 50;
|
||||
private static Font backButtonFont = new Font("Segoe UI", 21, FontStyle.Regular);
|
||||
private static int maxNumberOfElement = 50;
|
||||
private static Font numberLabelFont = new Font("Segoe UI", 34, FontStyle.Bold);
|
||||
|
||||
Histogram hist = new Histogram();
|
||||
ListView list = new ListView() {
|
||||
View = System.Windows.Forms.View.Details,
|
||||
HeaderStyle = ColumnHeaderStyle.None,
|
||||
AutoArrange = false
|
||||
};
|
||||
Panel scrollView = new Panel() {
|
||||
AutoScroll = true
|
||||
};
|
||||
Button backButton = new Button() {
|
||||
Text = " ⟨ Back",
|
||||
AutoSize = false,
|
||||
TextAlign = ContentAlignment.MiddleLeft,
|
||||
Font = backButtonFont
|
||||
};
|
||||
TrackBar track = new TrackBar() {
|
||||
Minimum = 1
|
||||
};
|
||||
Label numberLabel = new Label() {
|
||||
Font = numberLabelFont,
|
||||
TextAlign = ContentAlignment.BottomLeft,
|
||||
AutoSize = true
|
||||
};
|
||||
|
||||
private void updateNumberLabelText() {
|
||||
numberLabel.Text = track.Value == 1 ?
|
||||
$"Top word" :
|
||||
$"Top {track.Value} words";
|
||||
}
|
||||
|
||||
public void Reset() {
|
||||
track.Value = 1;
|
||||
}
|
||||
|
||||
public ResultPresenter() {
|
||||
backButton.Click += (_, __) => {
|
||||
DidClickBackButton?.Invoke();
|
||||
};
|
||||
track.ValueChanged += (_, __) => {
|
||||
updateNumberLabelText();
|
||||
hist.Count = track.Value;
|
||||
};
|
||||
list.SelectedIndexChanged += (_, __) => {
|
||||
hist.SelectedIndices = list.SelectedIndices;
|
||||
};
|
||||
controls.Add(list);
|
||||
controls.Add(scrollView);
|
||||
scrollView.Controls.Add(hist);
|
||||
controls.Add(backButton);
|
||||
controls.Add(track);
|
||||
controls.Add(numberLabel);
|
||||
}
|
||||
|
||||
public override void Layout(System.Drawing.Size rect) {
|
||||
backButton.FlatStyle = FlatStyle.System;
|
||||
backButton.Top = paddingBetweenElements;
|
||||
backButton.Left = paddingBetweenElements;
|
||||
backButton.Width = backButtonWidth;
|
||||
backButton.Height = backButtonHeight;
|
||||
|
||||
numberLabel.Left = backButton.Right + paddingBetweenElements;
|
||||
numberLabel.Top = backButton.Bottom - numberLabel.Height;
|
||||
|
||||
list.Width = Math.Max((rect.Width - paddingBetweenElements * 3) / 5, minListWidth);
|
||||
list.Height = rect.Height - 2*paddingBetweenElements;
|
||||
list.Left = rect.Width - paddingBetweenElements - list.Width;
|
||||
list.Top = paddingBetweenElements;
|
||||
list.FullRowSelect = true;
|
||||
list.Columns[2].Width = list.Width - list.Columns[1].Width - SystemInformation.VerticalScrollBarWidth - list.Columns[0].Width - 4;
|
||||
|
||||
track.Width = rect.Width - 3*paddingBetweenElements - list.Width;
|
||||
track.Left = paddingBetweenElements;
|
||||
track.Top = rect.Height - paddingBetweenElements - track.Height;
|
||||
|
||||
scrollView.Height = rect.Height - paddingBetweenElements*4 - track.Height - backButton.Height;
|
||||
scrollView.Width = rect.Width - 3 * paddingBetweenElements - list.Width;
|
||||
scrollView.Top = paddingBetweenElements*2 + backButton.Height;
|
||||
scrollView.Left = paddingBetweenElements;
|
||||
hist.Height = scrollView.Height - SystemInformation.HorizontalScrollBarHeight;
|
||||
hist.Invalidate();
|
||||
}
|
||||
|
||||
public void Consume(KeyValuePair<string, int>[] values) {
|
||||
list.Clear();
|
||||
|
||||
var maxInt = values.First().Value;
|
||||
var numWidth = WidthFor(maxInt, numberFont, list.CreateGraphics());
|
||||
|
||||
list.Columns.Add("", 0, HorizontalAlignment.Right);
|
||||
list.Columns.Add("", numWidth, HorizontalAlignment.Right);
|
||||
list.Columns.Add("", 0, HorizontalAlignment.Left);
|
||||
|
||||
var itemsToAdd = new ListViewItem[values.Count()];
|
||||
var i = 0;
|
||||
|
||||
foreach (var val in values) {
|
||||
var item = new ListViewItem("");
|
||||
item.UseItemStyleForSubItems = false;
|
||||
|
||||
var numItem = new ListViewItem.ListViewSubItem(item, $"{val.Value}");
|
||||
numItem.ForeColor = numberColor;
|
||||
numItem.Font = numberFont;
|
||||
|
||||
item.SubItems.Add(numItem);
|
||||
|
||||
var wordItem = new ListViewItem.ListViewSubItem(item, $"{val.Key}");
|
||||
wordItem.Font = wordFont;
|
||||
wordItem.ForeColor = wordColor;
|
||||
|
||||
item.SubItems.Add(wordItem);
|
||||
|
||||
itemsToAdd[i] = item;
|
||||
|
||||
i += 1;
|
||||
}
|
||||
|
||||
|
||||
list.Items.AddRange(itemsToAdd);
|
||||
|
||||
hist.values = values;
|
||||
|
||||
track.Maximum = Math.Min(maxNumberOfElement, values.Length);
|
||||
|
||||
updateNumberLabelText();
|
||||
hist.Count = track.Value;
|
||||
}
|
||||
|
||||
public static int WidthFor(int number, Font font, Graphics g) {
|
||||
var count = $"{number}".Length;
|
||||
var st = g.MeasureString(new String(Enumerable.Repeat('8', count + 1).ToArray()), font);
|
||||
return (int) (st.Width);
|
||||
}
|
||||
|
||||
public event Action DidClickBackButton;
|
||||
}
|
||||
}
|
BIN
Frequencies/bin/Debug/Frequencies.exe
Normal file
BIN
Frequencies/bin/Debug/Frequencies.exe
Normal file
Binary file not shown.
BIN
Frequencies/bin/Debug/Frequencies.pdb
Normal file
BIN
Frequencies/bin/Debug/Frequencies.pdb
Normal file
Binary file not shown.
Binary file not shown.
@ -0,0 +1 @@
|
||||
5ab0ac5eac6561fba22f2f85df6e52adaa436025
|
@ -0,0 +1,18 @@
|
||||
/Users/ilya/Developer/HSE/Frequencies/Frequencies/bin/Debug/Frequencies.exe
|
||||
/Users/ilya/Developer/HSE/Frequencies/Frequencies/bin/Debug/Frequencies.pdb
|
||||
/Users/ilya/Developer/HSE/Frequencies/Frequencies/obj/Debug/Frequencies.csproj.CoreCompileInputs.cache
|
||||
/Users/ilya/Developer/HSE/Frequencies/Frequencies/obj/Debug/Frequencies.exe
|
||||
/Users/ilya/Developer/HSE/Frequencies/Frequencies/obj/Debug/Frequencies.pdb
|
||||
//Mac/Home/Developer/HSE/Frequencies/Frequencies/bin/Debug/Frequencies.exe
|
||||
//Mac/Home/Developer/HSE/Frequencies/Frequencies/bin/Debug/Frequencies.pdb
|
||||
//Mac/Home/Developer/HSE/Frequencies/Frequencies/obj/Debug/Frequencies.csprojResolveAssemblyReference.cache
|
||||
//Mac/Home/Developer/HSE/Frequencies/Frequencies/obj/Debug/Frequencies.csproj.CoreCompileInputs.cache
|
||||
//Mac/Home/Developer/HSE/Frequencies/Frequencies/obj/Debug/Frequencies.exe
|
||||
//Mac/Home/Developer/HSE/Frequencies/Frequencies/obj/Debug/Frequencies.pdb
|
||||
/Users/ilya/Developer/HSE/Frequencies/Frequencies/obj/Debug/Frequencies.csprojResolveAssemblyReference.cache
|
||||
Z:\Developer\HSE\Frequencies\Frequencies\bin\Debug\Frequencies.exe
|
||||
Z:\Developer\HSE\Frequencies\Frequencies\bin\Debug\Frequencies.pdb
|
||||
Z:\Developer\HSE\Frequencies\Frequencies\obj\Debug\Frequencies.csprojResolveAssemblyReference.cache
|
||||
Z:\Developer\HSE\Frequencies\Frequencies\obj\Debug\Frequencies.csproj.CoreCompileInputs.cache
|
||||
Z:\Developer\HSE\Frequencies\Frequencies\obj\Debug\Frequencies.exe
|
||||
Z:\Developer\HSE\Frequencies\Frequencies\obj\Debug\Frequencies.pdb
|
Binary file not shown.
BIN
Frequencies/obj/Debug/Frequencies.exe
Normal file
BIN
Frequencies/obj/Debug/Frequencies.exe
Normal file
Binary file not shown.
BIN
Frequencies/obj/Debug/Frequencies.pdb
Normal file
BIN
Frequencies/obj/Debug/Frequencies.pdb
Normal file
Binary file not shown.
Binary file not shown.
@ -0,0 +1 @@
|
||||
f7b9765ff9fc4e1f19e462c1daae6ea482439ec5
|
@ -0,0 +1,6 @@
|
||||
/Users/ilya/Developer/HSE/Frequencies/Frequencies/obj/x86/Debug/Frequencies.csproj.CoreCompileInputs.cache
|
||||
/Users/ilya/Developer/HSE/Frequencies/Frequencies/bin/Debug/Frequencies.exe
|
||||
/Users/ilya/Developer/HSE/Frequencies/Frequencies/bin/Debug/Frequencies.pdb
|
||||
/Users/ilya/Developer/HSE/Frequencies/Frequencies/obj/x86/Debug/Frequencies.exe
|
||||
/Users/ilya/Developer/HSE/Frequencies/Frequencies/obj/x86/Debug/Frequencies.pdb
|
||||
/Users/ilya/Developer/HSE/Frequencies/Frequencies/obj/x86/Debug/Frequencies.csprojResolveAssemblyReference.cache
|
Binary file not shown.
BIN
Frequencies/obj/x86/Debug/Frequencies.exe
Normal file
BIN
Frequencies/obj/x86/Debug/Frequencies.exe
Normal file
Binary file not shown.
BIN
Frequencies/obj/x86/Debug/Frequencies.pdb
Normal file
BIN
Frequencies/obj/x86/Debug/Frequencies.pdb
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user