示例#1
0
 def index(self):
     platform_id = int(self.get_argument('platform_id',6))
     run_id = int(self.get_argument('run_id',0))
     plan_id = int(self.get_argument('plan_id',0))
     partner_id = int(self.get_argument('partner_id',0))
     version_name = self.get_argument('version_name','').replace('__','.')
     product_name = self.get_argument('product_name','')
     #perm
     run_list=self.run_list()
     run_list = self.filter_run_id_perms(run_list=run_list)
     run_id_list = [run['run_id'] for run in run_list]      
     if run_id == 0 and run_id_list: # has perm and doesn't select a run_id
         if len(run_id_list) == len(Run.mgr().Q().extra("status<>'hide'").data()):
             run_id = 0  # user has all run_id perms
         else:
             run_id = run_id_list[0]
     if run_id not in run_id_list and run_id != 0: # don't has perm and selete a run_id
         scope = None
     # scope 
     else:
         scope = Scope.mgr().Q().filter(platform_id=platform_id,run_id=run_id,plan_id=plan_id,
                   partner_id=partner_id,version_name=version_name,product_name=product_name)[0]
     tody = self.get_date()
     yest = tody - datetime.timedelta(days=1)
     last = yest - datetime.timedelta(days=1)
     start = tody - datetime.timedelta(days=30)
     basics,topn_sch,topn_hw,b_books,c_books = [],[],[],[],[]
     visit_y = dict([(i,{'pv':0,'uv':0}) for i in PAGE_TYPE])
     visit_l = dict([(i,{'pv':0,'uv':0}) for i in PAGE_TYPE])
     if scope:
         # basic stat
         dft = dict([(i,0) for i in BasicStatv3._fields])
         basic_y = BasicStatv3.mgr().Q(time=yest).filter(scope_id=scope.id,mode='day',time=yest)[0] 
         basic_l = BasicStatv3.mgr().Q(time=last).filter(scope_id=scope.id,mode='day',time=last)[0] 
         basic_m = BasicStatv3.mgr().get_data(scope.id,'day',start,tody,ismean=True)
         basic_p = BasicStatv3.mgr().get_peak(scope.id,'day',start,tody)
         basic_y,basic_l = basic_y or dft,basic_l or dft
         basic_y['title'],basic_l['title'] = '昨日统计','前日统计'
         basic_m['title'],basic_p['title'] = '每日平均','历史峰值'
         basics = [basic_y,basic_l,basic_m,basic_p]
         # page visit
         for i in VisitStat.mgr().Q().filter(scope_id=scope.id,mode='day',time=yest):
             visit_y[i['type']] = i
         for i in VisitStat.mgr().Q().filter(scope_id=scope.id,mode='day',time=last):
             visit_l[i['type']] = i
         # topN search & hotword
         q = TopNStat.mgr().Q().filter(scope_id=scope.id,mode='day',time=yest)
         topn_sch = q.filter(type='search').orderby('no')[:10]
         topn_hw = q.filter(type='hotword').orderby('no')[:10]
         # books of by-book & by-chapter
         q = BookStat.mgr().Q(time=yest).filter(scope_id=scope.id,mode='day',time=yest)
         b_books = Service.inst().fill_book_info(q.filter(charge_type='book').orderby('fee','DESC')[:10])
         c_books = Service.inst().fill_book_info(q.filter(charge_type='chapter').orderby('fee','DESC')[:10])
     self.render('data/basic.html',
                 platform_id=platform_id,run_id=run_id,plan_id=plan_id,
                 partner_id=partner_id,version_name=version_name,product_name=product_name,
                 run_list=self.run_list(),plan_list=self.plan_list(),date=tody.strftime('%Y-%m-%d'),
                 basics = basics,visit_y=visit_y,visit_l=visit_l,topn_sch = topn_sch,
                 topn_hw=topn_hw,b_books=b_books,c_books=c_books
                 )
示例#2
0
 def import_toptag_bybook(self, mode, start):
     '''
     mode: hour,day,week,month
     start: start time
     return: top tags by download user count of each book in it
     '''
     if mode != 'day':
         return
     start, end = self.normlize_time(mode, start)
     q = Scope.mgr().Q().extra(
         "status in ('pas','nice') AND find_in_set('book',mask)")
     import_num = 0
     for scope in q:
         result = {}
         for i in BookStat.mgr().Q(time=start).filter(scope_id=scope.id,
                                                      mode=mode,
                                                      time=start):
             info = Service.inst().extern.get_book_info2(i.book_id)
             if info and 'tag' in info.keys():
                 for t in info['tag'].split(','):
                     t = t.lower().strip()
                     if t in result:
                         result[t]['pay_down'] += i.pay_down
                         result[t]['free_down'] += i.free_down
                         result[t]['pay_user'] += i.pay_user
                         result[t]['free_user'] += i.free_user
                         result[t]['pv'] += i.pv
                         result[t]['uv'] += i.uv
                         result[t]['fee'] += i.fee
                     else:
                         result[t] = {
                             'pay_down': i.pay_down,
                             'free_down': i.free_down,
                             'pay_user': i.pay_user,
                             'free_user': i.free_user,
                             'pv': i.pv,
                             'uv': i.uv,
                             'fee': i.fee
                         }
         for t in result:
             try:
                 item = result[t]
                 stat = BookTagStat.new()
                 stat.scope_id = scope['id']
                 stat.mode = mode
                 stat.time = start
                 stat.tag = t.encode('utf-8')
                 stat.pay_down = item['pay_down']
                 stat.free_down = item['free_down']
                 stat.pay_user = item['pay_user']
                 stat.free_user = item['free_user']
                 stat.pv = item['pv']
                 stat.uv = item['uv']
                 stat.fee = item['fee']
                 stat.save()
                 import_num += 1
             except Exception, e:
                 logging.error('%s\n', str(e), exc_info=True)
示例#3
0
def get_book_data(cp, time):
    q = BookStat.mgr().Q(time=time).filter(scope_id=1,mode='day',time=time)
    books = q[:]
    books = Service.inst().fill_book_info(books)
    res = []
    for i in books:
        if i['cp'].encode("UTF-8") == cp:
            res.append(i)
    return res
示例#4
0
def get_book_data(cp, time):
    q = BookStat.mgr().Q(time=time).filter(scope_id=1, mode='day', time=time)
    books = q[:]
    books = Service.inst().fill_book_info(books)
    res = []
    for i in books:
        if i['cp'].encode("UTF-8") == cp:
            res.append(i)
    return res
示例#5
0
 def import_toptag_bybook(self, mode, start):
     '''
     mode: hour,day,week,month
     start: start time
     return: top tags by download user count of each book in it
     '''
     if mode != 'day':
         return
     start,end = self.normlize_time(mode,start)
     q = Scope.mgr().Q().extra("status in ('pas','nice') AND find_in_set('book',mask)")
     import_num = 0
     for scope in q:
         result = {}
         for i in BookStat.mgr().Q(time=start).filter(scope_id=scope.id,mode=mode,time=start):
             info = Service.inst().extern.get_book_info2(i.book_id)
             if info and 'tag' in info.keys():
                 for t in info['tag'].split(','):
                     t = t.lower().strip()
                     if t in result:
                         result[t]['pay_down'] += i.pay_down
                         result[t]['free_down'] += i.free_down
                         result[t]['pay_user'] += i.pay_user
                         result[t]['free_user'] += i.free_user
                         result[t]['pv'] += i.pv
                         result[t]['uv'] += i.uv
                         result[t]['fee'] += i.fee
                     else:
                         result[t] = {'pay_down':i.pay_down,'free_down':i.free_down,'pay_user':i.pay_user,
                                      'free_user':i.free_user,'pv':i.pv,'uv':i.uv,'fee':i.fee}
         for t in result:
             try:
                 item = result[t]
                 stat = BookTagStat.new()
                 stat.scope_id = scope['id']
                 stat.mode = mode
                 stat.time = start
                 stat.tag = t.encode('utf-8')
                 stat.pay_down = item['pay_down']
                 stat.free_down = item['free_down']
                 stat.pay_user = item['pay_user']
                 stat.free_user = item['free_user']
                 stat.pv = item['pv']
                 stat.uv = item['uv']
                 stat.fee = item['fee']
                 stat.save()
                 import_num += 1
             except Exception,e:
                 logging.error('%s\n',str(e),exc_info=True)
