我有一个Azure服务器的数组Log(点击数组)我想订购,这是请求:
$http({
method: 'Get',
headers: {
'Host': 'api.applicationinsights.io',
'x-api-key': 'xxxxxxxxxxxxxx'
},
url: 'https://api.applicationinsights.io/v1/apps/20exxxx-xxxx-xxxx-xxxx-cf8bc569d261/query?query=requests | where timestamp > datetime(2018-03-13) and timestamp <= datetime(2018-03-22) %2B 1d | where name contains "GetCode" | where name contains "9278"'
})
.success(function (data) {
$scope.clicks = data.tables[0].rows;
console.log($scope.clicks)
})
这是我出去的阵列(约275.000行):
0:
Array(37)
0:"2018-03-22T08:37:02.982Z"
1:"|ypdKJH+nmLI=.aeeeecd8_"
2:null
3:"GET /content/GetCode/192.0/9278"
etc.
1:
Array(37)
0:"2018-03-22T08:37:04.877Z"
1:"|nynZFXWHS7g=.aeeeece2_"
2:null
3:"GET /content/GetCode/1773.0/9278"
etc.
现在我只在我的NG-Repet中使用[3],所以我做了以下内容:
<div ng-repeat="click in clicks">
click: {{(click[3].split('GET /content/GetCode/')[1]).split('/9278')[0]}}
</div>
它很好地列出了时间列表
192.0
1773.0
198.5
112,0
32.8
3148.7
etc. x 100.000
我怎样才能将这个列表分组,让我们说每分钟,所以我将它们全部收集在一起,每组30秒。
所以这样:
0- 30: 0
31- 60: 1 (aka 32.8)
61- 90: 0
91-120: 1 (aka 112.0)
121-150: 0
151-180: 0
181-210: 2 (aka 192.0 & 198.5)
211-240: 0 etc. etc. you get the idea i guess.
我怎么能这样做?
答案 0 :(得分:0)
你需要使用JS:
$scope.groupedArray = []
var clicks = {
1: [
'asd', 'asdasd', 'GET /content/GetCode/192.0/9278'
],
2: [
'asd', 'asdasd', 'GET /content/GetCode/1773.0/9278'
]
}
var a = []
for (var key in clicks) {
a.push((clicks[key][2].split('GET /content/GetCode/')[1]).split('/9278')[0])
}
a = a.sort(function(a, b) {
return a - b;
})
for(let i = 0; i<a.length; i++) {
arrayIndex = parseInt(a[i]/30);
$scope.groupedArray[arrayIndex] = ($scope.groupedArray[arrayIndex] == undefined) ? 1 : ($scope.groupedArray[arrayIndex] + 1);
}
for(let i = 0; i<$scope.groupedArray.length; i++) {
$scope.groupedArray[i] = ($scope.groupedArray[i] == undefined) ? 0 : $scope.groupedArray[i]
}
HTML
<ul>
<li ng-repeat="item in groupedArray">
{{($index) * 30}} - {{($index + 1) * 30}} -> {{item}}
</li>
</ul>