Skip to content

Commit

Permalink
fixed bug on ClimaCell primary pollutant
Browse files Browse the repository at this point in the history
added solarghi on ClimaCell dataloader
  • Loading branch information
DarraghRogan committed Mar 9, 2021
1 parent d6c6a93 commit 09f769c
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@
filePath = "Miasma/DataLoaderClimaCell.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "87"
endingLineNumber = "87"
startingLineNumber = "88"
endingLineNumber = "88"
landmarkName = "loadClimaCellData(lat:lon:)"
landmarkType = "7">
</BreakpointContent>
Expand All @@ -78,8 +78,8 @@
filePath = "Miasma/DataLoaderClimaCell.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "89"
endingLineNumber = "89"
startingLineNumber = "90"
endingLineNumber = "90"
landmarkName = "loadClimaCellData(lat:lon:)"
landmarkType = "7">
</BreakpointContent>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
<key>Miasma WidgetExtension.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>8</integer>
<integer>10</integer>
</dict>
<key>Miasma iOS.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>10</integer>
<integer>8</integer>
</dict>
<key>Miasma.xcscheme_^#shared#^_</key>
<dict>
Expand Down
11 changes: 6 additions & 5 deletions Miasma/DataLoaderClimaCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ struct DataClass: Codable {

// MARK: - Timeline
struct Timeline: Codable {
// var timestep: String?
// var startTime, endTime: Date?
// var timestep: String?
// var startTime, endTime: Date?
var intervals: [Interval]?
}

// MARK: - Interval
struct Interval: Codable {
// var startTime: Date?
// var startTime: Date?
var values: Values?
}

Expand All @@ -40,6 +40,7 @@ struct Values: Codable {
var weatherCode: Int?
var windDirection, windSpeed: Double?
var epaIndex, epaPrimaryPollutant: Int?
var solarGHI: Double?
}


Expand All @@ -60,7 +61,7 @@ public class DataLoaderClimaCell {
]

let request = NSMutableURLRequest(url: NSURL(string:
"https://data.climacell.co/v4/timelines?location=\(lat),\(lon)&fields=treeIndex,grassIndex,weedIndex,temperatureApparent,weatherCode,windDirection,windSpeed,epaIndex,epaPrimaryPollutant&apikey=\(APIKeyClimaCellV4)")! as URL,
"https://data.climacell.co/v4/timelines?location=\(lat),\(lon)&fields=treeIndex,grassIndex,weedIndex,temperatureApparent,weatherCode,windDirection,windSpeed,epaIndex,epaPrimaryPollutant,solarGHI&apikey=\(APIKeyClimaCellV4)")! as URL,
cachePolicy: .useProtocolCachePolicy,
timeoutInterval: 10.0)

