Skip to content

Commit

Permalink
Merge pull request #3 from Iune/dotnet
Browse files Browse the repository at this point in the history
Implementing in F#
  • Loading branch information
Iune authored Jan 16, 2021
2 parents 22cdd24 + 7f3d279 commit ac49482
Show file tree
Hide file tree
Showing 12 changed files with 436 additions and 341 deletions.
231 changes: 119 additions & 112 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,117 @@

# Created by https://www.gitignore.io/api/macos,python,visualstudiocode
# Edit at https://www.gitignore.io/?templates=macos,python,visualstudiocode
# Created by https://www.toptal.com/developers/gitignore/api/fsharp,dotnetcore,intellij+all,visualstudiocode,macos
# Edit at https://www.toptal.com/developers/gitignore?templates=fsharp,dotnetcore,intellij+all,visualstudiocode,macos

### DotnetCore ###
# .NET Core build folders
bin/
obj/

# Common node modules locations
/node_modules
/wwwroot/node_modules

### fsharp ###
lib/debug
lib/release
Debug
*.suo
*.user
obj
bin
/build/
*.exe
!.paket/paket.bootstrapper.exe
.ionide/

### Intellij+all ###
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839

# User-specific stuff
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/**/usage.statistics.xml
.idea/**/dictionaries
.idea/**/shelf

# Generated files
.idea/**/contentModel.xml

# Sensitive or high-churn files
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
.idea/**/dbnavigator.xml

# Gradle
.idea/**/gradle.xml
.idea/**/libraries

# Gradle and Maven with auto-import
# When using Gradle or Maven with auto-import, you should exclude module files,
# since they will be recreated, and may cause churn. Uncomment if using
# auto-import.
# .idea/artifacts
# .idea/compiler.xml
# .idea/jarRepositories.xml
# .idea/modules.xml
# .idea/*.iml
# .idea/modules
# *.iml
# *.ipr

# CMake
cmake-build-*/

# Mongo Explorer plugin
.idea/**/mongoSettings.xml

# File-based project format
*.iws

# IntelliJ
out/

# mpeltonen/sbt-idea plugin
.idea_modules/

# JIRA plugin
atlassian-ide-plugin.xml

# Cursive Clojure plugin
.idea/replstate.xml

# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties

# Editor-based Rest Client
.idea/httpRequests

# Android studio 3.1+ serialized cache file
.idea/caches/build_file_checksums.ser

### Intellij+all Patch ###
# Ignores the whole .idea folder and all .iml files
# See https://github.com/joeblau/gitignore.io/issues/186 and https://github.com/joeblau/gitignore.io/issues/360

.idea/

# Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-249601023

*.iml
modules.xml
.idea/misc.xml
*.ipr

# Sonarlint plugin
.idea/sonarlint

### macOS ###
# General
Expand All @@ -11,6 +122,7 @@
# Icon must end with two \r
Icon


# Thumbnails
._*

Expand All @@ -30,120 +142,15 @@ Network Trash Folder
Temporary Items
.apdisk

### Python ###
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
pip-wheel-metadata/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
.hypothesis/
.pytest_cache/

# Translations
*.mo
*.pot

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# pyenv
.python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# celery beat schedule file
celerybeat-schedule

# SageMath parsed files
*.sage.py

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# Mr Developer
.mr.developer.cfg
.project
.pydevproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

### VisualStudioCode ###
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
#!.vscode/tasks.json
#!.vscode/launch.json
*.code-workspace

### VisualStudioCode Patch ###
# Ignore all local history of files
.history
.ionide

# End of https://www.gitignore.io/api/macos,python,visualstudiocode
# End of https://www.toptal.com/developers/gitignore/api/fsharp,dotnetcore,intellij+all,visualstudiocode,macos
1 change: 0 additions & 1 deletion .tool-versions

This file was deleted.

34 changes: 34 additions & 0 deletions Ida.sln
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
63 changes: 63 additions & 0 deletions Ida/Console.fs
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)
Loading

0 comments on commit ac49482

Please sign in to comment.