示例#6
0
 def patch_book(self, mode, start, **kargs):
     scope = kargs if 'id' in kargs else self.get_scope(**kargs)
     if not scope:
         return None
     start,end = self.normlize_time(mode,start)
     try:
         s = BookStat.mgr(ismaster=1).Q(time=start).filter(scope_id=scope['id'],mode=mode,time=start)
         batch = self.down.get_batch_basic(start, end, **kargs)
         debat = {'bid':0,'batch_pv':0,'batch_uv':0,'batch_fee':0}
         for book in s: 
             book_id = book.book_id
             down = batch.get(book_id, debat)
             book.batch_pv = down['batch_pv']
             book.batch_uv = down['batch_uv']
             book.batch_fee = down['batch_fee']
             book.save()
     except Exception,e:
         s = None
         logging.error('%s\n',str(e),exc_info=True)
示例#7
0
 def patch_book(self, mode, start, **kargs):
     scope = kargs if 'id' in kargs else self.get_scope(**kargs)
     if not scope:
         return None
     start, end = self.normlize_time(mode, start)
     try:
         s = BookStat.mgr(ismaster=1).Q(time=start).filter(
             scope_id=scope['id'], mode=mode, time=start)
         batch = self.down.get_batch_basic(start, end, **kargs)
         debat = {'bid': 0, 'batch_pv': 0, 'batch_uv': 0, 'batch_fee': 0}
         for book in s:
             book_id = book.book_id
             down = batch.get(book_id, debat)
             book.batch_pv = down['batch_pv']
             book.batch_uv = down['batch_uv']
             book.batch_fee = down['batch_fee']
             book.save()
     except Exception, e:
         s = None
         logging.error('%s\n', str(e), exc_info=True)
示例#8
0
 def import_book_stat(self, mode, start, num, **kargs):
     '''
     mode: hour,day,week,month
     start: start time
     kargs:platform_id,run_id,plan_id,partner_id,version_name,product_name
     return: number of book stat
     '''
     scope = kargs if 'id' in kargs else self.get_scope(**kargs)
     if not scope:
         return 0
     import_num = 0
     start, end = self.normlize_time(mode, start)
     for dtype, books in self.merge_book_stat(start, end, **kargs):
         for i in books:
             try:
                 stat = BookStat.new()
                 stat.scope_id = scope['id']
                 stat.mode = mode
                 stat.time = start
                 stat.book_id = i['bid']
                 stat.charge_type = dtype
                 stat.pv = i['pv']
                 stat.uv = i['uv']
                 stat.pay_down = i['pay_down']
                 stat.free_down = i['free_down']
                 stat.pay_user = i['pay_user']
                 stat.free_user = i['free_user']
                 stat.fee = i['fee']
                 stat.real_fee = i['real_fee']
                 stat.batch_pv = i['batch_pv']
                 stat.batch_uv = i['batch_uv']
                 stat.batch_fee = i['batch_fee']
                 stat.save()
                 import_num += 1
             except Exception, e:
                 logging.error('%s\n', str(e), exc_info=True)
示例#9
0
 def import_book_stat(self, mode, start, num, **kargs):
     '''
     mode: hour,day,week,month
     start: start time
     kargs:platform_id,run_id,plan_id,partner_id,version_name,product_name
     return: number of book stat
     '''
     scope = kargs if 'id' in kargs else self.get_scope(**kargs)
     if not scope:
         return 0
     import_num = 0
     start,end = self.normlize_time(mode,start)
     for dtype,books in self.merge_book_stat(start,end,**kargs):
         for i in books:
             try:
                 stat = BookStat.new()
                 stat.scope_id = scope['id']
                 stat.mode = mode
                 stat.time = start
                 stat.book_id = i['bid']
                 stat.charge_type = dtype
                 stat.pv = i['pv']
                 stat.uv = i['uv']
                 stat.pay_down = i['pay_down']
                 stat.free_down = i['free_down']
                 stat.pay_user = i['pay_user']
                 stat.free_user = i['free_user']
                 stat.fee = i['fee']
                 stat.real_fee = i['real_fee']
                 stat.batch_pv = i['batch_pv']
                 stat.batch_uv = i['batch_uv']
                 stat.batch_fee = i['batch_fee']
                 stat.save()
                 import_num += 1
             except Exception,e:
                 logging.error('%s\n',str(e),exc_info=True)
示例#10
0
    def get_sum_stat(self):
        tody  = time_start(datetime.datetime.now(),'day')
        #start6 = datetime.datetime.strptime('2012-06-01','%Y-%m-%d')
        #end6 = datetime.datetime.strptime('2012-07-01','%Y-%m-%d')
        q1 = BookStat.mgr().get_data_by_multi_days(scope_id=1,mode='day',start=datetime.datetime.strptime('2012-06-01','%Y-%m-%d'),end=datetime.datetime.strptime('2012-07-01','%Y-%m-%d'),charge_type='')
        q2 = BookStat.mgr().get_data_by_multi_days(scope_id=1,mode='day',start=datetime.datetime.strptime('2012-07-01','%Y-%m-%d'),end=datetime.datetime.strptime('2012-08-01','%Y-%m-%d'),charge_type='')
        q3 = BookStat.mgr().get_data_by_multi_days(scope_id=1,mode='day',start=datetime.datetime.strptime('2012-08-01','%Y-%m-%d'),end=datetime.datetime.strptime('2012-09-01','%Y-%m-%d'),charge_type='')
        q4 = BookStat.mgr().get_data_by_multi_days(scope_id=1,mode='day',start=datetime.datetime.strptime('2012-09-01','%Y-%m-%d'),end=datetime.datetime.strptime('2012-10-01','%Y-%m-%d'),charge_type='')
        q5 = BookStat.mgr().get_data_by_multi_days(scope_id=1,mode='day',start=datetime.datetime.strptime('2012-10-01','%Y-%m-%d'),end=datetime.datetime.strptime('2012-11-01','%Y-%m-%d'),charge_type='')
        q6 = BookStat.mgr().get_data_by_multi_days(scope_id=1,mode='day',start=datetime.datetime.strptime('2012-11-01','%Y-%m-%d'),end=datetime.datetime.strptime('2012-12-01','%Y-%m-%d'),charge_type='')
        q7 = BookStat.mgr().get_data_by_multi_days(scope_id=1,mode='day',start=datetime.datetime.strptime('2012-12-01','%Y-%m-%d'),end=datetime.datetime.strptime('2013-01-01','%Y-%m-%d'),charge_type='')
        q8 = BookStat.mgr().get_data_by_multi_days(scope_id=1,mode='day',start=datetime.datetime.strptime('2013-01-01','%Y-%m-%d'),end=datetime.datetime.strptime('2013-02-01','%Y-%m-%d'),charge_type='')
        q9 = BookStat.mgr().get_data_by_multi_days(scope_id=1,mode='day',start=datetime.datetime.strptime('2013-02-01','%Y-%m-%d'),end=datetime.datetime.strptime('2013-03-01','%Y-%m-%d'),charge_type='')
        q10 = BookStat.mgr().get_data_by_multi_days(scope_id=1,mode='day',start=datetime.datetime.strptime('2013-03-01','%Y-%m-%d'),end=datetime.datetime.strptime('2013-04-01','%Y-%m-%d'),charge_type='')
        q11 = BookStat.mgr().get_data_by_multi_days(scope_id=1,mode='day',start=datetime.datetime.strptime('2013-04-01','%Y-%m-%d'),end=datetime.datetime.strptime('2013-05-01','%Y-%m-%d'),charge_type='')
        q12 = BookStat.mgr().get_data_by_multi_days(scope_id=1,mode='day',start=datetime.datetime.strptime('2013-05-01','%Y-%m-%d'),end=datetime.datetime.strptime('2013-06-01','%Y-%m-%d'),charge_type='')
        q13 = BookStat.mgr().get_data_by_multi_days(scope_id=1,mode='day',start=datetime.datetime.strptime('2013-06-01','%Y-%m-%d'),end=datetime.datetime.strptime('2013-07-01','%Y-%m-%d'),charge_type='')
        q14 = BookStat.mgr().get_data_by_multi_days(scope_id=1,mode='day',start=datetime.datetime.strptime('2013-07-01','%Y-%m-%d'),end=tody,charge_type='')

        data = [q1,q2,q5,q6,q7,q8,q9,q10,q11,q12,q13,q14]
        #data = [q1,q2]
        for q in data:
            print len(q)

        book_id_list = self.get_all_book_id_in_ebk5()
        #book_id_list = book_id_list[0:10]
        
        res = self.merge_multi_month_data_by_bookid(book_id_list,data)
        return res
