Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
1
1weather
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Dmitriy Stepanets
1weather
Commits
e007d965
Commit
e007d965
authored
Apr 08, 2021
by
Demid Merzlyakov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Air Quality: Sort of correct limits for pollutants.
parent
98860eea
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
121 additions
and
23 deletions
+121
-23
1Weather/Model/ModelObjects/Health/Health.swift
+121
-23
No files found.
1Weather/Model/ModelObjects/Health/Health.swift
View file @
e007d965
...
...
@@ -23,8 +23,13 @@ public struct AirQuality: Equatable, Hashable {
return
progressValue
}
public
var
status
:
HealthStatus
{
get
{
HealthStatus
(
value
:
index
)
switch
index
{
case
0
...
50
:
return
.
good
case
51
...
100
:
return
.
moderate
case
101
...
150
:
return
.
unhealthyForSensitiveGroups
case
151
...
200
:
return
.
unhealthy
case
201
...
300
:
return
.
veryUnhealthy
default
:
return
.
hazardous
}
}
}
...
...
@@ -37,23 +42,6 @@ public enum HealthStatus: String {
case
veryUnhealthy
=
"health.airquality.status.veryUnhealthy"
case
hazardous
=
"health.airquality.status.hazardous"
public
init
(
value
:
Double
)
{
switch
value
{
case
0
...
50
:
self
=
.
good
case
51
...
100
:
self
=
.
moderate
case
101
...
150
:
self
=
.
unhealthyForSensitiveGroups
case
151
...
200
:
self
=
.
unhealthy
case
201
...
300
:
self
=
.
veryUnhealthy
default
:
self
=
.
hazardous
}
}
public
var
localized
:
String
{
return
self
.
rawValue
.
localized
()
}
...
...
@@ -192,13 +180,123 @@ public struct Pollutant: Equatable, Hashable {
public
let
name
:
String
public
let
value
:
Double
public
var
progress
:
CGFloat
{
var
progressValue
=
max
(
0
,
CGFloat
(
value
/
500
))
guard
let
hazardousLevelStart
=
self
.
hazardousLevelStart
else
{
return
0.1
// not great, not terrible
}
var
progressValue
=
max
(
0
,
CGFloat
(
value
/
hazardousLevelStart
))
progressValue
=
min
(
1
,
progressValue
)
return
progressValue
}
public
var
status
:
HealthStatus
{
get
{
HealthStatus
(
value
:
value
)
public
init
(
name
:
String
,
value
:
Double
)
{
self
.
name
=
name
self
.
value
=
value
var
statusValue
=
HealthStatus
.
good
let
shortName
=
name
.
trimmingCharacters
(
in
:
.
whitespacesAndNewlines
)
.
replacingOccurrences
(
of
:
" "
,
with
:
""
)
.
lowercased
()
if
let
statusLimits
:
[
HealthStatus
:
Double
]
=
Pollutant
.
upperLimits
[
shortName
]
{
let
statusesSequence
:
[
HealthStatus
]
=
[
.
good
,
.
moderate
,
.
unhealthyForSensitiveGroups
,
.
unhealthy
,
.
veryUnhealthy
,
.
hazardous
]
for
possibleStatus
:
HealthStatus
in
statusesSequence
{
if
let
limit
:
Double
=
statusLimits
[
possibleStatus
]
{
if
value
<
limit
{
statusValue
=
possibleStatus
break
}
}
else
{
assertionFailure
(
"No limit for status
\(
possibleStatus
)
of pollutant
\(
name
)
"
)
// should never happen.
statusValue
=
possibleStatus
continue
}
}
if
let
veryUnhealthyUpperLimit
=
statusLimits
[
.
veryUnhealthy
]
{
hazardousLevelStart
=
veryUnhealthyUpperLimit
}
else
{
assertionFailure
(
"No limit for status
\(
HealthStatus
.
veryUnhealthy
)
of pollutant
\(
name
)
"
)
// should never happen.
hazardousLevelStart
=
nil
}
}
else
{
assertionFailure
(
"No limits for Pollutant
\(
name
)
!"
)
statusValue
=
.
good
hazardousLevelStart
=
nil
}
self
.
status
=
statusValue
}
public
private
(
set
)
var
status
:
HealthStatus
private
let
hazardousLevelStart
:
Double
?
/// Preferably these should be configurable from the server.
/// See https://en.wikipedia.org/wiki/Air_quality_index
/// The "AQI Category, Pollutants and Health Breakpoints" table.
private
static
let
upperLimits
:
[
String
:
[
HealthStatus
:
Double
]]
=
[
"pm10"
:
[
.
good
:
50.0
,
.
moderate
:
100.0
,
.
unhealthyForSensitiveGroups
:
250.0
,
.
unhealthy
:
350.0
,
.
veryUnhealthy
:
430.0
,
.
hazardous
:
Double
.
infinity
],
"pm2.5"
:
[
.
good
:
30.0
,
.
moderate
:
60.0
,
.
unhealthyForSensitiveGroups
:
90.0
,
.
unhealthy
:
120.0
,
.
veryUnhealthy
:
250.0
,
.
hazardous
:
Double
.
infinity
],
"no2"
:
[
.
good
:
40.0
,
.
moderate
:
80.0
,
.
unhealthyForSensitiveGroups
:
180.0
,
.
unhealthy
:
280.0
,
.
veryUnhealthy
:
400.0
,
.
hazardous
:
Double
.
infinity
],
"o3"
:
[
.
good
:
50.0
,
.
moderate
:
100.0
,
.
unhealthyForSensitiveGroups
:
168.0
,
.
unhealthy
:
208.0
,
.
veryUnhealthy
:
748.0
,
.
hazardous
:
Double
.
infinity
],
"co"
:
[
.
good
:
1.0
,
.
moderate
:
2.0
,
.
unhealthyForSensitiveGroups
:
10.0
,
.
unhealthy
:
17.0
,
.
veryUnhealthy
:
34.0
,
.
hazardous
:
Double
.
infinity
],
"so2"
:
[
.
good
:
40.0
,
.
moderate
:
80.0
,
.
unhealthyForSensitiveGroups
:
380.0
,
.
unhealthy
:
800.0
,
.
veryUnhealthy
:
1600.0
,
.
hazardous
:
Double
.
infinity
],
"nh3"
:
[
.
good
:
200.0
,
.
moderate
:
400.0
,
.
unhealthyForSensitiveGroups
:
800.0
,
.
unhealthy
:
1200.0
,
.
veryUnhealthy
:
1800.0
,
.
hazardous
:
Double
.
infinity
],
"pb"
:
[
.
good
:
0.5
,
.
moderate
:
1.0
,
.
unhealthyForSensitiveGroups
:
2.0
,
.
unhealthy
:
3.0
,
.
veryUnhealthy
:
3.5
,
.
hazardous
:
Double
.
infinity
]
]
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment