Mule4的新手,可以玩耍。我有一个setPayload变压器,并且在设置下 我要添加以下内容
#[payload ++ " " ++ message.attributes.queryParams.lname]
但是我遇到以下错误。正确的做法是什么?
表达式'payload ++“” ++ message.attributes.queryParams.lname'的脚本语言错误。原因:无法使用参数(字符串,字符串|空)重载调用函数++
的任何重载:
答案 0 :(得分:0)
您不能将字符串(即“ Hello”)与空值(即,attributes.queryParams.lname可以为空)连接在一起。。因此,在这种情况下,您将必须为右侧表达式设置默认值。尝试下面的脚本->
import pandas as pd
data = [{'time': '2019-01-05 11:00:00', 'sensor_value' : 200},
{'time': '2019-01-05 14:37:52', 'sensor_value' : 220},
{'time': '2019-01-05 17:55:12', 'sensor_value' : 235},
{'time': '2019-01-06 12:00:00', 'sensor_value' : 250},
{'time': '2019-01-07 13:00:00', 'sensor_value' : 300},
{'time': '2019-01-08 14:00:00', 'sensor_value' : 250},
{'time': '2019-01-09 15:00:00', 'sensor_value' : 320}]
df = pd.DataFrame(data)
df['time'] = pd.to_datetime(df['time'])
def calc_rul(df, threshold):
# calculate all datetime where the threshold is exceeded
df_sub = sorted(df[df['sensor_value'] >= threshold]['time'].tolist())
# variable to store all days
remaining_days = []
for v1 in df['time'].tolist():
for v2 in df_sub:
# if the exceeding date is the first in future calculate the days difference
if(v2 > v1):
remaining_days.append((v2-v1).days)
break
elif(v2 == v1):
remaining_days.append(0)
break
df['RUL'] = pd.Series(remaining_days)
calc_rul(df, 300)