| 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 |     @Published var capsuleTotal : Int = 0
 | 
        
           |  |  | 13 |     @Published var capsuleTotalStarted : Int = 0
 | 
        
           |  |  | 14 |     @Published var capsuleTotalForStart : Int = 0
 | 
        
           |  |  | 15 |     @Published var capsuleTotalCompleted : Int = 0
 | 
        
           |  |  | 16 |     @Published var capsuleTotalIncompleted : Int = 0
 | 
        
           |  |  | 17 |     @Published var capsuleTotalWithReturning : Int = 0
 | 
        
           |  |  | 18 |     @Published var capsuleTotalWithoutReturning : Int = 0
 | 
        
           |  |  | 19 |   | 
        
           |  |  | 20 |     @Published var percentajeCapsuleComplete: Double = 0
 | 
        
           |  |  | 21 |     @Published var percentajeCapsuleIncomplete: Double = 0
 | 
        
           |  |  | 22 |   | 
        
           |  |  | 23 |     private var appData = AppData.sharedInstance
 | 
        
           |  |  | 24 |   | 
        
           |  |  | 25 | public func load()
 | 
        
           |  |  | 26 |     {
 | 
        
           | 17 | efrain | 27 |         let capsuleDao = CapsuleDao()
 | 
        
           | 1 | efrain | 28 |         capsuleTotal = capsuleDao.getCountAll()
 | 
        
           |  |  | 29 |   | 
        
           | 17 | efrain | 30 |         let progressDao = ProgressDao()
 | 
        
           | 1 | efrain | 31 |   | 
        
           |  |  | 32 |         capsuleTotalCompleted = progressDao.getCountCapsulesCompletedByUserUuid(userUuid: appData.userUuid)
 | 
        
           |  |  | 33 |   | 
        
           |  |  | 34 |         capsuleTotalIncompleted = progressDao.getCountCapsulesIncompletedByUserUuid(userUuid: appData.userUuid)
 | 
        
           |  |  | 35 |   | 
        
           |  |  | 36 |         capsuleTotalForStart = capsuleTotal - (capsuleTotalCompleted + capsuleTotalIncompleted)
 | 
        
           |  |  | 37 |         capsuleTotalStarted = capsuleTotalCompleted + capsuleTotalIncompleted
 | 
        
           |  |  | 38 |   | 
        
           |  |  | 39 |         capsuleTotalWithReturning = progressDao.getCountCapsulesCompletedWithReturningByUserUuid(userUuid: appData.userUuid)
 | 
        
           |  |  | 40 |   | 
        
           |  |  | 41 |         capsuleTotalWithoutReturning = capsuleTotal - capsuleTotalWithReturning
 | 
        
           |  |  | 42 |   | 
        
           |  |  | 43 |             //progressDao.getCountCapsulesCompletedWithoutReturningByUserUuid(userUuid: appData.userUuid)
 | 
        
           |  |  | 44 |   | 
        
           |  |  | 45 |   | 
        
           |  |  | 46 |         if capsuleTotal > 0 {
 | 
        
           |  |  | 47 |   | 
        
           |  |  | 48 |             percentajeCapsuleComplete = (Double(capsuleTotalCompleted) * 100) / Double(capsuleTotal)
 | 
        
           |  |  | 49 |             percentajeCapsuleIncomplete = 100 - percentajeCapsuleComplete
 | 
        
           |  |  | 50 |         }
 | 
        
           |  |  | 51 |   | 
        
           |  |  | 52 |   | 
        
           |  |  | 53 |     }
 | 
        
           |  |  | 54 | }
 |