-
Notifications
You must be signed in to change notification settings - Fork 0
feat(metrics): Clarify energy impact ownership and sampling continuity #112
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
f2f43f8
refactor(energy): define honest impact states
bigtomcat6 8f8dc10
fix(energy): key baselines by process generation
bigtomcat6 c63df90
feat(energy): clarify impact presentation
bigtomcat6 083bc5a
test(energy): isolate localized rendering fixture
bigtomcat6 422aec5
fix(energy): use monotonic sample timing
bigtomcat6 3a32087
fix(energy): stabilize visible sampling
bigtomcat6 5edeae4
fix(energy): preserve ranking and status state
bigtomcat6 d03ab32
refactor(energy): assign unique process owners
bigtomcat6 59e0078
fix(energy): preserve partial sampling state
bigtomcat6 4618f77
fix(energy): invalidate broken sampling continuity
bigtomcat6 631841d
fix(energy): close ownership and stale state gaps
bigtomcat6 311389a
fix(energy): address PR review and coverage
bigtomcat6 19beba0
test(energy): cover smoothing fallback
bigtomcat6 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
Sources/MacActivityApp/Models/EnergyImpactPresentation.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| import Foundation | ||
| import MacActivityCore | ||
|
|
||
| enum EnergyImpactPresentation { | ||
| static func powerText(microwatts: Double, locale: Locale) -> String { | ||
| guard microwatts.isFinite, microwatts >= 0 else { return "—" } | ||
| if microwatts >= 1_000 { | ||
| let value = (microwatts / 1_000).formatted( | ||
| .number.locale(locale).precision(.fractionLength(0...1)) | ||
| ) | ||
| return "\(value) mW" | ||
| } | ||
| let value = microwatts.formatted( | ||
| .number.locale(locale).precision(.fractionLength(0...1)) | ||
| ) | ||
| return "\(value) µW" | ||
| } | ||
|
|
||
| static func powerText( | ||
| microwatts: Double?, | ||
| status: EnergyImpactStatus, | ||
| bundle: Bundle? = nil | ||
| ) -> String { | ||
| if status == .stale { | ||
| guard let microwatts, microwatts.isFinite, microwatts >= 0 else { | ||
| return AppLocalization.string(.energyImpactStale, bundle: bundle) | ||
| } | ||
| return AppLocalization.string( | ||
| .energyImpactStaleWithValue, | ||
| powerText( | ||
| microwatts: microwatts, | ||
| locale: AppLocalization.currentLocale(bundle: bundle) | ||
| ), | ||
| bundle: bundle | ||
| ) | ||
| } | ||
| guard let microwatts, microwatts.isFinite, microwatts >= 0 else { | ||
| let key: AppLocalization.Key = switch status { | ||
| case .collecting: .energyImpactCollecting | ||
| case .partial: .energyImpactPartial | ||
| case .stale: .energyImpactStale | ||
| case .stable, .unavailable: .energyImpactUnavailable | ||
| } | ||
| return AppLocalization.string(key, bundle: bundle) | ||
| } | ||
| return powerText( | ||
| microwatts: microwatts, | ||
| locale: AppLocalization.currentLocale(bundle: bundle) | ||
| ) | ||
| } | ||
|
|
||
| static func accessibilityLabel( | ||
| entry: EnergyImpactEntry, | ||
| rank: Int, | ||
| bundle: Bundle? = nil | ||
| ) -> String { | ||
| let value = powerText( | ||
| microwatts: entry.displayPowerMicrowatts, | ||
| status: entry.status, | ||
| bundle: bundle | ||
| ) | ||
| return AppLocalization.string( | ||
| .energyImpactRowAccessibility, | ||
| entry.name, | ||
| rank, | ||
| value, | ||
| bundle: bundle | ||
| ) | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.