-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPitcher.swift
68 lines (62 loc) · 1.7 KB
/
Pitcher.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
//
// Pitcher.swift
// NoblesStatsMax
//
// Created by Harrison on 4/10/23.
//
import Foundation
import CoreData
//Request these variables from the coach
@objc(Pitcher)
public class Pitcher: NSManagedObject, Identifiable {
@nonobjc public class func fetchRequest() -> NSFetchRequest<Pitcher> {
return NSFetchRequest<Pitcher>(entityName: "Pitcher")
}
@NSManaged public var hitsAgainst: Int32
@NSManaged public var innings: Double
@NSManaged public var earnedRuns: Int32
@NSManaged public var bb: Int32
@NSManaged public var strikeouts: Int32
@NSManaged public var pitchCount: Int32
@NSManaged public var pitcherName: String
@NSManaged public var atBatsPitcher: Int32
@NSManaged public var hbpPitcher: Int32
@NSManaged public var wPitcher: Int32
@NSManaged public var lPitcher: Int32
var ERA: Double {
get {
guard innings != 0 else {
return 0
}
return (Double(earnedRuns) / Double(innings)) * 9
}
set { }
}
var BB9: Double {
get {
guard innings != 0 else {
return 0
}
return ((Double(bb) * 9.0) / Double(innings))
}
set { }
}
var WHIP: Double {
get {
guard innings != 0 else {
return 0
}
return ((Double(bb) + Double(hitsAgainst)) / Double(innings))
}
set { }
}
var BAA: Double {
get {
guard atBatsPitcher != 0 else {
return 0
}
return (Double(hitsAgainst)) / (Double(atBatsPitcher) + Double(bb) + Double(hbpPitcher))
}
set { }
}
}