userengagement.js 9.8 KB
(function(){
    angular.module("app.collect")
        .controller("userengagementCtrl",["$rootScope","$scope","HttpService","ToolService","DateService","$filter", "$translate",userengagementCtrl]);

    function userengagementCtrl($rootScope,$scope,HttpService,ToolService,DateService,$filter, $translate){
        //时间控件
        $scope.beginDate = DateService.getDay(0);
        $scope.$on("beginDate",function(e,msg){
            $scope.beginDate = msg;
            $scope.contrastType=='channel'&&$scope.query();
        });

        $scope.contrastType = 'channel';
        $scope.changeContrastType = function(flag) {
            if($scope.contrastType==flag){return false};
            $scope.contrastType = flag;
            $scope.channelid = '';
            $scope.beginDateList = [];
            flag=='channel'&&$scope.query();
        }

        $scope.querySelectInfos = function() {
            $translate(["请选择", "自然量"]).then(function(translations) {
                $scope.initSelects(translations["请选择"], translations["自然量"]);
            }, function(tranIds) {
                $scope.initSelects(tranIds["请选择"], tranIds["自然量"]);
            });
        }
        $scope.initSelects = function(noFilter, nat) {
            var channelparams = ToolService.getChannelCampaignParams("channel", $scope.appid);
            var channelPM = HttpService.getInfo(channelparams.url);
            $scope.channelNameInit = noFilter + channelparams.txt;;
            channelPM.then(function(data) {
                if (!(!$rootScope.isall && $rootScope.curRoleAuth && !$rootScope.curRoleAuth.isNatureOpen)) {
                    data.unshift({ id: "-1", name: nat });
                }
                $scope.channelList = data;
            });

            var params = {
                appid: $scope.appid,
                datatype: 'list',
                viewtype: 'chart',
                func: 'duration'
            }
            var pageListPM = HttpService.getReportData('page_duration_ids',params);
            pageListPM.then(function(data){
                data.val.filter(function(value){
                    value.name = value.pageid
                })
                data.val.unshift({pageid: "all",name:$filter('translate')('请选择pageid')})
                $scope.pageList = data.val;
            });
        }
        $scope.channelid = '';
        $scope.$on("channelid", function(e, msg) {
            $scope.channelid = msg.info;
            $scope.query();
        });

        $scope.beginDateList = [];
        $scope.$on("beginDateList",function(e,msg){
            $scope.beginDateList = msg
            $scope.query();
        });
        $scope.channelRe = 0;
        $scope.clear = function(){
            $scope.channelid = '';
            $scope.channelRe++
            $scope.beginDateList = [];
            $scope.query();
        }

        $scope.pageList = [];
        $scope.pageListInit = 'all';
        $scope.pageId = 'all';
        $scope.$on('pageId', function(e, msg) {
            if($scope.pageId == msg.info.pageid){return false};
            $scope.pageId = msg.info.pageid;
            $scope.pageViewDurationQuery()
        });

        $scope.$watch("{appid:appid,lang:lang}", function(n, o) {
            if (angular.isUndefined($scope.appid)) { return false; }
            $scope.channelid = '';
            $scope.channelRe++
            $scope.querySelectInfos();
            $scope.query();
            if(n && o && n!==o){
                // $scope.initData();
                // console.log(1)
            }
        });

        $scope.report = [
            {name:'userengagement_session_by',title:'单次使用时长分布'},
            {name:'userengagement_user_by',title:'使用时长分布'},
            {name:'userengagement_page_by',title:'App页面浏览时长分布'},
            {name:'userengagement_freq_by',title:'使用频率分布'},
        ]

        // var color5 = ["#5c6bc0", "#50bd3e", "#cddc39", "#fb7f0b", "#fec107"];
        var color5 = ["#1FB9E9", "#A0E1F5", "#F8A20F", "#FBD799", "#00B37F", "#93DFC9", "#F9593A", "#FCC2B7", "#5F97FB",  '#ca8622'];
        var opacity = 0.1;
        $scope.query = function() {
            if (angular.isUndefined($scope.appid)) { return false; }
            var params = {
                startdate: $scope.beginDate,
                enddate: $scope.beginDate,
                appid: $scope.appid,
                datatype: 'chart',
                viewtype: 'chart',
                func: 'duration',
                duration_dates:$scope.beginDateList.join(','),
                duration_cid:$scope.channelid
            }
            $scope.singleUseTimeQuery(params)
            $scope.totalUseTimeQuery(params)
            $scope.pageViewDurationQuery()
            $scope.usageFrequencyQuery(params)
        }
        $scope.singleUseTimeQuery = function(params) {
            var by = $scope.contrastType=='channel'&&$scope.channelid==''?'date':$scope.contrastType;
            $scope.singleUseTimeConfig = {color:color5,opacity:opacity};
            var singleUseTimePM = HttpService.getReportData($scope.report[0].name + by,params);
            $scope.singleUseTimeLoading = true;
            singleUseTimePM.then(function(data){
                $scope.singleUseTimeData = data;
                $scope.singleUseTimeLoading = false;
            });
            var params1 = JSON.parse(JSON.stringify(params));
            params1.viewtype = 'list'
            var singleUseTimeListPM = HttpService.getReportData($scope.report[0].name + $scope.contrastType,params1);
            singleUseTimeListPM.then(function(data){
                $scope.singleUseTimeTableData = data;
                $scope.singleUseTimeDataCondition = ToolService.getChartConditions($filter('translate')("用户参与度-")+$scope.report[0].title,$scope.report[0].name + $scope.contrastType,params1);
            });
        }
        $scope.totalUseTimeQuery = function(params) {
            var by = $scope.contrastType=='channel'&&$scope.channelid==''?'date':$scope.contrastType;
            $scope.totalUseTimeConfig = {color:color5,opacity:opacity};
            var totalUseTimePM = HttpService.getReportData($scope.report[1].name + by,params);
            $scope.totalUseTimeLoading = true;
            totalUseTimePM.then(function(data){
                $scope.totalUseTimeData = data;
                $scope.totalUseTimeLoading = false;
            });
            var params1 = JSON.parse(JSON.stringify(params));
            params1.viewtype = 'list'
            var totalUseTimeListPM = HttpService.getReportData($scope.report[1].name + $scope.contrastType,params1);
            totalUseTimeListPM.then(function(data){
                $scope.totalUseTimeTableData = data;
                $scope.totalUseTimeDataCondition = ToolService.getChartConditions($filter('translate')("用户参与度-")+$scope.report[1].title,$scope.report[1].name + $scope.contrastType,params1);
            });
        }
        $scope.pageViewDurationQuery = function() {
            var params = {
                startdate: $scope.beginDate,
                enddate: $scope.beginDate,
                appid: $scope.appid,
                datatype: 'chart',
                viewtype: 'chart',
                func: 'duration',
                duration_dates:$scope.beginDateList.join(','),
                duration_cid:$scope.channelid
            }
            $scope.pageId!='all'?params.duration_pageid = $scope.pageId:'';
            var by = $scope.contrastType=='channel'&&$scope.channelid==''?'date':$scope.contrastType;
            $scope.pageViewDurationConfig = {color:color5,opacity:opacity};
            var pageViewDurationPM = HttpService.getReportData($scope.report[2].name+ by,params);
            $scope.pageViewDurationLoading = true;
            pageViewDurationPM.then(function(data){
                $scope.pageViewDurationData = data;
                $scope.pageViewDurationLoading = false;
            });
            var params1 = JSON.parse(JSON.stringify(params));
            params1.viewtype = 'list'
            var pageViewDurationListPM = HttpService.getReportData($scope.report[2].name + $scope.contrastType,params1);
            pageViewDurationListPM.then(function(data){
                $scope.pageViewDurationTableData = data;
                $scope.pageViewDurationDataCondition = ToolService.getChartConditions($filter('translate')("用户参与度-")+$scope.report[2].title,$scope.report[2].name + $scope.contrastType,params1);
            });
        }
        $scope.usageFrequencyQuery = function(params) {
            var by = $scope.contrastType=='channel'&&$scope.channelid==''?'date':$scope.contrastType;
            $scope.usageFrequencyConfig = {color:color5,opacity:opacity};
            var usageFrequencyPM = HttpService.getReportData($scope.report[3].name+ by,params);
            $scope.usageFrequencyLoading = true;
            usageFrequencyPM.then(function(data){
                $scope.usageFrequencyData = data;
                $scope.usageFrequencyLoading = false;
            });
            var params1 = JSON.parse(JSON.stringify(params));
            params1.viewtype = 'list'
            var usageFrequencyListPM = HttpService.getReportData($scope.report[3].name + $scope.contrastType,params1);
            usageFrequencyListPM.then(function(data){
                $scope.usageFrequencyTableData = data;
                $scope.usageFrequencyDataCondition = ToolService.getChartConditions($filter('translate')("用户参与度-")+$scope.report[3].title,$scope.report[3].name + $scope.contrastType,params1);
            });
        }
        // $scope.mapData = {
        //     help:[],
        //     name:['排重激活设备数'],
        //     column:['省份'],
        //     key:['北京','上海','河北','黑龙江','新疆'],
        //     val:[['111','222','234','323','1234']]
        // }
    }
        
})();