CDN加速

时序预测

更新时间:2019-12-12 17:32:11
适用产品:定制化接口

接口描述

时间序列预测,根据历史一段时间数据,预测未来一段时间数值

请求参数

参数名称类型必填描述
datadict输入的基础数据。格式如下 "data": """ts-bw 1569725450-12000.55 1569725750-13000.98 1569726050-13600.98 1569726350-13800.98 """ 可参考示例
frequencydict参数2:周期 5分钟粒度时序数据,周期按天,则为288 5分钟粒度时序数据,周期按周,则为288*7 可参考示例
modedict参数3:时序分解的方式:(1)加法模式:additive;(2)乘法模式:multiplicative 可参考示例
predictNumdict参数4:预测长度 例如:如5分钟粒度数据预测长度为30,则预测未来150分钟的数据。 注意:输入时序长度应至少大于2个周期,如周期是288,则时序长度应大于288*2,否则会异常 可参考示例

返回参数

参数名称类型描述
datadict(1)函数返回格式 result列表,alpha,beta,gamma,rmse (2)输出例子: [29379.4942, 29400.7056, 29421.9465],0.9899,0.0,0.1,13993.0560
codestring返回调用结果的状态
messagestring调用接口,返回状态码的说明

错误码

错误代码(code)描述(message)HTTP状态码语义
30052002post字段没有数据200

示例

示例说明
请求示例
复制
#!/usr/bin/env python
# -- coding: utf-8 --


import requests
import sys
import os
import json
import base64
import time
from hashlib import sha256

url = 'http://open.chinanetcenter.com/aiops/v1/time-series/predict'

username = 'xxx'
apikey = 'xxx'
__curPath__ = os.path.split(os.path.realpath(__file__))[0]


def getDate():
    import datetime
    GMT_FORMAT = '%a, %d %b %Y %H:%M:%S GMT'
    date_gmt = datetime.datetime.utcnow().strftime(GMT_FORMAT)
    print("getDate: " + date_gmt)
    return date_gmt


def sha(date):
    import hmac
    print("sha: " + date)
    signed_apikey = hmac.new(apikey.encode(
        'utf-8'), date.encode('utf-8'), sha256).digest()
    signed_apikey = base64.b64encode(signed_apikey)
    print("sha: " + signed_apikey.decode())
    return signed_apikey


def encode(time):
    print("encode: " + time.decode())
    msg = username + ":" + time.decode()
    result = base64.b64encode(msg.encode('utf-8'))
    print("encode: " + result.decode())
    return result


def getAuth():
    return encode(sha(getDate()))

def getABase64StrFromFile(fname):
    with open(fname, 'rb') as f:
        c = f.read()
        c = base64.b64encode(c)
        return str(c, encoding='utf-8') 

def connect():
    auth = getAuth()
    auth = 'Basic ' + auth.decode()
    d = {"data": """ts-bw
    1569725450-12000.55
    1569725750-13000.98
    1569726050-13600.98
    1569726350-13800.98
    """,
        "frequency":2, "mode":"additive","predictNum":2}
    headers = {'Content-Type': 'application/json', 'Accept': "application/json",
               "Date": getDate(), 'Authorization': auth}
    r = requests.post(url, headers=headers, data=json.dumps(d))
    ret = r.text
    print(ret)

if __name__ == '__main__':
    connect()
返回示例
复制
{"code": "0", "message": "Success", "data": [[14034.03601226176, 14413.096586199887], 0.08478216641764892, 0.0, 0.1, 521.642898887474]}