示例#11
0
 def basic(self):
     platform_id = int(self.get_argument('platform_id',6))
     run_id = int(self.get_argument('run_id',0))
     plan_id = int(self.get_argument('plan_id',0))
     partner_id = int(self.get_argument('partner_id',0))
     version_name = self.get_argument('version_name','').replace('__','.')
     product_name = self.get_argument('product_name','')
     
     tody = self.get_date()
     yest = tody - datetime.timedelta(days=1)
     last = yest - datetime.timedelta(days=1)
     run_list = [i for i in self.run_list() if i['run_id'] in IOS_RUN_ID_LIST]
     basics = []
     if run_id == 0: #不限
         if partner_id:
             scope = Scope.mgr().Q().filter(platform_id=platform_id,run_id=run_id,plan_id=plan_id,
                 partner_id=partner_id,version_name=version_name,product_name=product_name)[0]
             if scope:
                 scope_id_list = str(scope['id'])
                 dft = dict([(i,0) for i in BasicStatv3._fields])
                 basic_y = BasicStatv3.mgr().get_sum_data_by_multi_scope(scope_id_list,yest)[0]
                 basic_l = BasicStatv3.mgr().get_sum_data_by_multi_scope(scope_id_list,last)[0]
                 basic_y,basic_l = basic_y or dft,basic_l or dft
                 basic_y['title'],basic_l['title'] = '昨日统计','前日统计'
                 basics = [basic_y,basic_l]
                 for basic in basics:
                     basic['cfee'] = long(basic['cfee'])
                     basic['bfee'] = long(basic['bfee'])
                     basic['batch_fee'] = long(basic['batch_fee'])
         else:
             scope = Scope.mgr().get_ios_scope_id_list()
             if scope:
                 scope_id_list = ','.join([str(i['id']) for i in scope]) 
                 dft = dict([(i,0) for i in BasicStatv3._fields])
                 basic_y = BasicStatv3.mgr().get_sum_data_by_multi_scope(scope_id_list,yest)[0]
                 basic_l = BasicStatv3.mgr().get_sum_data_by_multi_scope(scope_id_list,last)[0]
                 basic_y,basic_l = basic_y or dft,basic_l or dft
                 basic_y['title'],basic_l['title'] = '昨日统计','前日统计'
                 basics = [basic_y,basic_l]
                 for basic in basics:
                     basic['cfee'] = long(basic['cfee'])
                     basic['bfee'] = long(basic['bfee'])
                     basic['batch_fee'] = long(basic['batch_fee'])
     else:
         # scope 
         scope = Scope.mgr().Q().filter(platform_id=platform_id,run_id=run_id,plan_id=plan_id,
                   partner_id=partner_id,version_name=version_name,product_name=product_name)[0]
         tody = self.get_date()
         yest = tody - datetime.timedelta(days=1)
         last = yest - datetime.timedelta(days=1)
         start = tody - datetime.timedelta(days=30)
         basics,topn_sch,topn_hw,b_books,c_books = [],[],[],[],[]
         visit_y = dict([(i,{'pv':0,'uv':0}) for i in PAGE_TYPE])
         visit_l = dict([(i,{'pv':0,'uv':0}) for i in PAGE_TYPE])
         if scope:
             # basic stat
             dft = dict([(i,0) for i in BasicStatv3._fields])
             basic_y = BasicStatv3.mgr().Q(time=yest).filter(scope_id=scope.id,mode='day',time=yest)[0] 
             basic_l = BasicStatv3.mgr().Q(time=last).filter(scope_id=scope.id,mode='day',time=last)[0] 
             basic_m = BasicStatv3.mgr().get_data(scope.id,'day',start,tody,ismean=True)
             basic_p = BasicStatv3.mgr().get_peak(scope.id,'day',start,tody)
             basic_y,basic_l = basic_y or dft,basic_l or dft
             basic_y['title'],basic_l['title'] = '昨日统计','前日统计'
             basic_m['title'],basic_p['title'] = '每日平均','历史峰值'
             basics = [basic_y,basic_l,basic_m,basic_p]
             for basic in basics:
                 basic['cfee'] = long(basic['cfee'])
                 basic['bfee'] = long(basic['bfee'])
                 basic['batch_fee'] = long(basic['batch_fee'])
             # page visit
             for i in VisitStat.mgr().Q().filter(scope_id=scope.id,mode='day',time=yest):
                 visit_y[i['type']] = i
             for i in VisitStat.mgr().Q().filter(scope_id=scope.id,mode='day',time=last):
                 visit_l[i['type']] = i
             # topN search & hotword
             q = TopNStat.mgr().Q().filter(scope_id=scope.id,mode='day',time=yest)
             topn_sch = q.filter(type='search').orderby('no')[:10]
             topn_hw = q.filter(type='hotword').orderby('no')[:10]
             # books of by-book & by-chapter
             q = BookStat.mgr().Q(time=yest).filter(scope_id=scope.id,mode='day',time=yest)
             b_books = Service.inst().fill_book_info(q.filter(charge_type='book').orderby('fee','DESC')[:10])
             c_books = Service.inst().fill_book_info(q.filter(charge_type='chapter').orderby('fee','DESC')[:10])
     self.render('data/ios_basic.html',
                 run_id=run_id,
                 partner_id=partner_id,
                 run_list=run_list,date=tody.strftime('%Y-%m-%d'),
                 basics = basics
                 )
