Skip to content

Commit 4ff0151

Browse files
committed
Renaming of Balancing Authority to Region
Renaming of Balancing Authority to Region through all code and comments. This will also need updating through documentation.
1 parent 8127a92 commit 4ff0151

File tree

9 files changed

+92
-92
lines changed

9 files changed

+92
-92
lines changed

src/CarbonAware.DataSources/CarbonAware.DataSources.WattTime/src/Client/IWattTimeClient.cs

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -11,90 +11,90 @@ internal interface IWattTimeClient
1111
public const string NamedAuthenticationClient = "WattTimeAuthenticationClient";
1212

1313
/// <summary>
14-
/// Async method to get observed emission data for a given balancing authority and time period.
14+
/// Async method to get observed emission data for a given region and time period.
1515
/// </summary>
16-
/// <param name="balancingAuthorityAbbreviation">Balancing authority abbreviation</param>
16+
/// <param name="regionAbbreviation">Region abbreviation</param>
1717
/// <param name="startTime">Start time of the time period</param>
1818
/// <param name="endTime">End time of the time period</param>
1919
/// <returns>An <see cref="Task{IEnumerable}{GridEmissionDataPoint}"/> which contains all emissions data points in a period.</returns>
2020
/// <exception cref="WattTimeClientException">Can be thrown when errors occur connecting to WattTime client. See the WattTimeClientException class for documentation of expected status codes.</exception>
21-
Task<GridEmissionsDataResponse> GetDataAsync(string balancingAuthorityAbbreviation, DateTimeOffset startTime, DateTimeOffset endTime);
21+
Task<GridEmissionsDataResponse> GetDataAsync(string regionAbbreviation, DateTimeOffset startTime, DateTimeOffset endTime);
2222

2323
/// <summary>
24-
/// Async method to get observed emission data for a given balancing authority and time period.
24+
/// Async method to get observed emission data for a given region and time period.
2525
/// </summary>
26-
/// <param name="balancingAuthority">Balancing authority</param>
26+
/// <param name="region">Region</param>
2727
/// <param name="startTime">Start time of the time period</param>
2828
/// <param name="endTime">End time of the time period</param>
2929
/// <returns>An <see cref="Task{IEnumerable}{GridEmissionDataPoint}"/> which contains all emissions data points in a period.</returns>
3030
/// <exception cref="WattTimeClientException">Can be thrown when errors occur connecting to WattTime client. See the WattTimeClientException class for documentation of expected status codes.</exception>
31-
Task<GridEmissionsDataResponse> GetDataAsync(RegionResponse balancingAuthority, DateTimeOffset startTime, DateTimeOffset endTime);
31+
Task<GridEmissionsDataResponse> GetDataAsync(RegionResponse region, DateTimeOffset startTime, DateTimeOffset endTime);
3232

3333
/// <summary>
34-
/// Async method to get the most recent 24 hour forecasted emission data for a given balancing authority.
34+
/// Async method to get the most recent 24 hour forecasted emission data for a given region.
3535
/// </summary>
36-
/// <param name="balancingAuthorityAbbreviation">Balancing authority abbreviation</param>
36+
/// <param name="regionAbbreviation">region abbreviation</param>
3737
/// <returns>An <see cref="Task{Forecast}"/> which contains forecasted emissions data points.</returns>
3838
/// <exception cref="WattTimeClientException">Can be thrown when errors occur connecting to WattTime client. See the WattTimeClientException class for documentation of expected status codes.</exception>
39-
Task<ForecastEmissionsDataResponse> GetCurrentForecastAsync(string balancingAuthorityAbbreviation);
39+
Task<ForecastEmissionsDataResponse> GetCurrentForecastAsync(string regionAbbreviation);
4040

4141
/// <summary>
42-
/// Async method to get the most recent 24 hour forecasted emission data for a given balancing authority.
42+
/// Async method to get the most recent 24 hour forecasted emission data for a given region.
4343
/// </summary>
44-
/// <param name="balancingAuthority">Balancing authority</param>
44+
/// <param name="region">region</param>
4545
/// <returns>An <see cref="Task{Forecast}"/> which contains forecasted emissions data points.</returns>
4646
/// <exception cref="WattTimeClientException">Can be thrown when errors occur connecting to WattTime client. See the WattTimeClientException class for documentation of expected status codes.</exception>
47-
Task<ForecastEmissionsDataResponse> GetCurrentForecastAsync(RegionResponse balancingAuthority);
47+
Task<ForecastEmissionsDataResponse> GetCurrentForecastAsync(RegionResponse region);
4848

