<commit_before>//
//  API+ViewHelpers.swift
//  TripKit
//
//  Created by <NAME> on 01.08.19.
//  Copyright © 2019 SkedGo Pty Ltd. All rights reserved.
//

import Foundation

extension TKAPI.VehicleOccupancy {
  
  /// - Parameter all: Nested vehicle components
  /// - Returns: Average occupancy in the provided nested list of vehicle components, `nil` if no occupancy found.
  public static func average(in all: [[TKAPI.VehicleComponents]]?) -> (TKAPI.VehicleOccupancy, title: String)? {
    guard let all = all else { return nil }
    
    let components = all.flatMap { $0 }
    if components.isEmpty {
      return nil
    } else if components.count == 1, let component = components.first {
      let occupancy = component.occupancy ?? .unknown
      return occupancy != .unknown
        ? (occupancy, component.occupancyText ?? occupancy.localizedTitle)
        : nil
    }
    
    guard let average = average(in: components.compactMap(\.occupancy)) else { return nil }
    #warning("Consider occupancyTitle")
    return (average, average.localizedTitle)
  }
  
  /// - Parameter all: List of occupancies
  /// - Returns: Average occupancy, `nil` if list was empty
  private static func average(in all: [TKAPI.VehicleOccupancy]) -> TKAPI.VehicleOccupancy? {
    guard !all.isEmpty else { return nil }
    let sum = all.reduce(0) { $0 + $1.intValue }
    return TKAPI.VehicleOccupancy(intValue: sum / all.count)
  }
  
  public var color: TKColor? {
    switch self {
    case .unknown: return nil
    case .empty, .manySeatsAvailable: return #colorLiteral(red: 0, green: 0.7333984971, blue: 0.4438126683, alpha: 1)
    case .fewSeatsAvailable: return #colorLiteral(red: 1, green: 0.7553820014, blue: 0, alpha: 1)
    case .standingRoomOnly, .crushedStandingRoomOnly: return #colorLiteral(red: 1, green: 0.6531761289, blue: 0, alpha: 1)<commit_msg>Address warning<commit_after>//
//  API+ViewHelpers.swift
//  TripKit
//
//  Created by <NAME> on 01.08.19.
//  Copyright © 2019 SkedGo Pty Ltd. All rights reserved.
//

import Foundation

extension TKAPI.VehicleOccupancy {
  
  /// - Parameter all: Nested vehicle components
  /// - Returns: Average occupancy in the provided nested list of vehicle components, `nil` if no occupancy found.
  public static func average(in all: [[TKAPI.VehicleComponents]]?) -> (TKAPI.VehicleOccupancy, title: String)? {
    guard let all = all else { return nil }
    
    let components = all.flatMap { $0 }
    if components.isEmpty {
      return nil
    } else if components.count == 1, let component = components.first {
      let occupancy = component.occupancy ?? .unknown
      return occupancy != .unknown
        ? (occupancy, component.occupancyText ?? occupancy.localizedTitle)
        : nil
    }
    
    if components.contains(where: { $0.occupancyText != nil }),
      let best = components.min(by: { $0.occupancy?.intValue ?? 0 < $1.occupancy?.intValue ?? 0 } ) {
      // If any has a title, we pick the best (as we aren't guaranteed to have
      // an appropriate title for the average value)
      return (best, best.localizedTitle)
      
    } else if let average = average(in: components.compactMap(\.occupancy)) {
      return (average, average.localizedTitle)

    } else {
      return nil
    }
  }
  
  /// - Parameter all: List of occupancies
  /// - Returns: Average occupancy, `nil` if list was empty
  private static func average(in all: [TKAPI.VehicleOccupancy]) -> TKAPI.VehicleOccupancy? {
    guard !all.isEmpty else { return nil }
    let sum = all.reduce(0) { $0 + $1.intValue }
    return TKAPI.VehicleOccupancy(intValue: sum / all.count)
  }
  
  public var color: TKColor? {
    switch self {
    case .unknown: return nil
    case .empty, .manySeatsAvailable: return #colorLiteral(red: 0, green: 0.7333984971, blue: 0.4438126683, alpha: 1)
    case .fewSeatsAvailable: return #colorLiteral(red: 1, green: 0.7553820014, blue: 0, alpha: 1)
    case .standingRoomOnly, .crushedStandingRoomOnly: return #colorLiteral(red: 1, green: 0.6531761289, blue: 0, alpha: 1)
{'fraction_non_alphanumeric': 0.11581291759465479, 'fraction_numerical': 0.034397426379609006, 'mean_word_length': 3.0704934541792546, 'pattern_counts': {'":': 0, '<': 6, '<?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': '5554101', 'n_tokens_mistral': 1358, 'n_tokens_neox': 1243, 'n_words': 387}