示例#12
0
    def chart(self):
        platform_id = int(self.get_argument('platform_id',6))
        run_id = int(self.get_argument('run_id',0))
        plan_id = int(self.get_argument('plan_id',0))
        partner_id = int(self.get_argument('partner_id',0))
        version_name = self.get_argument('version_name','').replace('__','.')
        product_name = self.get_argument('product_name','')
        page = int(self.get_argument('pageNum',1))
        psize = int(self.get_argument('numPerPage',400))
        charge_type = self.get_argument('charge_type','')
        book_ids = self.get_argument('book_ids','')
        bookid_list = [i for i in book_ids.split(',') if i]
        action = self.get_argument('action','')
        #perm
        run_list=self.run_list()
        run_list = self.filter_run_id_perms(run_list=run_list)
        run_id_list = [run['run_id'] for run in run_list]      
        if run_id == 0 and run_id_list: # has perm and doesn't select a run_id
            if len(run_id_list) == len(Run.mgr().Q().extra("status<>'hide'").data()):
                run_id = 0  # user has all run_id perms
            else:
                run_id = run_id_list[0]
        if run_id not in run_id_list and run_id != 0: # don't has perm and selete a run_id
            scope = None
        else:
        # scope 
            scope = Scope.mgr().Q().filter(platform_id=platform_id,run_id=run_id,plan_id=plan_id,
                      partner_id=partner_id,version_name=version_name,product_name=product_name)[0]
        tody = self.get_date(1) + datetime.timedelta(days=1)
        yest = tody - datetime.timedelta(days=1)
        start = self.get_argument('start','')
        
        if start:
            start = datetime.datetime.strptime(start,'%Y-%m-%d')
        else:
            start = tody - datetime.timedelta(days=7)
        # x_axis
        delta = tody - start
        days = [start+datetime.timedelta(days=i) for i in range(delta.days)]
        x_axis = ['%s'%i.strftime('%m-%d') for i in days]
        count,books = 0,[]
        if scope:
            # books of by-book & by-chapter
            result = BookStat.mgr().get_data(scope.id,'day',start,tody,charge_type,bookid_list,page,psize)
            count = result['count']
            books = Service.inst().fill_book_info(result['list'])
            while (self.do_books_have_two_or_empty_title(books)): #this is for Fu Rong's request, but books can't deepcopy, so I have to do this way, so egg pain !
                books = self.remove_books_two_or_empty_title(books)

        # pagination
        results = {}
        excludes = ('id','scope_id','mode','time','uptime','category_1','category_0','charge_type','author','book_id','arpu','category_0')
        for k in [i for i in BookStat._fields if i not in excludes]:
            results[k] ={'title':BookStat._fieldesc[k],'data':','.join([str(i.get(k,0)) for i in books])}
        page_count = (count+psize-1)/psize
        if action == 'export':
            title = [('time','时间'),('book_id','书ID'),('name','书名'),('author','作者'),
                    ('cp','版权'),('category_2','类别'),('category_1','子类'),('category_0','三级分类'),('state','状态'),
                    ('charge_type','计费类型'),('fee','收益'),('pay_down','付费下载数'),
                    ('pay_user','付费下载用户数'),('free_down','免费下载数'),
                    ('free_user','免费下载用户数'),('pv','简介访问数'),('uv','简介访问人数'),
                    ('batch_fee','批量订购阅饼消费'),('batch_pv','批量订购PV'),('batch_uv','批量订购UV')]
            xls = Excel().generate(title,books,1)
            filename = 'book_%s.xls' % (yest.strftime('%Y-%m-%d'))
            self.set_header('Content-Disposition','attachment;filename=%s'%filename)
            self.finish(xls)
        else:
            self.render('data/book_chart.html',x_axis=x_axis,results=results,
                    platform_id=platform_id,run_id=run_id,plan_id=plan_id,date=yest.strftime('%Y-%m-%d'),
                    partner_id=partner_id,version_name=version_name,product_name=product_name,
                    run_list=self.run_list(),plan_list=self.plan_list(),page=page, psize=psize,
                    count=count, page_count=page_count, books=books, charge_type=charge_type,
                    book_ids=book_ids,start=start.strftime('%Y-%m-%d')
                    )
示例#13
0
 def get_yest_book_data(self,delta=1):
     tody = time_start(datetime.datetime.now(),'day')
     yest = tody - datetime.timedelta(days=delta)
     q = BookStat.mgr().Q(time=yest).filter(scope_id=1,mode='day',time=yest)
     return q 
示例#14
0
 def category(self):
     platform_id = int(self.get_argument('platform_id',6))
     run_id = int(self.get_argument('run_id',0))
     plan_id = int(self.get_argument('plan_id',0))
     partner_id = int(self.get_argument('partner_id',0))
     version_name = self.get_argument('version_name','').replace('__','.')
     product_name = self.get_argument('product_name','')
     page = int(self.get_argument('pageNum',1))
     psize = int(self.get_argument('numPerPage',20))
     charge_type = self.get_argument('charge_type','')
     order_field = self.get_argument('orderField','fee')
     cate_type = self.get_argument('cate_type','')
     assert order_field in ('pay_user','free_user','pay_down','free_down','pv','uv','fee','batch_fee','batch_pv','batch_uv')
     action = self.get_argument('action','')
     #perm
     run_list=self.run_list()
     run_list = self.filter_run_id_perms(run_list=run_list)
     run_id_list = [run['run_id'] for run in run_list]      
     if run_id == 0 and run_id_list: # has perm and doesn't select a run_id
         if len(run_id_list) == len(Run.mgr().Q().extra("status<>'hide'").data()):
             run_id = 0  # user has all run_id perms
         else:
             run_id = run_id_list[0]
     if run_id not in run_id_list and run_id != 0: # don't has perm and selete a run_id
         scope = None
     else:
     # scope 
         scope = Scope.mgr().Q().filter(platform_id=platform_id,run_id=run_id,plan_id=plan_id,
                   partner_id=partner_id,version_name=version_name,product_name=product_name)[0]
     tody = self.get_date(1) + datetime.timedelta(days=1)
     yest = tody - datetime.timedelta(days=1)
     last = yest - datetime.timedelta(days=1)
     start = self.get_argument('start','')
     if start:
         start = datetime.datetime.strptime(start,'%Y-%m-%d')   
     else:
         start = yest
     if start > yest:
         start = yest
     count,books = 0,[]
     res_all = {}
     if scope:
         if start != yest:
             q = BookStat.mgr().get_data_by_multi_days(scope_id=scope.id,mode='day',start=start,end=tody,charge_type=charge_type)  
             q = q.orderby(order_field,'DESC')
             count = len(q)
             if action == 'export':
                 books = q.data()
             else:
                 books = q[:]
         else:
             q = BookStat.mgr().Q(time=yest).filter(scope_id=scope.id,mode='day',time=yest)
             charge_type and q.filter(charge_type=charge_type)
             count = q.count()
             q = q.orderby(order_field,'DESC')
             if action == 'export':
                 books = q.data()
             else:
                 books = q[:]
         books = Service.inst().fill_book_info(books)
         res0,res1,res2 = self.counting_category_stat(books)
         #merge dict
         if not cate_type:
             res_all = dict(dict(res0,**res1),**res2)
         elif cate_type == 'cate0':
             res_all = res0
         elif cate_type == 'cate1':
             res_all = res1
         else:
             res_all = res2
         count = len(res_all.keys())
         #dict->list
         res_list = []
         for i in res_all:
             res_list.append({i:res_all[i]})
         #sort
         res_list = self.bubblesort_double_dict_in_list(res_list,'fee')
         self.render('data/book_category.html',
                     platform_id=platform_id,run_id=run_id,plan_id=plan_id,date=yest.strftime('%Y-%m-%d'),
                     partner_id=partner_id,version_name=version_name,product_name=product_name,
                     run_list=self.run_list(),plan_list=self.plan_list(),page=page, psize=psize,
                     count=count,res_list=res_list,charge_type=charge_type,cate_type=cate_type,
                     start=start.strftime('%Y-%m-%d')
                     )
