<commit_before>//
//  SeasonState.swift
//  Stats
//
//  Created by <NAME> on 3/28/17.
//  Copyright © 2017 AppsByPJ. All rights reserved.
//

import Foundation

struct SeasonState: State {
    
    var currentSeasonId: String? {
        return App.core.state.statState.currentSeasonId ?? App.core.state.teamState.currentTeam?.currentSeasonId
    }
    var allSeasonsDict = [String: [Season]]()
    
    var currentSeason: Season? {
        return allSeasons.first(where: { $0.id == currentSeasonId })
    }
    fileprivate var allSeasons: [Season] {
        return Array(allSeasonsDict.values.joined())
    }
    
    func seasons(for team: Team) -> [Season] {
        return allSeasonsDict[team.id] ?? []
    }
    
    mutating func react(to event: Event) {
        switch event {
        case let event as TeamEntitiesUpdated<Season>:
            allSeasonsDict[event.teamId] = event.entities
        default:
            break
        }
    }
    
}<commit_msg>Tries to fix season switch stats bug<commit_after>//
//  SeasonState.swift
//  Stats
//
//  Created by <NAME> on 3/28/17.
//  Copyright © 2017 AppsByPJ. All rights reserved.
//

import Foundation

struct SeasonState: State {
    
    var currentSeasonId: String? {
        return App.core.state.statState.currentSeasonId ?? App.core.state.teamState.currentTeam?.currentSeasonId
    }
    var allSeasonsDict = [String: [Season]]()
    
    var currentSeason: Season? {
        return allSeasons.first(where: { $0.id == currentSeasonId })
    }
    fileprivate var allSeasons: [Season] {
        return Array(allSeasonsDict.values.joined())
    }
    
    func seasons(for team: Team) -> [Season] {
        return allSeasonsDict[team.id] ?? []
    }
    
    mutating func react(to event: Event) {
        switch event {
        case let event as TeamEntitiesUpdated<Season>:
            allSeasonsDict[event.teamId] = event.entities
            App.core.fire(command: UpdateStats())
        default:
            break
        }
    }
    
}
{'fraction_non_alphanumeric': 0.11321695760598503, 'fraction_numerical': 0.00997506234413965, 'mean_word_length': 2.283142389525368, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, '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': '3358308', 'n_tokens_mistral': 643, 'n_tokens_neox': 609, 'n_words': 140}