Skip to content

Conversation

@peterdudfield
Copy link
Contributor

@peterdudfield peterdudfield commented Nov 26, 2025

Update capacityToValueMultiplier to use 10's not 10^3's. This means we can get atleast 4.s.f.

I needed to remove a constraint in the sql code too

Example:
Before 32768 would get rounded to 33 x 10^3, and now it goes rounded to 3277 x 10^1

This helps fix #71

  • Have you followed the Open Climate Fix Contribution Guidelines?
  • Have you referenced the Issue this PR addresses?
  • Have you checked to ensure there aren't other open Pull Requests for the same change?
  • Have you added a summary of the changes?
  • Have you written new tests for your changes?.
  • Have you successfully run make lint with your changes locally?
  • Have you successfully run make gen with your changes locally?
  • Have you successfully run make test with your changes locally?

@github-actions
Copy link

Benchmark Results

Benchmark results
?   	github.com/openclimatefix/data-platform/cmd	[no test files]
?   	github.com/openclimatefix/data-platform/internal/gen/ocf/dp	[no test files]
?   	github.com/openclimatefix/data-platform/internal/interceptors	[no test files]
PASS
ok  	github.com/openclimatefix/data-platform/internal/server/dummy	0.005s
{"level":"debug","time":"2025-11-26T17:38:06Z","message":"Running migrations"}
goos: linux
goarch: amd64
pkg: github.com/openclimatefix/data-platform/internal/server/postgres
cpu: AMD EPYC 7763 64-Core Processor                
BenchmarkPostgresClient/6144000/GetForecastAsTimeseries-4         	     151	   7602875 ns/op
BenchmarkPostgresClient/6144000/GetForecastAtTimestamp-4          	      38	  28892374 ns/op
BenchmarkPostgresClient/6144000/GetObservationsAsTimeseries-4     	     883	   1261007 ns/op
BenchmarkPostgresClient/6144000/CreateForecast-4                  	     258	   4246921 ns/op
PASS
ok  	github.com/openclimatefix/data-platform/internal/server/postgres	189.983s
?   	github.com/openclimatefix/data-platform/internal/server/postgres/gen	[no test files]
Benchmark vs base branch
goos: linux
goarch: amd64
pkg: github.com/openclimatefix/data-platform/internal/server/postgres
cpu: AMD EPYC 7763 64-Core Processor                
                                                     │ bench-main.txt │ bench-capacity-to-value-multiplier.txt │
                                                     │     sec/op     │     sec/op      vs base                │
PostgresClient/6144000/GetForecastAsTimeseries-4         4.826m ± ∞ ¹     7.603m ± ∞ ¹       ~ (p=1.000 n=1) ²
PostgresClient/6144000/GetForecastAtTimestamp-4         105.00m ± ∞ ¹     28.89m ± ∞ ¹       ~ (p=1.000 n=1) ²
PostgresClient/6144000/GetObservationsAsTimeseries-4     1.307m ± ∞ ¹     1.261m ± ∞ ¹       ~ (p=1.000 n=1) ²
PostgresClient/6144000/CreateForecast-4                  2.612m ± ∞ ¹     4.247m ± ∞ ¹       ~ (p=1.000 n=1) ²
geomean                                                  6.449m           5.857m        -9.19%
¹ need >= 6 samples for confidence interval at level 0.95
² need >= 4 samples to detect a difference at alpha level 0.05

@peterdudfield peterdudfield requested a review from devsjc November 26, 2025 17:49
Copy link
Contributor

@devsjc devsjc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good other than potentially some more test cases. I think there's probably still a discussion to be had around whether it's worth using NUMERIC/BIGINT here - if this is something we're likely to rub up against a lot; I don't think it would be too big of a hit since we're not doing much calculation with this value in the database anyway.

Comment on lines +123 to +131
{500000, 5000, 2, false},
{32767000, 32767, 3, false},
{32768000, 33, 6, false}, // Needs rounding, should go to 33 MW
{33000000, 33, 6, false},
{1000000000000, 1000, 9, false}, // 1TW
{32768000, 3277, 4, false}, // Needs rounding, should go to 33.77 MW (4.s.f.)
{33000000, 3300, 4, false},
{1000000000000, 10000, 8, false}, // 1TW
{12345678000, 12346, 6, false}, // 12 GW
{20233169, 20233, 3, false},
{1398373, 13984, 2, false}, // 1.3 MW
{444234720, 4442, 5, false}, // 444.2 MW (4.s.f.)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it worth adding in those cases you were seeing that caused this ticket in the first place?

Copy link
Contributor Author

@peterdudfield peterdudfield Dec 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The bottom three are, unless ive missed one

@devsjc devsjc changed the title Capacity to value multiplier fix(postgres): Store capacities with finer prefix Dec 1, 2025
@devsjc
Copy link
Contributor

devsjc commented Dec 8, 2025

I'm going to close this in favour of #92

@devsjc devsjc closed this Dec 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Different capacity numbers

3 participants