示例#15
0
 def bookcategory(self):
     platform_id = int(self.get_argument('platform_id',6))
     run_id = int(self.get_argument('run_id',0))
     plan_id = int(self.get_argument('plan_id',0))
     partner_id = int(self.get_argument('partner_id',0))
     version_name = self.get_argument('version_name','').replace('__','.')
     product_name = self.get_argument('product_name','')
     page = int(self.get_argument('pageNum',1))
     psize = int(self.get_argument('numPerPage',20))
     charge_type = self.get_argument('charge_type','')
     order_field = self.get_argument('orderField','fee')
     cate_type = self.get_argument('cate_type','')
     action = self.get_argument('action','')
     #perm
     run_list=self.run_list()
     run_list = self.filter_run_id_perms(run_list=run_list)
     run_id_list = [run['run_id'] for run in run_list]      
     if run_id == 0 and run_id_list: # has perm and doesn't select a run_id
         if len(run_id_list) == len(Run.mgr().Q().extra("status<>'hide'").data()):
             run_id = 0  # user has all run_id perms
         else:
             run_id = run_id_list[0]
     if run_id not in run_id_list and run_id != 0: # don't has perm and selete a run_id
         scope = None
     else:
     # scope 
         scope = Scope.mgr().Q().filter(platform_id=platform_id,run_id=run_id,plan_id=plan_id,
                   partner_id=partner_id,version_name=version_name,product_name=product_name)[0]
     tody = self.get_date(1) + datetime.timedelta(days=1)
     yest = tody - datetime.timedelta(days=1)
     last = yest - datetime.timedelta(days=1)
     start = self.get_argument('start','')
     if start:
         start = datetime.datetime.strptime(start,'%Y-%m-%d')   
     else:
         start = yest
     if start > yest:
         start = yest
     count,books = 0,[]
     res_all = {}
     if scope:
         if start != yest:
             q = BookStat.mgr().get_data_by_multi_days(scope_id=scope.id,mode='day',start=start,end=tody,charge_type=charge_type)  
             q = q.orderby(order_field,'DESC')
             count = len(q)
             if action == 'export':
                 books = q.data()
             else:
                 books = q[:]
         else:
             q = BookStat.mgr().Q(time=yest).filter(scope_id=scope.id,mode='day',time=yest)
             charge_type and q.filter(charge_type=charge_type)
             count = q.count()
             q = q.orderby(order_field,'DESC')
             if action == 'export':
                 books = q.data()
             else:
                 books = q[:]
     books = self.get_fill_category_id(books)
     cates = self.counting_category(books)
     cates = self.fill_category_name(cates)
     cates = self.bubblesort(cates,'fee')        
     if action == 'export': 
         title = [('category_no3','类别'),('category_no2','二级分类'),('category_no1','三级分类'),('fee','阅饼消费'),('batch_fee','批量下载阅饼消费')]
         xls = Excel().generate(title,cates,1)
         filename = 'category.xls'
         self.set_header('Content-Disposition','attachment;filename=%s'%filename)
         self.finish(xls)
     else:
         self.render('data/book_category2.html',
                 platform_id=platform_id,run_id=run_id,plan_id=plan_id,date=yest.strftime('%Y-%m-%d'),
                 partner_id=partner_id,version_name=version_name,product_name=product_name,
                 run_list=self.run_list(),plan_list=self.plan_list(),page=page, psize=psize,
                 count=count,charge_type=charge_type,cates=cates,
                 start=start.strftime('%Y-%m-%d'))
示例#16
0
 def index(self):
     platform_id = int(self.get_argument('platform_id',6))
     run_id = int(self.get_argument('run_id',0))
     plan_id = int(self.get_argument('plan_id',0))
     partner_id = int(self.get_argument('partner_id',0))
     version_name = self.get_argument('version_name','').replace('__','.')
     product_name = self.get_argument('product_name','')
     page = int(self.get_argument('pageNum',1))
     psize = int(self.get_argument('numPerPage',20))
     charge_type = self.get_argument('charge_type','')
     order_field = self.get_argument('orderField','fee')
     assert order_field in ('pay_user','free_user','pay_down','free_down','pv','uv','fee','batch_fee','batch_pv','batch_uv','real_fee')
     action = self.get_argument('action','')
     #perm
     run_list=self.run_list()
     run_list = self.filter_run_id_perms(run_list=run_list)
     run_id_list = [run['run_id'] for run in run_list]      
     if run_id == 0 and run_id_list: # has perm and doesn't select a run_id
         if len(run_id_list) == len(Run.mgr().Q().extra("status<>'hide'").data()):
             run_id = 0  # user has all run_id perms
         else:
             run_id = run_id_list[0]
     if run_id not in run_id_list and run_id != 0: # don't has perm and selete a run_id
         scope = None
     else:
     # scope 
         scope = Scope.mgr().Q().filter(platform_id=platform_id,run_id=run_id,plan_id=plan_id,
                   partner_id=partner_id,version_name=version_name,product_name=product_name)[0]
     tody = self.get_date(1) + datetime.timedelta(days=1)
     yest = tody - datetime.timedelta(days=1)
     last = yest - datetime.timedelta(days=1)
     start = self.get_argument('start','')
     if start:
         start = datetime.datetime.strptime(start,'%Y-%m-%d')   
     else:
         start = yest
     if start > yest:
         start = yest
     count,books = 0,[]
     if scope:
         if start != yest:
             q = BookStat.mgr().get_data_by_multi_days(scope_id=scope.id,mode='day',start=start,end=tody,charge_type=charge_type)  
             q = q.orderby(order_field,'DESC')
             count = len(q)
             if action == 'export':
                 books = q.data()
             else:
                 books = q[(page-1)*psize:page*psize]
         else:
             q = BookStat.mgr().Q(time=yest).filter(scope_id=scope.id,mode='day',time=yest)
             charge_type and q.filter(charge_type=charge_type)
             count = q.count()
             q = q.orderby(order_field,'DESC')
             if action == 'export':
                 books = q.data()
             else:
                 books = q[(page-1)*psize:page*psize]
         books = Service.inst().fill_book_info(books)
     # pagination
     page_count = (count+psize-1)/psize
     if action == 'export':
         books = Service.inst().fill_book_count_info(books)
         while (self.do_books_have_two_or_empty_title(books)): 
             books = self.remove_books_two_or_empty_title(books) 
         title = [('time','时间'),('book_id','书ID'),('name','书名'),('author','作者'),
                  ('cp','版权'),('category_2','类别'),('category_1','子类'),('category_0','三级分类'),('state','状态'),
                  ('charge_type','计费类型'),('fee','收益'),('pay_down','付费下载数'),
                  ('pay_user','付费下载用户数'),('free_down','免费下载数'),
                  ('free_user','免费下载用户数'),('pv','简介访问数'),('uv','简介访问人数'),
                  ('batch_fee','批量订购阅饼消费'),('batch_pv','批量订购PV'),('batch_uv','批量订购UV'),
                  ('chapterCount','总章数'),('wordCount','总字数')]
         xls = Excel().generate(title,books,1)
         filename = 'book_%s.xls' % (yest.strftime('%Y-%m-%d'))
         self.set_header('Content-Disposition','attachment;filename=%s'%filename)
         self.finish(xls)
     else:
         self.render('data/book.html',
                     platform_id=platform_id,run_id=run_id,plan_id=plan_id,date=yest.strftime('%Y-%m-%d'),
                     partner_id=partner_id,version_name=version_name,product_name=product_name,
                     run_list=self.run_list(),plan_list=self.plan_list(),page=page, psize=psize,
                     count=count,page_count=page_count,books=books,charge_type=charge_type,
                     order_field = order_field,start=start.strftime('%Y-%m-%d')
                     )
