-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscoreController.swift
183 lines (138 loc) · 7.74 KB
/
scoreController.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
import UIKit
class scoreController: UIViewController {
@IBOutlet weak var progressView: UIView!
@IBOutlet weak var stackSV: UIStackView!
@IBOutlet weak var stackC: UIStackView!
@IBOutlet weak var stackS: UIStackView!
@IBOutlet weak var stackA: UIStackView!
@IBOutlet weak var stackB: UIStackView!
@IBOutlet weak var bLbl: UILabel!
@IBOutlet weak var aLbl: UILabel!
@IBOutlet weak var sLbl: UILabel!
@IBOutlet weak var cLbl: UILabel!
@IBOutlet weak var sgLbl: UILabel!
@IBOutlet weak var conteoTLbl: UILabel!
@IBOutlet weak var conteoCLbl: UILabel!
var conteo = [0,0]
let userViewModel = UserViewModel()
var progress: CGFloat = 0.5 // Ajusta este valor según tus necesidades (de 0 a 1)
var porcentage = 0
override func viewDidLoad() {
super.viewDidLoad()
if Reachability.isConnectedToNetwork(){
//code
configureStackView(stackSV, color: UIColor(red: 0.729, green: 0.890, blue: 0.820, alpha: 1.0)) // Verde pastel claro
configureStackView(stackC, color: UIColor(red: 1.000, green: 0.796, blue: 0.796, alpha: 1.0)) // Rojo pastel claro
configureStackView(stackS, color: UIColor(red: 0.788, green: 0.847, blue: 1.000, alpha: 1.0)) // Azul pastel claro
configureStackView(stackA, color: UIColor(red: 1.000, green: 1.000, blue: 0.710, alpha: 1.0)) // Amarillo pastel claro
configureStackView(stackB, color: UIColor(red: 0.788, green: 0.710, blue: 1.000, alpha: 1.0)) // Morado pastel claro
userViewModel.fetchCT {
self.userViewModel.fetchCat(collection: "rqBonus"){
self.getPorcentage(puntajeCollection: self.userViewModel.puntajeCollection)
self.bLbl.text = String(self.porcentage) + "%"
self.userViewModel.fetchCat(collection: "rqAnatomia"){
self.getPorcentage(puntajeCollection: self.userViewModel.puntajeCollection)
self.aLbl.text = String(self.porcentage) + "%"
self.userViewModel.fetchCat(collection: "rqSintomas"){
self.getPorcentage(puntajeCollection: self.userViewModel.puntajeCollection)
self.sLbl.text = String(self.porcentage) + "%"
self.userViewModel.fetchCat(collection: "rqCuracion"){
self.getPorcentage(puntajeCollection: self.userViewModel.puntajeCollection)
self.cLbl.text = String(self.porcentage) + "%"
self.userViewModel.fetchCat(collection: "rqSignosVitales"){
self.getPorcentage(puntajeCollection: self.userViewModel.puntajeCollection)
self.sgLbl.text = String(self.porcentage) + "%"
}
}
}
}
}
}
userViewModel.fetchCT {
let conteoT = self.userViewModel.conteoT
let conteoC = self.userViewModel.conteoC
self.conteoTLbl.text = String(conteoT)
self.conteoCLbl.text = String(conteoC)
print(conteoC, conteoT)
self.progress = CGFloat(CGFloat(conteoC)/CGFloat(conteoT))
print(self.progress)
self.drawProgressCircle()
self.addPercentageLabel()
self.addSubtitleLabel()
}
print("Conexión válida")
} else {
print("Conexión Inválida")
let alertController = UIAlertController(title: "Conexión Perdida", message: "Reconectate y vuelve a intentar", preferredStyle: .alert)
// Agregar acciones (botones) a la alerta
let okAction = UIAlertAction(title: "Ok", style: .default) { _ in
self.viewDidLoad()
}
alertController.addAction(okAction)
// Mostrar la alerta
DispatchQueue.main.async {
self.present(alertController, animated: true, completion: nil)
}
}
}
func getPorcentage(puntajeCollection: Int){
let conteoT = self.userViewModel.conteoT
let conteoC = self.userViewModel.conteoC
self.conteo[0] = conteoT
self.conteo[1] = conteoC
let total = self.conteo[1]
if total == 0{
print("total igual a 0, porcentaje finalizado")
} else {
self.porcentage = (puntajeCollection * 100)/total
}
}
func configureStackView(_ stackView: UIStackView, color: UIColor) {
// Asignar el color al fondo
stackView.backgroundColor = color
// Redondear los bordes
stackView.layer.cornerRadius = 10.0 // Ajusta según sea necesario
stackView.layer.masksToBounds = true
}
func drawProgressCircle() {
// Asegúrate de que bounds.midX y bounds.midY correspondan al centro real del progressView
let center = CGPoint(x: progressView.bounds.width / 2.0 - 5.5, y: progressView.bounds.height / 2.0)
let radius = (min(progressView.bounds.width, progressView.bounds.height) / 2.0)
let startAngle = -CGFloat.pi / 2
let endAngle = startAngle + 2 * CGFloat.pi * progress
// Crear la capa del círculo
let circleLayer = CAShapeLayer()
let circlePath = UIBezierPath(arcCenter: center, radius: radius, startAngle: startAngle, endAngle: endAngle, clockwise: true)
circleLayer.path = circlePath.cgPath
circleLayer.strokeColor = UIColor(red: 0.294, green: 0.580, blue: 0.376, alpha: 1.0).cgColor
circleLayer.lineWidth = 10.0 // Ancho de la línea del círculo
circleLayer.fillColor = UIColor.clear.cgColor
// Agregar la capa al UIView
progressView.layer.borderWidth = 0.0
progressView.layer.addSublayer(circleLayer)
}
func addPercentageLabel() {
// Crear etiqueta
let label = UILabel()
label.text = "\(Int(progress * 100))%" // Convierte el valor de progreso a porcentaje
label.textColor = UIColor(red: 0.294, green: 0.580, blue: 0.376, alpha: 1.0)
label.font = UIFont.systemFont(ofSize: 20.0, weight: .bold)
label.sizeToFit()
// Posicionar la etiqueta en el centro de progressView
label.center = CGPoint(x: progressView.bounds.width / 2.0, y: progressView.bounds.height / 2.0)
// Agregar la etiqueta a progressView
progressView.addSubview(label)
}
func addSubtitleLabel() {
// Crear subtítulo
let subtitleLabel = UILabel()
subtitleLabel.text = "Efectividad"
subtitleLabel.textColor = UIColor.lightGray
subtitleLabel.font = UIFont.systemFont(ofSize: 14.0)
subtitleLabel.sizeToFit()
// Posicionar el subtítulo debajo del label de porcentaje
subtitleLabel.center = CGPoint(x: progressView.bounds.width / 2.0, y: progressView.bounds.height / 2.0 + 20.0) // Ajusta el valor de 20 según tus necesidades
// Agregar el subtítulo a progressView
progressView.addSubview(subtitleLabel)
}
}