From 2bff65040ddff60c65f50a8c3adba9c9181e8f49 Mon Sep 17 00:00:00 2001 From: Andreas Granig Date: Wed, 27 Nov 2013 14:06:29 +0100 Subject: [PATCH] MT#5103 Add date picker to call distribution graph --- lib/NGCP/Panel/Controller/Calls.pm | 27 +++++++++++++++++++++- share/static/js/libs/ngcp-chord.js | 31 ++++++++++++++++++------- share/templates/calls/chord.tt | 36 ++++++++++++++++++++++++------ 3 files changed, 78 insertions(+), 16 deletions(-) diff --git a/lib/NGCP/Panel/Controller/Calls.pm b/lib/NGCP/Panel/Controller/Calls.pm index ce8a1d3ac0..0d019e8830 100644 --- a/lib/NGCP/Panel/Controller/Calls.pm +++ b/lib/NGCP/Panel/Controller/Calls.pm @@ -1,5 +1,6 @@ package NGCP::Panel::Controller::Calls; use Sipwise::Base; +use DateTime::Format::Strptime; BEGIN { extends 'Catalyst::Controller'; } @@ -29,7 +30,31 @@ sub calls_matrix_ajax :Chained('/') :PathPart('calls/ajax') :Args(0) { my $matrix = []; my $countries = []; - my $rs = $c->model('DB')->resultset('cdr')->search({}, { + my $from = $c->req->params->{from}; + my $to = $c->req->params->{to}; + my $parse_time = DateTime::Format::Strptime->new(pattern => '%F'); + + my $from_epoch; + if($from) { + $from_epoch = $parse_time->parse_datetime($from)->epoch(); + } else { + $from_epoch = NGCP::Panel::Utils::DateTime::current_local->truncate(to => 'day')->epoch(); + } + my $to_epoch; + if($to) { + $to_epoch = $parse_time->parse_datetime($to)->add(days => 1)->epoch(); + } else { + $to_epoch = NGCP::Panel::Utils::DateTime::current_local->truncate(to => 'day')->add(days => 1)->epoch(); + } + + use Data::Printer; p $from_epoch; p $to_epoch; + + my $rs = $c->model('DB')->resultset('cdr')->search({ + -and => [ + start_time => { '>=' => $from_epoch }, + start_time => { '<=' => $to_epoch }, + ], + }, { select => [qw/source_cli destination_user_in/], }); diff --git a/share/static/js/libs/ngcp-chord.js b/share/static/js/libs/ngcp-chord.js index ba4a2620d1..ca50aab054 100644 --- a/share/static/js/libs/ngcp-chord.js +++ b/share/static/js/libs/ngcp-chord.js @@ -1,26 +1,40 @@ -console.log("foo bar"); var chord; -jQuery.ajax({ - url: "/calls/ajax", - type: "post", +function loadChord() { + +$("#ngcp-cdr-chord-loading").remove(); +$("#ngcp-cdr-chord").append( + '
' + + ' loading' + + ' crunching data, please be patient - it might take a while...' + + '
' +); + +$.ajax({ + url: "/calls/ajax?from=" + $("#datepicker_start").val() + "&to=" + $("#datepicker_end").val(), + type: "get", async: true, datatype: "json", error: function(xhr, textStatus, errorThrown) { $("#ngcp-cdr-chord-loading").remove(); - $("#ngcp-cdr-chord").append('
Failed to load call data
'); + $("#ngcp-cdr-chord").append('
Failed to load call data
'); }, success: function(resjson, textStatus, XMLHttpRequest) { $("#ngcp-cdr-chord-loading").remove(); var json = $.parseJSON(resjson); var countries = json.countries; var matrix = json.calls; + + if(matrix.length == 0) { + $("#ngcp-cdr-chord").append('
No call data for the specified date range found
'); + return; + } + + var width = 720, height = 720, outerRadius = Math.min(width, height) / 2 - 10, innerRadius = outerRadius - 24; - console.log(json); - //var formatPercent = d3.format(".1%"); var formatPercent = function(v) { return Math.floor(v); @@ -38,7 +52,6 @@ jQuery.ajax({ var path = d3.svg.chord() .radius(innerRadius); - console.log("appending svg"); var svg = d3.select("#ngcp-cdr-chord").append("svg") .attr("width", width) .attr("height", height) @@ -105,6 +118,8 @@ jQuery.ajax({ } }); +} + function mouseover(d, i) { chord.classed("fade", function(p) { return p.source.index != i diff --git a/share/templates/calls/chord.tt b/share/templates/calls/chord.tt index b17a2e99ac..68bf9356fa 100644 --- a/share/templates/calls/chord.tt +++ b/share/templates/calls/chord.tt @@ -32,6 +32,8 @@ + +
Back @@ -43,14 +45,34 @@

Mouseover on a country name to focus on calls to or from a single country. The thickness of links between countries encodes the relative frequency of calls between two countries: thicker links represent more calls.

Links are colored by the more frequent origin. Mouseover on a link to see the direction details.

-
-
- loading - crunching data, please be patient - it might take a while... +
+
+ +
+
+ +
+
+ - - - +
+
[% # vim: set tabstop=4 syntax=html expandtab: -%]