Пример #1
0
    def __init__(self, msgh, config):
        CalcManager.__init__(self, msgh)
        self.report_fd = None
        self.config = config
        self.stat_user = StatUser(config['start'], config['end'])
        self.rpt_print_intvl = 40
        self.category_count = {1001: 0, # play
                               1002: 0, # zongyi
                               1003: 0, 
                               1004: 0, # movie
                               1005: 0, # catoon
                               1006: 0,
                               1007: 0, # sport
                               1008: 0,
                               1009: 0,
                               1010: 0,
                               1011: 0,
                               1012: 0, # child
                               1013: 0,
                               1014: 0,
                               1015: 0,
                               1016: 0,
                               1017: 0,
                               1100: 0
                               }
        self.country_count = {}

        #self.eh.register_timer(self.rpt_print_intvl * 1000,
        #                       TMTAGS.PRINT_REPORT, True)
        self.db = Mydb()
        self.db.connect('report')
Пример #2
0
 def __init__(self, msgh, mgrq, myname, config):
     CalcWorker.__init__(self, msgh, mgrq, myname, config)
     self.report_intvl = 4
     self.report_threshold = 50
     #self.eh.register_timer(self.report_intvl * 1000,
     #                       TMTAGS.SEND_REPORT, True)
     self.stat_user = StatUser(self.config['start'], self.config['end'])
Пример #3
0
 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')
Пример #4
0
 def __init__(self, msgh, mgrq, myname, config):
     CalcWorker.__init__(self, msgh, mgrq, myname, config)
     self.report_intvl = 4
     self.report_threshold = 50
     #self.eh.register_timer(self.report_intvl * 1000,
     #                       TMTAGS.SEND_REPORT, True)
     self.stat_user = StatUser(self.config['start'], self.config['end'])
Пример #5
0
 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')
Пример #6
0
class PlayTimeCalc(CalcWorker):
    def __init__(self, msgh, mgrq, myname, config):
        CalcWorker.__init__(self, msgh, mgrq, myname, config)
        self.report_intvl = 4
        self.report_threshold = 50
        #self.eh.register_timer(self.report_intvl * 1000,
        #                       TMTAGS.SEND_REPORT, True)
        self.stat_user = StatUser(self.config['start'], self.config['end'])

    def _process_msg(self, msg):
        msgtype = msg.get_msgtype()
        if msgtype == MsgType.MsgPlayRetentionCalc:
            calc_msg = MsgPlayRetentionCalc()
            calc_msg.cast(msg)
            calc_msg.parse()
            ts = calc_msg.get_timestamp()
            user = calc_msg.get_userid()
            vender = calc_msg.get_vender()
            retention = calc_msg.get_retention()
            if int(retention) > 14400:
                print "------invalid retention", retention
                return
            #print "PlayTimeCalc::_process_msg() user: %s, vender: %s"%(user, vender)
            if vender in vender_dict:
                vender = vender_dict[vender]
            if ts.find('.') != -1 or ts.isdigit() is False:
                warn("invalid timestamp %s for user %s"%(ts, user))
                return
            #print '-calc------', ts, user, vender, retention
            self.stat_user.mark(user, ts, vender, int(retention))
            #print "marked user: %s, ts: %s, vender: %s"%(user, ts, vender)
            #print "current user: %s, current count: %s"%(self.stat_user.count_user(),self.current)
            
            if self.stat_user.count_user() > self.report_threshold:
                self._send_report()
            self.current += 1
        else:
            super(PlayTimeCalc, self)._process_msg(msg)

    def _process_timer(self, msg):
        tag = msg.get_tag()
        if tag == TMTAGS.SEND_REPORT:
            self._send_report()
        else:
            super(PlayTimeCalc, self)._process_timer(msg)

    def _send_report(self):
        ptr_msg = MsgPlayTimeReport()
         #self.stat_user.show_user_info().replace('\\', '')
        ptr_msg.set_report_info(
            self.stat_user.show_user_info())
        self.queue.send(self.mgrq, ptr_msg)
        self.stat_user.clear_data()

    def _final(self):
        self._send_report()
        super(PlayTimeCalc, self)._final()
Пример #7
0
 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.analysis_time = StatTime(config['start_analysis'],
                                   config['end_analysis'])
     self.rpt_print_intvl = 40
     self.commit_intvl = 30
     self.eh.register_timer(self.commit_intvl * 1000, TMTAGS.DB_COMMIT,
                            True)
     self.db = Mydb()
     self.db.connect('repository')
     self.dbsession = self.db.open('all_users')
