本文为您介绍如何通过SDK调用如下算法API:GetAivppAlgoJob- 获取AIVPP算法任务结果。
前提条件
已安装SDK,并已获取云账号AK信息。
接口参数
请求参数
字段名称 | 字段详情 |
JobId string | 创建任务接口返回的 JobId,输入后可以查询异步接口的生成的任务实时详情 示例值:5854bfa6-f002-43c2-8e1d-e9b2c28f9384 |
返回参数
字段名称 | 字段详情 |
RequestId string | Id of the request 示例值:68738E75-43C1-5AE5-9F3A-AFEF576D7B5F |
Success string | 是否调用成功。
示例值:True |
Code string | 状态码。 说明 200 表示成功。 示例值:200 |
Message string | 返回信息。 示例值:successful |
- Data object | 返回的数据内容。 |
--Completed boolean | 操作是否完成,取值范围: True:当前 Job 已经执行完成。 False:当前 Job 还在执行中。 示例值:False |
--CreateTime string | 任务创建时间。 示例值:2024-12-10 17:50:48 |
--Error string | 当前操作异常或者失败时的错误信息 示例值:"" |
--JobId string | 任务 ID。 示例值:5854bfa6-f002-43c2-8e1d-e9b2c28f9384 |
--Progress integer<int32> | 任务进度,取值范围为 0~100。 示例值:100 |
--- Response object | 计算任务的结果 |
----DebugInfo any | 调试信息 示例值:{} |
----JobType string | 计算任务类型,枚举值:LoadForecast PowerForecast 示例值:PowerForecast |
----Result any | 任务结果 示例值:{} |
--Status string | 任务状态,枚举值: RUNNING, SUCCESS, FAIL 示例值:RUNNING |
不同JobType对应的Result结果格式不同。需要根据JobType来分别解析Result内容。参考后续的返回结果示例。
返回示例
{
"RequestId": "68738E75-43C1-5AE5-9F3A-AFEF576D7B5F",
"Success": "True",
"Code": "200",
"Message": "successful",
"Data": {
"Completed": true,
"CreateTime": "2024-12-10 17:50:48",
"Error": "\"\"",
"JobId": "5854bfa6-f002-43c2-8e1d-e9b2c28f9384",
"Progress": 100,
"Response": {
"DebugInfo": "{}",
"JobType": "PowerForecast",
"Result": "{}"
},
"Status": "RUNNING"
}
}
不同JobType对应的Result结果格式不同。下文给出几个API的算法结果。
用电负荷预测结果示例
"result": [
{"runTime": "2023-05-06 20:00:00","value": 1.8},
{"runTime": "2023-05-06 20:15:00","value": 1.9},
{"runTime": "2023-05-06 20:30:00","value": 2.0},
{"runTime": "2023-05-06 20:45:00","value": 2.1}
]
value表示负荷,单位kW。
新能源功率预测结果示例
"result": [
{"runTime": "2023-05-06 20:00:00","value": 1.8},
{"runTime": "2023-05-06 20:15:00","value": 1.9},
{"runTime": "2023-05-06 20:30:00","value": 2.0},
{"runTime": "2023-05-06 20:45:00","value": 2.1}
]
value表示功率,单位kW。
储能运行优化策略结果示例
"result":[
{
"systemType":"ess",
"systemId": 2,
"optStrategy":[
{"runTime": "2024-12-10 18:00:00","value": -1000.45},
{"runTime": "2024-12-10 18:15:00","value": 1554.54},
...
{"runTime": "2024-12-11 23:45:00","value": -1000}
]
}
]
runTime表示时间段 左闭右开; value是功率 单位:kW, 正放负充。
SDK调用示例
Java SDK使用示例
当不需要并发调用时,可以使用Java同步的方式调用SDK;当需要并发调用时,使用Java异步的方式调用SDK。
Java同步(pom.xml):
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>brain_industrial20200920</artifactId>
<version>2.1.0</version>
</dependency>
Java同步(sample.java):
// This file is auto-generated, don't edit it. Thanks.
package com.aliyun.sample;
import com.aliyun.tea.*;
public class Sample {
/**
* <b>description</b> :
* <p>使用凭据初始化账号Client</p>
* @return Client
*
* @throws Exception
*/
public static com.aliyun.brain_industrial20200920.Client createClient() throws Exception {
// 工程代码建议使用更安全的无AK方式,凭据配置方式请参见: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);
// Endpoint 请参考 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.GetAivppAlgoJobRequest getAivppAlgoJobRequest = new com.aliyun.brain_industrial20200920.models.GetAivppAlgoJobRequest()
.setJobId("24628746-3742-2384-8df9-2e6e54679a2a");
com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions();
try {
// 复制代码运行请自行打印 API 的返回值
client.getAivppAlgoJobWithOptions(getAivppAlgoJobRequest, runtime);
} catch (TeaException error) {
// 此处仅做打印展示,请谨慎对待异常处理,在工程项目中切勿直接忽略异常。
// 错误 message
System.out.println(error.getMessage());
// 诊断地址
System.out.println(error.getData().get("Recommend"));
com.aliyun.teautil.Common.assertAsString(error.message);
} catch (Exception _error) {
TeaException error = new TeaException(_error.getMessage(), _error);
// 此处仅做打印展示,请谨慎对待异常处理,在工程项目中切勿直接忽略异常。
// 错误 message
System.out.println(error.getMessage());
// 诊断地址
System.out.println(error.getData().get("Recommend"));
com.aliyun.teautil.Common.assertAsString(error.message);
}
}
}
Java异步(pom.xml):
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>alibabacloud-brain_industrial20200920</artifactId>
<version>2.0.2</version>
</dependency>
Java异步(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 GetAivppAlgoJob {
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()
// Endpoint 请参考 https://api.aliyun.com/product/brain-industrial
.setEndpointOverride("brain-industrial.cn-hangzhou.aliyuncs.com")
//.setConnectTimeout(Duration.ofSeconds(30))
)
.build();
// Parameter settings for API request
GetAivppAlgoJobRequest getAivppAlgoJobRequest = GetAivppAlgoJobRequest.builder()
.jobId("24628746-3742-2384-8df9-2e6e54679a2a")
// 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<GetAivppAlgoJobResponse> response = client.getAivppAlgoJob(getAivppAlgoJobRequest);
// Synchronously get the return value of the API request
GetAivppAlgoJobResponse 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使用示例
Python依赖:
pip install alibabacloud_brain_industrial20200920==2.1.0
# -*- 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:
"""
使用凭据初始化账号Client
@return: Client
@throws Exception
"""
# 工程代码建议使用更安全的无AK方式,凭据配置方式请参见:https://help.aliyun.com/document_detail/378659.html。
credential = CredentialClient()
config = open_api_models.Config(
credential=credential
)
# Endpoint 请参考 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()
get_aivpp_algo_job_request = brain_industrial_20200920_models.GetAivppAlgoJobRequest(
job_id='24628746-3742-2384-8df9-2e6e54679a2a'
)
runtime = util_models.RuntimeOptions()
try:
# 复制代码运行请自行打印 API 的返回值
client.get_aivpp_algo_job_with_options(get_aivpp_algo_job_request, runtime)
except Exception as error:
# 此处仅做打印展示,请谨慎对待异常处理,在工程项目中切勿直接忽略异常。
# 错误 message
print(error.message)
# 诊断地址
print(error.data.get("Recommend"))
UtilClient.assert_as_string(error.message)
@staticmethod
async def main_async(
args: List[str],
) -> None:
client = Sample.create_client()
get_aivpp_algo_job_request = brain_industrial_20200920_models.GetAivppAlgoJobRequest(
job_id='24628746-3742-2384-8df9-2e6e54679a2a'
)
runtime = util_models.RuntimeOptions()
try:
# 复制代码运行请自行打印 API 的返回值
await client.get_aivpp_algo_job_with_options_async(get_aivpp_algo_job_request, runtime)
except Exception as error:
# 此处仅做打印展示,请谨慎对待异常处理,在工程项目中切勿直接忽略异常。
# 错误 message
print(error.message)
# 诊断地址
print(error.data.get("Recommend"))
UtilClient.assert_as_string(error.message)
if __name__ == '__main__':
Sample.main(sys.argv[1:])