Skip to content

Commit 637acb1

Browse files
committed
Adding option to show raw PurpleAir values in the widget - iOS client changes
1 parent e0fddc3 commit 637acb1

5 files changed

Lines changed: 69 additions & 13 deletions

File tree

client/ios/Widget/LocationSelection.intentdefinition

Lines changed: 47 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@
99
<key>INIntentDefinitionNamespace</key>
1010
<string>88xZPY</string>
1111
<key>INIntentDefinitionSystemVersion</key>
12-
<string>19H2</string>
12+
<string>20G95</string>
1313
<key>INIntentDefinitionToolsBuildVersion</key>
14-
<string>12A7300</string>
14+
<string>12E507</string>
1515
<key>INIntentDefinitionToolsVersion</key>
16-
<string>12.0.1</string>
16+
<string>12.5.1</string>
1717
<key>INIntents</key>
1818
<array>
1919
<dict>
@@ -30,10 +30,10 @@
3030
<key>INIntentIneligibleForSuggestions</key>
3131
<true/>
3232
<key>INIntentLastParameterTag</key>
33-
<integer>4</integer>
33+
<integer>6</integer>
3434
<key>INIntentManagedParameterCombinations</key>
3535
<dict>
36-
<key>location</key>
36+
<key>location,display_purpleair</key>
3737
<dict>
3838
<key>INIntentParameterCombinationSupportsBackgroundExecution</key>
3939
<true/>
@@ -81,6 +81,48 @@
8181
<key>INIntentParameterType</key>
8282
<string>Placemark</string>
8383
</dict>
84+
<dict>
85+
<key>INIntentParameterConfigurable</key>
86+
<true/>
87+
<key>INIntentParameterDisplayName</key>
88+
<string>Show Raw PurpleAir values</string>
89+
<key>INIntentParameterDisplayNameID</key>
90+
<string>gyzQoM</string>
91+
<key>INIntentParameterDisplayPriority</key>
92+
<integer>2</integer>
93+
<key>INIntentParameterMetadata</key>
94+
<dict>
95+
<key>INIntentParameterMetadataFalseDisplayName</key>
96+
<string>false</string>
97+
<key>INIntentParameterMetadataFalseDisplayNameID</key>
98+
<string>C9JREb</string>
99+
<key>INIntentParameterMetadataTrueDisplayName</key>
100+
<string>true</string>
101+
<key>INIntentParameterMetadataTrueDisplayNameID</key>
102+
<string>Pp5b6V</string>
103+
</dict>
104+
<key>INIntentParameterName</key>
105+
<string>display_purpleair</string>
106+
<key>INIntentParameterPromptDialogs</key>
107+
<array>
108+
<dict>
109+
<key>INIntentParameterPromptDialogCustom</key>
110+
<true/>
111+
<key>INIntentParameterPromptDialogType</key>
112+
<string>Configuration</string>
113+
</dict>
114+
<dict>
115+
<key>INIntentParameterPromptDialogCustom</key>
116+
<true/>
117+
<key>INIntentParameterPromptDialogType</key>
118+
<string>Primary</string>
119+
</dict>
120+
</array>
121+
<key>INIntentParameterTag</key>
122+
<integer>6</integer>
123+
<key>INIntentParameterType</key>
124+
<string>Boolean</string>
125+
</dict>
84126
</array>
85127
<key>INIntentResponse</key>
86128
<dict>