Пример #8
0
class PlayTimeCalc(CalcWorker):
    def __init__(self, msgh, mgrq, myname, config):
        CalcWorker.__init__(self, msgh, mgrq, myname, config)
        self.report_intvl = 4
        self.report_threshold = 50
        #self.eh.register_timer(self.report_intvl * 1000,
        #                       TMTAGS.SEND_REPORT, True)
        self.stat_user = StatUser(self.config['start'], self.config['end'])

    def _process_msg(self, msg):
        msgtype = msg.get_msgtype()
        if msgtype == MsgType.MsgPlayRetentionCalc:
            calc_msg = MsgPlayRetentionCalc()
            calc_msg.cast(msg)
            calc_msg.parse()
            ts = calc_msg.get_timestamp()
            user = calc_msg.get_userid()
            vender = calc_msg.get_vender()
            retention = calc_msg.get_retention()
            if int(retention) > 14400:
                print "------invalid retention", retention
                return
            #print "PlayTimeCalc::_process_msg() user: %s, vender: %s"%(user, vender)
            if vender in vender_dict:
                vender = vender_dict[vender]
            if ts.find('.') != -1 or ts.isdigit() is False:
                warn("invalid timestamp %s for user %s" % (ts, user))
                return
            #print '-calc------', ts, user, vender, retention
            self.stat_user.mark(user, ts, vender, int(retention))
            #print "marked user: %s, ts: %s, vender: %s"%(user, ts, vender)
            #print "current user: %s, current count: %s"%(self.stat_user.count_user(),self.current)

            if self.stat_user.count_user() > self.report_threshold:
                self._send_report()
            self.current += 1
        else:
            super(PlayTimeCalc, self)._process_msg(msg)

    def _process_timer(self, msg):
        tag = msg.get_tag()
        if tag == TMTAGS.SEND_REPORT:
            self._send_report()
        else:
            super(PlayTimeCalc, self)._process_timer(msg)

    def _send_report(self):
        ptr_msg = MsgPlayTimeReport()
        #self.stat_user.show_user_info().replace('\\', '')
        ptr_msg.set_report_info(self.stat_user.show_user_info())
        self.queue.send(self.mgrq, ptr_msg)
        self.stat_user.clear_data()

    def _final(self):
        self._send_report()
        super(PlayTimeCalc, self)._final()
Пример #9
0
class ActiveUserCalc(CalcWorker):
    def __init__(self, msgh, mgrq, myname, config):
        CalcWorker.__init__(self, msgh, mgrq, myname, config)
        self.report_intvl = 4
        self.report_threshold = 50
        self.stat_user = StatUser(self.config['start'], self.config['end'])

    def _process_msg(self, msg):
        msgtype = msg.get_msgtype()
        if msgtype == MsgType.MsgActiveUserCalc:
            calc_msg = MsgActiveUserCalc()
            calc_msg.cast(msg)
            calc_msg.parse()
            ts = calc_msg.get_timestamp()
            user = calc_msg.get_userid()
            vender = calc_msg.get_vender()
            if vender in vender_dict:
                vender = vender_dict[vender]
            if ts.find('.') != -1 or ts.isdigit() is False:
                warn("invalid timestamp %s for user %s"%(ts, user))
                return
            self.stat_user.mark(user, ts, vender)
            
            if self.stat_user.count_user() > self.report_threshold:
                self._send_report()
            self.current += 1
        else:
            super(ActiveUserCalc, self)._process_msg(msg)

    def _process_timer(self, msg):
        tag = msg.get_tag()
        if tag == TMTAGS.SEND_REPORT:
            self._send_report()
        else:
            super(ActiveUserCalc, self)._process_timer(msg)

    def _send_report(self):
        ptr_msg = MsgActiveUserReport()
        ptr_msg.set_report_info(
            self.stat_user.show_user_info())
        self.queue.send(self.mgrq, ptr_msg)
        self.stat_user.clear_data()

    def _final(self):
        self._send_report()
        super(ActiveUserCalc, self)._final()