示例#17
0
    def chart(self):
        platform_id = int(self.get_argument('platform_id', 6))
        run_id = int(self.get_argument('run_id', 0))
        plan_id = int(self.get_argument('plan_id', 0))
        partner_id = int(self.get_argument('partner_id', 0))
        version_name = self.get_argument('version_name', '').replace('__', '.')
        product_name = self.get_argument('product_name', '')
        page = int(self.get_argument('pageNum', 1))
        psize = int(self.get_argument('numPerPage', 400))
        charge_type = self.get_argument('charge_type', '')
        book_ids = self.get_argument('book_ids', '')
        bookid_list = [i for i in book_ids.split(',') if i]
        action = self.get_argument('action', '')
        #perm
        run_list = self.run_list()
        run_list = self.filter_run_id_perms(run_list=run_list)
        run_id_list = [run['run_id'] for run in run_list]
        if run_id == 0 and run_id_list:  # has perm and doesn't select a run_id
            if len(run_id_list) == len(
                    Run.mgr().Q().extra("status<>'hide'").data()):
                run_id = 0  # user has all run_id perms
            else:
                run_id = run_id_list[0]
        if run_id not in run_id_list and run_id != 0:  # don't has perm and selete a run_id
            scope = None
        else:
            # scope
            scope = Scope.mgr().Q().filter(platform_id=platform_id,
                                           run_id=run_id,
                                           plan_id=plan_id,
                                           partner_id=partner_id,
                                           version_name=version_name,
                                           product_name=product_name)[0]
        tody = self.get_date(1) + datetime.timedelta(days=1)
        yest = tody - datetime.timedelta(days=1)
        start = self.get_argument('start', '')

        if start:
            start = datetime.datetime.strptime(start, '%Y-%m-%d')
        else:
            start = tody - datetime.timedelta(days=7)
        # x_axis
        delta = tody - start
        days = [start + datetime.timedelta(days=i) for i in range(delta.days)]
        x_axis = ['%s' % i.strftime('%m-%d') for i in days]
        count, books = 0, []
        if scope:
            # books of by-book & by-chapter
            result = BookStat.mgr().get_data(scope.id, 'day', start, tody,
                                             charge_type, bookid_list, page,
                                             psize)
            count = result['count']
            books = Service.inst().fill_book_info(result['list'])
            while (
                    self.do_books_have_two_or_empty_title(books)
            ):  #this is for Fu Rong's request, but books can't deepcopy, so I have to do this way, so egg pain !
                books = self.remove_books_two_or_empty_title(books)

        # pagination
        results = {}
        excludes = ('id', 'scope_id', 'mode', 'time', 'uptime', 'category_1',
                    'category_0', 'charge_type', 'author', 'book_id', 'arpu',
                    'category_0')
        for k in [i for i in BookStat._fields if i not in excludes]:
            results[k] = {
                'title': BookStat._fieldesc[k],
                'data': ','.join([str(i.get(k, 0)) for i in books])
            }
        page_count = (count + psize - 1) / psize
        if action == 'export':
            title = [('time', '时间'), ('book_id', '书ID'), ('name', '书名'),
                     ('author', '作者'), ('cp', '版权'), ('category_2', '类别'),
                     ('category_1', '子类'), ('category_0', '三级分类'),
                     ('state', '状态'), ('charge_type', '计费类型'), ('fee', '收益'),
                     ('pay_down', '付费下载数'), ('pay_user', '付费下载用户数'),
                     ('free_down', '免费下载数'), ('free_user', '免费下载用户数'),
                     ('pv', '简介访问数'), ('uv', '简介访问人数'),
                     ('batch_fee', '批量订购阅饼消费'), ('batch_pv', '批量订购PV'),
                     ('batch_uv', '批量订购UV')]
            xls = Excel().generate(title, books, 1)
            filename = 'book_%s.xls' % (yest.strftime('%Y-%m-%d'))
            self.set_header('Content-Disposition',
                            'attachment;filename=%s' % filename)
            self.finish(xls)
        else:
            self.render('data/book_chart.html',
                        x_axis=x_axis,
                        results=results,
                        platform_id=platform_id,
                        run_id=run_id,
                        plan_id=plan_id,
                        date=yest.strftime('%Y-%m-%d'),
                        partner_id=partner_id,
                        version_name=version_name,
                        product_name=product_name,
                        run_list=self.run_list(),
                        plan_list=self.plan_list(),
                        page=page,
                        psize=psize,
                        count=count,
                        page_count=page_count,
                        books=books,
                        charge_type=charge_type,
                        book_ids=book_ids,
                        start=start.strftime('%Y-%m-%d'))
示例#18
0
 def index(self):
     platform_id = int(self.get_argument('platform_id', 6))
     run_id = int(self.get_argument('run_id', 0))
     plan_id = int(self.get_argument('plan_id', 0))
     partner_id = int(self.get_argument('partner_id', 0))
     version_name = self.get_argument('version_name', '').replace('__', '.')
     product_name = self.get_argument('product_name', '')
     page = int(self.get_argument('pageNum', 1))
     psize = int(self.get_argument('numPerPage', 20))
     charge_type = self.get_argument('charge_type', '')
     order_field = self.get_argument('orderField', 'fee')
     assert order_field in ('pay_user', 'free_user', 'pay_down',
                            'free_down', 'pv', 'uv', 'fee', 'batch_fee',
                            'batch_pv', 'batch_uv', 'real_fee')
     action = self.get_argument('action', '')
     #perm
     run_list = self.run_list()
     run_list = self.filter_run_id_perms(run_list=run_list)
     run_id_list = [run['run_id'] for run in run_list]
     if run_id == 0 and run_id_list:  # has perm and doesn't select a run_id
         if len(run_id_list) == len(
                 Run.mgr().Q().extra("status<>'hide'").data()):
             run_id = 0  # user has all run_id perms
         else:
             run_id = run_id_list[0]
     if run_id not in run_id_list and run_id != 0:  # don't has perm and selete a run_id
         scope = None
     else:
         # scope
         scope = Scope.mgr().Q().filter(platform_id=platform_id,
                                        run_id=run_id,
                                        plan_id=plan_id,
                                        partner_id=partner_id,
                                        version_name=version_name,
                                        product_name=product_name)[0]
     tody = self.get_date(1) + datetime.timedelta(days=1)
     yest = tody - datetime.timedelta(days=1)
     last = yest - datetime.timedelta(days=1)
     start = self.get_argument('start', '')
     if start:
         start = datetime.datetime.strptime(start, '%Y-%m-%d')
     else:
         start = yest
     if start > yest:
         start = yest
     count, books = 0, []
     if scope:
         if start != yest:
             q = BookStat.mgr().get_data_by_multi_days(
                 scope_id=scope.id,
                 mode='day',
                 start=start,
                 end=tody,
                 charge_type=charge_type)
             q = q.orderby(order_field, 'DESC')
             count = len(q)
             if action == 'export':
                 books = q.data()
             else:
                 books = q[(page - 1) * psize:page * psize]
         else:
             q = BookStat.mgr().Q(time=yest).filter(scope_id=scope.id,
                                                    mode='day',
                                                    time=yest)
             charge_type and q.filter(charge_type=charge_type)
             count = q.count()
             q = q.orderby(order_field, 'DESC')
             if action == 'export':
                 books = q.data()
             else:
                 books = q[(page - 1) * psize:page * psize]
         books = Service.inst().fill_book_info(books)
     # pagination
     page_count = (count + psize - 1) / psize
     if action == 'export':
         books = Service.inst().fill_book_count_info(books)
         while (self.do_books_have_two_or_empty_title(books)):
             books = self.remove_books_two_or_empty_title(books)
         title = [('time', '时间'), ('book_id', '书ID'), ('name', '书名'),
                  ('author', '作者'), ('cp', '版权'), ('category_2', '类别'),
                  ('category_1', '子类'), ('category_0', '三级分类'),
                  ('state', '状态'), ('charge_type', '计费类型'), ('fee', '收益'),
                  ('pay_down', '付费下载数'), ('pay_user', '付费下载用户数'),
                  ('free_down', '免费下载数'), ('free_user', '免费下载用户数'),
                  ('pv', '简介访问数'), ('uv', '简介访问人数'),
                  ('batch_fee', '批量订购阅饼消费'), ('batch_pv', '批量订购PV'),
                  ('batch_uv', '批量订购UV'), ('chapterCount', '总章数'),
                  ('wordCount', '总字数')]
         xls = Excel().generate(title, books, 1)
         filename = 'book_%s.xls' % (yest.strftime('%Y-%m-%d'))
         self.set_header('Content-Disposition',
                         'attachment;filename=%s' % filename)
         self.finish(xls)
     else:
         self.render('data/book.html',
                     platform_id=platform_id,
                     run_id=run_id,
                     plan_id=plan_id,
                     date=yest.strftime('%Y-%m-%d'),
                     partner_id=partner_id,
                     version_name=version_name,
                     product_name=product_name,
                     run_list=self.run_list(),
                     plan_list=self.plan_list(),
                     page=page,
                     psize=psize,
                     count=count,
                     page_count=page_count,
                     books=books,
                     charge_type=charge_type,
                     order_field=order_field,
                     start=start.strftime('%Y-%m-%d'))
