prep for statistics table
This commit is contained in:
209
Sources/App/Content/AllStats.swift
Normal file
209
Sources/App/Content/AllStats.swift
Normal file
@@ -0,0 +1,209 @@
|
||||
//
|
||||
// Stats.swift
|
||||
// App
|
||||
//
|
||||
// Created by Michael Simard on 5/29/20.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
|
||||
import Fluent
|
||||
import Vapor
|
||||
|
||||
struct DataPoint : Content {
|
||||
var x:Double
|
||||
var y:Double
|
||||
var label:String
|
||||
|
||||
init(x:Double, y:Double, label:String) {
|
||||
self.x = x
|
||||
self.y = y
|
||||
self.label = label
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
final class AllStats: Content {
|
||||
var overall:StatsWithMostRecentDailyRecord
|
||||
var mwStats:StatsWithMostRecentDailyRecord
|
||||
var bocwStats:StatsWithMostRecentDailyRecord
|
||||
var byMonth: [MonthStats]
|
||||
var mostRecentRecord:String
|
||||
|
||||
init( overall:StatsWithMostRecentDailyRecord, mwStats:StatsWithMostRecentDailyRecord, bocwStats:StatsWithMostRecentDailyRecord, byMonth:[MonthStats], mostRecentRecord:String) {
|
||||
self.overall = overall
|
||||
self.byMonth = byMonth
|
||||
self.mostRecentRecord = mostRecentRecord
|
||||
self.mwStats = mwStats;
|
||||
self.bocwStats = bocwStats;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
final class OverallStats: Content {
|
||||
var overall:StatsWithMostRecentDailyRecord
|
||||
var mwStats:StatsWithMostRecentDailyRecord
|
||||
var bocwStats:StatsWithMostRecentDailyRecord
|
||||
var mostRecentRecord:String
|
||||
|
||||
var statsWithHyder:Stats
|
||||
var statsWithoutHyder:Stats
|
||||
|
||||
var dashboardItems:[DashboardItem] = []
|
||||
|
||||
init( overall:StatsWithMostRecentDailyRecord, mwStats:StatsWithMostRecentDailyRecord, bocwStats:StatsWithMostRecentDailyRecord, mostRecentRecord:String, statsWithHyder:Stats, statsWithoutHyder:Stats, dashboardItems:[DashboardItem]){
|
||||
|
||||
self.overall = overall
|
||||
self.mwStats = mwStats;
|
||||
self.bocwStats = bocwStats;
|
||||
self.mostRecentRecord = mostRecentRecord
|
||||
|
||||
self.statsWithHyder = statsWithHyder
|
||||
self.statsWithoutHyder = statsWithoutHyder
|
||||
|
||||
self.dashboardItems = dashboardItems
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
final class MonthStats: Content {
|
||||
var stats:Stats
|
||||
var month:String
|
||||
var year: String
|
||||
|
||||
init( month:Int, year:Int, stats:Stats) {
|
||||
self.month = Utilities.monthToString(month: month)
|
||||
self.year = String(year)
|
||||
self.stats = stats
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
final class Stats: Content {
|
||||
|
||||
var winLossRatio:String {
|
||||
get {
|
||||
return getRatio()
|
||||
}
|
||||
}
|
||||
var totalWins:Int
|
||||
var totalLosses:Int
|
||||
|
||||
init( totalWins:Int, totalLosses:Int) {
|
||||
self.totalWins = totalWins
|
||||
self.totalLosses = totalLosses
|
||||
}
|
||||
|
||||
var record:String {
|
||||
return "\(totalWins)-\(totalLosses)"
|
||||
}
|
||||
|
||||
private func getRatio() -> String {
|
||||
var returnString = ""
|
||||
let deno = (totalLosses != 0) ? totalLosses : 1
|
||||
returnString = String(getRatioDouble())
|
||||
if deno == 0 {
|
||||
returnString = returnString + "+"
|
||||
}
|
||||
return returnString
|
||||
}
|
||||
|
||||
func getRatioDouble() -> Double {
|
||||
let deno = (totalLosses != 0) ? totalLosses : 1
|
||||
|
||||
return (Double(totalWins) / Double(deno)).truncate(places: 3)
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
final class StatsWithMostRecentDailyRecord: Content {
|
||||
var winLossRatio:String
|
||||
var totalWins:Int
|
||||
var totalLosses:Int
|
||||
var mostRecentRecord:String
|
||||
|
||||
|
||||
var winRate:String {
|
||||
return "\((Double((Double(totalWins)/Double(totalWins + totalLosses))) * 100.0).truncate(places: 1))%"
|
||||
}
|
||||
init( winLoss:String, totalWins:Int, totalLosses:Int, mostRecentRecord:String ) {
|
||||
self.winLossRatio = winLoss
|
||||
self.totalWins = totalWins
|
||||
self.totalLosses = totalLosses
|
||||
self.mostRecentRecord = mostRecentRecord
|
||||
}
|
||||
|
||||
var record:String {
|
||||
return "\(totalWins)-\(totalLosses)"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
final class AllDailyStats: Content {
|
||||
var dailyStats : [DailyStats]
|
||||
|
||||
init(dailyStats:[DailyStats]) {
|
||||
self.dailyStats = dailyStats
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
final class AllRollingStats: Content {
|
||||
var cumulativeStats:[DailyStats]
|
||||
}
|
||||
|
||||
final class DailyStats: Content {
|
||||
|
||||
var day: String
|
||||
var month:String
|
||||
var year: String
|
||||
var cumulativeRatio:String
|
||||
var stats:Stats
|
||||
|
||||
init(day:Int, month:Int, year:Int, stats:Stats, cumulativeRatio:String) {
|
||||
self.day = String(day)
|
||||
self.month = Utilities.monthToString(month: month)
|
||||
self.year = String(year)
|
||||
self.stats = stats
|
||||
self.cumulativeRatio = cumulativeRatio
|
||||
}
|
||||
}
|
||||
|
||||
class Utilities {
|
||||
class func monthToString(month:Int) -> String {
|
||||
switch month {
|
||||
case 1 :
|
||||
return "January"
|
||||
case 2:
|
||||
return "February"
|
||||
case 3:
|
||||
return "March"
|
||||
case 4:
|
||||
return "April"
|
||||
case 5:
|
||||
return "May"
|
||||
case 6:
|
||||
return "June"
|
||||
case 7:
|
||||
return "July"
|
||||
case 8:
|
||||
return "August"
|
||||
case 9:
|
||||
return "September"
|
||||
case 10:
|
||||
return "October"
|
||||
case 11:
|
||||
return "November"
|
||||
case 12:
|
||||
return "December"
|
||||
default:
|
||||
return "error"
|
||||
}
|
||||
}
|
||||
}
|
||||
19
Sources/App/Content/DashboardItem.swift
Normal file
19
Sources/App/Content/DashboardItem.swift
Normal file
@@ -0,0 +1,19 @@
|
||||
//
|
||||
// DashboardItem.swift
|
||||
// App
|
||||
//
|
||||
// Created by Michael Simard on 1/9/21.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import Fluent
|
||||
import Vapor
|
||||
|
||||
struct DashboardItem: Content {
|
||||
var title:String
|
||||
var content:String
|
||||
var title2:String? = nil
|
||||
var content2:String? = nil
|
||||
|
||||
|
||||
}
|
||||
16
Sources/App/Content/Map.swift
Normal file
16
Sources/App/Content/Map.swift
Normal file
@@ -0,0 +1,16 @@
|
||||
//
|
||||
// Map.swift
|
||||
// App
|
||||
//
|
||||
// Created by Michael Simard on 1/10/21.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
struct Map: Hashable, Codable {
|
||||
var id: Int
|
||||
var name:String
|
||||
var imageName:String
|
||||
}
|
||||
|
||||
|
||||
16
Sources/App/Content/MapRecord.swift
Normal file
16
Sources/App/Content/MapRecord.swift
Normal file
@@ -0,0 +1,16 @@
|
||||
//
|
||||
// MapRecord.swift
|
||||
// App
|
||||
//
|
||||
// Created by Michael Simard on 1/10/21.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import Vapor
|
||||
import Fluent
|
||||
|
||||
struct MapRecord: Content {
|
||||
var map:Map
|
||||
var stats:Stats
|
||||
var ratio:String
|
||||
}
|
||||
23
Sources/App/Content/MatchHistory.swift
Normal file
23
Sources/App/Content/MatchHistory.swift
Normal file
@@ -0,0 +1,23 @@
|
||||
//
|
||||
// MatchHistory.swift
|
||||
// App
|
||||
//
|
||||
// Created by Michael Simard on 12/15/20.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import Fluent
|
||||
import Vapor
|
||||
|
||||
final class MatchHistory: Content {
|
||||
var total:Int
|
||||
var matches:[Match]
|
||||
var hasMorePages:Bool
|
||||
|
||||
init( total:Int, matches:[Match],hasMorePages:Bool) {
|
||||
self.total = total;
|
||||
self.matches = matches
|
||||
self.hasMorePages = hasMorePages
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user