예제 #1
0
def get_user_online_stat(server_id):
    
    cursor = connection.cursor()
    
    today = get_date() + ' 00:00:00'
    tomorrow = get_tomorrow_str_by_str(today)
    
    try:
        user_online_stat = cursor.fetchall("SELECT * FROM stat_online WHERE server_id='%s' AND stat_time BETWEEN '%s' AND '%s'" % (server_id, today, tomorrow))
    finally:
        cursor.close()
    
    return user_online_stat
예제 #2
0
class UseToolLogStat(BaseClient):
    CLIENT_NAME = "use_tool_log"
    date = get_yestoday_str_by_str(get_date(), '%Y-%m-%d')
    server_id = None

    def __init__(self, date=None, server_id=None):
        super(self.__class__, self).__init__(self.__class__.CLIENT_NAME)
        if date is not None:
            self.date = date
        if server_id is not None:
            self.server_id = server_id

    def run(self):

        server_list = self.get_server_list()
        for server in server_list:
            try:
                self.stat(server, self.date)
            except:
                self.log(traceback.format_exc())
                pass

    def stat(self, server, date):
        db_config = server_util.str_to_dbconfig(server.db_connect)
        connect = get_connection(db_config)
        page = 1
        data_map = {}
        """ 统计金币消耗  """

        self.log('server_name:[%s] stat gold start,date:[%s]' %
                 (server.server_name, date))
        while True:
            num = (page - 1) * 10000
            sql = "SELECT SUM(amount) as total ,use_type,flag FROM (SELECT * FROM user_gold_use_log WHERE DATE(created_time) = '%s' LIMIT %d,10000) t GROUP BY use_type,flag" % (
                date, num)
            cursor = None
            try:
                cursor = connect.cursor()
                datas = cursor.fetchall(sql)
                if not datas:
                    break
                for data in datas:
                    key = str(data['use_type']) + ',' + str(data['flag'])
                    total = data_map.get(key, 0)
                    total += data['total']
                    data_map[key] = total
            except Exception, ex:
                self.log(ex)
                self.log("server_name:[%s],page:[%s] stat fail " %
                         (server.server_name, page))
            finally:
예제 #3
0
def get_user_online_stat(server_id):

    cursor = connection.cursor()

    today = get_date() + ' 00:00:00'
    tomorrow = get_tomorrow_str_by_str(today)

    try:
        user_online_stat = cursor.fetchall(
            "SELECT * FROM stat_online WHERE server_id='%s' AND stat_time BETWEEN '%s' AND '%s'"
            % (server_id, today, tomorrow))
    finally:
        cursor.close()

    return user_online_stat
예제 #4
0
class StatServerDateCountry(BaseClient):

    CLIENT_NAME = "stat_server_data_country"
    statServerDatass = []
    isInsert = True
    date = get_date()
    server_id = None
    is_input = False

    def __init__(self, isInsert=True, date=None, server_id=None):
        super(self.__class__, self).__init__(self.__class__.CLIENT_NAME)
        self.statServerDatass = []
        self.isInsert = isInsert
        if date is not None:
            self.is_input = True
            self.date = date
        if server_id is not None:
            self.server_id = server_id

    def run(self):
        server_list = self.get_server_list()
        self.log("StatServerDate start %s" % get_time())

        if self.server_id is None:
            statServerDatas = StatServerDataCountry.query(
                condition="stat_date ='%s'" % self.date)
        else:
            statServerDatas = StatServerDataCountry.query(
                condition="stat_date ='%s' and server_id = '%s' " %
                (self.date, self.server_id))
        if not statServerDatas:
            for server in server_list:
                try:
                    if server.server_status == 100:
                        continue
                    countries = self.getServerCountryCode(server)
                    if countries:
                        for country in countries:
                            self.stat(server, self.date, country['idfa'])
                except Exception, ex:
                    self.log("server_name[%s] error" % server.server_name)
                    self.log(ex)

            self.log("StatServerDate end %s" % get_time())
