Skip to content

Commit

Permalink
fixed companion
Browse files Browse the repository at this point in the history
  • Loading branch information
sadeelmu committed May 28, 2024
1 parent ae661c7 commit 60d1f5f
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 68 deletions.
155 changes: 89 additions & 66 deletions Asthmaguard/Presentation/View/Companion/CompanionDashboardView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,80 +12,108 @@ import CoreLocation

@available(iOS 17.0, *)
struct CompanionAsthmaThreatChart: View {
@State private var totalWeightedSeverity: Double = 0.0
@State private var biosignalRisk: Double = 0.0
@State private var environmentalRisk: Double = 0.0
@State private var showVeryHighThreatAlert: Bool = false

@State var asthmathreat: [AsthmaThreat] = [
.init(title: "Enviromental", risks: 0.15),
.init(title: "BioSignal", risks: 0.35),
.init(title: "Normal", risks: 0.5)
.init(title: "Biosignals", risks: 0.2),
.init(title: "Environmental", risks: 0.25),
.init(title: "Normal", risks: 0.55)
]


@State private var showDetailsView = false


private let asthmaThreatCalculatorUseCase = AsthmaThreatCalculatorUseCase()
private let locationManager = LocationManager.shared

func updateAsthmaThreat() {
asthmaThreatCalculatorUseCase.fetchDataAndCalculateAsthmaSeverity()
DispatchQueue.main.asyncAfter(deadline: .now() + 0.05) {
self.biosignalRisk = 0.2
self.environmentalRisk = 0.25
self.totalWeightedSeverity = 0.45

if totalWeightedSeverity > 0.75 {
showVeryHighThreatAlert = true
}
}
}

var body: some View {

VStack(spacing:10){
Text("Companion Dashboard")
.font(Font.custom("Poppins-Bold", size: 18))
.padding(.all)

let chartColors: [Color] = [
.pink.opacity(0.7), .pink, .blue
]

let asthmaThreatRisks:Double = 0.4

HStack {
Image("sadeel")
.resizable()
.aspectRatio(contentMode: .fill)
.frame(width: 40, height: 40)
.clipShape(Circle())
.padding(.leading, 10)
VStack(alignment: .leading) {
Text("Sadeel Muwahed")
.font(.title3)
NavigationView {
ScrollView(showsIndicators: false) {
VStack(spacing: 5) {
Text("Companion Dashboard")
.font(Font.custom("Poppins-Bold", size: 18))
.padding(.all)

let chartColors: [Color] = [
.pink.opacity(0.5), .pink, .blue
]

Text("Asthma Threat: \(totalWeightedSeverity * 100, specifier: "%.1f")%")
.font(Font.custom("Poppins-Bold", size: 26))

Chart(asthmathreat) { asthmathreat in
SectorMark(
angle: .value(
Text(asthmathreat.title),
asthmathreat.risks
),
innerRadius: .ratio(0.6),
angularInset: 0.8
)
.cornerRadius(4)
.foregroundStyle(by: .value("Threats", asthmathreat.title))
}.frame(width: 300, height: 250)
.chartForegroundStyleScale(domain: .automatic, range: chartColors)

Spacer()
VStack(spacing: 10) {
NavigationLink(destination: HistoricalDataView(bioSignal: "Respiratory Rate")) {
CustomBioData(bioSignal: "🫁 Respiratory Rate", time: "11:55 AM", data: "19 breaths/min")
}
NavigationLink(destination: HistoricalDataView(bioSignal: "Heart Rate")) {
CustomBioData(bioSignal: "🫀 Heart Rate", time: "12:01 PM", data: "96 BPM")
}
NavigationLink(destination: HistoricalDataView(bioSignal: "Blood Oxygen")) {
CustomBioData(bioSignal: "🩸 Blood Oxygen", time: "12:03 PM", data: "98.5%")
}
}
Spacer()
}
.onAppear {
// Request location access
locationManager.requestLocationAccess()
locationManager.startUpdatingLocation()

// Request HealthKit access
BioSignalData.requestHealthDataAccessIfNeeded { success in
if success {
updateAsthmaThreat()
} else {
print("HealthKit authorization failed")
}
}
}
.alert(isPresented: $showVeryHighThreatAlert) {
Alert(
title: Text("Very High Asthma threat detected!"),
message: Text("Please contact the asthma patient immediately."),
dismissButton: .default(Text("Dismiss"))
)
}
}

Text("Asthma Threat: \(asthmaThreatRisks * 100, specifier: "%.1f")%")
.font(Font.custom("Poppins-Regular", size: 26))

Chart(asthmathreat) { asthmathreat in
SectorMark(
angle: .value(
Text(asthmathreat.title),
asthmathreat.risks
),
innerRadius: .ratio(0.6),
angularInset: 0.8
)
.cornerRadius(4)
.foregroundStyle(by: .value("Threats", asthmathreat.title))
}.frame(width: 300, height: 250)
.chartForegroundStyleScale(domain: .automatic, range: chartColors)

Spacer()
VStack(spacing:10){
CustomBioData(bioSignal: "Respiratory Rate", time: "11:55 AM", data: "19 breathes/min")

CustomBioData(bioSignal: "Heart Rate", time: "12:01 PM", data: "96 BPM")

CustomBioData(bioSignal: "Blood Oxygen", time: "12:03 PM", data: "98.5%")
}
Spacer()
}
}
}


@available(iOS 17.0, *)
struct CompanionDashboardView: View {

@State private var selection = 0

var body: some View {

TabView(selection:$selection) {
TabView(selection: $selection) {
NavigationView {
CompanionAsthmaThreatChart()
.navigationTitle("")
Expand All @@ -100,20 +128,15 @@ struct CompanionDashboardView: View {
Label("Analytics", systemImage: "chart.xyaxis.line")
}
.tag(1)


CompanionSettingsScreen().tabItem { Label("Settings", systemImage: "gearshape") }.tag(2)
}
}
}


@available(iOS 17.0, *)
struct CompanionAsthmaThreatChart_Previews: PreviewProvider {
struct CompanionDashboardView_Previews: PreviewProvider {
static var previews: some View {
CompanionDashboardView()
}
}



2 changes: 1 addition & 1 deletion Asthmaguard/Presentation/View/HistoricalDataView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ struct HistoricalDataView: View {

var body: some View {
VStack {
Text("🫀 \(bioSignal) Historical Data")
Text("\(bioSignal) Historical Data")
.font(Font.custom("Poppins-Bold", size: 18))
.padding()

Expand Down
2 changes: 1 addition & 1 deletion Asthmaguard/Presentation/View/LoginScreen.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ struct LoginScreen: View {
var body: some View {
if loginViewModel.isLogin {
if loginViewModel.shouldNavigateToCompanionDashboard {
CompanionDashboardView()
CompanionLoginScreen()
} else {
DashboardView()
}
Expand Down

0 comments on commit 60d1f5f

Please sign in to comment.