<commit_before>open System
let sampleCompetition = 
        ["Αllegoric Alaskians;Blithering Badgers;win";
         "Devastating Donkeys;Courageous Californians;draw";
         "Devastating Donkeys;Αllegoric Alaskians;win";
         "Courageous Californians;Blithering Badgers;loss";
         "Blithering Badgers;Devastating Donkeys;loss";
         "Αllegoric Alaskians;Courageous Californians;win"]

type TeamStats = 
    {   
        MatchesPlayed: int
        MatchesWon: int
        MatchesLost: int
        MatchesDrawn: int
        Points: int }

let initialTeamStats =
    {   
        MatchesPlayed = 0
        MatchesWon = 0
        MatchesLost = 0
        MatchesDrawn = 0
        Points = 0 }

type GameOutcome = Win | Loss | Draw

// type Team =
//     {   Name: string
//         Stats: TeamStats }    

let parseOutcome outcome =
    match outcome with
    | "win" -> Win
    | "loss" -> Loss
    | "draw" -> Draw
    | _ -> failwith "Invalid outcome (valid outcomes are 'win', 'loss' and 'draw')."

// type GameResult = { Team1: Team; Team2: Team }

let updateWinnerTeam team =
    {   team with 
                MatchesWon = team.MatchesWon + 1
                Points = team.Points + 3 }

let updateLoosingTeam team = { team with MatchesLost = team.MatchesLost + 1 }

let updateTiedTeam team = { team with MatchesDrawn = team.MatchesDrawn + 1 }

let updateMatchesPlayed team = { team with MatchesPlayed = team.MatchesPlayed + 1 }

let updateTeamAfterPlayed f x = f x |> updateMatchesPlayed

let updateTeamsWithWinner winner looser =
    updateTeamAfterPlayed updateWinnerTeam winner, updateTeamAfterPlayed updateLoosingTeam looser
// updateTeamsWithWinner initialTeamStats initialTeamStats

let updateTiedTeams team1 team2 = 
    updateTeamAfterPlayed updateTiedTeam team1, updateTeamAfterPlayed updateTiedTeam team2
// updateTiedTeams initialTeamStats initialTeamStats


// let parseGame team1 team2 input =
    
    // let gameStats = String.Split [|';'|] input
    // let firstTeam = gameStats.[0]
    // let secondTeam = gameStats.[1]
    // let gameOutcome = parseOutcome gameStats.[2]

    // match gameOutcome with
    // | Win ->
    // | Loss -> 
    // | Draw ->     

// let foo = "aaa;bbb;ccc"
// let bla = foo.Split ';'
// bla


/// For some reason I think that I need a collection of all playing teams... ===============

/// Input: "foo;bar;baz"
/// Output: ["foo"; "bar"]
let getTeams (line: string) =
    line.Split ';' 
    |> Seq.take 2
// getTeams "foo;bar;baz"

// let list1 = ["a"]
// let list2 = ["b"]
// List.append list1 list2


let addOnlyNewTeams teams newTeams = 
    List.append teams newTeams
    |> List.distinct
// addOnlyNewTeams ["a"; "b"] ["a"; "x"] = ["a"; "b"; "x"]

/// =========================================================================================

let tally input =
    let teams = input |> initializeTeams<commit_msg>refactored mapping per line and per team<commit_after>open System
let sampleCompetition = 
        ["Αllegoric Alaskians;Blithering Badgers;win";
         "Devastating Donkeys;Courageous Californians;draw";
         "Devastating Donkeys;Αllegoric Alaskians;win";
         "Courageous Californians;Blithering Badgers;loss";
         "Blithering Badgers;Devastating Donkeys;loss";
         "Αllegoric Alaskians;Courageous Californians;win"]

type TeamStats = 
    {   
        MatchesPlayed: int
        MatchesWon: int
        MatchesLost: int
        MatchesDrawn: int
        Points: int }

let initialTeamStats =
    {   
        MatchesPlayed = 0
        MatchesWon = 0
        MatchesLost = 0
        MatchesDrawn = 0
        Points = 0 }

type GameOutcome = Win | Loss | Draw

// type Team =
//     {   Name: string
//         Stats: TeamStats }    

let parseOutcome outcome =
    match outcome with
    | "win" -> Win
    | "loss" -> Loss
    | "draw" -> Draw
    | _ -> failwith "Invalid outcome (valid outcomes are 'win', 'loss' and 'draw')."

// type GameResult = { Team1: Team; Team2: Team }

let updateWinnerTeam team =
    {   team with 
                MatchesWon = team.MatchesWon + 1
                Points = team.Points + 3 }

let updateLoosingTeam team = { team with MatchesLost = team.MatchesLost + 1 }

let updateTiedTeam team = { team with MatchesDrawn = team.MatchesDrawn + 1 }

let updateMatchesPlayed team = { team with MatchesPlayed = team.MatchesPlayed + 1 }

let updateTeamAfterPlayed f x = f x |> updateMatchesPlayed

let updateTeamsWithWinner winner looser =
    updateTeamAfterPlayed updateWinnerTeam winner, updateTeamAfterPlayed updateLoosingTeam looser
// updateTeamsWithWinner initialTeamStats initialTeamStats

let updateTiedTeams team1 team2 = 
    updateTeamAfterPlayed updateTiedTeam team1, updateTeamAfterPlayed updateTiedTeam team2
// updateTiedTeams initialTeamStats initialTeamStats


// let parseGame team1 team2 input =
    
    // let gameStats = String.Split [|';'|] input
    // let firstTeam = gameStats.[0]
    // let secondTeam = gameStats.[1]
    // let gameOutcome = parseOutcome gameStats.[2]

    // match gameOutcome with
    // | Win ->
    // | Loss -> 
    // | Draw ->     

// let foo = "aaa;bbb;ccc"
// let bla = foo.Split ';'
// bla


/// For some reason I think that I need a collection of all playing teams... ===============

/// Input: "foo;bar;baz"
/// Output: ["foo"; "bar"]
let getTeamsFromLine (line: string) =
    line.Split ';' 
    |> Seq.take 2
// getTeams "foo;bar;baz"

// let list1 = ["a"]
// let list2 = ["b"]
// List.append list1 list2


let addOnlyNewTeams teams newTeams = 
    Seq.append teams newTeams
    |> Seq.distinct
// addOnlyNewTeams ["a"; "b"] ["a"; "x"] = ["a"; "b"; "x"]

"Αllegoric Alaskians;Blithering Badgers;win"
|> getTeamsFromLine
|> addOnlyNewTeams []

let getTeams previousTeams = getTeamsFromLine >> addOnlyNewTeams previousTeams

"Αllegoric Alaskians;Blithering Badgers;win"
|> getTeams []

// sampleCompetition
["a1;b1;c"; "a1;b2;c"; "a2;b2;c"]
|> Seq.map(getTeamsFromLine)
|> Seq.append []
|> Seq.concat
|> Seq.distinct

/// =========================================================================================

let tally input =
    let teams = input |> initializeTeams
{'fraction_non_alphanumeric': 0.14162881245944192, 'fraction_numerical': 0.009409474367293965, 'mean_word_length': 2.894504106127606, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 34, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1985727', 'n_tokens_mistral': 2049, 'n_tokens_neox': 1963, 'n_words': 518}