client/ios/Widget/Widget.swift

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ struct MapProvider : IntentTimelineProvider {
2626

2727
func getSnapshot(for intent: LocationSelectionIntent, in context: Context, completion: @escaping (MapEntry) -> Void) {
2828
var location = self._location(for: intent)
29+
let readingType = self._readingType(for: intent)
2930
if location == nil {
3031
let locationManager = CLLocationManager()
3132
locationManager.desiredAccuracy = kCLLocationAccuracyKilometer
@@ -48,7 +49,7 @@ struct MapProvider : IntentTimelineProvider {
4849
}
4950
}
5051
}
51-
self._mapImage(location: location, size: context.displaySize) { (mapImage) in
52+
self._mapImage(location: location, size: context.displaySize, readingType: readingType) { (mapImage) in
5253
completion(MapEntry(date: Date(), mapImage: mapImage ?? UIImage(named: "MapPlaceholder")!))
5354
}
5455
}
@@ -65,7 +66,12 @@ struct MapProvider : IntentTimelineProvider {
6566
return intent.location?.location
6667
}
6768

68-
private func _mapImage(location: CLLocation?, size: CGSize, callback: @escaping (UIImage?) -> Void) {
69+
private func _readingType(for intent: LocationSelectionIntent) -> AQI.ReadingType {
70+
let displayPurpleAir = intent.display_purpleair?.boolValue ?? false
71+
return displayPurpleAir ? .rawPurpleAir : .epaCorrected
72+
}
73+
74+
private func _mapImage(location: CLLocation?, size: CGSize, readingType: AQI.ReadingType, callback: @escaping (UIImage?) -> Void) {
6975
let coordinate: CLLocationCoordinate2D
7076
if let location = location {
7177
coordinate = location.coordinate
@@ -81,7 +87,7 @@ struct MapProvider : IntentTimelineProvider {
8187
callback(nil)
8288
return
8389
}
84-
AQI.downloadCompactReadings { (readings, error) in
90+
AQI.downloadCompactReadings(type: readingType) { (readings, error) in
8591
if let readings = readings {
8692
var region = options.region
8793
if size.width > size.height {

client/swift/AQI/Download.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import GameKit
66
private let aqiDataURL = URL(string: "https://dfddnmlutocpt.cloudfront.net/sensors.pb")!
77
private let particulateMatterDataURL = URL(string: "https://dfddnmlutocpt.cloudfront.net/sensors.raw.pb")!
88
private let compactDataURL = URL(string: "https://dfddnmlutocpt.cloudfront.net/sensors.compact.pb")!
9+
private let compactParticulateMatterDataURL = URL(string: "https://dfddnmlutocpt.cloudfront.net/sensors.raw.compact.pb")!
910

1011
/// The type of air quality measurement
1112
public enum ReadingType {
@@ -37,11 +38,11 @@ public func downloadReadings(type: ReadingType, onProgess: @escaping (Float) ->
3738
/// - onResponse: The callback to which we report the parsed download response
3839
@available(iOS 13.0, *)
3940
@available(macOS 10.12, *)
40-
public func downloadCompactReadings(onResponse: @escaping (GKRTree<Reading>?, Error?) -> Void) {
41+
public func downloadCompactReadings(type: ReadingType, onResponse: @escaping (GKRTree<Reading>?, Error?) -> Void) {
4142
let client = DownloadClient(onProgess: { (percentage) in
4243
}, onResponse: onResponse)
4344
let session = URLSession(configuration: URLSessionConfiguration.default, delegate: client, delegateQueue: OperationQueue.main)
44-
session.downloadTask(with: compactDataURL).resume()
45+
session.downloadTask(with: type == .epaCorrected ? compactDataURL : compactParticulateMatterDataURL).resume()
4546
}
4647

4748
@available(iOS 13.0, *)

server/template.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ Resources:
7171
AWS_S3_OBJECT: !Ref S3Key
7272
AWS_S3_OBJECT_RAW: !Ref S3KeyRaw
7373
AWS_S3_OBJECT_COMPACT: !Ref S3KeyCompact
74+
AWS_S3_OBJECT_RAW_COMPACT: !Ref S3KeyRawCompact
7475
Policies:
7576
- Statement:
7677
- Sid: UpdateDataPolicy
@@ -127,3 +128,6 @@ Parameters:
127128
S3KeyCompact:
128129
Type: String
129130
Default: sensors.compact.pb
131+
S3KeyRawCompact:
132+
Type: String
133+
Default: sensors.raw.compact.pb

server/update_data/app.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,24 @@ def update_sensor_data(
1717
We download JSON from PurpleAir and convert to our proprietary Protocol
1818
Buffer format, which is used by all clients.
1919
20-
We upload three versions of the protocol buffer data:
20+
We upload four versions of the protocol buffer data:
2121
(1) The corrected EPA AQI readings
2222
(2) Raw PurpleAir PM2.5 AQI readings
2323
(3) A compact data, with just a single AQI reading, used by the widget
24+
(4) A raw compact data, to represent raw single AQI readings in the widget
2425
"""
2526
start_time = time.time()
2627
raw = urllib.request.urlopen(purpleair.api_url(purpleair_api_key)).read()
2728
download_time = time.time()
2829
data = purpleair.parse_api(raw, epa_correction=True)
2930
raw_data = purpleair.parse_api(raw, epa_correction=False)
3031
compact_data = purpleair.compact_sensor_data(data)
32+
raw_compact_data = purpleair.compact_sensor_data(raw_data)
3133
parse_time = time.time()
3234
s3 = boto3.client("s3")
3335
update(s3, s3_bucket, data=data, object_name=s3_object)
3436
update(s3, s3_bucket, data=compact_data, object_name=compact_s3_object)
35-
update(s3, s3_bucket, data=raw_data, object_name=raw_s3_object)
37+
update(s3, s3_bucket, data=raw_data, object_name=raw_compact_s3_object)
3638
s3_time = time.time()
3739
total_time = time.time() - start_time
3840
logging.info("Processed PurpleAir in %.1fs (download: %.1fs, parse: %.1fs, "
@@ -55,4 +57,5 @@ def lambda_handler(event, context):
5557
s3_bucket=os.environ["AWS_S3_BUCKET"],
5658
s3_object=os.environ["AWS_S3_OBJECT"],
5759
raw_s3_object=os.environ["AWS_S3_OBJECT_RAW"],
58-
compact_s3_object=os.environ["AWS_S3_OBJECT_COMPACT"])
60+
compact_s3_object=os.environ["AWS_S3_OBJECT_COMPACT"],
61+
raw_compact_s3_object=os.environ["AWS_S3_OBJECT_RAW_COMPACT"])

0 commit comments

Comments
 (0)