Power load prediction
This topic describes how to use an SDK to call the CreateLoadForecastJob API and create a load prediction task.
Prerequisites
You have installed the SDK and obtained the AccessKey information for your Alibaba Cloud account.
API parameters
Request parameters
Field name | Field details |
DeviceType string | The device type. The supported device types for each systemType are as follows: System type: Device type
Example:electricityMeter |
- HistoryData array<object> | The historical load data. 90 days of historical data is required. |
-- object | |
----RunTime string | The time for each {freq} minute interval, in the "yyyy-MM-dd HH:mm:ss" format. The data frequency must snap to the freq field. Example:2025-12-12 00:00:00 |
----Value number<double> | The load data. Example:1.0 |
Freq string | The default value is 15min. This must be consistent with the data frequency of historyData. Enumeration values:
Example:FIFTEEN_MINEnumeration values:FIFTEEN_MIN, FIVE_MIN, ONE_HOUR, ONE_DAY |
Duration integer<int32> | The prediction duration in days, starting from the run date (inclusive). This parameter is optional. The default value is 1 day. Example:1 |
SystemType string | The system type. Supported system types:
Example:load |
RunDate string | The run date, accurate to the day, in the "yyyy-MM-dd" format. Example:2025-12-12 |
TimeZone string | The time zone. The default time zone is Asia/Shanghai. Example:Asia/Shanghai |
ModelVersion string | The version number of the model. The default value is latest. Example:latest |
BusinessKey string | The business key, such as the name or ID of a station. Example:stationA |
ForecastHorizon string | The prediction time scale. Enumeration values:
Example:DAY_AHEAD |
DataMode string | The data mode for this call. Enumeration values:
Example:FULL |
Request example
The following is an example in JSON format:
{
"historyData":[
{"runTime": "2023-05-06 20:00:00","value": 1.8},
{"runTime": "2023-05-06 20:15:00","value": 1.9},
...
{"runTime": "2023-08-05 19:45:00","value": 1.7}
],
"systemType": "load",
"deviceType": "electricityMeter",
"runDate": "2023-08-06",
"duration": 1,
"freq": "FIFTEEN_MIN",
"timeZone": "Asia/Shanghai",
"modelVersion": "latest",
"businessKey": "stationA"
}Response parameters
Field name | Field details |
RequestId string | The ID of the request. Example:68738E75-43C1-5AE5-9F3A-AFEF576D7B5F |
Success string | Indicates whether the call was successful.
Example:True |
Code string | The status code. Note A status code of 200 indicates success. Example:200 |
Message string | The returned message. Example:successful |
- Data object | Returns the details of the job. |
--Completed boolean | Indicates whether the operation is complete. Valid values: True: The current job is complete. False: The current job is still running. Example:True |
--CreateTime string | The time when the task was created. Example:2024-12-22 00:00:21 |
--Error string | The error message returned if the current operation is abnormal or fails. Example:"" |
--JobId string | The ID of the algorithm calculation task. Example:8c0ca18a-246a-4acd-80ca-e16d8ff5ef33 |
--Progress integer<int32> | The progress. Example:25 |
--- Response object | The result of the calculation task. |
----DebugInfo any | The debugging information. Example:{} |
----JobType string | The type of the calculation task. Enumeration values: LoadForecast, PowerForecast Example:PowerForecast |
----Result any | The result of the calculation task. Example:{} |
--Status string | The task status. Enumeration values: RUNNING, SUCCESS, FAIL Example:RUNNING |
This is an asynchronous task. To obtain the final result, you must use the JobId to query the result.
Response example
{
"RequestId": "68738E75-43C1-5AE5-9F3A-AFEF576D7B5F",
"Success": "True",
"Code": "200",
"Message": "successful",
"Data": {
"Completed": true,
"CreateTime": "2024-12-22 00:00:21",
"Error": "\"\"",
"JobId": "8c0ca18a-246a-4acd-80ca-e16d8ff5ef33",
"Progress": 25,
"Response": {
"DebugInfo": "{}",
"JobType": "PowerForecast",
"Result": "{}"
},
"Status": "RUNNING"
}
}SDK call examples
Java SDK example
Use the synchronous method for non-concurrent calls and the asynchronous method for concurrent calls.
Java synchronous (pom.xml):
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>brain_industrial20200920</artifactId>
<version>2.1.2</version>
</dependency>Java synchronous (sample.java):
// This file is auto-generated, don't edit it. Thanks.
package com.aliyun.sample;
import com.aliyun.tea.*;
public class Sample {
/**
* description :
* <p>Initializes the account Client using credentials.</p>
* @return Client
*
* @throws Exception
*/
public static com.aliyun.brain_industrial20200920.Client createClient() throws Exception {
// We recommend that you use a more secure method that does not require an AccessKey pair for your project. For more information about how to configure credentials, see https://help.aliyun.com/document_detail/378657.html.
com.aliyun.credentials.Client credential = new com.aliyun.credentials.Client();
com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config()
.setCredential(credential);
// For the endpoint, see https://api.aliyun.com/product/brain-industrial
config.endpoint = "brain-industrial.cn-hangzhou.aliyuncs.com";
return new com.aliyun.brain_industrial20200920.Client(config);
}
public static void main(String[] args_) throws Exception {
com.aliyun.brain_industrial20200920.Client client = Sample.createClient();
com.aliyun.brain_industrial20200920.models.CreateLoadForecastJobRequest.CreateLoadForecastJobRequestHistoryData historyData0 = new com.aliyun.brain_industrial20200920.models.CreateLoadForecastJobRequest.CreateLoadForecastJobRequestHistoryData()
.setRunTime("2025-01-01 00:00:00")
.setValue(3.5D);
com.aliyun.brain_industrial20200920.models.CreateLoadForecastJobRequest createLoadForecastJobRequest = new com.aliyun.brain_industrial20200920.models.CreateLoadForecastJobRequest()
.setDeviceType("electricityMeter")
.setHistoryData(java.util.Arrays.asList(
historyData0
))
.setFreq("FIFTEEN_MIN")
.setDuration(1)
.setSystemType("load")
.setRunDate("2025-01-02")
.setBusinessKey("stationA");
com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions();
try {
// Copy the code to run it, and print the return value of the API.
client.createLoadForecastJobWithOptions(createLoadForecastJobRequest, runtime);
} catch (TeaException error) {
// This is for printing and display purposes only. Handle exceptions with caution. Do not ignore exceptions in your project.
// Error message
System.out.println(error.getMessage());
// Diagnosis address
System.out.println(error.getData().get("Recommend"));
com.aliyun.teautil.Common.assertAsString(error.message);
} catch (Exception _error) {
TeaException error = new TeaException(_error.getMessage(), _error);
// This is for printing and display purposes only. Handle exceptions with caution. Do not ignore exceptions in your project.
// Error message
System.out.println(error.getMessage());
// Diagnosis address
System.out.println(error.getData().get("Recommend"));
com.aliyun.teautil.Common.assertAsString(error.message);
}
}
}Asynchronous Java (pom.xml):
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>alibabacloud-brain_industrial20200920</artifactId>
<version>2.0.4</version>
</dependency>Asynchronous Java sample (sample.java):
// This file is auto-generated, don't edit it. Thanks.
package demo;
import com.aliyun.auth.credentials.Credential;
import com.aliyun.auth.credentials.provider.StaticCredentialProvider;
import com.aliyun.core.http.HttpClient;
import com.aliyun.core.http.HttpMethod;
import com.aliyun.core.http.ProxyOptions;
import com.aliyun.httpcomponent.httpclient.ApacheAsyncHttpClientBuilder;
import com.aliyun.sdk.service.brain_industrial20200920.models.*;
import com.aliyun.sdk.service.brain_industrial20200920.*;
import com.google.gson.Gson;
import darabonba.core.RequestConfiguration;
import darabonba.core.client.ClientOverrideConfiguration;
import darabonba.core.utils.CommonUtil;
import darabonba.core.TeaPair;
//import javax.net.ssl.KeyManager;
//import javax.net.ssl.X509TrustManager;
import java.net.InetSocketAddress;
import java.time.Duration;
import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.io.*;
public class CreateLoadForecastJob {
public static void main(String[] args) throws Exception {
// HttpClient Configuration
/*HttpClient httpClient = new ApacheAsyncHttpClientBuilder()
.connectionTimeout(Duration.ofSeconds(10)) // Set the connection timeout time, the default is 10 seconds
.responseTimeout(Duration.ofSeconds(10)) // Set the response timeout time, the default is 20 seconds
.maxConnections(128) // Set the connection pool size
.maxIdleTimeOut(Duration.ofSeconds(50)) // Set the connection pool timeout, the default is 30 seconds
// Configure the proxy
.proxy(new ProxyOptions(ProxyOptions.Type.HTTP, new InetSocketAddress("<your-proxy-hostname>", 9001))
.setCredentials("<your-proxy-username>", "<your-proxy-password>"))
// If it is an https connection, you need to configure the certificate, or ignore the certificate(.ignoreSSL(true))
.x509TrustManagers(new X509TrustManager[]{})
.keyManagers(new KeyManager[]{})
.ignoreSSL(false)
.build();*/
// Configure Credentials authentication information, including ak, secret, token
StaticCredentialProvider provider = StaticCredentialProvider.create(Credential.builder()
// Please ensure that the environment variables ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET are set.
.accessKeyId(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"))
.accessKeySecret(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"))
//.securityToken(System.getenv("ALIBABA_CLOUD_SECURITY_TOKEN")) // use STS token
.build());
// Configure the Client
AsyncClient client = AsyncClient.builder()
.region("cn-hangzhou") // Region ID
//.httpClient(httpClient) // Use the configured HttpClient, otherwise use the default HttpClient (Apache HttpClient)
.credentialsProvider(provider)
//.serviceConfiguration(Configuration.create()) // Service-level configuration
// Client-level configuration rewrite, can set Endpoint, Http request parameters, etc.
.overrideConfiguration(
ClientOverrideConfiguration.create()
// For the endpoint, see https://api.aliyun.com/product/brain-industrial
.setEndpointOverride("brain-industrial.cn-hangzhou.aliyuncs.com")
//.setConnectTimeout(Duration.ofSeconds(30))
)
.build();
// Parameter settings for API request
CreateLoadForecastJobRequest.HistoryData historyData0 = CreateLoadForecastJobRequest.HistoryData.builder()
.runTime("2025-01-01 00:00:00")
.value(3.5D)
.build();
CreateLoadForecastJobRequest createLoadForecastJobRequest = CreateLoadForecastJobRequest.builder()
.deviceType("electricityMeter")
.historyData(java.util.Arrays.asList(
historyData0
))
.freq("FIFTEEN_MIN")
.duration(1)
.systemType("load")
.runDate("2025-01-02")
.businessKey("stationA")
// Request-level configuration rewrite, can set Http request parameters, etc.
// .requestConfiguration(RequestConfiguration.create().setHttpHeaders(new HttpHeaders()))
.build();
// Asynchronously get the return value of the API request
CompletableFuture<CreateLoadForecastJobResponse> response = client.createLoadForecastJob(createLoadForecastJobRequest);
// Synchronously get the return value of the API request
CreateLoadForecastJobResponse resp = response.get();
System.out.println(new Gson().toJson(resp));
// Asynchronous processing of return values
/*response.thenAccept(resp -> {
System.out.println(new Gson().toJson(resp));
}).exceptionally(throwable -> { // Handling exceptions
System.out.println(throwable.getMessage());
return null;
});*/
// Finally, close the client
client.close();
}
}Python SDK example
Python dependencies:
pip install alibabacloud_brain_industrial20200920==2.1.2# -*- coding: utf-8 -*-
# This file is auto-generated, don't edit it. Thanks.
import os
import sys
from typing import List
from alibabacloud_brain_industrial20200920.client import Client as brain_industrial20200920Client
from alibabacloud_credentials.client import Client as CredentialClient
from alibabacloud_tea_openapi import models as open_api_models
from alibabacloud_brain_industrial20200920 import models as brain_industrial_20200920_models
from alibabacloud_tea_util import models as util_models
from alibabacloud_tea_util.client import Client as UtilClient
class Sample:
def __init__(self):
pass
@staticmethod
def create_client() -> brain_industrial20200920Client:
"""
Initializes the account Client using credentials.
@return: Client
@throws Exception
"""
# We recommend that you use a more secure method that does not require an AccessKey pair for your project. For more information about how to configure credentials, see https://help.aliyun.com/document_detail/378659.html.
credential = CredentialClient()
config = open_api_models.Config(
credential=credential
)
# For the endpoint, see https://api.aliyun.com/product/brain-industrial
config.endpoint = f'brain-industrial.cn-hangzhou.aliyuncs.com'
return brain_industrial20200920Client(config)
@staticmethod
def main(
args: List[str],
) -> None:
client = Sample.create_client()
history_data_0 = brain_industrial_20200920_models.CreateLoadForecastJobRequestHistoryData(
run_time='2025-01-01 00:00:00',
value=3.5
)
create_load_forecast_job_request = brain_industrial_20200920_models.CreateLoadForecastJobRequest(
device_type='electricityMeter',
history_data=[
history_data_0
],
freq='FIFTEEN_MIN',
duration=1,
system_type='load',
run_date='2025-01-02',
business_key='stationA'
)
runtime = util_models.RuntimeOptions()
try:
# Copy the code to run it, and print the return value of the API.
client.create_load_forecast_job_with_options(create_load_forecast_job_request, runtime)
except Exception as error:
# This is for printing and display purposes only. Handle exceptions with caution. Do not ignore exceptions in your project.
# Error message
print(error.message)
# Diagnosis address
print(error.data.get("Recommend"))
UtilClient.assert_as_string(error.message)
@staticmethod
async def main_async(
args: List[str],
) -> None:
client = Sample.create_client()
history_data_0 = brain_industrial_20200920_models.CreateLoadForecastJobRequestHistoryData(
run_time='2025-01-01 00:00:00',
value=3.5
)
create_load_forecast_job_request = brain_industrial_20200920_models.CreateLoadForecastJobRequest(
device_type='electricityMeter',
history_data=[
history_data_0
],
freq='FIFTEEN_MIN',
duration=1,
system_type='load',
run_date='2025-01-02',
business_key='stationA'
)
runtime = util_models.RuntimeOptions()
try:
# Copy the code to run it, and print the return value of the API.
await client.create_load_forecast_job_with_options_async(create_load_forecast_job_request, runtime)
except Exception as error:
# This is for printing and display purposes only. Handle exceptions with caution. Do not ignore exceptions in your project.
# Error message
print(error.message)
# Diagnosis address
print(error.data.get("Recommend"))
UtilClient.assert_as_string(error.message)
if __name__ == '__main__':
Sample.main(sys.argv[1:])