Пример #10
0
class PlayUserCalc(CalcWorker):
    def __init__(self, msgh, mgrq, myname, config):
        CalcWorker.__init__(self, msgh, mgrq, myname, config)
        self.report_intvl = 4
        self.report_threshold = 50
        self.stat_user = StatUser(self.config['start'], self.config['end'])

    def _process_msg(self, msg):
        msgtype = msg.get_msgtype()
        if msgtype == MsgType.MsgPlayUserCalc:
            calc_msg = MsgPlayUserCalc()
            calc_msg.cast(msg)
            calc_msg.parse()
            ts = calc_msg.get_timestamp()
            user = calc_msg.get_userid()
            vender = calc_msg.get_vender()
            if vender in vender_dict:
                vender = vender_dict[vender]
            if ts.find('.') != -1 or ts.isdigit() is False:
                warn("invalid timestamp %s for user %s"%(ts, user))
                return
            self.stat_user.mark(user, ts, vender)
            
            if self.stat_user.count_user() > self.report_threshold:
                self._send_report()
            self.current += 1
        else:
            super(PlayUserCalc, self)._process_msg(msg)

    def _process_timer(self, msg):
        tag = msg.get_tag()
        if tag == TMTAGS.SEND_REPORT:
            self._send_report()
        else:
            super(PlayUserCalc, self)._process_timer(msg)

    def _send_report(self):
        ptr_msg = MsgPlayUserReport()
        ptr_msg.set_report_info(
            self.stat_user.show_user_info())
        self.queue.send(self.mgrq, ptr_msg)
        self.stat_user.clear_data()

    def _final(self):
        self._send_report()
        super(PlayUserCalc, self)._final()
Пример #11
0
class TopMediasCalc(CalcWorker):
    def __init__(self, msgh, mgrq, myname, config):
        CalcWorker.__init__(self, msgh, mgrq, myname, config)
        self.report_intvl = 4
        self.report_threshold= 100
        self.report_counter = 0
        self.stat_user = StatUser(self.config['start'], self.config['end'])

    def _process_msg(self, msg):
        msgtype = msg.get_msgtype()
        if msgtype == MsgType.MsgTopMediasCalc:
            calc_msg = MsgTopMediasCalc()
            calc_msg.cast(msg)
            calc_msg.parse()
            ts = calc_msg.get_timestamp()
            user = calc_msg.get_userid()

            ff = open("fff", "a")
            try:
                cts = call_convert(float(ts)/1000)
            except:
                return
            aa = "media(%s), ts(%s)\n"%(user, cts)
            ff.write(aa)
            ff.close()
            
            vender = calc_msg.get_vender()
            if vender in vender_dict:
                vender = vender_dict[vender]
            if ts.find('.') != -1 or ts.isdigit() is False:
                warn("invalid timestamp %s for user %s"%(ts, user))
                return
            self.stat_user.mark(user, ts, vender)
            #print "after mark ", self.stat_user.show_user_info()
            
            if self.report_counter > self.report_threshold:
                self.report_counter = 0
                self._send_report()
            self.current += 1
            self.report_counter += 1
        else:
            super(TopMediasCalc, self)._process_msg(msg)

    def _process_timer(self, msg):
        tag = msg.get_tag()
        if tag == TMTAGS.SEND_REPORT:
            self._send_report()
        else:
            super(TopMediasCalc, self)._process_timer(msg)

    def _send_report(self):
        ptr_msg = MsgTopMediasReport()
        ptr_msg.set_report_info(
            self.stat_user.show_user_info())
        #print "--send_report--", ptr_msg.get_body()
        self.queue.send(self.mgrq, ptr_msg)
        self.stat_user.clear_data()

    def _final(self):
        self._send_report()
        super(TopMediasCalc, self)._final()
Пример #12
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()
Пример #13
0
 def __init__(self, msgh, mgrq, myname, config):
     CalcWorker.__init__(self, msgh, mgrq, myname, config)
     self.report_intvl = 4
     self.report_threshold = 50
     self.stat_user = StatUser(self.config['start'], self.config['end'])