4949
/// <summary>
50-
/// Async method to get generated forecast at requested time and balancing authority.
50+
/// Async method to get generated forecast at requested time and region.
5151
/// </summary>
52-
/// <param name="region">Balancing authority abbreviation</param>
52+
/// <param name="region">region abbreviation</param>
5353
/// <param name="requestedAt">The historical time used to fetch the most recent forecast generated as of that time.</param>
5454
/// <returns>An <see cref="Task{Forecast}"/> which contains forecasted emissions data points or null if no Forecast generated at the requested time.</returns>
5555
/// <exception cref="WattTimeClientException">Can be thrown when errors occur connecting to WattTime client. See the WattTimeClientException class for documentation of expected status codes.</exception>
5656
Task<HistoricalForecastEmissionsDataResponse?> GetForecastOnDateAsync(string region, DateTimeOffset requestedAt);
5757

5858
/// <summary>
59-
/// Async method to get generated forecast at requested time and balancing authority.
59+
/// Async method to get generated forecast at requested time and region.
6060
/// </summary>
61-
/// <param name="balancingAuthority">Balancing authority</param>
61+
/// <param name="region">region</param>
6262
/// <param name="requestedAt">The historical time used to fetch the most recent forecast generated as of that time.</param>
6363
/// <returns>An <see cref="Task{Forecast}"/> which contains forecasted emissions data points or null if no Forecast generated at the requested time.</returns>
6464
/// <exception cref="WattTimeClientException">Can be thrown when errors occur connecting to WattTime client. See the WattTimeClientException class for documentation of expected status codes.</exception>
65-
Task<HistoricalForecastEmissionsDataResponse?> GetForecastOnDateAsync(RegionResponse balancingAuthority, DateTimeOffset requestedAt);
65+
Task<HistoricalForecastEmissionsDataResponse?> GetForecastOnDateAsync(RegionResponse region, DateTimeOffset requestedAt);
6666

6767
/// <summary>
68-
/// Async method to get the balancing authority for a given location.
68+
/// Async method to get the region for a given location.
6969
/// </summary>
7070
/// <param name="latitude">Latitude of the location</param>
7171
/// <param name="longitude">Longitude of the location</param>
72-
/// <returns>An <see cref="Task{BalancingAuthority}"/> which contains the balancing authority details.</returns>
72+
/// <returns>An <see cref="Task{region}"/> which contains the region details.</returns>
7373
/// <exception cref="WattTimeClientException">Can be thrown when errors occur connecting to WattTime client. See the WattTimeClientException class for documentation of expected status codes.</exception>
7474
Task<RegionResponse> GetRegionAsync(string latitude, string longitude);
7575

7676
/// <summary>
77-
/// Async method to get the balancing authority abbreviation for a given location.
77+
/// Async method to get the region abbreviation for a given location.
7878
/// </summary>
7979
/// <param name="latitude">Latitude of the location</param>
8080
/// <param name="longitude">Longitude of the location</param>
81-
/// <returns>A string which contains the balancing authority details.</returns>
81+
/// <returns>A string which contains the region details.</returns>
8282
/// <exception cref="WattTimeClientException">Can be thrown when errors occur connecting to WattTime client. See the WattTimeClientException class for documentation of expected status codes.</exception>
83-
Task<string?> GetBalancingAuthorityAbbreviationAsync(string latitude, string longitude);
83+
Task<string?> GetRegionAbbreviationAsync(string latitude, string longitude);
8484

8585
/// <summary>
86-
/// Async method to get binary data (representing a zip file) of the historical emissions data for the given balancing authority.
86+
/// Async method to get binary data (representing a zip file) of the historical emissions data for the given region.
8787
/// </summary>
88-
/// <param name="balancingAuthorityAbbreviation">Balancing authority abbreviation</param>
88+
/// <param name="regionAbbreviation">region abbreviation</param>
8989
/// <returns>An <see cref="Task{Stream}"/> which contains the binary data stream of the .zip file.</returns>
9090
/// <exception cref="WattTimeClientException">Can be thrown when errors occur connecting to WattTime client. See the WattTimeClientException class for documentation of expected status codes.</exception>
91-
Task<Stream> GetHistoricalDataAsync(string balancingAuthorityAbbreviation);
91+
Task<Stream> GetHistoricalDataAsync(string regionAbbreviation);
9292

9393
/// <summary>
94-
/// Async method to get binary data (representing a zip file) of the historical emissions data for the given balancing authority.
94+
/// Async method to get binary data (representing a zip file) of the historical emissions data for the given region.
9595
/// </summary>
96-
/// <param name="balancingAuthority">Balancing authority</param>
96+
/// <param name="region">region</param>
9797
/// <returns>An <see cref="Task{Stream}"/> which contains the data Stream of the .zip file.</returns>
9898
/// <exception cref="WattTimeClientException">Can be thrown when errors occur connecting to WattTime client. See the WattTimeClientException class for documentation of expected status codes.</exception>
99-
Task<Stream> GetHistoricalDataAsync(RegionResponse balancingAuthority);
99+
Task<Stream> GetHistoricalDataAsync(RegionResponse region);
100100
}

src/CarbonAware.DataSources/CarbonAware.DataSources.WattTime/src/Client/WattTimeClient.cs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public Task<GridEmissionsDataResponse> GetDataAsync(RegionResponse region, DateT
8888
public async Task<ForecastEmissionsDataResponse> GetCurrentForecastAsync(string region)
8989
{
9090

91-
_log.LogInformation("Requesting current forecast from balancing authority {balancingAuthority}", region);
91+
_log.LogInformation("Requesting current forecast from region: {region}", region);
9292

9393
var parameters = new Dictionary<string, string>()
9494
{
@@ -109,15 +109,15 @@ public async Task<ForecastEmissionsDataResponse> GetCurrentForecastAsync(string
109109
}
110110

111111
/// <inheritdoc/>
112-
public Task<ForecastEmissionsDataResponse> GetCurrentForecastAsync(RegionResponse balancingAuthority)
112+
public Task<ForecastEmissionsDataResponse> GetCurrentForecastAsync(RegionResponse region)
113113
{
114-
return this.GetCurrentForecastAsync(balancingAuthority.Region);
114+
return this.GetCurrentForecastAsync(region.Region);
115115
}
116116

117117
/// <inheritdoc/>
118118
public async Task<HistoricalForecastEmissionsDataResponse?> GetForecastOnDateAsync(string region, DateTimeOffset requestedAt)
119119
{
120-
_log.LogInformation($"Requesting forecast from balancingAuthority {region} generated at {requestedAt}.");
120+
_log.LogInformation($"Requesting forecast from region {region} generated at {requestedAt}.");
121121

122122
var parameters = new Dictionary<string, string>()
123123
{
@@ -147,24 +147,24 @@ public Task<ForecastEmissionsDataResponse> GetCurrentForecastAsync(RegionRespons
147147
/// <inheritdoc/>
148148
public async Task<RegionResponse> GetRegionAsync(string latitude, string longitude)
149149
{
150-
_log.LogInformation("Requesting balancing authority for lattitude {lattitude} and longitude {longitude}", latitude, longitude);
151-
return await GetBalancingAuthorityFromCacheAsync(latitude, longitude);
150+
_log.LogInformation("Requesting region for lattitude {lattitude} and longitude {longitude}", latitude, longitude);
151+
return await GetRegionFromCacheAsync(latitude, longitude);
152152
}
153153

154154
/// <inheritdoc/>
155-
public async Task<string?> GetBalancingAuthorityAbbreviationAsync(string latitude, string longitude)
155+
public async Task<string?> GetRegionAbbreviationAsync(string latitude, string longitude)
156156
{
157157
return (await this.GetRegionAsync(latitude, longitude))?.Region;
158158
}
159159

160160
/// <inheritdoc/>
161-
public async Task<Stream> GetHistoricalDataAsync(string balancingAuthorityAbbreviation)
161+
public async Task<Stream> GetHistoricalDataAsync(string regionAbbreviation)
162162
{
163-
_log.LogInformation("Requesting historical data for balancing authority {balancingAuthority}", balancingAuthorityAbbreviation);
163+
_log.LogInformation("Requesting historical data for region {regionAbbreviation}", regionAbbreviation);
164164

165165
var parameters = new Dictionary<string, string>()
166166
{
167-
{ QueryStrings.Region, balancingAuthorityAbbreviation }
167+
{ QueryStrings.Region, regionAbbreviation }
168168
};
169169

170170
var url = BuildUrlWithQueryString(Paths.Historical, parameters);
@@ -179,9 +179,9 @@ public async Task<Stream> GetHistoricalDataAsync(string balancingAuthorityAbbrev
179179
}
180180

181181
/// <inheritdoc/>
182-
public Task<Stream> GetHistoricalDataAsync(RegionResponse balancingAuthority)
182+
public Task<Stream> GetHistoricalDataAsync(RegionResponse region)
183183
{
184-
return this.GetHistoricalDataAsync(balancingAuthority.Region);
184+
return this.GetHistoricalDataAsync(region.Region);
185185
}
186186

187187
private async Task<HttpResponseMessage> GetAsyncWithAuthRetry(string uriPath)
@@ -293,10 +293,10 @@ private string BuildUrlWithQueryString(string url, IDictionary<string, string> q
293293
return result;
294294
}
295295

296-
private async Task<RegionResponse> GetBalancingAuthorityFromCacheAsync(string latitude, string longitude)
296+
private async Task<RegionResponse> GetRegionFromCacheAsync(string latitude, string longitude)
297297
{
298298
var key = new Tuple<string, string>(latitude, longitude);
299-
var balancingAuthority = await this._memoryCache.GetOrCreateAsync(key, async entry =>
299+
var region = await this._memoryCache.GetOrCreateAsync(key, async entry =>
300300
{
301301
var parameters = new Dictionary<string, string>()
302302
{
@@ -312,11 +312,11 @@ private async Task<RegionResponse> GetBalancingAuthorityFromCacheAsync(string la
312312
{ QueryStrings.SignalType, SignalTypes.co2_moer }
313313
};
314314
var result = await this.MakeRequestGetStreamAsync(Paths.RegionFromLocation, parameters, tags);
315-
var baValue = await JsonSerializer.DeserializeAsync<RegionResponse>(result, _options) ?? throw new WattTimeClientException($"Error getting Balancing Authority for latitude {latitude} and longitude {longitude}");
316-
entry.AbsoluteExpirationRelativeToNow = TimeSpan.FromSeconds(_configuration.BalancingAuthorityCacheTTL);
317-
entry.Value = baValue;
318-
return baValue;
315+
var regionResponse = await JsonSerializer.DeserializeAsync<RegionResponse>(result, _options) ?? throw new WattTimeClientException($"Error getting Region for latitude {latitude} and longitude {longitude}");
316+
entry.AbsoluteExpirationRelativeToNow = TimeSpan.FromSeconds(_configuration.RegionCacheTTL);
317+
entry.Value = regionResponse;
318+
return regionResponse;
319319
});
320-
return balancingAuthority;
320+
return region;
321321
}
322322
}

src/CarbonAware.DataSources/CarbonAware.DataSources.WattTime/src/Client/WattTimeClientHttpException.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public WattTimeClientHttpException(string message, HttpResponseMessage response)
2222
/// Gets the status code for the exception. See remarks for the status codes that can be returned.
2323
/// </summary>
2424
/// <remarks>
25-
/// 400: Returned when the lattitude/longitude provided aren't associated with a known balancing authority.
25+
/// 400: Returned when the lattitude/longitude provided aren't associated with a known region.
2626
/// 401: Returned when no authorization header is passed. You should not expect to receive this status code.
2727
/// 403: Returned when an invalid username or password is used for login. Please check your configuration and verify your account when this error is received.
2828
/// 429: Returned when the number of requests has exceeded the WattTime rate limit, currently at 3,000 per rolling 5 minute window. For current limits, see https://www.watttime.org/api-documentation/#restrictions

src/CarbonAware.DataSources/CarbonAware.DataSources.WattTime/src/Configuration/WattTimeClientConfiguration.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ internal class WattTimeClientConfiguration
3232
public string AuthenticationBaseUrl { get; set; } = "https://api.watttime.org/";
3333

3434
/// <summary>
35-
/// Gets or sets the cached expiration time (in seconds) for a BalancingAuthority instance.
35+
/// Gets or sets the cached expiration time (in seconds) for a Region instance.
3636
/// It defaults to 86400 secs.
3737
/// </summary>
38-
public int BalancingAuthorityCacheTTL { get; set; } = 86400;
38+
public int RegionCacheTTL { get; set; } = 86400;
3939

4040
/// <summary>
4141
/// Validate that this object is properly configured.

src/CarbonAware.DataSources/CarbonAware.DataSources.WattTime/src/Model/GridEmissionDataPoint.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
namespace CarbonAware.DataSources.WattTime.Model;
44

55
/// <summary>
6-
/// An object describing the emissions for a given time period and balancing authority.
6+
/// An object describing the emissions for a given time period and region.
77
/// </summary>
88
[Serializable]
99
internal record GridEmissionDataPoint

src/CarbonAware.DataSources/CarbonAware.DataSources.WattTime/src/Model/RegionResponse.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
namespace CarbonAware.DataSources.WattTime.Model;
44

55
/// <summary>
6-
/// The details of the balancing authority (BA) serving a particular location.
6+
/// The details of the region serving a particular location.
77
/// </summary>
88
[Serializable]
99
internal record RegionResponse

0 commit comments

Comments
 (0)