示例#19
0
 def category(self):
     platform_id = int(self.get_argument('platform_id', 6))
     run_id = int(self.get_argument('run_id', 0))
     plan_id = int(self.get_argument('plan_id', 0))
     partner_id = int(self.get_argument('partner_id', 0))
     version_name = self.get_argument('version_name', '').replace('__', '.')
     product_name = self.get_argument('product_name', '')
     page = int(self.get_argument('pageNum', 1))
     psize = int(self.get_argument('numPerPage', 20))
     charge_type = self.get_argument('charge_type', '')
     order_field = self.get_argument('orderField', 'fee')
     cate_type = self.get_argument('cate_type', '')
     assert order_field in ('pay_user', 'free_user', 'pay_down',
                            'free_down', 'pv', 'uv', 'fee', 'batch_fee',
                            'batch_pv', 'batch_uv')
     action = self.get_argument('action', '')
     #perm
     run_list = self.run_list()
     run_list = self.filter_run_id_perms(run_list=run_list)
     run_id_list = [run['run_id'] for run in run_list]
     if run_id == 0 and run_id_list:  # has perm and doesn't select a run_id
         if len(run_id_list) == len(
                 Run.mgr().Q().extra("status<>'hide'").data()):
             run_id = 0  # user has all run_id perms
         else:
             run_id = run_id_list[0]
     if run_id not in run_id_list and run_id != 0:  # don't has perm and selete a run_id
         scope = None
     else:
         # scope
         scope = Scope.mgr().Q().filter(platform_id=platform_id,
                                        run_id=run_id,
                                        plan_id=plan_id,
                                        partner_id=partner_id,
                                        version_name=version_name,
                                        product_name=product_name)[0]
     tody = self.get_date(1) + datetime.timedelta(days=1)
     yest = tody - datetime.timedelta(days=1)
     last = yest - datetime.timedelta(days=1)
     start = self.get_argument('start', '')
     if start:
         start = datetime.datetime.strptime(start, '%Y-%m-%d')
     else:
         start = yest
     if start > yest:
         start = yest
     count, books = 0, []
     res_all = {}
     if scope:
         if start != yest:
             q = BookStat.mgr().get_data_by_multi_days(
                 scope_id=scope.id,
                 mode='day',
                 start=start,
                 end=tody,
                 charge_type=charge_type)
             q = q.orderby(order_field, 'DESC')
             count = len(q)
             if action == 'export':
                 books = q.data()
             else:
                 books = q[:]
         else:
             q = BookStat.mgr().Q(time=yest).filter(scope_id=scope.id,
                                                    mode='day',
                                                    time=yest)
             charge_type and q.filter(charge_type=charge_type)
             count = q.count()
             q = q.orderby(order_field, 'DESC')
             if action == 'export':
                 books = q.data()
             else:
                 books = q[:]
         books = Service.inst().fill_book_info(books)
         res0, res1, res2 = self.counting_category_stat(books)
         #merge dict
         if not cate_type:
             res_all = dict(dict(res0, **res1), **res2)
         elif cate_type == 'cate0':
             res_all = res0
         elif cate_type == 'cate1':
             res_all = res1
         else:
             res_all = res2
         count = len(res_all.keys())
         #dict->list
         res_list = []
         for i in res_all:
             res_list.append({i: res_all[i]})
         #sort
         res_list = self.bubblesort_double_dict_in_list(res_list, 'fee')
         self.render('data/book_category.html',
                     platform_id=platform_id,
                     run_id=run_id,
                     plan_id=plan_id,
                     date=yest.strftime('%Y-%m-%d'),
                     partner_id=partner_id,
                     version_name=version_name,
                     product_name=product_name,
                     run_list=self.run_list(),
                     plan_list=self.plan_list(),
                     page=page,
                     psize=psize,
                     count=count,
                     res_list=res_list,
                     charge_type=charge_type,
                     cate_type=cate_type,
                     start=start.strftime('%Y-%m-%d'))
示例#20
0
 def bookcategory(self):
     platform_id = int(self.get_argument('platform_id', 6))
     run_id = int(self.get_argument('run_id', 0))
     plan_id = int(self.get_argument('plan_id', 0))
     partner_id = int(self.get_argument('partner_id', 0))
     version_name = self.get_argument('version_name', '').replace('__', '.')
     product_name = self.get_argument('product_name', '')
     page = int(self.get_argument('pageNum', 1))
     psize = int(self.get_argument('numPerPage', 20))
     charge_type = self.get_argument('charge_type', '')
     order_field = self.get_argument('orderField', 'fee')
     cate_type = self.get_argument('cate_type', '')
     action = self.get_argument('action', '')
     #perm
     run_list = self.run_list()
     run_list = self.filter_run_id_perms(run_list=run_list)
     run_id_list = [run['run_id'] for run in run_list]
     if run_id == 0 and run_id_list:  # has perm and doesn't select a run_id
         if len(run_id_list) == len(
                 Run.mgr().Q().extra("status<>'hide'").data()):
             run_id = 0  # user has all run_id perms
         else:
             run_id = run_id_list[0]
     if run_id not in run_id_list and run_id != 0:  # don't has perm and selete a run_id
         scope = None
     else:
         # scope
         scope = Scope.mgr().Q().filter(platform_id=platform_id,
                                        run_id=run_id,
                                        plan_id=plan_id,
                                        partner_id=partner_id,
                                        version_name=version_name,
                                        product_name=product_name)[0]
     tody = self.get_date(1) + datetime.timedelta(days=1)
     yest = tody - datetime.timedelta(days=1)
     last = yest - datetime.timedelta(days=1)
     start = self.get_argument('start', '')
     if start:
         start = datetime.datetime.strptime(start, '%Y-%m-%d')
     else:
         start = yest
     if start > yest:
         start = yest
     count, books = 0, []
     res_all = {}
     if scope:
         if start != yest:
             q = BookStat.mgr().get_data_by_multi_days(
                 scope_id=scope.id,
                 mode='day',
                 start=start,
                 end=tody,
                 charge_type=charge_type)
             q = q.orderby(order_field, 'DESC')
             count = len(q)
             if action == 'export':
                 books = q.data()
             else:
                 books = q[:]
         else:
             q = BookStat.mgr().Q(time=yest).filter(scope_id=scope.id,
                                                    mode='day',
                                                    time=yest)
             charge_type and q.filter(charge_type=charge_type)
             count = q.count()
             q = q.orderby(order_field, 'DESC')
             if action == 'export':
                 books = q.data()
             else:
                 books = q[:]
     books = self.get_fill_category_id(books)
     cates = self.counting_category(books)
     cates = self.fill_category_name(cates)
     cates = self.bubblesort(cates, 'fee')
     if action == 'export':
         title = [('category_no3', '类别'), ('category_no2', '二级分类'),
                  ('category_no1', '三级分类'), ('fee', '阅饼消费'),
                  ('batch_fee', '批量下载阅饼消费')]
         xls = Excel().generate(title, cates, 1)
         filename = 'category.xls'
         self.set_header('Content-Disposition',
                         'attachment;filename=%s' % filename)
         self.finish(xls)
     else:
         self.render('data/book_category2.html',
                     platform_id=platform_id,
                     run_id=run_id,
                     plan_id=plan_id,
                     date=yest.strftime('%Y-%m-%d'),
                     partner_id=partner_id,
                     version_name=version_name,
                     product_name=product_name,
                     run_list=self.run_list(),
                     plan_list=self.plan_list(),
                     page=page,
                     psize=psize,
                     count=count,
                     charge_type=charge_type,
                     cates=cates,
                     start=start.strftime('%Y-%m-%d'))
