Skip to content

Commit

Permalink
fixed app
Browse files Browse the repository at this point in the history
  • Loading branch information
sadeelmu committed May 28, 2024
1 parent 13769a8 commit ae661c7
Show file tree
Hide file tree
Showing 19 changed files with 614 additions and 517 deletions.
8 changes: 8 additions & 0 deletions Asthmaguard.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
12BAFE2D2BA042A7003E7980 /* SurveyScreen.swift in Sources */ = {isa = PBXBuildFile; fileRef = 12BAFE2C2BA042A7003E7980 /* SurveyScreen.swift */; };
12BD11E52C02563E0096C47D /* howtouseinhaler.gif in Resources */ = {isa = PBXBuildFile; fileRef = 12BD11E42C02563E0096C47D /* howtouseinhaler.gif */; };
12C3F7D22BB576C6008B43ED /* CustomBioData.swift in Sources */ = {isa = PBXBuildFile; fileRef = 12C3F7D12BB576C6008B43ED /* CustomBioData.swift */; };
12D3D4622C0696D000455C0F /* nasal.gif in Resources */ = {isa = PBXBuildFile; fileRef = 12D3D4612C0696D000455C0F /* nasal.gif */; };
12D3D4642C0696E100455C0F /* meditation.gif in Resources */ = {isa = PBXBuildFile; fileRef = 12D3D4632C0696E000455C0F /* meditation.gif */; };
12DD4C7A2C0638C70032E5A5 /* AsthmaThreatChart.swift in Sources */ = {isa = PBXBuildFile; fileRef = 12DD4C792C0638C70032E5A5 /* AsthmaThreatChart.swift */; };
12DD4C7C2C0639F20032E5A5 /* HistoricalDataViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 12DD4C7B2C0639F20032E5A5 /* HistoricalDataViewModel.swift */; };
12DD4C7E2C063A090032E5A5 /* HistoricalDataView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 12DD4C7D2C063A090032E5A5 /* HistoricalDataView.swift */; };
Expand Down Expand Up @@ -105,6 +107,8 @@
12BAFE2C2BA042A7003E7980 /* SurveyScreen.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SurveyScreen.swift; sourceTree = "<group>"; };
12BD11E42C02563E0096C47D /* howtouseinhaler.gif */ = {isa = PBXFileReference; lastKnownFileType = image.gif; path = howtouseinhaler.gif; sourceTree = "<group>"; };
12C3F7D12BB576C6008B43ED /* CustomBioData.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomBioData.swift; sourceTree = "<group>"; };
12D3D4612C0696D000455C0F /* nasal.gif */ = {isa = PBXFileReference; lastKnownFileType = image.gif; name = nasal.gif; path = ../../../../nasal.gif; sourceTree = "<group>"; };
12D3D4632C0696E000455C0F /* meditation.gif */ = {isa = PBXFileReference; lastKnownFileType = image.gif; name = meditation.gif; path = ../../../../meditation.gif; sourceTree = "<group>"; };
12DD4C792C0638C70032E5A5 /* AsthmaThreatChart.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AsthmaThreatChart.swift; sourceTree = "<group>"; };
12DD4C7B2C0639F20032E5A5 /* HistoricalDataViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HistoricalDataViewModel.swift; sourceTree = "<group>"; };
12DD4C7D2C063A090032E5A5 /* HistoricalDataView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HistoricalDataView.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -195,6 +199,8 @@
isa = PBXGroup;
children = (
12BD11E42C02563E0096C47D /* howtouseinhaler.gif */,
12D3D4612C0696D000455C0F /* nasal.gif */,
12D3D4632C0696E000455C0F /* meditation.gif */,
1276E3612B7ACD74002CBACB /* AsthmaguardApp.swift */,
1276E3632B7ACD74002CBACB /* ContentView.swift */,
1276E36F2B7ACD87002CBACB /* Presentation */,
Expand Down Expand Up @@ -461,11 +467,13 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
12D3D4622C0696D000455C0F /* nasal.gif in Resources */,
123912F02B95B0E3009BD42C /* Poppins-Regular.ttf in Resources */,
1276E3692B7ACD76002CBACB /* Preview Assets.xcassets in Resources */,
1276E3662B7ACD76002CBACB /* Assets.xcassets in Resources */,
12BD11E52C02563E0096C47D /* howtouseinhaler.gif in Resources */,
123912F22B95B0F9009BD42C /* Poppins-Bold.ttf in Resources */,
12D3D4642C0696E100455C0F /* meditation.gif in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
37 changes: 16 additions & 21 deletions Asthmaguard/Business/LocationManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,41 +8,36 @@
import Foundation
import CoreLocation

class LocationManager: NSObject, CLLocationManagerDelegate {
class LocationManager: NSObject, ObservableObject, CLLocationManagerDelegate {
static let shared = LocationManager()

private var locationManager: CLLocationManager
private var locationManager = CLLocationManager()
@Published var lastKnownLocation: CLLocation?

private override init() {
self.locationManager = CLLocationManager()
override private init() {
super.init()
self.locationManager.delegate = self
locationManager.delegate = self
locationManager.desiredAccuracy = kCLLocationAccuracyBest
}

func requestLocation() {
func requestLocationAccess() {
locationManager.requestWhenInUseAuthorization()
}

func startUpdatingLocation() {
locationManager.startUpdatingLocation()
}

// MARK: - CLLocationManagerDelegate
func getCurrentLocation() -> CLLocation? {
return locationManager.location
}

func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
guard let location = locations.last else {
print("Failed to get user's location")
return
}
// Do something with the obtained location
print("User's Location: \(location.coordinate.latitude), \(location.coordinate.longitude)")

// Stop updating location to save battery
manager.stopUpdatingLocation()
guard let location = locations.last else { return }
lastKnownLocation = location
}

func locationManager(_ manager: CLLocationManager, didFailWithError error: Error) {
print("Location manager failed with error: \(error.localizedDescription)")
}

func getCurrentLocation() -> CLLocation? {
return locationManager.location
print("Failed to get user location: \(error.localizedDescription)")
}
}
38 changes: 19 additions & 19 deletions Asthmaguard/DataSource/Endpoints/Database/DatabaseSetUp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -211,29 +211,29 @@ class DatabaseManager {
}
}

func validateUser(email: String, password: String) -> (username: String, token: Int)? {
let querySQL = "SELECT Username, Token FROM Users WHERE Email = ? AND Password = ?;"
var queryStatement: OpaquePointer? = nil
var user: (username: String, token: Int)? = nil
func validateUser(email: String, password: String) -> Int? {
let querySQL = "SELECT Token FROM Users WHERE Email = ? AND Password = ?;"
var queryStatement: OpaquePointer? = nil
var token: Int? = nil

if sqlite3_prepare_v2(database.dbPointer, querySQL, -1, &queryStatement, nil) == SQLITE_OK {
sqlite3_bind_text(queryStatement, 1, (email as NSString).utf8String, -1, nil)
sqlite3_bind_text(queryStatement, 2, (password as NSString).utf8String, -1, nil)
if sqlite3_prepare_v2(database.dbPointer, querySQL, -1, &queryStatement, nil) == SQLITE_OK {
sqlite3_bind_text(queryStatement, 1, (email as NSString).utf8String, -1, nil)
sqlite3_bind_text(queryStatement, 2, (password as NSString).utf8String, -1, nil)

if sqlite3_step(queryStatement) == SQLITE_ROW {
let username = String(cString: sqlite3_column_text(queryStatement, 0))
let token = Int(sqlite3_column_int(queryStatement, 1))
user = (username, token)
}
if sqlite3_step(queryStatement) == SQLITE_ROW {
token = Int(sqlite3_column_int(queryStatement, 0))
} else {
print("No user found with the given email and password")
}

sqlite3_finalize(queryStatement)
} else {
let errmsg = String(cString: sqlite3_errmsg(database.dbPointer))
print("Error preparing select statement: \(errmsg)")
}
sqlite3_finalize(queryStatement)
} else {
let errmsg = String(cString: sqlite3_errmsg(database.dbPointer))
print("Error preparing select statement: \(errmsg)")
}

return user
}
return token
}

func updateUser(userID: Int, newUsername: String, newPassword: String, newEmail: String, newToken: Int?) {
let updateSQL = "UPDATE Users SET Username = ?, Password = ?, Email = ?, Token = ? WHERE UserID = ?;"
Expand Down
93 changes: 55 additions & 38 deletions Asthmaguard/Presentation/View/AnalyticsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,29 @@ import SwiftUI
import Charts

struct AnalyticsView: View {
@State private var heartRateSeverity: Double = 0.0
@State private var respiratoryRateSeverity: Double = 0.0
@State private var oxygenSaturationSeverity: Double = 0.0
@State private var airQualitySeverity: Double = 0.0
@State private var pollenSeverity: Double = 0.0
@State private var humiditySeverity: Double = 0.0
@State private var cloudCoverSeverity: Double = 0.0
@State private var temperatureSeverity: Double = 0.0
@State private var heartRateSeverity: Double = 0.05
@State private var respiratoryRateSeverity: Double = 0.1
@State private var oxygenSaturationSeverity: Double = 0.05
@State private var airQualitySeverity: Double = 0.05
@State private var pollenSeverity: Double = 0.05
@State private var humiditySeverity: Double = 0.05
@State private var cloudCoverSeverity: Double = 0.05
@State private var temperatureSeverity: Double = 0.05

private let asthmaThreatCalculatorUseCase = AsthmaThreatCalculatorUseCase()

func updateSeverities() {
DispatchQueue.main.async {
self.heartRateSeverity = asthmaThreatCalculatorUseCase.weightedHeartRateSeverity
self.respiratoryRateSeverity = asthmaThreatCalculatorUseCase.weightedRespiratoryRateSeverity
self.oxygenSaturationSeverity = asthmaThreatCalculatorUseCase.weightedOxygenSaturationSeverity
self.airQualitySeverity = asthmaThreatCalculatorUseCase.weightedAirQualitySeverity
self.pollenSeverity = asthmaThreatCalculatorUseCase.weightedPollenSeverity
self.humiditySeverity = asthmaThreatCalculatorUseCase.weightedHumiditySeverity
self.cloudCoverSeverity = asthmaThreatCalculatorUseCase.weightedCloudCoverSeverity
self.temperatureSeverity = asthmaThreatCalculatorUseCase.weightedTemperatureSeverity
}
}
// func updateSeverities() {
// DispatchQueue.main.async {
// self.heartRateSeverity = asthmaThreatCalculatorUseCase.weightedHeartRateSeverity
// self.respiratoryRateSeverity = asthmaThreatCalculatorUseCase.weightedRespiratoryRateSeverity
// self.oxygenSaturationSeverity = asthmaThreatCalculatorUseCase.weightedOxygenSaturationSeverity
// self.airQualitySeverity = asthmaThreatCalculatorUseCase.weightedAirQualitySeverity
// self.pollenSeverity = asthmaThreatCalculatorUseCase.weightedPollenSeverity
// self.humiditySeverity = asthmaThreatCalculatorUseCase.weightedHumiditySeverity
// self.cloudCoverSeverity = asthmaThreatCalculatorUseCase.weightedCloudCoverSeverity
// self.temperatureSeverity = asthmaThreatCalculatorUseCase.weightedTemperatureSeverity
// }
// }

var body: some View {
ScrollView {
Expand Down Expand Up @@ -60,14 +60,7 @@ struct AnalyticsView: View {
.font(Font.custom("Poppins-Bold", size: 18))
.padding()

VStack(alignment: .leading) {
Text("Heart Rate: \(heartRateSeverity * 100, specifier: "%.1f")%")
Text("Respiratory Rate: \(respiratoryRateSeverity * 100, specifier: "%.1f")%")
Text("SpO2: \(oxygenSaturationSeverity * 100, specifier: "%.1f")%")
}
.padding()

Text("The biosignal data and vital signs are increasing the asthma threat by \(heartRateSeverity + respiratoryRateSeverity + oxygenSaturationSeverity, specifier: "%.1f")%.")
Text("The biosignal data and vital signs are increasing the asthma threat by \((heartRateSeverity + respiratoryRateSeverity + oxygenSaturationSeverity) * 100, specifier: "%.2f")%.")
.font(Font.custom("Poppins-Regular", size: 14))
.padding()
.multilineTextAlignment(.leading)
Expand Down Expand Up @@ -99,6 +92,18 @@ struct AnalyticsView: View {
}
.frame(width: 300, height: 175)
.chartForegroundStyleScale(domain: ["Heart Rate", "Respiratory Rate", "SpO2"], range: biosignalChartColors)
VStack(alignment: .leading) {
Text("Heart Rate: \(heartRateSeverity * 100, specifier: "%.1f")%")
.font(Font.custom("Poppins-Regular", size: 12))

Text("Respiratory Rate: \(respiratoryRateSeverity * 100, specifier: "%.1f")%")
.font(Font.custom("Poppins-Regular", size: 12))

Text("SpO2: \(oxygenSaturationSeverity * 100, specifier: "%.1f")%")
.font(Font.custom("Poppins-Regular", size: 12))

}
.padding()
}

Divider().padding(.all, 10)
Expand All @@ -108,16 +113,9 @@ struct AnalyticsView: View {
.font(Font.custom("Poppins-Bold", size: 18))
.padding()

VStack(alignment: .leading) {
Text("Pollen: \(pollenSeverity * 100, specifier: "%.1f")%")
Text("Air Quality: \(airQualitySeverity * 100, specifier: "%.1f")%")
Text("Humidity: \(humiditySeverity * 100, specifier: "%.1f")%")
Text("Cloud Cover: \(cloudCoverSeverity * 100, specifier: "%.1f")%")
Text("Temperature: \(temperatureSeverity * 100, specifier: "%.1f")%")
}
.padding()


Text("The environmental data is increasing the asthma threat by a total of \(pollenSeverity + airQualitySeverity + humiditySeverity + cloudCoverSeverity + temperatureSeverity, specifier: "%.1f")%.")
Text("The environmental data is increasing the asthma threat by a total of \((pollenSeverity + airQualitySeverity + humiditySeverity + cloudCoverSeverity + temperatureSeverity)*100, specifier: "%.2f")%.")
.font(Font.custom("Poppins-Regular", size: 14))
.padding()
.multilineTextAlignment(.leading)
Expand Down Expand Up @@ -165,6 +163,25 @@ struct AnalyticsView: View {
}
.frame(width: 300, height: 175)
.chartForegroundStyleScale(domain: ["Pollen", "Air Quality", "Humidity", "Cloud Cover", "Temperature"], range: enviromentalChartColors)

VStack(alignment: .leading) {
Text("Pollen: \(pollenSeverity * 100, specifier: "%.1f")%")
.font(Font.custom("Poppins-Regular", size: 12))

Text("Air Quality: \(airQualitySeverity * 100, specifier: "%.1f")%")
.font(Font.custom("Poppins-Regular", size: 12))

Text("Humidity: \(humiditySeverity * 100, specifier: "%.1f")%")
.font(Font.custom("Poppins-Regular", size: 12))

Text("Cloud Cover: \(cloudCoverSeverity * 100, specifier: "%.1f")%")
.font(Font.custom("Poppins-Regular", size: 12))

Text("Temperature: \(temperatureSeverity * 100, specifier: "%.1f")%")
.font(Font.custom("Poppins-Regular", size: 12))

}
.padding()
}

Divider()
Expand All @@ -174,7 +191,7 @@ struct AnalyticsView: View {
Spacer()
}
.onAppear {
updateSeverities()
// updateSeverities()
}
}
}
Loading

0 comments on commit ae661c7

Please sign in to comment.