Exemple #1
0
class PlayTimeCalcMgr(CalcManager):
    def __init__(self, msgh, config):
        CalcManager.__init__(self, msgh)
        self.report_fd = None
        self.collectors = {}
        self.config = config
        self.stat_user = StatUser(config['start'], config['end'])
        self.rpt_print_intvl = 10
        #self.eh.register_timer(self.rpt_print_intvl * 1000,
        #                       TMTAGS.PRINT_REPORT, True)
        self.db = Mydb()
        self.db.connect('report')

    def set_config(self, config):
        self.config = config

    def _process_msg(self, msg):
        debug("PlayTimeCalcMgr::_process_msg() enter")
        msgtype = msg.get_msgtype()
        if msgtype == MsgType.MsgPlayTimeReport:
            debug("PlayTimeCalcMgr::_process_msg() got "
                  "report message %s"%msg.get_body())
            #print "PlayerStartupCalcMgr::_process_msg() got "\
            #      "report message %s"%msg.get_body()
            ptr_msg = MsgPlayTimeReport()
            ptr_msg.cast(msg)
            data = json.loads(ptr_msg.get_report_info())
            for user, play_info in data.items():
                self.stat_user.merge_user_info(user, play_info)
            #for vender, counts in data.items():
            #    self.collectors[vender].stat_time.merge(counts)
        else:
            super(PlayTimeCalcMgr, self)._process_msg(msg)

    def _process_timer(self, msg):
        #tag = msg.get_tag()
        #if tag == TMTAGS.PRINT_REPORT:
        #    self._print_report()
        #else:
        #    super(PlayTimeCalcMgr, self)._process_timer(msg)
        super(PlayTimeCalcMgr, self)._process_timer(msg)

    def _print_report(self):
        print "currently the total user:"******"vender": '',
                'date': '',
                'time': 0}
        
        venders_time = self.stat_user.gen_stat_count_by_vender_per_day()
        venders_user = self.stat_user.gen_stat_users_by_vender_per_day()

        for vender, stat_time in venders_time.items():
            print "--------", vender, stat_time.show_info()

        for vender, stat_time in venders_user.items():
            print "_duration_rate_day(): ", vender, stat_time.show_info()
            if vender not in venders_time:
                warn('_duration_rate_day():user vender %s is not in time venders[%s]'%(vender, str(venders_time)))
                continue
            time_infos = venders_time[vender].show_info()
            user_infos = stat_time.show_info()
            total, rate = 0, 0
            data['vender'] = vender
            for day, count in user_infos.items():
                if day not in time_infos:
                    warn("_duration_rate_day():user day %s is not in time days[%s]"%(day, str(time_infos.keys())))
                    continue
                rate = int(time_infos[day]) / int(count)
                data['date'] = day
                data['time'] = rate
                self.dbsession.insert(data)
            self.dbsession.commit()

        total, rate = 0, 0
        time_infos = self.stat_user.gen_stat_times().show_info()
        user_infos = self.stat_user.gen_stat_users().show_info()
        data['vender'] = 'HISENSE'
        for day, count in user_infos.items():
            if day not in time_infos:
                warn('user ay %s is not in time days[%s]'%(day, str(time_infos.keys())))
                continue
            rate = int(time_infos[day]) / int(count)
            data['date'] = day
            data['time'] = rate
            self.dbsession.insert(data)
        self.dbsession.commit()
        self.dbsession.close()
        
    def _duration_rate(self):
        self.dbsession = self.db.open('play_duration_rate')
        data = {"vender": '',
                'date': '%s_%s'%(self.config['start'],
                                 self.config['end']),
                'time': 0}
        
        venders_time = self.stat_user.gen_stat_count_by_vender_per_day()
        venders_user = self.stat_user.gen_stat_users_by_vender_per_day()
        for vender, stat_time in venders_user.items():
            if vender not in venders_time:
                continue
            time_infos = venders_time[vender].show_info()
            user_infos = stat_time.show_info()
            total, rate, u = 0, 0, 0
            for day, count in user_infos.items():
                if day not in time_infos:
                    continue
                total += int(time_infos[day]) / int(count)
                u += 1
            if u == 0:
                continue
            rate = total / u
            data['vender'] = vender
            data['time'] = rate
            self.dbsession.insert(data)
        self.dbsession.commit()

        total, rate, u = 0, 0, 0
        time_infos = self.stat_user.gen_stat_times().show_info()
        user_infos = self.stat_user.gen_stat_users().show_info()
        for day, count in user_infos.items():
            if day not in time_infos:
                continue
            total += int(time_infos[day]) / int(count)
            u += 1
        if u == 0:
            return
        rate = total / u
        data['vender'] = 'HISENSE'
        data['time'] = rate
        self.dbsession.insert(data)
        self.dbsession.commit()
        self.dbsession.close()

    def _duration_total_day(self):
        self.dbsession = self.db.open('play_duration_day')
        data = {"vender": '',
                'date': '',
                'time': 0}
        venders_time = self.stat_user.gen_stat_count_by_vender_per_day()
        for vender, stat_time in venders_time.items():
            time_infos = stat_time.show_info()
            data['vender'] = vender
            for day, count in time_infos.items():
                data['date'] = day
                data['time'] = count
                self.dbsession.insert(data)
        self.dbsession.commit()
        
        time_infos = self.stat_user.gen_stat_times().show_info()
        for day, count in time_infos.items():
            data['vender'] = 'HISENSE'
            data['date'] = day
            data['time'] = count
            self.dbsession.insert(data)

        self.dbsession.commit()
        self.dbsession.close()

    def _final(self):
        self._print_report()
        super(PlayTimeCalcMgr, self)._final()