Expand All @@ -78,7 +79,7 @@ public class DataLoaderClimaCell {
let httpResponse = response as? HTTPURLResponse
print("Received from the ClimaCell API")
if let data = data,
let urlContent = NSString(data: data, encoding: String.Encoding.ascii.rawValue) {
let urlContent = NSString(data: data, encoding: String.Encoding.ascii.rawValue) {
print(urlContent)
} else {
print("error with printing string encoded data")
Expand Down
32 changes: 16 additions & 16 deletions Miasma/Menu.swift
Original file line number Diff line number Diff line change
Expand Up @@ -741,15 +741,15 @@ class menuFunctions: NSObject {
switch ClimaCellPrimaryPollutant {
case _ where ClimaCellPrimaryPollutant == 0:
ClimaCellPrimaryPollutantText = "PM₂.₅"
case _ where ClimaCellWeatherCode == 1:
case _ where ClimaCellPrimaryPollutant == 1:
ClimaCellPrimaryPollutantText = "PM₁₀"
case _ where ClimaCellWeatherCode == 2:
case _ where ClimaCellPrimaryPollutant == 2:
ClimaCellPrimaryPollutantText = "O₃"
case _ where ClimaCellWeatherCode == 3:
case _ where ClimaCellPrimaryPollutant == 3:
ClimaCellPrimaryPollutantText = "NO₂"
case _ where ClimaCellWeatherCode == 4:
case _ where ClimaCellPrimaryPollutant == 4:
ClimaCellPrimaryPollutantText = "CO"
case _ where ClimaCellWeatherCode == 5:
case _ where ClimaCellPrimaryPollutant == 5:
ClimaCellPrimaryPollutantText = "SO₂"
default:
ClimaCellPrimaryPollutantText = "Unknown"
Expand Down Expand Up @@ -1182,15 +1182,15 @@ class menuFunctions: NSObject {
switch ClimaCellPrimaryPollutant {
case _ where ClimaCellPrimaryPollutant == 0:
ClimaCellPrimaryPollutantText = "PM₂.₅"
case _ where ClimaCellWeatherCode == 1:
case _ where ClimaCellPrimaryPollutant == 1:
ClimaCellPrimaryPollutantText = "PM₁₀"
case _ where ClimaCellWeatherCode == 2:
case _ where ClimaCellPrimaryPollutant == 2:
ClimaCellPrimaryPollutantText = "O₃"
case _ where ClimaCellWeatherCode == 3:
case _ where ClimaCellPrimaryPollutant == 3:
ClimaCellPrimaryPollutantText = "NO₂"
case _ where ClimaCellWeatherCode == 4:
case _ where ClimaCellPrimaryPollutant == 4:
ClimaCellPrimaryPollutantText = "CO"
case _ where ClimaCellWeatherCode == 5:
case _ where ClimaCellPrimaryPollutant == 5:
ClimaCellPrimaryPollutantText = "SO₂"
default:
ClimaCellPrimaryPollutantText = "Unknown"
Expand Down Expand Up @@ -1496,7 +1496,7 @@ class menuFunctions: NSObject {
self.smartCitizenPM2_5.title = "☁️: \(String(aQI_CalculatedRounded)) US EPA AQI PM₂.₅ / \(String(smartCitizenData.data?.sensors?[8].value ?? 0)) μg/m³ PM₂.₅ (Current) \(pM2_5ColourButton)"


self.smartCitizenOtherPollutants.title = "☁️: VOC \(String(smartCitizenData.data?.sensors?[0].value ?? 0))\(String(smartCitizenData.data?.sensors?[0].unit ?? "0")) / CO2 \(String(smartCitizenData.data?.sensors?[1].value ?? 0))\(String(smartCitizenData.data?.sensors?[1].unit ?? "0"))"
self.smartCitizenOtherPollutants.title = "☁️: VOC \(String(smartCitizenData.data?.sensors?[0].value ?? 0))\(String(smartCitizenData.data?.sensors?[0].unit ?? "0")) / CO₂ \(String(smartCitizenData.data?.sensors?[1].value ?? 0))\(String(smartCitizenData.data?.sensors?[1].unit ?? "0"))"

self.smartCitizenTemperature.title = "🌡: \(String(smartCitizenData.data?.sensors?[10].value ?? 0))"

Expand Down Expand Up @@ -1680,15 +1680,15 @@ class menuFunctions: NSObject {
switch ClimaCellPrimaryPollutant {
case _ where ClimaCellPrimaryPollutant == 0:
ClimaCellPrimaryPollutantText = "PM₂.₅"
case _ where ClimaCellWeatherCode == 1:
case _ where ClimaCellPrimaryPollutant == 1:
ClimaCellPrimaryPollutantText = "PM₁₀"
case _ where ClimaCellWeatherCode == 2:
case _ where ClimaCellPrimaryPollutant == 2:
ClimaCellPrimaryPollutantText = "O₃"
case _ where ClimaCellWeatherCode == 3:
case _ where ClimaCellPrimaryPollutant == 3:
ClimaCellPrimaryPollutantText = "NO₂"
case _ where ClimaCellWeatherCode == 4:
case _ where ClimaCellPrimaryPollutant == 4:
ClimaCellPrimaryPollutantText = "CO"
case _ where ClimaCellWeatherCode == 5:
case _ where ClimaCellPrimaryPollutant == 5:
ClimaCellPrimaryPollutantText = "SO₂"
default:
ClimaCellPrimaryPollutantText = "Unknown"
Expand Down

0 comments on commit 09f769c

Please sign in to comment.