如何使用 Azure 流分析计算每一行的百分比?
How to calculate percentage for each row using azure stream analytics?
我正在通过事件中心从 NSE(国家证券交易所)实时获取数据以进行如下格式的流式分析:
[{symbol: 'HCLTECH',
openPrice: '1,097.00',
highPrice: '1,125.00',
lowPrice: '1,092.30',
ltp: '1,122.80'},
{ symbol: 'BPCL',
openPrice: '342.00',
highPrice: '351.45',
lowPrice: '337.50',
ltp: '350.45'
}]
正如您在 json 中所做的那样,开盘价 - 今天的起始价,
ltp——当前价格
如果开盘价是 100 并且 ltp 是 150 那么变化是 50%
如何使用 Azure 流分析对所有行执行此操作。
在 ASA 的 Mathematical Functions,so you have to calculate it by yourself with UDF 中找不到除法功能。
UDF:
function main(arg1, arg2) {
var f = parseFloat((arg2-arg1)/arg1);
if (isNaN(f)) {
return '0%';
}
f = Math.round(f*100)/100;
return f*100+"%";
}
SQL:
SELECT
udf.divCal(input.openPrice,input.ltp)
FROM input
我正在通过事件中心从 NSE(国家证券交易所)实时获取数据以进行如下格式的流式分析:
[{symbol: 'HCLTECH',
openPrice: '1,097.00',
highPrice: '1,125.00',
lowPrice: '1,092.30',
ltp: '1,122.80'},
{ symbol: 'BPCL',
openPrice: '342.00',
highPrice: '351.45',
lowPrice: '337.50',
ltp: '350.45'
}]
正如您在 json 中所做的那样,开盘价 - 今天的起始价, ltp——当前价格 如果开盘价是 100 并且 ltp 是 150 那么变化是 50% 如何使用 Azure 流分析对所有行执行此操作。
在 ASA 的 Mathematical Functions,so you have to calculate it by yourself with UDF 中找不到除法功能。
UDF:
function main(arg1, arg2) {
var f = parseFloat((arg2-arg1)/arg1);
if (isNaN(f)) {
return '0%';
}
f = Math.round(f*100)/100;
return f*100+"%";
}
SQL:
SELECT
udf.divCal(input.openPrice,input.ltp)
FROM input