Exemple #2
0
class PlayUserCalcMgr(CalcManager):
    def __init__(self, msgh, config):
        CalcManager.__init__(self, msgh)
        self.report_fd = None
        self.collectors = {}
        self.config = config
        self.stat_user = StatUser(config['start'], config['end'])
        self.rpt_print_intvl = 40
        #self.eh.register_timer(self.rpt_print_intvl * 1000,
        #                       TMTAGS.PRINT_REPORT, True)
        self.db = Mydb()
        self.db.connect('report')

    def set_config(self, config):
        self.config = config

    def _process_msg(self, msg):
        debug("PlayUserCalcMgr::_process_msg() enter")
        msgtype = msg.get_msgtype()
        if msgtype == MsgType.MsgPlayUserReport:
            debug("PlayUserCalcMgr::_process_msg() got "
                  "report message %s"%msg.get_body())
            ptr_msg = MsgPlayUserReport()
            ptr_msg.cast(msg)
            data = json.loads(ptr_msg.get_report_info())
            for user, play_info in data.items():
                self.stat_user.merge_user_info(user, play_info)

        else:
            super(PlayUserCalcMgr, self)._process_msg(msg)

    def _process_timer(self, msg):
        #tag = msg.get_tag()
        #if tag == TMTAGS.PRINT_REPORT:
        #    self._print_report()
        #else:
        #    super(PlayUserCalcMgr, self)._process_timer(msg)
        super(PlayUserCalcMgr, self)._process_timer(msg)

    def _print_report(self):
        self._user_report_total()
        self._user_report_day()
        self._times_report_total()
        self._times_report_day()

    def _final(self):
        echo("going to generate final report ...")
        self._print_report()
        echo("report generation completed")
        super(PlayUserCalcMgr, self)._final()

    def _user_report_total(self):
        venders = self.stat_user.gen_stat_users_by_vender()
        self.dbsession = self.db.open('play_users_total')
        data = {"vender": "",
                'date': '%s_%s'%(self.config['start'],
                                 self.config['end']),
                'count': 0}
        for vender, count in venders.items():
            data['vender'] = vender
            data['count'] = count
            self.dbsession.insert(data)
        self.dbsession.commit()
        
        data['vender'] = "HISENSE"
        data['count'] = self.stat_user.count_user()
        self.dbsession.insert(data)
        self.dbsession.commit()
        self.dbsession.close()
        
    def _user_report_day(self):
        venders = self.stat_user.gen_stat_users_by_vender_per_day()
        self.dbsession = self.db.open('play_users_day')
        data = {"vender": "",
                'date': "",
                'count': 0}
        for vender, stat_time in venders.items():
            infos = stat_time.show_info()
            data['vender'] = vender
            for day, count in infos.items():
                data['date'] = day
                data['count'] = count
                self.dbsession.insert(data)
        self.dbsession.commit()

        infos = self.stat_user.gen_stat_users().show_info()
        data['vender'] = 'HISENSE'
        for day, count in infos.items():
            data['date'] = day
            data['count'] = count
            self.dbsession.insert(data)
        self.dbsession.commit()
        self.dbsession.close()

    def _times_report_total(self):
        venders = self.stat_user.gen_stat_count_by_vender()
        self.dbsession = self.db.open('play_times_total')
        data = {"vender": "",
                'date': '%s_%s'%(self.config['start'],
                                 self.config['end']),
                'count': 0}
        for vender, count in venders.items():
            data['vender'] = vender
            data['count'] = count
            self.dbsession.insert(data)
        self.dbsession.commit()

        data['vender'] = "HISENSE"
        data['count'] = self.stat_user.gen_stat_count()
        self.dbsession.insert(data)
        self.dbsession.commit()
        self.dbsession.close()

    def _times_report_day(self):
        venders = self.stat_user.gen_stat_count_by_vender_per_day()
        self.dbsession = self.db.open('play_times_day')
        data = {"vender": "",
                'date': "",
                'count': 0}
        for vender, stat_time in venders.items():
            infos = stat_time.show_info()
            data['vender'] = vender
            for day, count in infos.items():
                data['date'] = day
                data['count'] = count
                self.dbsession.insert(data)
        self.dbsession.commit()

        infos = self.stat_user.gen_stat_times().show_info()
        data['vender'] = 'HISENSE'
        for day, count in infos.items():
            data['date'] = day
            data['count'] = count
            self.dbsession.insert(data)
        self.dbsession.commit()
        self.dbsession.close()