Пример #14
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()
Пример #15
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()
Пример #16
0
class ActiveUserCalcMgr(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("ActiveUserCalcMgr::_process_msg() enter")
        msgtype = msg.get_msgtype()
        if msgtype == MsgType.MsgActiveUserReport:
            debug("ActiveUserCalcMgr::_process_msg() got "
                  "report message %s"%msg.get_body())
            ptr_msg = MsgActiveUserReport()
            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(ActiveUserCalcMgr, self)._process_msg(msg)

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

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

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

    def _user_report_total(self):
        models = self.stat_user.gen_stat_users_by_model()
        self.dbsession = self.db.open('active_users_total')
        from common.models_list import models_hash
        data = {"model": "",
                'date': '%s_%s'%(self.config['start'],
                                 self.config['end']),
                'count': 0}
        for model, count in models.items():
            if model in models_hash:
                data['model'] = models_hash[model]
                data['count'] = count
            else:
                #print "%s --> %s"%(model, count)
                data['model'] = model
                data['count'] = count
            self.dbsession.insert(data)
        self.dbsession.commit()
        
        data['model'] = "HISENSE"
        data['count'] = self.stat_user.count_user()
        self.dbsession.insert(data)
        self.dbsession.commit()
        self.dbsession.close()
        
    def _user_report_day(self):
        models = self.stat_user.gen_stat_users_by_model_per_day()
        from common.models_list import models_hash
        self.dbsession = self.db.open('active_users_day')
        data = {"model": "",
                'date': "",
                'count': 0}
        for m, stat_time in models.items():
            infos = stat_time.show_info()
            model = ""
            if m in models_hash:
                model = models_hash[m]
            else:
                model = m
            data['model'] = model
            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['model'] = 'HISENSE'
        for day, count in infos.items():
            data['date'] = day
            data['count'] = count
            self.dbsession.insert(data)
        self.dbsession.commit()
        self.dbsession.close()
Пример #17
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()
Пример #18
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 medias:", self.stat_user.count_user()
        self._category_play_duration()
        
    def _category_play_duration(self):
        from common.media_type import media_types
        from common.fetch_media_data import VodMedia
        self.dbsession = self.db.open('play_top_media_types_duration')

        data = {"seq": "",
                'date':'%s_%s'%(self.config['start'],
                                self.config['end']),
                'categoryid': "",
                'category_name':'',
                'count': 0}
        media_type_count = {}
        for mediaid, play_info in self.stat_user.users_info.users.items():
            infos = play_info.count_with_index()
            total = 0
            for index, count in infos.items():
                total += count
            media = VodMedia(mediaid)
            title = media.get_title()
            print "id: %s, cid: %s, title: %s"%\
                  (mediaid, media.get_category_id(), unicode(title, 'utf-8'))
            cid = media.get_category_id()
            if cid is None:
                continue
            cid = int(cid)
            if cid in media_type_count:
                media_type_count[cid] += total
            else:
                media_type_count[cid] = total

        sorted_types = sorted(media_type_count.items(), key=lambda d: d[1], reverse=True)
        for i in range(len(sorted_types)):
            data['seq'] = i
            category_id = sorted_types[i][0]
            data['categoryid'] = category_id
            if category_id in media_types:
                data['category_name'] = media_types[category_id]
            else:
                data['category_name'] = category_id
            data['count'] = sorted_types[i][1]
            self.dbsession.insert(data)
        self.dbsession.commit()
        self.dbsession.close()
                
    def _final(self):
        self._print_report()
        super(PlayTimeCalcMgr, self)._final()
Пример #19
0
 def __init__(self, msgh, mgrq, myname, config):
     CalcWorker.__init__(self, msgh, mgrq, myname, config)
     self.report_intvl = 4
     self.report_threshold= 100
     self.report_counter = 0
     self.stat_user = StatUser(self.config['start'], self.config['end'])
Пример #20
0
class TopMediasCalcMgr(CalcManager):
    def __init__(self, msgh, config):
        CalcManager.__init__(self, msgh)
        self.report_fd = None
        self.config = config
        self.stat_user = StatUser(config['start'], config['end'])
        self.rpt_print_intvl = 40
        self.category_count = {1001: 0, # play
                               1002: 0, # zongyi
                               1003: 0, 
                               1004: 0, # movie
                               1005: 0, # catoon
                               1006: 0,
                               1007: 0, # sport
                               1008: 0,
                               1009: 0,
                               1010: 0,
                               1011: 0,
                               1012: 0, # child
                               1013: 0,
                               1014: 0,
                               1015: 0,
                               1016: 0,
                               1017: 0,
                               1100: 0
                               }
        self.country_count = {}

        #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("TopMediasCalcMgr::_process_msg() enter")
        msgtype = msg.get_msgtype()
        if msgtype == MsgType.MsgTopMediasReport:
            debug("TopMediasCalcMgr::_process_msg() got "
                  "report message %s"%msg.get_body())
            ptr_msg = MsgTopMediasReport()
            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(TopMediasCalcMgr, self)._process_msg(msg)

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

    def _print_report(self):
        self._top_medias()
        self._top_media_type()
        self._top_country()
        self._category_times()

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

    def _count_medias_for_category(self, cid):
        if cid not in self.category_count:
            return
        self.category_count[cid] += 1

    def _count_media_for_country(self, country, count):
        if country in self.country_count:
            self.country_count[country] += count
        else:
            self.country_count[country] = count

    def _top_medias(self):
        top_list = self.stat_user.gen_stat_tops()
        echo("there are totaly %s top medias"%len(top_list))
        self.dbsession = self.db.open('play_top_medias')
        data = {"seq": "",
                'date':'%s_%s'%(self.config['start'],
                                self.config['end']),
                'mediaid': "",
                'media_name':'',
                'count': 0}
        i = 0
        from common.fetch_media_data import VodMedia
        for mediaid, count in top_list:
            data['seq'] = i
            data['mediaid'] = mediaid
            media = VodMedia(mediaid)
            title = media.get_title()
            print "id: %s, cid: %s, title: %s"%\
                  (mediaid, media.get_category_id(), title)
            #print "%s(%s) -- %s"%(title, mediaid, media.get_category_id())
            data['media_name'] = title
            data['count'] = count
            self.dbsession.insert(data)
            i += 1
        self.dbsession.commit()
        self.dbsession.close()
        
        
    def _top_media_type(self):
        from common.media_type import media_types
        from common.fetch_media_data import VodMedia
        self.dbsession = self.db.open('play_top_media_types_times')

        data = {"seq": "",
                'date':'%s_%s'%(self.config['start'],
                                self.config['end']),
                'categoryid': "",
                'category_name':'',
                'count': 0}
        media_type_count = {}
        for mediaid, play_info in self.stat_user.users_info.users.items():
            infos = play_info.count_with_index()
            total = 0
            for index, count in infos.items():
                total += count
            media = VodMedia(mediaid)
            title = media.get_title()
            print "id: %s, cid: %s, title: %s"%\
                  (mediaid, media.get_category_id(), unicode(title, 'utf-8'))
            cid = media.get_category_id()
            if cid is None:
                continue

            country = media.get_country()

            self._count_medias_for_category(int(cid))
            self._count_media_for_country(country, total)
            
            # count the media play times
            if cid in media_type_count:
                media_type_count[cid] += total
            else:
                media_type_count[cid] = total
                
        sorted_types = sorted(media_type_count.items(), key=lambda d: d[1], reverse=True)
        for i in range(len(sorted_types)):
            data['seq'] = i
            category_id = sorted_types[i][0]
            data['categoryid'] = category_id
            if category_id in media_types:
                data['category_name'] = media_types[category_id]
            else:
                data['category_name'] = category_id
            data['count'] = sorted_types[i][1]
            self.dbsession.insert(data)
        self.dbsession.commit()
        self.dbsession.close()

    def _category_times(self):
        print "### most popular categories play info ###"
        from common.media_type import media_types
        for cid, count in self.category_count.items():
            print "%s : %s"%(media_types[cid], count)
        
    def _top_country(self):
        print "### most popular country play info ###"
        for country, count in self.country_count.items():
            print "%s : %s"%(country, count)
Пример #21
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 medias:", self.stat_user.count_user()
        self._category_play_duration()

    def _category_play_duration(self):
        from common.media_type import media_types
        from common.fetch_media_data import VodMedia
        self.dbsession = self.db.open('play_top_media_types_duration')

        data = {
            "seq": "",
            'date': '%s_%s' % (self.config['start'], self.config['end']),
            'categoryid': "",
            'category_name': '',
            'count': 0
        }
        media_type_count = {}
        for mediaid, play_info in self.stat_user.users_info.users.items():
            infos = play_info.count_with_index()
            total = 0
            for index, count in infos.items():
                total += count
            media = VodMedia(mediaid)
            title = media.get_title()
            print "id: %s, cid: %s, title: %s"%\
                  (mediaid, media.get_category_id(), unicode(title, 'utf-8'))
            cid = media.get_category_id()
            if cid is None:
                continue
            cid = int(cid)
            if cid in media_type_count:
                media_type_count[cid] += total
            else:
                media_type_count[cid] = total

        sorted_types = sorted(media_type_count.items(),
                              key=lambda d: d[1],
                              reverse=True)
        for i in range(len(sorted_types)):
            data['seq'] = i
            category_id = sorted_types[i][0]
            data['categoryid'] = category_id
            if category_id in media_types:
                data['category_name'] = media_types[category_id]
            else:
                data['category_name'] = category_id
            data['count'] = sorted_types[i][1]
            self.dbsession.insert(data)
        self.dbsession.commit()
        self.dbsession.close()

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