Skip to content

Commit

Permalink
- Added explanation of what the Carbon Intensity number means in IEA …
Browse files Browse the repository at this point in the history
…terms

- Added ug/m3 units for PM2.5 for PurpleAir
- Fixed pagination of graphs
  • Loading branch information
DarraghRogan committed Nov 24, 2020
1 parent da8082f commit 09e6a59
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 26 deletions.
8 changes: 4 additions & 4 deletions Miasma.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -824,7 +824,7 @@
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 20;
CURRENT_PROJECT_VERSION = 21;
DEVELOPMENT_TEAM = VDLCQ62KZH;
ENABLE_HARDENED_RUNTIME = YES;
EXCLUDED_ARCHS = "";
Expand All @@ -834,7 +834,7 @@
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 10.12;
MARKETING_VERSION = 1.12;
MARKETING_VERSION = 1.13;
PRODUCT_BUNDLE_IDENTIFIER = "Darragh-Rogan.Miasma";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 5.0;
Expand All @@ -850,7 +850,7 @@
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 20;
CURRENT_PROJECT_VERSION = 21;
DEVELOPMENT_TEAM = VDLCQ62KZH;
ENABLE_HARDENED_RUNTIME = YES;
EXCLUDED_ARCHS = "";
Expand All @@ -860,7 +860,7 @@
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 10.12;
MARKETING_VERSION = 1.12;
MARKETING_VERSION = 1.13;
PRODUCT_BUNDLE_IDENTIFIER = "Darragh-Rogan.Miasma";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 5.0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,19 @@
<key>Miasma iOS.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>8</integer>
<integer>9</integer>
</dict>
<key>Miasma.xcscheme_^#shared#^_</key>
<dict>
<key>isShown</key>
<true/>
<key>orderHint</key>
<integer>0</integer>
</dict>
<key>MiasmaLauncher.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>9</integer>
<integer>8</integer>
</dict>
<key>MiasmaLauncherApplication.xcscheme_^#shared#^_</key>
<dict>
Expand Down
4 changes: 2 additions & 2 deletions Miasma/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele
let runningApps = NSWorkspace.shared.runningApplications
let isRunning = !runningApps.filter { $0.bundleIdentifier == launcherAppId }.isEmpty

// SMLoginItemSetEnabled(launcherAppId as CFString, true)
SMLoginItemSetEnabled(launcherAppId as CFString, self.defaults.bool(forKey: "AutorunAtStartup"))

if isRunning {
DistributedNotificationCenter.default().post(name: .killLauncher, object: Bundle.main.bundleIdentifier!)
}
Expand Down
6 changes: 3 additions & 3 deletions Miasma/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="17156" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="17506" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
<dependencies>
<deployment identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="17156"/>
<plugIn identifier="com.apple.MapKitIBPlugin" version="17156"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="17506"/>
<plugIn identifier="com.apple.MapKitIBPlugin" version="17506"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
Expand Down
14 changes: 7 additions & 7 deletions Miasma/DataLoaderSmartCitizen.swift
Original file line number Diff line number Diff line change
Expand Up @@ -440,13 +440,13 @@ public class DataLoaderSmartCitizen {
print(error)
} else {
let httpResponse = response as? HTTPURLResponse
print("Received from the SmartCitizen API")
if let data = data,
let urlContent = NSString(data: data, encoding: String.Encoding.ascii.rawValue) {
print(urlContent)
} else {
print("error with printing string encoded data")
}
// print("Received from the SmartCitizen API")
// if let data = data,
// let urlContent = NSString(data: data, encoding: String.Encoding.ascii.rawValue) {
// print(urlContent)
// } else {
// print("error with printing string encoded data")
// }
//Parse JSON
let decoder = JSONDecoder()
do {
Expand Down
53 changes: 47 additions & 6 deletions Miasma/Menu.swift
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,10 @@ class menuFunctions: NSObject {
return NSMenuItem(title: "🌍: ", action: nil, keyEquivalent: "")
}()

var cO2levelComparedTo100g : NSMenuItem = {
return NSMenuItem(title: "🔥: ", action: nil, keyEquivalent: "")
}()

var cO2FossilFuelMix : NSMenuItem = {
return NSMenuItem(title: "⚡️: ", action: nil, keyEquivalent: "")
}()
Expand Down Expand Up @@ -283,6 +287,7 @@ class menuFunctions: NSObject {
menu.addItem(CO2Link)

menu.addItem(cO2Country)
menu.addItem(cO2levelComparedTo100g)
menu.addItem(cO2FossilFuelMix)

}
Expand Down Expand Up @@ -504,7 +509,7 @@ class menuFunctions: NSObject {
self.purpleAirPM2_5StatusBarIcon.title = ""
statusItem.button?.title = "M \(self.purpleAirPM2_5StatusBarIcon.title)"
}
self.purpleAirPM2_5.title = "☁️: \(String(aQI_CalculatedRounded)) US EPA AQI PM₂.₅ (Current) \(pM2_5ColourButton)"
self.purpleAirPM2_5.title = "☁️: \(String(aQI_CalculatedRounded)) US EPA AQI / \(String(pM2_5Value)) μg/m³ PM₂.₅ (Current) \(pM2_5ColourButton)"

// note including -8F & +4% corrections to temp & RH per: https://www.reddit.com/r/PurpleAir/comments/j14qln/temperature_reported_from_web_map_vs_api_mismatch/

Expand Down Expand Up @@ -532,14 +537,25 @@ class menuFunctions: NSObject {
default:
pressure_visual = ""
}
self.purpleAirPressure.title = "🌬️: \(String(purpleAirData.sensor?.pressureA ?? 0)) millibar \(pressure_visual)"
self.purpleAirPressure.title = "🌬️: \(String(purpleAirData.sensor?.pressureA ?? 0)) millibar \(pressure_visual)"
self.purpleAirReadingAge.title = "⏳: \(String(Int((NSDate().timeIntervalSince1970))-(purpleAirData.sensor?.lastSeen ?? 0))) seconds old at Miasma refresh time"
})

