-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from Iune/dotnet
Implementing in F#
- Loading branch information
Showing
12 changed files
with
436 additions
and
341 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio 15 | ||
VisualStudioVersion = 15.0.26124.0 | ||
MinimumVisualStudioVersion = 15.0.26124.0 | ||
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Ida", "Ida\Ida.fsproj", "{A0968778-E863-45CB-B79A-A6D148C669A1}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Debug|x64 = Debug|x64 | ||
Debug|x86 = Debug|x86 | ||
Release|Any CPU = Release|Any CPU | ||
Release|x64 = Release|x64 | ||
Release|x86 = Release|x86 | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{A0968778-E863-45CB-B79A-A6D148C669A1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{A0968778-E863-45CB-B79A-A6D148C669A1}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{A0968778-E863-45CB-B79A-A6D148C669A1}.Debug|x64.ActiveCfg = Debug|Any CPU | ||
{A0968778-E863-45CB-B79A-A6D148C669A1}.Debug|x64.Build.0 = Debug|Any CPU | ||
{A0968778-E863-45CB-B79A-A6D148C669A1}.Debug|x86.ActiveCfg = Debug|Any CPU | ||
{A0968778-E863-45CB-B79A-A6D148C669A1}.Debug|x86.Build.0 = Debug|Any CPU | ||
{A0968778-E863-45CB-B79A-A6D148C669A1}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{A0968778-E863-45CB-B79A-A6D148C669A1}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{A0968778-E863-45CB-B79A-A6D148C669A1}.Release|x64.ActiveCfg = Release|Any CPU | ||
{A0968778-E863-45CB-B79A-A6D148C669A1}.Release|x64.Build.0 = Release|Any CPU | ||
{A0968778-E863-45CB-B79A-A6D148C669A1}.Release|x86.ActiveCfg = Release|Any CPU | ||
{A0968778-E863-45CB-B79A-A6D148C669A1}.Release|x86.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
EndGlobal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
module Ida.Console | ||
|
||
open System | ||
open Ida.Parser | ||
open Spectre.Console | ||
|
||
let printVotes (votes: ParsedVotes) = | ||
let mutable ptsCol = new TableColumn("Points") | ||
ptsCol <- ptsCol.Centered() | ||
|
||
let mutable table = new Table() | ||
table <- table.AddColumn(ptsCol) | ||
table <- table.AddColumn("Country") | ||
table <- table.AddColumn("Artist") | ||
table <- table.AddColumn("Song") | ||
|
||
votes.Votes | ||
|> List.iter (fun vote -> | ||
let countryName = | ||
vote.Entry.Country.PrimaryName | ||
|> Option.defaultValue "" | ||
|
||
table <- table.AddRow(vote.Points.ToString(), countryName, vote.Entry.Artist, vote.Entry.Song)) | ||
|
||
AnsiConsole.Render(table) | ||
AnsiConsole.WriteLine() | ||
|
||
votes.Warnings | ||
|> List.iter (fun warning -> AnsiConsole.MarkupLine($"[red]Warning: {warning}[/]")) | ||
|
||
|
||
// See https://stackoverflow.com/a/27796307 | ||
let readLines () = | ||
let read _ = Console.ReadLine() | ||
|
||
let isValid = | ||
function | ||
| null -> false | ||
| _ -> true | ||
|
||
Seq.initInfinite read | ||
|> Seq.takeWhile isValid | ||
|> Seq.toList | ||
|
||
let rec voterLoop (parser: Parser, firstVoter: bool) = | ||
if not firstVoter then | ||
let rule = new Rule() | ||
AnsiConsole.Render(rule) | ||
|
||
let voter = | ||
AnsiConsole.Ask<string>("Voter Name") | ||
|> parser.Contest.FindVoter | ||
|
||
AnsiConsole.WriteLine() | ||
AnsiConsole.MarkupLine("Votes:") | ||
|
||
let lines = readLines () | ||
let votes = parser.Parse(voter, lines) | ||
|
||
AnsiConsole.WriteLine() | ||
printVotes (votes) | ||
|
||
voterLoop (parser, false) |
Oops, something went wrong.