예제 #5
0
def get_stat_server(begindate, enddate=None):
    statServerDatas = []
    if begindate == date_utils.get_date():
        statServerDate = StatServerDate(False)
        statServerDate.start()
        statServerDatas = statServerDate.statServerDatass
    elif enddate is not None:
        sql = (
            "SELECT server_name,server_id, sum(new_register) as new_register, sum(create_user) as create_user, sum(date_active) as date_active, sum(pay_people) as pay_people, sum(pay_money) as pay_money, sum(max_online) as max_online, sum(new_user_pay) as new_user_pay\
        , sum(old_user_pay) as old_user_pay, sum(new_payer) as new_payer, sum(old_payer) as old_payer  FROM stat_server_data where stat_date>= '%s' and stat_date<='%s' group by server_id;"
            % (begindate, enddate)
        )
        cursor = connection.cursor()
        try:
            datas = cursor.fetchall(sql)
            for data in datas:
                statServerDatas.append(data)
        finally:
            cursor.close()
    else:
        sql = "SELECT * from stat_server_data where stat_date = '%s'" % begindate
        cursor = connection.cursor()
        try:
            datas = cursor.fetchall(sql)
            for data in datas:
                statServerDatas.append(data)
        finally:
            cursor.close()
        # statServerDatas = StatServerData.query(condition="stat_date ='%s'" % begindate)

    total = 0
    statServerDatas_s = []
    for s in statServerDatas:
        if not s:
            continue
        try:
            server_id = s["server_id"]
        except:
            server_id = s.server_id
        server = Server.load(server_id=server_id)
        try:
            if server and server.is_test == 0:
                statServerDatas_s.append(s)
                total += s["pay_money"]
            if s["pay_people"] != 0 and s["date_active"] != 0:
                value = round(s["pay_people"] / (s["date_active"]), 5) * 100
                s.temp = value
            else:
                s.temp = 0
        except:
            if server and server.is_test == 0:
                total += s.pay_money
            if s.pay_money != 0 and s.date_active != 0:
                value = round(s.pay_money / (s.date_active), 5) * 100
                s.temp = value
            else:
                s.temp = 0
    stat_server_datas_map = {}
    for s in statServerDatas_s:
        if not s:
            continue
        try:
            server_id = s["server_id"]
        except:
            server_id = s.server_id
        server = Server.load(server_id=server_id)
        server_zone = server.server_zone
        server_zone_server_list = stat_server_datas_map.get(server_zone, [])
        server_zone_server_list.append(s)
        stat_server_datas_map[server_zone] = server_zone_server_list

    items = stat_server_datas_map.items()
    items.sort()
    for k, values in stat_server_datas_map.iteritems():
        try:
            server_id = s["server_id"]
            values = sorted(values, cmp=lambda x, y: cmp(int(x["server_id"][1:]), int(y["server_id"][1:])))
        except:
            values = sorted(values, cmp=lambda x, y: cmp(int(x.server_id[1:]), int(y.server_id[1:])))
        stat_server_datas_map[k] = values

    # statServerDatas_s.sort(cmp=lambda x,y:cmp(int(x.server_id[1:]), int(y.server_id[1:])))
    return stat_server_datas_map, total, server_zone_map
예제 #6
0
            statServerData = StatServerDataCountry()
            statServerData.country_code = country
            for k, v in values.iteritems():
                setattr(statServerData, k, v)
            statServerData.stat_date = date
            if self.isInsert:
                statServerData.persist()
                #print ''
            else:
                self.statServerDatass.append(statServerData)

            date = get_date_str_by_day(date, 1, '%Y-%m-%d')
            #             if self.is_input:
            #                 break
            if string_to_datetime(date, '%Y-%m-%d') >= string_to_datetime(
                    get_date(), '%Y-%m-%d'):
                break

    def get_server_list(self):
        servers = []
        #         servers = []
        #         s1 = Server()
        #         s1.db_connect = "server=118.244.198.81,3306;database=ldsg_h10;user=ldsg_h10_op;pwd=3e454ss3kd40e24;"
        #         s1.server_id = 1
        #         s2 = Server()
        #         s2.db_connect = "server=118.244.198.86,3306;database=ldsg_h11;user=ldsg_h11_rd;pwd=e727484b3251bc;"
        #         s2.server_id = 2
        #         servers.append(s1)
        #         servers.append(s2)
        if self.server_id is not None:
            server = Server.load(server_id=self.server_id)
            statServerData = StatServerDataCountry()
            statServerData.country_code=country
            for k, v in values.iteritems():
                setattr(statServerData, k, v)
            statServerData.stat_date = date
            if self.isInsert:
                statServerData.persist()
                #print ''
            else:
                self.statServerDatass.append(statServerData)
            
            
            date = get_date_str_by_day(date,1,'%Y-%m-%d')
