示例#1
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()
示例#2
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()
示例#3
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()
示例#4
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()
示例#5
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()