if AppDelegate().defaults.integer(forKey:"CO2SignalInUse") == 1 {
DispatchQueue.main.asyncAfter(deadline: .now() + 10.1, execute: {
self.cO2Country.title = "🌍: Carbon Intensity in \(cO2Data.countryCode ?? ""): \(String(format: "%.1f", locale: Locale.current, cO2Data.data?.carbonIntensity ?? 0))gCO₂eq/kWh"

if cO2Data.data?.carbonIntensity ?? 100 < 100
{
self.cO2levelComparedTo100g.title = "🔥: Lower than IEA target of 100gCO₂eq/kWh 👍"

}
else {
var cO2Intensity = cO2Data.data?.carbonIntensity ?? 100
let cO2IntensityMultiplier = cO2Intensity/100
self.cO2levelComparedTo100g.title = "🔥: \(String(format: "%.1f", locale: Locale.current, cO2IntensityMultiplier)) times the IEA target of 100gCO₂eq/kWh 👎"
}

var fossilFuelPercentage = cO2Data.data?.fossilFuelPercentage ?? 0
let fossilFuelPercentage_visual: String
// ranges for pressure values from https://www.thoughtco.com/how-to-read-a-barometer-3444043
Expand Down Expand Up @@ -571,6 +587,7 @@ class menuFunctions: NSObject {
}

self.cO2FossilFuelMix.title = "⚡️: Low / High Carbon Energy mix: \(fossilFuelPercentage_visual)"


})
}
Expand Down Expand Up @@ -660,6 +677,7 @@ class menuFunctions: NSObject {
menu.addItem(CO2Link)

menu.addItem(cO2Country)
menu.addItem(cO2levelComparedTo100g)
menu.addItem(cO2FossilFuelMix)

}
Expand Down Expand Up @@ -845,7 +863,7 @@ class menuFunctions: NSObject {
self.wAQIAQIColourButton.title = ""
statusItem.button?.title = "M \(self.wAQIAQIColourButton.title)"
}
self.wAQIAQI.title = "☁️: \(String(wAQIData.data?.aqi ?? 0)) AQI (US EPA, Current) \(wAQIAQIColourButton)"
self.wAQIAQI.title = "☁️: \(String(wAQIData.data?.aqi ?? 0)) AQI (US EPA, Current) \(wAQIAQIColourButton)"

self.wAQIDominentPol.title = "🎯: Dominant Pollutant: \(String(wAQIData.data?.dominentpol ?? "0"))"

