-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCalculatorModel.swift
66 lines (52 loc) · 1.58 KB
/
CalculatorModel.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
//
// CalculatorModel.swift
// Snake Oil Calculator
//
// Created by Samuel Hazlehurst on 2/5/15.
// Copyright (c) 2015 Terranian Farm. All rights reserved.
//
import Foundation
class CalculatorModel {
// google answer for "acre to sq ft" divided by 1,000
private struct Constants {
static let ACRE_TO_K_SQFT : Double = 43.560
static let MILLION : Double = 1000000
static let RequirementLabel = "Pound Nutrient recommended:"
}
enum Area : CustomStringConvertible {
case K_SQFT
case ACRE
var description : String {
get {
switch self {
case .K_SQFT:
return "K_SQFT"
case .ACRE:
return "ACRE"
}
}
}
}
var ppm = true
var inputType = Area.K_SQFT
var outputType = Area.K_SQFT
var concentration : Double = 0
var requirement : Double = 0
func getConcentration() -> Double {
var actualConcentration = concentration
if ppm {
actualConcentration = concentration / Constants.MILLION
}
else {
actualConcentration = concentration / 100
}
if (outputType == inputType)
{
return requirement / actualConcentration
}
if (outputType == Area.K_SQFT) {
return requirement / actualConcentration / Constants.ACRE_TO_K_SQFT
}
return requirement / actualConcentration * Constants.ACRE_TO_K_SQFT
}
}