-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Fixed tariff: fix sorting zones with deviating months or days #26425
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
Draft
iseeberg79
wants to merge
14
commits into
evcc-io:master
Choose a base branch
from
iseeberg79:fix/fixed_dev
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
e276eed
Fixed tariff: fix sorting zones with deviating months or days
andig 7ebe633
wip
andig b026142
wip
andig 8ce22dd
wip
andig 777e462
adapt clock
iseeberg79 04a1914
fix fixed tariff
iseeberg79 974c992
add test
iseeberg79 4182e81
happy linter
iseeberg79 515e502
minimal
iseeberg79 59bb8a0
reduce
iseeberg79 3794bef
reduce
iseeberg79 341f04a
Revert "reduce"
iseeberg79 14c6c52
log ambiguous
iseeberg79 004a5fd
single timezone
iseeberg79 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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| package tariff | ||
|
|
||
| import ( | ||
| "testing" | ||
| "time" | ||
|
|
||
| "github.com/benbjohnson/clock" | ||
| "github.com/stretchr/testify/assert" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| func TestFixedSpecificity(t *testing.T) { | ||
| at, err := NewFixedFromConfig(map[string]any{ | ||
| "price": 0.30, | ||
| "zones": []struct { | ||
| Price float64 | ||
| Hours string | ||
| Months string | ||
| }{ | ||
| // REVERSED: specific first, general second | ||
| // Without MoreSpecific, this will fail! | ||
| {0.10, "0-5", "Jan-Mar,Oct-Dec"}, // specific (winter only) | ||
| {0.20, "0-5", ""}, // general (all year) | ||
| }, | ||
| }) | ||
| require.NoError(t, err) | ||
|
|
||
| testCases := []struct { | ||
| month time.Month | ||
| expected float64 | ||
| }{ | ||
| {time.January, 0.10}, // winter: specific zone wins | ||
| {time.June, 0.20}, // summer: general zone | ||
| {time.December, 0.10}, // winter: specific zone wins | ||
| } | ||
|
|
||
| for _, tc := range testCases { | ||
| clock := clock.NewMock() | ||
| at.(*Fixed).clock = clock | ||
| clock.Set(time.Date(2025, tc.month, 15, 3, 0, 0, 0, time.UTC)) | ||
|
|
||
| rr, err := at.Rates() | ||
| require.NoError(t, err) | ||
|
|
||
| r, err := rr.At(clock.Now()) | ||
| require.NoError(t, err) | ||
|
|
||
| assert.Equal(t, tc.expected, r.Value, | ||
| "TZ=%s, %s: expected %.2f", time.UTC, tc.month, tc.expected) | ||
| } | ||
| } | ||
|
|
||
| func TestPartiallyOverlappingMonths(t *testing.T) { | ||
| at, err := NewFixedFromConfig(map[string]any{ | ||
| "price": 0.0, | ||
| "zones": []struct { | ||
| Price float64 | ||
| Hours string | ||
| Months string | ||
| }{ | ||
| {0.10, "0-5", "Jan"}, | ||
| {0.20, "0-5", "Feb"}, | ||
| {0.30, "0-5", "Jan-Mar"}, | ||
| }, | ||
| }) | ||
| require.NoError(t, err) | ||
|
|
||
| clock := clock.NewMock() | ||
| tf := at.(*Fixed) | ||
| tf.clock = clock | ||
|
|
||
| // Test for January → should detect ambiguity (Zone 0 + Zone 2) | ||
| clock.Set(time.Date(2025, time.January, 10, 1, 0, 0, 0, time.UTC)) | ||
| _, _ = tf.Rates() // triggers warning | ||
|
|
||
| // Test for February → should detect ambiguity (Zone 1 + Zone 2) | ||
| clock.Set(time.Date(2025, time.February, 10, 1, 0, 0, 0, time.UTC)) | ||
| _, _ = tf.Rates() // triggers warning | ||
|
|
||
| // Test for March → only Zone 2 applies → no warning | ||
| clock.Set(time.Date(2025, time.March, 10, 1, 0, 0, 0, time.UTC)) | ||
| _, _ = tf.Rates() | ||
| } | ||
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.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Am Ende müssen vmtl. auch Überlappungen gehandhabt werden? In jedem Fall wäre es schön diese- wenn nicht vergleichbar- als Fehler identifizieren zu können.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
aber nur wenn wirklich "ambigious"? Das braucht ein paar Helper