-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathts_a_template.py
56 lines (48 loc) · 1.42 KB
/
ts_a_template.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# -*- coding: utf-8 -*-
import logging
import os
current_path = r'D:\github\pyncode'
os.chdir(current_path)
logging.basicConfig(level=logging.INFO, filename='debug.log')
def glyphscript(engineState):
ts_in0 = engineState.GetInputTimeSeries(0)
ts_out0 = engineState.GetOutputTimeSeries(0)
list1 = getTS(ts_in0)
putTS(ts_out0, ts_in0, list1)
logging.shutdown()
return ''
def putTS(tsobj,tartsobj,list1):
# 对时间序列进行赋值
# 复制tartsobj属性 到 tsobj中
# 将列表list1 作为数据 导入 tsobj中
import array
num = len(list1)
mdobj = tsobj.GetMetaData()
tarmdobj = tartsobj.GetMetaData()
if type(list1[0]) == list :
tsobj.SetChannelCount(num)
len_value = len(list1[0])
for n in range(num):
tsobj.CopyAttributes(tartsobj, n, n)
tsobj.CopyMetaData(tartsobj, n, n)
tsobj.SetPointCount(n, len_value)
arr1 = array.array('f', list1[n])
tsobj.PutValues(n, 0, len_value,arr1)
else:
tsobj.SetChannelCount(1)
tsobj.CopyAttributes(tartsobj, 0, 0)
tsobj.CopyMetaData(tartsobj, 0, 0)
tsobj.PutValues(0, num, 1, list1)
name = tarmdobj.GetItem(-1, 'TestName')
mdobj.SetItem(-1, 'InputTestInfo', 'TestName', 'string', name)
return None
def getTS(tsobj):
# 获取 time series 数据
# 转化为列表导出
num = tsobj.GetChannelCount()
list1 = []
for n in range(num):
listnum = tsobj.GetPointCount(n)
list_temp = tsobj.GetValuesAsList(n,0,listnum)
list1.append(list_temp)
return list1