Proyectos de Subversion Iphone Microlearning - Inconcert

Rev

Rev 17 | | Comparar con el anterior | Ultima modificación | Ver Log |

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