Exemple #3
0
class PlayUserCalcMgr(CalcManager):
    def __init__(self, msgh, config):
        CalcManager.__init__(self, msgh)
        self.report_fd = None
        self.collectors = {}
        self.config = config
        self.stat_user = StatUser(config['start'], config['end'])
        self.rpt_print_intvl = 40
        #self.eh.register_timer(self.rpt_print_intvl * 1000,
        #                       TMTAGS.PRINT_REPORT, True)
        self.db = Mydb()
        self.db.connect('report')

    def set_config(self, config):
        self.config = config

    def _process_msg(self, msg):
        debug("PlayUserCalcMgr::_process_msg() enter")
        msgtype = msg.get_msgtype()
        if msgtype == MsgType.MsgPlayUserReport:
            debug("PlayUserCalcMgr::_process_msg() got "
                  "report message %s" % msg.get_body())
            ptr_msg = MsgPlayUserReport()
            ptr_msg.cast(msg)
            data = json.loads(ptr_msg.get_report_info())
            for user, play_info in data.items():
                self.stat_user.merge_user_info(user, play_info)

        else:
            super(PlayUserCalcMgr, self)._process_msg(msg)

    def _process_timer(self, msg):
        #tag = msg.get_tag()
        #if tag == TMTAGS.PRINT_REPORT:
        #    self._print_report()
        #else:
        #    super(PlayUserCalcMgr, self)._process_timer(msg)
        super(PlayUserCalcMgr, self)._process_timer(msg)

    def _print_report(self):
        self._user_report_total()
        self._user_report_day()
        self._times_report_total()
        self._times_report_day()

    def _final(self):
        echo("going to generate final report ...")
        self._print_report()
        echo("report generation completed")
        super(PlayUserCalcMgr, self)._final()

    def _user_report_total(self):
        venders = self.stat_user.gen_stat_users_by_vender()
        self.dbsession = self.db.open('play_users_total')
        data = {
            "vender": "",
            'date': '%s_%s' % (self.config['start'], self.config['end']),
            'count': 0
        }
        for vender, count in venders.items():
            data['vender'] = vender
            data['count'] = count
            self.dbsession.insert(data)
        self.dbsession.commit()

        data['vender'] = "HISENSE"
        data['count'] = self.stat_user.count_user()
        self.dbsession.insert(data)
        self.dbsession.commit()
        self.dbsession.close()

    def _user_report_day(self):
        venders = self.stat_user.gen_stat_users_by_vender_per_day()
        self.dbsession = self.db.open('play_users_day')
        data = {"vender": "", 'date': "", 'count': 0}
        for vender, stat_time in venders.items():
            infos = stat_time.show_info()
            data['vender'] = vender
            for day, count in infos.items():
                data['date'] = day
                data['count'] = count
                self.dbsession.insert(data)
        self.dbsession.commit()

        infos = self.stat_user.gen_stat_users().show_info()
        data['vender'] = 'HISENSE'
        for day, count in infos.items():
            data['date'] = day
            data['count'] = count
            self.dbsession.insert(data)
        self.dbsession.commit()
        self.dbsession.close()

    def _times_report_total(self):
        venders = self.stat_user.gen_stat_count_by_vender()
        self.dbsession = self.db.open('play_times_total')
        data = {
            "vender": "",
            'date': '%s_%s' % (self.config['start'], self.config['end']),
            'count': 0
        }
        for vender, count in venders.items():
            data['vender'] = vender
            data['count'] = count
            self.dbsession.insert(data)
        self.dbsession.commit()

        data['vender'] = "HISENSE"
        data['count'] = self.stat_user.gen_stat_count()
        self.dbsession.insert(data)
        self.dbsession.commit()
        self.dbsession.close()

    def _times_report_day(self):
        venders = self.stat_user.gen_stat_count_by_vender_per_day()
        self.dbsession = self.db.open('play_times_day')
        data = {"vender": "", 'date': "", 'count': 0}
        for vender, stat_time in venders.items():
            infos = stat_time.show_info()
            data['vender'] = vender
            for day, count in infos.items():
                data['date'] = day
                data['count'] = count
                self.dbsession.insert(data)
        self.dbsession.commit()

        infos = self.stat_user.gen_stat_times().show_info()
        data['vender'] = 'HISENSE'
        for day, count in infos.items():
            data['date'] = day
            data['count'] = count
            self.dbsession.insert(data)
        self.dbsession.commit()
        self.dbsession.close()