示例#21
0
 def book_stat(self):
     page = int(self.get_argument('pageNum', 1))
     psize = int(self.get_argument('numPerPage', 20))
     charge_type = self.get_argument('charge_type', '')
     factory_id = int(self.get_argument('factory_id', 0))
     order_field = self.get_argument('orderField', 'fee')
     query_mode = self.get_argument('query_mode', 'accounting_book')
     group = self.get_argument('group', '')
     assert order_field in ('pay_user', 'free_user', 'pay_down',
                            'free_down', 'pv', 'uv', 'fee', 'batch_fee',
                            'batch_pv', 'batch_uv', 'real_fee')
     action = self.get_argument('action', '')
     # perm
     q = Factory.mgr().Q()
     group and q.filter(group=group)
     factory_list = self.filter_factory_acc(q[:], query_mode)
     # for safety reason, some time a perm doesn't have a val, and in this Situation a factory CANN'T see all factory accouting data!!!
     cuser = self.get_current_user()
     if len(factory_list) > 150 and (cuser['name'] not in SAFE_USER):
         factory_list = []
     if factory_id == 0 and factory_list:
         factory_id = factory_list[0].id
     partner_list = Partnerv2.mgr().Q().filter(factory_id=factory_id)[:]
     # scope list
     scopeid_list = []
     for i in partner_list:
         scope = Scope.mgr().Q().filter(platform_id=6,
                                        run_id=0,
                                        partner_id=i.partner_id)[0]
         if scope:
             scopeid_list.append(scope.id)
     tody = self.get_date(1) + datetime.timedelta(days=1)
     yest = tody - datetime.timedelta(days=1)
     last = yest - datetime.timedelta(days=1)
     start = self.get_argument('start', '')
     if start:
         start = datetime.datetime.strptime(start, '%Y-%m-%d')
     else:
         start = yest
     count, books = 0, []
     q = BookStat.mgr().get_accouting_multy_scope_stat(
         scopeid_list, order_field, start)
     charge_type and q.filter(charge_type=charge_type)
     q = q.orderby(order_field, 'DESC')
     count = len(q)
     if action == 'export':
         books = q.data()
         for i in books:
             i['batch_fee'] = "%0.2f" % i['batch_fee']
     else:
         books = q[(page - 1) * psize:page * psize]
         for i in books:
             i['batch_fee'] = "%0.2f" % i['batch_fee']
     books = Service.inst().fill_book_info(books)
     # pagination
     page_count = (count + psize - 1) / psize
     for book in books:
         book['fee'] = "%.01f" % float(book['fee'])
         book['real_fee'] = "%.01f" % float(book['real_fee'])
     if action == 'export':
         books = Service.inst().fill_book_count_info(books)
         while (self.do_books_have_two_or_empty_title(books)):
             books = self.remove_books_two_or_empty_title(books)
         title = [('time', '时间'), ('book_id', '书ID'), ('name', '书名'),
                  ('author', '作者'), ('cp', '版权'), ('category_2', '类别'),
                  ('category_1', '子类'), ('category_0', '三级分类'),
                  ('state', '状态'), ('charge_type', '计费类型'), ('fee', '收益'),
                  ('real_fee', '主账户收益'), ('pay_down', '付费下载数'),
                  ('pay_user', '付费下载用户数'), ('free_down', '免费下载数'),
                  ('free_user', '免费下载用户数'), ('pv', '简介访问数'),
                  ('uv', '简介访问人数'), ('batch_fee', '批量订购阅饼消费')]
         xls = Excel().generate(title, books, 1)
         filename = 'book_%s.xls' % (yest.strftime('%Y-%m-%d'))
         self.set_header('Content-Disposition',
                         'attachment;filename=%s' % filename)
         self.finish(xls)
     else:
         self.render('data/accounting_book.html',
                     page=page,
                     psize=psize,
                     count=count,
                     page_count=page_count,
                     books=books,
                     charge_type=charge_type,
                     order_field=order_field,
                     start=start.strftime('%Y-%m-%d'),
                     factory_id=factory_id,
                     factory_list=factory_list,
                     query_mode=query_mode)
 def book_stat(self):
     page = int(self.get_argument('pageNum',1))
     psize = int(self.get_argument('numPerPage',20))
     charge_type = self.get_argument('charge_type','')
     factory_id = int(self.get_argument('factory_id',0))
     order_field = self.get_argument('orderField','fee')
     query_mode = self.get_argument('query_mode','accounting_book')
     group = self.get_argument('group','')
     assert order_field in ('pay_user','free_user','pay_down','free_down','pv','uv','fee','batch_fee','batch_pv','batch_uv','real_fee')
     action = self.get_argument('action','')
     # perm
     q = Factory.mgr().Q()
     group and q.filter(group=group)
     factory_list = self.filter_factory_acc(q[:],query_mode)
     # for safety reason, some time a perm doesn't have a val, and in this Situation a factory CANN'T see all factory accouting data!!!
     cuser = self.get_current_user() 
     if len(factory_list)>150 and (cuser['name'] not in SAFE_USER):
         factory_list = []
     if factory_id == 0 and factory_list:
         factory_id = factory_list[0].id
     partner_list = Partnerv2.mgr().Q().filter(factory_id=factory_id)[:]
     # scope list
     scopeid_list = []
     for i in partner_list:
         scope = Scope.mgr().Q().filter(platform_id=6,run_id=0,partner_id=i.partner_id)[0]
         if scope:
             scopeid_list.append(scope.id)
     tody = self.get_date(1) + datetime.timedelta(days=1)
     yest = tody - datetime.timedelta(days=1)
     last = yest - datetime.timedelta(days=1)
     start = self.get_argument('start','')
     if start:
         start = datetime.datetime.strptime(start,'%Y-%m-%d')   
     else:
         start = yest
     count,books = 0,[]
     q = BookStat.mgr().get_accouting_multy_scope_stat(scopeid_list,order_field,start)
     charge_type and q.filter(charge_type=charge_type)
     q = q.orderby(order_field,'DESC')
     count = len(q)
     if action == 'export':
         books = q.data()
         for i in books:
             i['batch_fee'] = "%0.2f"%i['batch_fee'] 
     else:
         books = q[(page-1)*psize:page*psize]
         for i in books:
             i['batch_fee'] = "%0.2f"%i['batch_fee'] 
     books = Service.inst().fill_book_info(books)
     # pagination
     page_count = (count+psize-1)/psize
     for book in books:
         book['fee'] = "%.01f"%float(book['fee'])
         book['real_fee'] = "%.01f"%float(book['real_fee'])
     if action == 'export':
         books = Service.inst().fill_book_count_info(books)
         while (self.do_books_have_two_or_empty_title(books)): 
             books = self.remove_books_two_or_empty_title(books) 
         title = [('time','时间'),('book_id','书ID'),('name','书名'),('author','作者'),
                  ('cp','版权'),('category_2','类别'),('category_1','子类'),('category_0','三级分类'),('state','状态'),
                  ('charge_type','计费类型'),('fee','收益'),('real_fee','主账户收益'),('pay_down','付费下载数'),
                  ('pay_user','付费下载用户数'),('free_down','免费下载数'),('free_user','免费下载用户数'),('pv','简介访问数'),('uv','简介访问人数'),
                  ('batch_fee','批量订购阅饼消费')]
         xls = Excel().generate(title,books,1)
         filename = 'book_%s.xls' % (yest.strftime('%Y-%m-%d'))
         self.set_header('Content-Disposition','attachment;filename=%s'%filename)
         self.finish(xls)
     else:
         self.render('data/accounting_book.html',
                     page=page, psize=psize,
                     count=count,page_count=page_count,books=books,charge_type=charge_type,
                     order_field = order_field,start=start.strftime('%Y-%m-%d'),factory_id=factory_id,factory_list=factory_list,query_mode=query_mode
                     )