Expand All @@ -860,6 +878,17 @@ class menuFunctions: NSObject {
DispatchQueue.main.asyncAfter(deadline: .now() + 10.1, execute: {
self.cO2Country.title = "🌍: Carbon Intensity in \(cO2Data.countryCode ?? ""): \(String(format: "%.1f", locale: Locale.current, cO2Data.data?.carbonIntensity ?? 0))gCO₂eq/kWh"

if cO2Data.data?.carbonIntensity ?? 100 < 100
{
self.cO2levelComparedTo100g.title = "🔥: Lower than IEA target of 100gCO₂eq/kWh 👍"

}
else {
var cO2Intensity = cO2Data.data?.carbonIntensity ?? 100
let cO2IntensityMultiplier = cO2Intensity/100
self.cO2levelComparedTo100g.title = "🔥: \(String(format: "%.1f", locale: Locale.current, cO2IntensityMultiplier)) times the IEA target of 100gCO₂eq/kWh 👎"
}

var fossilFuelPercentage = cO2Data.data?.fossilFuelPercentage ?? 0
let fossilFuelPercentage_visual: String
// ranges for pressure values from https://www.thoughtco.com/how-to-read-a-barometer-3444043
Expand Down Expand Up @@ -958,7 +987,7 @@ class menuFunctions: NSObject {
menu.addItem(smartCitizenHumidity)
menu.addItem(smartCitizenPressure)
menu.addItem(smartCitizenPhysicalProperties)
// menu.addItem(smartCitizenReadingAge)
// menu.addItem(smartCitizenReadingAge)

menu.addItem(NSMenuItem.separator())

Expand All @@ -974,6 +1003,7 @@ class menuFunctions: NSObject {
menu.addItem(CO2Link)

menu.addItem(cO2Country)
menu.addItem(cO2levelComparedTo100g)
menu.addItem(cO2FossilFuelMix)

}
Expand Down Expand Up @@ -1193,7 +1223,7 @@ class menuFunctions: NSObject {
self.smartCitizenPM2_5StatusBarIcon.title = ""
statusItem.button?.title = "M \(self.smartCitizenPM2_5StatusBarIcon.title)"
}
self.smartCitizenPM2_5.title = "☁️: \(String(aQI_CalculatedRounded)) US EPA AQI PM₂.₅ (Current) \(pM2_5ColourButton)"
self.smartCitizenPM2_5.title = "☁️: \(String(aQI_CalculatedRounded)) US EPA AQI 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"))"
Expand All @@ -1215,7 +1245,7 @@ class menuFunctions: NSObject {
default:
pressure_visual = ""
}
self.smartCitizenPressure.title = "🌬️: \(String(smartCitizenData.data?.sensors?[5].value ?? 0))kilopascal \(pressure_visual)"
self.smartCitizenPressure.title = "🌬️: \(String(smartCitizenData.data?.sensors?[5].value ?? 0))kilopascal \(pressure_visual)"


self.smartCitizenPhysicalProperties.title = "🎤: Noise \(String(smartCitizenData.data?.sensors?[4].value ?? 0))\(String(smartCitizenData.data?.sensors?[4].unit ?? "0")) / Ambient Light \(String(smartCitizenData.data?.sensors?[2].value ?? 0))\(String(smartCitizenData.data?.sensors?[2].unit ?? "0"))"
Expand All @@ -1229,6 +1259,17 @@ class menuFunctions: NSObject {
DispatchQueue.main.asyncAfter(deadline: .now() + 10.1, execute: {
self.cO2Country.title = "🌍: Carbon Intensity in \(cO2Data.countryCode ?? ""): \(String(format: "%.1f", locale: Locale.current, cO2Data.data?.carbonIntensity ?? 0))gCO₂eq/kWh"

if cO2Data.data?.carbonIntensity ?? 100 < 100
{
self.cO2levelComparedTo100g.title = "🔥: Lower than IEA target of 100gCO₂eq/kWh 👍"

}
else {
var cO2Intensity = cO2Data.data?.carbonIntensity ?? 100
let cO2IntensityMultiplier = cO2Intensity/100
self.cO2levelComparedTo100g.title = "🔥: \(String(format: "%.1f", locale: Locale.current, cO2IntensityMultiplier)) times the IEA target of 100gCO₂eq/kWh 👎"
}

var fossilFuelPercentage = cO2Data.data?.fossilFuelPercentage ?? 0
let fossilFuelPercentage_visual: String
// ranges for pressure values from https://www.thoughtco.com/how-to-read-a-barometer-3444043
Expand Down
13 changes: 11 additions & 2 deletions Miasma/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -314,9 +314,18 @@
@IBAction func autoRunAtStartup(_ sender: Any) {
let launcherAppId = "Darragh-Rogan.MiasmaLauncher"

let isAuto = (sender as AnyObject).state == .on
// let isAuto = (sender as AnyObject).state == .on
//
// SMLoginItemSetEnabled(launcherAppId as CFString, isAuto)

SMLoginItemSetEnabled(launcherAppId as CFString, isAuto)
if autoRunAtStartup.state.self.rawValue == 0{
AppDelegate().defaults.set(false, forKey: "AutorunAtStartup")
SMLoginItemSetEnabled(launcherAppId as CFString, false)
}
else if autoRunAtStartup.state.self.rawValue == 1{
AppDelegate().defaults.set(true, forKey: "AutorunAtStartup")
SMLoginItemSetEnabled(launcherAppId as CFString, true)
}

// if autoRunAtStartup.state == NSControl.StateValue.off {
// AppDelegate().defaults.set(false, forKey: "AutorunAtStartup")
Expand Down

0 comments on commit 09e6a59

Please sign in to comment.