Exemple #4
0
class PlayTimeCalcMgr(CalcManager):
    def __init__(self, msgh, config):
        CalcManager.__init__(self, msgh)
        self.report_fd = None
        self.collectors = {}
        self.config = config
        self.stat_user = StatUser(config['start'], config['end'])
        self.rpt_print_intvl = 10
        #self.eh.register_timer(self.rpt_print_intvl * 1000,
        #                       TMTAGS.PRINT_REPORT, True)
        self.db = Mydb()
        self.db.connect('report')

    def set_config(self, config):
        self.config = config

    def _process_msg(self, msg):
        debug("PlayTimeCalcMgr::_process_msg() enter")
        msgtype = msg.get_msgtype()
        if msgtype == MsgType.MsgPlayTimeReport:
            debug("PlayTimeCalcMgr::_process_msg() got "
                  "report message %s" % msg.get_body())
            #print "PlayerStartupCalcMgr::_process_msg() got "\
            #      "report message %s"%msg.get_body()
            ptr_msg = MsgPlayTimeReport()
            ptr_msg.cast(msg)
            data = json.loads(ptr_msg.get_report_info())
            for user, play_info in data.items():
                self.stat_user.merge_user_info(user, play_info)
            #for vender, counts in data.items():
            #    self.collectors[vender].stat_time.merge(counts)
        else:
            super(PlayTimeCalcMgr, self)._process_msg(msg)

    def _process_timer(self, msg):
        #tag = msg.get_tag()
        #if tag == TMTAGS.PRINT_REPORT:
        #    self._print_report()
        #else:
        #    super(PlayTimeCalcMgr, self)._process_timer(msg)
        super(PlayTimeCalcMgr, self)._process_timer(msg)

    def _print_report(self):
        print "currently the total user:"******"vender": '', 'date': '', 'time': 0}

        venders_time = self.stat_user.gen_stat_count_by_vender_per_day()
        venders_user = self.stat_user.gen_stat_users_by_vender_per_day()

        for vender, stat_time in venders_time.items():
            print "--------", vender, stat_time.show_info()

        for vender, stat_time in venders_user.items():
            print "_duration_rate_day(): ", vender, stat_time.show_info()
            if vender not in venders_time:
                warn(
                    '_duration_rate_day():user vender %s is not in time venders[%s]'
                    % (vender, str(venders_time)))
                continue
            time_infos = venders_time[vender].show_info()
            user_infos = stat_time.show_info()
            total, rate = 0, 0
            data['vender'] = vender
            for day, count in user_infos.items():
                if day not in time_infos:
                    warn(
                        "_duration_rate_day():user day %s is not in time days[%s]"
                        % (day, str(time_infos.keys())))
                    continue
                rate = int(time_infos[day]) / int(count)
                data['date'] = day
                data['time'] = rate
                self.dbsession.insert(data)
            self.dbsession.commit()

        total, rate = 0, 0
        time_infos = self.stat_user.gen_stat_times().show_info()
        user_infos = self.stat_user.gen_stat_users().show_info()
        data['vender'] = 'HISENSE'
        for day, count in user_infos.items():
            if day not in time_infos:
                warn('user ay %s is not in time days[%s]' %
                     (day, str(time_infos.keys())))
                continue
            rate = int(time_infos[day]) / int(count)
            data['date'] = day
            data['time'] = rate
            self.dbsession.insert(data)
        self.dbsession.commit()
        self.dbsession.close()

    def _duration_rate(self):
        self.dbsession = self.db.open('play_duration_rate')
        data = {
            "vender": '',
            'date': '%s_%s' % (self.config['start'], self.config['end']),
            'time': 0
        }

        venders_time = self.stat_user.gen_stat_count_by_vender_per_day()
        venders_user = self.stat_user.gen_stat_users_by_vender_per_day()
        for vender, stat_time in venders_user.items():
            if vender not in venders_time:
                continue
            time_infos = venders_time[vender].show_info()
            user_infos = stat_time.show_info()
            total, rate, u = 0, 0, 0
            for day, count in user_infos.items():
                if day not in time_infos:
                    continue
                total += int(time_infos[day]) / int(count)
                u += 1
            if u == 0:
                continue
            rate = total / u
            data['vender'] = vender
            data['time'] = rate
            self.dbsession.insert(data)
        self.dbsession.commit()

        total, rate, u = 0, 0, 0
        time_infos = self.stat_user.gen_stat_times().show_info()
        user_infos = self.stat_user.gen_stat_users().show_info()
        for day, count in user_infos.items():
            if day not in time_infos:
                continue
            total += int(time_infos[day]) / int(count)
            u += 1
        if u == 0:
            return
        rate = total / u
        data['vender'] = 'HISENSE'
        data['time'] = rate
        self.dbsession.insert(data)
        self.dbsession.commit()
        self.dbsession.close()

    def _duration_total_day(self):
        self.dbsession = self.db.open('play_duration_day')
        data = {"vender": '', 'date': '', 'time': 0}
        venders_time = self.stat_user.gen_stat_count_by_vender_per_day()
        for vender, stat_time in venders_time.items():
            time_infos = stat_time.show_info()
            data['vender'] = vender
            for day, count in time_infos.items():
                data['date'] = day
                data['time'] = count
                self.dbsession.insert(data)
        self.dbsession.commit()

        time_infos = self.stat_user.gen_stat_times().show_info()
        for day, count in time_infos.items():
            data['vender'] = 'HISENSE'
            data['date'] = day
            data['time'] = count
            self.dbsession.insert(data)

        self.dbsession.commit()
        self.dbsession.close()

    def _final(self):
        self._print_report()
        super(PlayTimeCalcMgr, self)._final()