我正在尝试使用JavaScript和tsiclient库从Azure时序见解预览中查询数据。我的代码遵循github文档中的格式,但是当我推送查询时,出现500个“内部服务错误” POST错误。
我的代码:
import datetime
import pytz
def diff_hours_tz(from_tz_name, to_tz_name, negative=False):
"""
Returns difference hours between timezones
res = diff_hours_tz("UTC", "Europe/Paris") : 2
"""
from_tz = pytz.timezone(from_tz_name)
to_tz = pytz.timezone(to_tz_name)
utc_dt = datetime.datetime.now(datetime.timezone.utc)
dt_from = dt_to = datetime.datetime.utcnow()
dt_from = from_tz.localize(dt_from)
dt_to = to_tz.localize(dt_to)
from_d = dt_from - utc_dt
if from_d.days < 0:
return diff_hours_tz(to_tz_name, from_tz_name, True)
dt_delta = dt_from - dt_to
negative_int = -1 if negative else 1
return int(dt_delta.seconds/3600)*negative_int
def dt_tz_to_tz(dt, from_tz_name, to_tz_name):
"""
Apply difference hours between timezones to a datetime object
dt_new = dt_tz_to_tz(datetime.datetime.now(), "UTC", "Europe/Paris")
"""
hours = diff_hours_tz(from_tz_name, to_tz_name)
return dt+datetime.timedelta(hours=hours)
# Usage example
res = diff_hours_tz("Europe/Paris", "America/New_York")
# Result : -6
res = diff_hours_tz("UTC", "Europe/Paris")
# Result : 2
now = datetime.datetime.now()
# Result : 2019-06-18 15:10:31.720105
dt_new = dt_tz_to_tz(now, "UTC", "Europe/Paris")
# Result : 2019-06-18 17:10:31.720105
dt_new = dt_tz_to_tz(now, "Europe/Paris", "America/New_York")
# Result : 2019-06-18 09:10:31.720105
dt_new = dt_tz_to_tz(now, "America/New_York", "Europe/Paris")
# Result : 2019-06-18 21:10:31.720105
有人对此有任何经验吗?
编辑-完整回复:
var data = [];
data.push(new tsiClient.ux.TsqExpression(
// instanceObject
{
timeSeriesId: ['CSIRO_Density-SC503_DPV']
},
// variableObject
{
rawdata: {
kind: 'numeric',
value: {
tsx: 'rawdata.value'
},
filter: null,
aggregation: null
}
},
// searchSpan
{
from: startDate,
to: endDate,
bucketSize: '5m'
},
// color
'#60B9AE',
// alias
'Tag_Values',
// contextMenu
null
));
authContext.getTsiToken().then(function(token) {
tsiClient.server.getTsqResults(
token,
environmentFqdn,
data.map(ae => ae.toTsq())).then(function(result) {
console.log(result);
});
});
最后编辑!我发现了问题-变量对象的语法错误:
code: "InternalServerError"
message: "Internal server error. Please retry your request later."
应该是
'rawdata.value'
答案 0 :(得分:0)
您正确使用了Value
变量,应该像下面这样。
value: {tsx: '$event.value'}
这是我尝试使用PAYG SKU进行基本图表的示例,并且对我有用。
var linechartTsqExpressions = [];
var startDate = new Date('2017-04-20T20:00:00Z');
var endDate = new Date(startDate.valueOf() + 1000*60*60*24*30);
linechartTsqExpressions.push(new tsiClient.ux.TsqExpression(
{timeSeriesId: ['df4412c4-dba2-4a52-87af-780e78ff156b']}, // instance json
{Max: {
kind: 'numeric',
value: {tsx: '$event.value.Double'},
filter: null,
aggregation: {tsx: 'max($value)'}
}}, // variable json
{ from: startDate, to: endDate, bucketSize: '6h' }, // search span
'#60B9AE', // color
'MaxValue')); // alias
linechartTsqExpressions.push(new tsiClient.ux.TsqExpression(
{timeSeriesId: ['df4412c4-dba2-4a52-87af-780e78ff156b']}, // instance json
{Avg: {
kind: 'numeric',
value: {tsx: '$event.value.Double'},
filter: null,
aggregation: {tsx: 'avg($value)'}
}}, // variable json
{ from: startDate, to: endDate, bucketSize: '6h' }, // search span
'#D869CB', // color
'AvgValue')); //
var eventsTsqExpressions = [new tsiClient.ux.TsqExpression(
{timeSeriesId: ['df4412c4-dba2-4a52-87af-780e78ff156b']}, // instance json
{Avg: {
kind: 'numeric',
value: {tsx: '$event.value.Double'},
filter: null,
aggregation: {tsx: 'avg($value)'}
}}, // variable json
{ from: startDate, to: new Date(startDate.valueOf() + 1000*60*60*2), bucketSize: '1m'}, // search span
'#D869CB', // color
'AvgValue')]; //
authContext.getTsiToken().then(function(token){
tsiClient.server.getTsqResults(token, '10000000-0000-0000-0000-100000000109.env.timeseries.azure.com', linechartTsqExpressions.map(function(ae){return ae.toTsq()})).then(function(result){
var transformedResult = tsiClient.ux.transformTsqResultsForVisualization(result, linechartTsqExpressions);
var lineChart = new tsiClient.ux.LineChart(document.getElementById('chart1'));
lineChart.render(transformedResult, {theme: 'dark', grid: true, tooltip: true, legend: 'compact'}, linechartTsqExpressions);
});
tsiClient.server.getTsqResults(token, '10000000-0000-0000-0000-100000000109.env.timeseries.azure.com', eventsTsqExpressions.map(function(ae){return ae.toTsq(true, true)})).then(function(result){
var transformedEvents = tsiClient.ux.transformTsqResultsToEventsArray(result);
var eventsTable = tsiClient.ux.EventsTable(document.getElementById('chart2'));
eventsTable.render(transformedEvents, {theme: 'dark', offset: 'Local'}, true);
});
});
您可以将此repo用于将来的参考。希望对您有所帮助。