#             if self.is_input:
#                 break
            if string_to_datetime(date,'%Y-%m-%d') >= string_to_datetime(get_date(),'%Y-%m-%d') :
                break;
            
    def get_server_list(self):
        servers = []
#         servers = []
#         s1 = Server()
#         s1.db_connect = "server=118.244.198.81,3306;database=ldsg_h10;user=ldsg_h10_op;pwd=3e454ss3kd40e24;"
#         s1.server_id = 1
#         s2 = Server()
#         s2.db_connect = "server=118.244.198.86,3306;database=ldsg_h11;user=ldsg_h11_rd;pwd=e727484b3251bc;"
#         s2.server_id = 2
#         servers.append(s1)
#         servers.append(s2)
        if self.server_id is not None:
            server = Server.load(server_id = self.server_id)
예제 #8
0
def get_stat_server(begindate, enddate=None):
    statServerDatas = []
    if begindate == date_utils.get_date():
        statServerDate = StatServerDate(False)
        statServerDate.start()
        statServerDatas = statServerDate.statServerDatass
    elif enddate is not None:
        sql = "SELECT server_name,server_id, sum(new_register) as new_register, sum(create_user) as create_user, sum(date_active) as date_active, sum(pay_people) as pay_people, sum(pay_money) as pay_money, sum(max_online) as max_online, sum(new_user_pay) as new_user_pay\
        , sum(old_user_pay) as old_user_pay, sum(new_payer) as new_payer, sum(old_payer) as old_payer  FROM stat_server_data where stat_date>= '%s' and stat_date<='%s' group by server_id;" % (
            begindate, enddate)
        cursor = connection.cursor()
        try:
            datas = cursor.fetchall(sql)
            for data in datas:
                statServerDatas.append(data)
        finally:
            cursor.close()
    else:
        sql = "SELECT * from stat_server_data where stat_date = '%s'" % begindate
        cursor = connection.cursor()
        try:
            datas = cursor.fetchall(sql)
            for data in datas:
                statServerDatas.append(data)
        finally:
            cursor.close()
        #statServerDatas = StatServerData.query(condition="stat_date ='%s'" % begindate)

    total = 0
    statServerDatas_s = []
    for s in statServerDatas:
        if not s:
            continue
        try:
            server_id = s["server_id"]
        except:
            server_id = s.server_id
        server = Server.load(server_id=server_id)
        try:
            if server and server.is_test == 0:
                statServerDatas_s.append(s)
                total += s["pay_money"]
            if s["pay_people"] != 0 and s["date_active"] != 0:
                value = round(s["pay_people"] / (s["date_active"]), 5) * 100
                s.temp = value
            else:
                s.temp = 0
        except:
            if server and server.is_test == 0:
                total += s.pay_money
            if s.pay_money != 0 and s.date_active != 0:
                value = round(s.pay_money / (s.date_active), 5) * 100
                s.temp = value
            else:
                s.temp = 0
    stat_server_datas_map = {}
    for s in statServerDatas_s:
        if not s:
            continue
        try:
            server_id = s["server_id"]
        except:
            server_id = s.server_id
        server = Server.load(server_id=server_id)
        server_zone = server.server_zone
        server_zone_server_list = stat_server_datas_map.get(server_zone, [])
        server_zone_server_list.append(s)
        stat_server_datas_map[server_zone] = server_zone_server_list

    items = stat_server_datas_map.items()
    items.sort()
    for k, values in stat_server_datas_map.iteritems():
        try:
            server_id = s["server_id"]
            values = sorted(values,
                            cmp=lambda x, y: cmp(int(x["server_id"][1:]),
                                                 int(y["server_id"][1:])))
        except:
            values = sorted(values,
                            cmp=lambda x, y: cmp(int(x.server_id[1:]),
                                                 int(y.server_id[1:])))
        stat_server_datas_map[k] = values

    #statServerDatas_s.sort(cmp=lambda x,y:cmp(int(x.server_id[1:]), int(y.server_id[1:])))
    return stat_server_datas_map, total, server_zone_map