@ -0,0 +1,64 @@ |
|||||
|
package main |
||||
|
|
||||
|
import ( |
||||
|
"fmt" |
||||
|
"strconv" |
||||
|
"strings" |
||||
|
"time" |
||||
|
|
||||
|
"gopkg.in/mgo.v2/bson" |
||||
|
) |
||||
|
|
||||
|
func timeToDate(blockTime int64) string { |
||||
|
stringTime := strconv.FormatInt(blockTime, 10) |
||||
|
i, err := strconv.ParseInt(stringTime, 10, 64) |
||||
|
if err != nil { |
||||
|
panic(err) |
||||
|
} |
||||
|
tm := time.Unix(i, 0) |
||||
|
fmt.Println(tm) |
||||
|
stringDate := tm.String() |
||||
|
fmt.Println(stringDate) |
||||
|
return stringDate |
||||
|
} |
||||
|
func hourAnalysis(e EdgeModel, blockTime int64) { |
||||
|
fmt.Println(blockTime) |
||||
|
date := timeToDate(blockTime) |
||||
|
date_hour := strings.Split(date, " ")[1] |
||||
|
hour := strings.Split(date_hour, ":")[0] |
||||
|
|
||||
|
hourCount := HourCountModel{} |
||||
|
err := hourCountCollection.Find(bson.M{"hour": hour}).One(&hourCount) |
||||
|
if err != nil { |
||||
|
//date not yet in DB
|
||||
|
var hourCount HourCountModel |
||||
|
hourCount.Hour = hour |
||||
|
hourCount.Count = 1 |
||||
|
err = hourCountCollection.Insert(hourCount) |
||||
|
check(err) |
||||
|
} else { |
||||
|
hourCount.Count++ |
||||
|
err = hourCountCollection.Update(bson.M{"hour": hour}, &hourCount) |
||||
|
check(err) |
||||
|
} |
||||
|
} |
||||
|
func dateAnalysis(e EdgeModel, blockTime int64) { |
||||
|
fmt.Println(blockTime) |
||||
|
date := timeToDate(blockTime) |
||||
|
|
||||
|
dateCount := DateCountModel{} |
||||
|
err := dateCountCollection.Find(bson.M{"date": date}).One(&dateCount) |
||||
|
if err != nil { |
||||
|
//date not yet in DB
|
||||
|
var dateCount DateCountModel |
||||
|
dateCount.Date = date |
||||
|
dateCount.Time = blockTime |
||||
|
dateCount.Count = 1 |
||||
|
err = dateCountCollection.Insert(dateCount) |
||||
|
check(err) |
||||
|
} else { |
||||
|
dateCount.Count++ |
||||
|
err = dateCountCollection.Update(bson.M{"date": date}, &dateCount) |
||||
|
check(err) |
||||
|
} |
||||
|
} |
@ -0,0 +1,13 @@ |
|||||
|
<div class="container"> |
||||
|
<div class="row"> |
||||
|
<div class="col-sm-12"> |
||||
|
<div class="panel-heading c_blueGrey300"> |
||||
|
<h3 class="panel-title">Tx for each Hour</h3> |
||||
|
</div> |
||||
|
<div class="panel-body"> |
||||
|
<canvas id="bar" class="chart chart-bar" chart-data="data" chart-labels="labels"> |
||||
|
</canvas> |
||||
|
</div> |
||||
|
</div> |
||||
|
</div> |
||||
|
</div> |
@ -0,0 +1,27 @@ |
|||||
|
'use strict'; |
||||
|
|
||||
|
angular.module('app.dateAnalysis', ['ngRoute', 'chart.js']) |
||||
|
|
||||
|
.config(['$routeProvider', function($routeProvider) { |
||||
|
$routeProvider.when('/dateAnalysis', { |
||||
|
templateUrl: 'views/dateAnalysis/dateAnalysis.html', |
||||
|
controller: 'DateAnalysisCtrl' |
||||
|
}); |
||||
|
}]) |
||||
|
|
||||
|
.controller('DateAnalysisCtrl', function($scope, $http, $routeParams) { |
||||
|
$scope.data=[]; |
||||
|
$scope.labels=[]; |
||||
|
|
||||
|
$http.get(urlapi + 'houranalysis') |
||||
|
.then(function(data, status, headers, config) { |
||||
|
console.log('data success'); |
||||
|
console.log(data); |
||||
|
|
||||
|
$scope.data = data.data.data; |
||||
|
$scope.labels=data.data.labels; |
||||
|
}, function(data, status, headers, config) { |
||||
|
console.log('data error'); |
||||
|
}); |
||||
|
|
||||
|
}); |