added months tx/day evolution chart
arnaucode arnaucode@gmail.com
Fri, 15 Sep 2017 09:41:50 +0200
17 files changed,
85 insertions(+),
13 deletions(-)
jump to
M
README.md
→
README.md
@@ -102,19 +102,10 @@
### Some screenshots Some screenshots can be old, and can contain errors. - -  - - - - -  -  - - +
M
mongoModels.go
→
mongoModels.go
@@ -98,7 +98,10 @@ type SankeyModel struct {
Nodes []SankeyNodeModel `json:"nodes"` Links []SankeyLinkModel `json:"links"` } - +type ChartCountFloat64Model struct { + Elem float64 `json:"elem"` + Count int `json:"count"` +} type ChartCountModel struct { Elem int `json:"elem"` Count int `json:"count"`
M
serverRoutes.go
→
serverRoutes.go
@@ -125,6 +125,12 @@ "/last7dayhour",
GetLast7DayHourAnalysis, }, Route{ + "GetLastMonthsAnalysis", + "Get", + "/lastmonths/{count}", + GetLastMonthsAnalysis, + }, + Route{ "GetAddressTimeChart", "GET", "/addresstimechart/{hash}",@@ -666,6 +672,50 @@ }
} hourLabels := []string{"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23"} resp.Labels = hourLabels + + //convert []resp struct to json + jsonResp, err := json.Marshal(resp) + check(err) + fmt.Fprintln(w, string(jsonResp)) +} +func GetLastMonthsAnalysis(w http.ResponseWriter, r *http.Request) { + ipFilter(w, r) + vars := mux.Vars(r) + count, err := strconv.Atoi(vars["count"]) + check(err) + fmt.Println(count) + fromDate := time.Now().AddDate(0, -count, 0) + toDate := time.Now() + + txs := []TxModel{} + err = txCollection.Find(bson.M{ + "datet": bson.M{ + "$gt": fromDate, + "$lt": toDate, + }, + }).Sort("-$natural").All(&txs) + check(err) + + //generate map with 24 hours + //hourFrequencies := map24hours() + dayFrequencies := make(map[float64]int) + for _, tx := range txs { + dayFrequencies[float64(tx.Date.Month) + float64(tx.Date.Day)/100]++ + } + var dayCount []ChartCountFloat64Model + for day, frequency := range dayFrequencies { + dayCount = append(dayCount, ChartCountFloat64Model{day, frequency}) + } + //sort by hour + sort.Slice(dayCount, func(i, j int) bool { + return dayCount[i].Elem < dayCount[j].Elem + }) + + var resp ChartAnalysisResp + for _, d := range dayCount { + resp.Labels = append(resp.Labels, strconv.FormatFloat(d.Elem, 'f', -1, 64)) + resp.Data = append(resp.Data, d.Count) + } //convert []resp struct to json jsonResp, err := json.Marshal(resp)
M
web/views/addressNetwork/addressNetwork.html
→
web/views/addressNetwork/addressNetwork.html
@@ -1,6 +1,6 @@
<div class="row"> <div class="col-sm-3"> - <div class="panel-heading c_blueGrey300"> + <div class="panel-heading c_deepPurpleG300to500"> <h3 class="panel-title">All addresses ({{addresses.length}})</h3> </div> <div class="panel-body" style="max-height: 500px;overflow-y: scroll;">@@ -17,7 +17,7 @@ </div>
</div> </div> <div class="col-sm-9"> - <div class="panel-heading c_blueGrey300"> + <div class="panel-heading c_deepPurpleG300to500"> <h3 class="panel-title">Address history Network Map {{selectedAddress.id}}, BlockHeight: {{selectedAddress.group}}</h3> </div> <div class="panel-body">
M
web/views/dateAnalysis/dateAnalysis.html
→
web/views/dateAnalysis/dateAnalysis.html
@@ -30,3 +30,15 @@ </canvas>
</div> </div> </div> +<br> +<div class="row"> + <div class="col-md-12"> + <div class="panel-heading c_deepPurpleG300to500"> + <h3 class="panel-title">Last {{monthsCount}} Months Tx/Hour</h3> + </div> + <div class="panel-body"> + <canvas id="line" class="chart chart-line" chart-data="lastmonths.data" chart-labels="lastmonths.labels" chart-series="lastmonths.series"> + </canvas> + </div> + </div> +</div>
M
web/views/dateAnalysis/dateAnalysis.js
→
web/views/dateAnalysis/dateAnalysis.js
@@ -57,4 +57,20 @@ $scope.last7dayhour.series = data.data.series;
}, function(data, status, headers, config) { console.log('data error'); }); + + $scope.lastmonths={ + data: [], + labels: [] + }; + $scope.monthsCount = 3; + $http.get(urlapi + 'lastmonths/' + $scope.monthsCount) + .then(function(data, status, headers, config) { + console.log('data success'); + console.log(data); + + $scope.lastmonths.data = data.data.data; + $scope.lastmonths.labels=data.data.labels; + }, function(data, status, headers, config) { + console.log('data error'); + }); });