1 |
efrain |
1 |
//
|
|
|
2 |
// ProgressViewModel.swift
|
|
|
3 |
// twogetskills
|
|
|
4 |
//
|
|
|
5 |
// Created by Efrain Yanez Recanatini on 5/6/22.
|
|
|
6 |
//
|
|
|
7 |
|
|
|
8 |
import Foundation
|
|
|
9 |
|
|
|
10 |
class ProgressViewModel: ObservableObject {
|
|
|
11 |
|
|
|
12 |
|
|
|
13 |
|
|
|
14 |
@Published var capsuleTotal : Int = 0
|
|
|
15 |
@Published var capsuleTotalStarted : Int = 0
|
|
|
16 |
@Published var capsuleTotalForStart : Int = 0
|
|
|
17 |
@Published var capsuleTotalCompleted : Int = 0
|
|
|
18 |
@Published var capsuleTotalIncompleted : Int = 0
|
|
|
19 |
@Published var capsuleTotalWithReturning : Int = 0
|
|
|
20 |
@Published var capsuleTotalWithoutReturning : Int = 0
|
|
|
21 |
|
|
|
22 |
@Published var percentajeCapsuleComplete: Double = 0
|
|
|
23 |
@Published var percentajeCapsuleIncomplete: Double = 0
|
|
|
24 |
|
|
|
25 |
|
|
|
26 |
public func load()
|
|
|
27 |
{
|
|
|
28 |
let preference = Preference.sharedInstance
|
|
|
29 |
|
|
|
30 |
let capsuleDao = CapsuleDao()
|
|
|
31 |
capsuleTotal = capsuleDao.getCountAll()
|
|
|
32 |
|
|
|
33 |
let progressDao = ProgressDao()
|
|
|
34 |
|
|
|
35 |
capsuleTotalCompleted = progressDao.getCountCapsulesCompletedByUserUuid(userUuid: preference.userUuid)
|
|
|
36 |
|
|
|
37 |
capsuleTotalIncompleted = progressDao.getCountCapsulesIncompletedByUserUuid(userUuid: preference.userUuid)
|
|
|
38 |
|
|
|
39 |
capsuleTotalForStart = capsuleTotal - (capsuleTotalCompleted + capsuleTotalIncompleted)
|
|
|
40 |
capsuleTotalStarted = capsuleTotalCompleted + capsuleTotalIncompleted
|
|
|
41 |
|
|
|
42 |
capsuleTotalWithReturning = progressDao.getCountCapsulesCompletedWithReturningByUserUuid(userUuid: preference.userUuid)
|
|
|
43 |
|
|
|
44 |
capsuleTotalWithoutReturning = capsuleTotal - capsuleTotalWithReturning
|
|
|
45 |
|
|
|
46 |
//progressDao.getCountCapsulesCompletedWithoutReturningByUserUuid(userUuid: preference.userUuid)
|
|
|
47 |
|
|
|
48 |
|
|
|
49 |
if capsuleTotal > 0 {
|
|
|
50 |
|
|
|
51 |
percentajeCapsuleComplete = (Double(capsuleTotalCompleted) * 100) / Double(capsuleTotal)
|
|
|
52 |
percentajeCapsuleIncomplete = 100 - percentajeCapsuleComplete
|
|
|
53 |
}
|
|
|
54 |
|
|
|
55 |
|
|
|
56 |
}
|
|
|
57 |
}
|