Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Learn more about F# at http://fsharp.org
- open System
- open System.Text.RegularExpressions
- open FSharp.Data
- type FlairComboDataRaw = CsvProvider<"https://pastebin.com/raw/gmH0JSw4", "|">
- let ReplaceEllipsis (s: string) = s.Replace("…", "...")
- type Flair = {
- Flair: string option
- Team: string
- }
- type FlairCombo = {
- Flair1: Flair
- Flair2: Flair
- }
- let FlairRegex = new Regex(" :([^:]+): ")
- let TeamRegex = new Regex(" ([^:]+) ")
- let ParseFlairCombo (row: FlairComboDataRaw.Row): seq<FlairCombo> =
- let m1 = TeamRegex.Match(row.``Team 1``)
- let m2 = TeamRegex.Match(row.``Team 2``)
- let f1 = FlairRegex.Match(row.``Team 1``)
- let f2 = FlairRegex.Match(row.``Team 2``)
- match (m1.Success, m2.Success, Int32.TryParse(row.Count)) with
- | (true, true, (true, count)) ->
- Seq.replicate count {
- Flair1 = {
- Flair = if f1.Success then Some f1.Groups.[1].Value else None
- Team = ReplaceEllipsis m1.Groups.[1].Value
- }
- Flair2 = {
- Flair = if f2.Success then Some f2.Groups.[1].Value else None
- Team = ReplaceEllipsis m2.Groups.[1].Value
- }
- }
- | _ ->
- Seq.empty
- type Team =
- | Wisconsin
- | WisconsinRiverFalls
- | WisconsinStout
- | WisconsinEauClaire
- | WisconsinLaCrosse
- | WisconsinStevensPoint
- | WisconsinPlatteville
- | WisconsinOshkosh
- | WisconsinWhitewater
- | WisconsinSuperior
- | WisconsinParkside
- | Milwaukee
- | Other
- type TeamCombo = {
- Team1: Team
- Team2: Team
- }
- let Normalize (flair: Flair): Team =
- match flair.Flair with
- | Some ":wisconsin:" -> Wisconsin
- | Some ":wisconsinriverfalls:" -> WisconsinRiverFalls
- | Some ":wisconsinstout:" -> WisconsinStout
- | Some ":wisconsineauclaire:" -> WisconsinEauClaire
- | Some ":wisconsinlacrosse:" -> WisconsinLaCrosse
- | Some ":wisconsinstevenspoint:" -> WisconsinStevensPoint
- | Some ":wisconsinplatteville:" -> WisconsinPlatteville
- | Some ":wisconsinoshkosh:" -> WisconsinOshkosh
- | Some ":wisconsinwhitewater:" -> WisconsinWhitewater
- | Some ":wisconsinsuperior:" -> WisconsinSuperior
- | Some ":wisconsinparkside:" -> WisconsinParkside
- | Some ":milwaukee:" -> Milwaukee
- | _ ->
- let team = flair.Team
- if team.StartsWith("Wisconsin-R") then WisconsinRiverFalls
- else if team.StartsWith("Wisconsin-Sto") then WisconsinStout
- else if team.StartsWith("Wisconsin-E") then WisconsinEauClaire
- else if team.StartsWith("Wisconsin-L") then WisconsinLaCrosse
- else if team.StartsWith("Wisconsin-Ste") then WisconsinStevensPoint
- else if team.StartsWith("Wisconsin-Pl") then WisconsinPlatteville
- else if team.StartsWith("Wisconsin-O") then WisconsinOshkosh
- else if team.StartsWith("Wisconsin-W") then WisconsinWhitewater
- else if team.StartsWith("Wisconsin-Su") then WisconsinSuperior
- else if team.StartsWith("Wisconsin-Pa") then WisconsinParkside
- else if team = "Milwaukee" then Milwaukee
- else if "Wisconsin".StartsWith(team.Replace("...", "")) then Wisconsin
- else Other
- let NormalizeCombo (f: FlairCombo): TeamCombo = {
- Team1 = Normalize f.Flair1
- Team2 = Normalize f.Flair2
- }
- let OnlyInvolvesWisconsin (t: TeamCombo) =
- match (t.Team1, t.Team2) with
- | Other, _ -> false
- | _, Other -> false
- | _ -> true
- let InvolvesWisconsinAndOther (t: TeamCombo) =
- match (t.Team1, t.Team2) with
- | Other, Other -> false
- | _, Other -> true
- | Other, _ -> true
- | _ -> false
- [<EntryPoint>]
- let main _ =
- let single = FlairComboDataRaw.Load("https://pastebin.com/raw/A1uwGrf9")
- let multiple = FlairComboDataRaw.Load("https://pastebin.com/raw/gmH0JSw4")
- let groups =
- [single.Rows; multiple.Rows]
- |> Seq.collect id
- |> Seq.collect ParseFlairCombo
- |> Seq.map NormalizeCombo
- |> Seq.where OnlyInvolvesWisconsin
- |> Seq.groupBy id
- |> Seq.sortByDescending (fun (_, g) -> Seq.length g)
- printfn "|Flair 1|Flair 2|Count|"
- printfn ":--|:--|:--|"
- for (f, g) in groups do
- printfn "|%A|%A|%d|" f.Team1 f.Team2 (Seq.length g)
- printfn ""
- 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement