Skip to content

Commit

Permalink
NET-417: initial Solcast irradiation cloud integration.
Browse files Browse the repository at this point in the history
  • Loading branch information
msqr committed Oct 29, 2024
1 parent b7a84be commit 8e319c4
Show file tree
Hide file tree
Showing 6 changed files with 717 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@
package net.solarnetwork.central.c2c.biz.impl;

import static net.solarnetwork.util.ObjectUtils.requireNonNullArgument;
import static net.solarnetwork.util.StringUtils.nonEmptyString;
import java.time.Clock;
import java.time.Duration;
import java.time.format.DateTimeParseException;
import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedHashMap;
Expand All @@ -42,6 +44,7 @@
import net.solarnetwork.central.c2c.dao.CloudDatumStreamMappingConfigurationDao;
import net.solarnetwork.central.c2c.dao.CloudDatumStreamPropertyConfigurationDao;
import net.solarnetwork.central.c2c.dao.CloudIntegrationConfigurationDao;
import net.solarnetwork.central.c2c.domain.CloudDatumStreamConfiguration;
import net.solarnetwork.settings.MultiValueSettingSpecifier;
import net.solarnetwork.settings.SettingSpecifier;
import net.solarnetwork.settings.support.BasicMultiValueSettingSpecifier;
Expand All @@ -62,9 +65,6 @@ public abstract class BaseSolcastCloudDatumStreamService
/** The setting for longitude. */
public static final String LONGITUDE_SETTING = "lon";

/** The setting for desired parameters. */
public static final String PARAMETERS_SETTING = "parameters";

/** The setting for azimuth. */
public static final String AZIMUTH_SETTING = "azimuth";

Expand All @@ -81,7 +81,7 @@ public abstract class BaseSolcastCloudDatumStreamService
public static final String DEFAULT_PARAMETERS = "air_temp,dni,ghi";

/** The {@code resolution} default value. */
public static final Duration DEFAULT_RESOLUTION = Duration.ofMinutes(30);
public static final Duration DEFAULT_RESOLUTION = Duration.ofMinutes(5);

/** The Solcast supported resolutions. */
public static final Set<Duration> SUPPORTED_RESOLUTIONS;
Expand Down Expand Up @@ -173,4 +173,34 @@ public BaseSolcastCloudDatumStreamService(String serviceIdentifier, String displ
this.clock = requireNonNullArgument(clock, "clock");
}

/**
* Resolve a resolution setting value.
*
* <p>
* The returned resolution will be limited to those in the
* {@link #SUPPORTED_RESOLUTIONS} set. If no {@link #RESOLUTION_SETTING} is
* available, or is not a supported resolution, then
* {@link #DEFAULT_RESOLUTION} will be returned.
* </p>
*
* @param datumStream
* the datum stream to resolve the resolution setting from
* @return the resolution, never {@literal null}
*/
public static Duration resolveResolution(CloudDatumStreamConfiguration datumStream) {
String resoValue = nonEmptyString(datumStream.serviceProperty(RESOLUTION_SETTING, String.class));
Duration result = DEFAULT_RESOLUTION;
if ( resoValue != null ) {
try {
result = Duration.parse(resoValue);
} catch ( DateTimeParseException e ) {
// ignore and fall back to default
}
}
if ( !SUPPORTED_RESOLUTIONS.contains(result) ) {
result = DEFAULT_RESOLUTION;
}
return result;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,14 @@ public class SolcastCloudIntegrationService extends BaseRestOperationsCloudInteg
/** The service identifier. */
public static final String SERVICE_IDENTIFIER = "s10k.c2c.i9n.solcast";

/** An API key setting name. */
public static final String API_KEY_SETTING = "apiKey";

/** The base URL to the Solcast API. */
public static final URI BASE_URI = URI.create("https://api.solcast.com.au");

/** An API key setting name. */
public static final String API_KEY_SETTING = "apiKey";
/** The URL path for life radiation and weather data. */
public static final String LIVE_RADIATION_URL_PATH = "/data/live/radiation_and_weather";

/** The latitude URL query parameter name. */
public static final String LATITUDE_PARAM = "latitude";
Expand All @@ -72,8 +75,20 @@ public class SolcastCloudIntegrationService extends BaseRestOperationsCloudInteg
/** The hours URL query parameter name. */
public static final String HOURS_PARAM = "hours";

/** The URL path for life radiation and weather data. */
private static final String LIVE_RADIATION_URL_PATH = "/data/live/radiation_and_weather";
/** The azimuth URL query parameter name. */
public static final String AZIMUTH_PARAM = "azimuth";

/** The tilt URL query parameter name. */
public static final String TILT_PARAM = "tilt";

/** The array type URL query parameter name. */
public static final String ARRAY_TYPE_PARAM = "array_type";

/** The output parameters URL query parameter name. */
public static final String OUTPUT_PARAMETERS_PARAM = "output_parameters";

/** The period URL query parameter name. */
public static final String PERIOD_PARAM = "period";

/**
* The well-known URLs.
Expand Down
Loading

0 comments on commit 8e319c4

Please sign in to comment.