本文整理汇总了Python中service.Service.inst方法的典型用法代码示例。如果您正苦于以下问题:Python Service.inst方法的具体用法?Python Service.inst怎么用?Python Service.inst使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类service.Service
的用法示例。
在下文中一共展示了Service.inst方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: index
# 需要导入模块: from service import Service [as 别名]
# 或者: from service.Service import inst [as 别名]
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: startpoint
# 需要导入模块: from service import Service [as 别名]
# 或者: from service.Service import inst [as 别名]
def startpoint(self):
plan_id = int(self.get_argument('plan_id',0))
partner_id = int(self.get_argument('partner_id',0))
page = int(self.get_argument('pageNum',1))
psize = int(self.get_argument('numPerPage',100))
order_field = self.get_argument('orderField','shujia')
assert order_field in ('shucheng','shujia','dabao')
action = self.get_argument('action','')
book_ids = self.get_argument('book_ids','')
bookid_list = [i for i in book_ids.split(',') if i]
count,books = 0,[]
q = EValueStartPointAll.mgr().get_all_data(bookid_list)
count = len(q)
if action == 'export':
res = q.orderby(order_field,'DESC')
else:
res = q.orderby(order_field,'DESC')[(page-1)*psize:page*psize]
books = Service.inst().fill_book_info_by_bid(res)
if action == 'export':
title = [('bid','书ID'),('name','书名'),('shucheng','书城'),
('shujia','书架'),('dabao','打包'),('top1','top1'),('top2','top2'),('top3','top3'),('top4','top4'),('top5','top5'),
('top6','top6'),('top7','top7'),('top8','top8'),('top9','top9'),('top10','top10')]
xls = Excel().generate(title,books,1)
filename = 'evalue_startpoint.xls'
self.set_header('Content-Disposition','attachment;filename=%s'%filename)
self.finish(xls)
else:
self.render('data/e_value_startpoint.html',
plan_id=plan_id,partner_id=partner_id,book_ids=book_ids,
page=page,psize=psize,books=books,count=count,order_field=order_field)
示例3: import_factory_stat
# 需要导入模块: from service import Service [as 别名]
# 或者: from service.Service import inst [as 别名]
def import_factory_stat(self, mode, start):
start,end = self.normlize_time(mode,start)
res_dict = Service.inst().stat.get_all_factstat(mode,start,end)
if res_dict == None:
return 0
import_num = 0
try:
for i in res_dict.keys():
stat = FactorySumStat.new()
stat.time = start
stat.factory_id = i
stat.visits = res_dict[i]['visits']
stat.imei = res_dict[i]['imei']
stat.user_run = res_dict[i]['user_run']
stat.new_user_run = res_dict[i]['new_user_run']
stat.user_visit = res_dict[i]['user_visit']
stat.new_user_visit = res_dict[i]['new_user_visit']
stat.active_user_visit = res_dict[i]['active_user_visit']
stat.user_retention = res_dict[i]['user_retention']
stat.pay_user = res_dict[i]['pay_user']
stat.cpay_down = res_dict[i]['cpay_down']
stat.cfree_down = res_dict[i]['cfree_down']
stat.bpay_down = res_dict[i]['bpay_down']
stat.bfree_down = res_dict[i]['bfree_down']
stat.cpay_user = res_dict[i]['cpay_user']
stat.cfree_user = res_dict[i]['cfree_user']
stat.bpay_user = res_dict[i]['bpay_user']
stat.bfree_user = res_dict[i]['bfree_user']
stat.cfee = res_dict[i]['cfee']
stat.bfee = res_dict[i]['bfee']
stat.save()
import_num += 1
except Exception,e:
logging.error('%s\n',str(e),exc_info=True)
示例4: baoyue_book_stat
# 需要导入模块: from service import Service [as 别名]
# 或者: from service.Service import inst [as 别名]
def baoyue_book_stat(self):
page = int(self.get_argument('pageNum',1))
psize = int(self.get_argument('numPerPage',100))
book_id = self.get_argument('book_id','')
tody = self.get_date(1) + datetime.timedelta(days=1)
start = self.get_argument('start','')
yest = tody - datetime.timedelta(days=1)
if not start:
start = tody - datetime.timedelta(days=1)
else:
start = datetime.datetime.strptime(start,'%Y-%m-%d')
end = yest
delta = tody - start
#days = [start+datetime.timedelta(days=i) for i in range(delta.days)]
books = []
#for i in days:
# stats = OperaBaoyueBook.mgr().get_one_day_stat(i,book_id)
# books.append(stats)
#if len(books) > 1: # for multi days
# res = self.operation_merge_multi_days_books(books)
#else:
# res = list(books[0])
#booid->book_id
stats = OperaBaoyueBook.mgr().get_stat(start,end,book_id)
res = stats
for i in res:
i['book_id'] = int(i['bookid'])
res = Service.inst().fill_book_info(res)
count = len(res)
res = res[(page-1)*psize:page*psize]
self.render('data/baoyue_book_stat.html',date=yest.strftime('%Y-%m-%d'),book_id=book_id,
start=start.strftime('%Y-%m-%d'),page=page,psize=psize,count=count,res=res)
示例5: index
# 需要导入模块: from service import Service [as 别名]
# 或者: from service.Service import inst [as 别名]
def index(self):
plan_id = int(self.get_argument('plan_id',0))
partner_id = int(self.get_argument('partner_id',0))
page = int(self.get_argument('pageNum',1))
psize = int(self.get_argument('numPerPage',100))
order_field = self.get_argument('orderField','usnum')
charge_type = self.get_argument('charge_type','')
assert order_field in ('cpay_user','cpay_user_percentage','cfee','ARPU','usnum')
action = self.get_argument('action','')
book_ids = self.get_argument('book_ids','')
bookid_list = [i for i in book_ids.split(',') if i]
startpoint = self.get_argument('startpoint','书架')
count,books = 0,[]
q = EValue.mgr().get_all_data(bookid_list,startpoint)
count = len(q)
if action == 'export':
res = q.orderby(order_field,'DESC')
else:
res = q.orderby(order_field,'DESC')[(page-1)*psize:page*psize]
books = Service.inst().fill_book_info_by_bid(res)
# pagination
if action == 'export':
title = [('bid','书ID'),('name','书名'),('cfee','章月饼消费'),
('usnum','总人数'),('cpay_user','付费人数'),('cpay_user_percentage','付费人数/总人数'),
('ARPU','ARPU')]
xls = Excel().generate(title,books,1)
filename = 'evalue_chapter.xls'
self.set_header('Content-Disposition','attachment;filename=%s'%filename)
self.finish(xls)
else:
self.render('data/e_value.html',
plan_id=plan_id,partner_id=partner_id,book_ids=book_ids,startpoint=startpoint,
page=page,psize=psize,charge_type=charge_type,books=books,
count=count,order_field=order_field)
示例6: max_cid_max_fee
# 需要导入模块: from service import Service [as 别名]
# 或者: from service.Service import inst [as 别名]
def max_cid_max_fee(self):
plan_id = int(self.get_argument('plan_id',0))
partner_id = int(self.get_argument('partner_id',0))
page = int(self.get_argument('pageNum',1))
psize = int(self.get_argument('numPerPage',100))
order_field = self.get_argument('orderField','maxfee')
assert order_field in ('maxcid','maxfee')
action = self.get_argument('action','')
book_ids = self.get_argument('book_ids','')
bookid_list = [i for i in book_ids.split(',') if i]
count,books = 0,[]
q = EValueMaxCidMaxFee.mgr().get_all_data(bookid_list)
count = len(q)
if action == 'export':
res = q.orderby(order_field,'DESC')
else:
res = q.orderby(order_field,'DESC')[(page-1)*psize:page*psize]
books = Service.inst().fill_book_info_by_bid(res)
if action == 'export':
title = [('bid','书ID'),('name','书名'),('author','作者'),('cp','版权'),('category_0','类别'),('category_1','子类'),
('charge_type','计费类型'),('state','状态'),('maxcid','最大章节'),('maxfee','最大收入')]
xls = Excel().generate(title,books,1)
filename = 'evalue_max_cid_max_fee.xls'
self.set_header('Content-Disposition','attachment;filename=%s'%filename)
self.finish(xls)
else:
self.render('data/e_value_max_cid_max_fee.html',
plan_id=plan_id,partner_id=partner_id,book_ids=book_ids,order_field=order_field,
page=page,psize=psize,books=books,count=count)
示例7: fill_category_name
# 需要导入模块: from service import Service [as 别名]
# 或者: from service.Service import inst [as 别名]
def fill_category_name(self, cates):
category_list = ['category_no1','category_no2','category_no3']
for cate in cates:
for category in category_list:
cate_name_from_mc = Service.inst().extern.get_category_name(cate[category])
if not cate_name_from_mc:
try:
cate_name = Ebk5Category.mgr().get_cate_name_by_cateID(cate[category])
if cate_name:
Service.inst().extern.save_category_name(cate[category],cate_name[0]['category_name'])
cate[category] = cate_name[0]['category_name']
else:
cate[category] = ''
except Exception, e:
logging.error('%s\n',str(e),exc_info=True)
else:
cate[category] = cate_name_from_mc
示例8: get_book_data
# 需要导入模块: from service import Service [as 别名]
# 或者: from service.Service import inst [as 别名]
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
示例9: compute_day
# 需要导入模块: from service import Service [as 别名]
# 或者: from service.Service import inst [as 别名]
def compute_day(factory_dict, result, day):
print 'start...',day
start,end = day,day+datetime.timedelta(days=1)
all_stats = Service.inst().stat.get_all_factstat('day',start,end)
acc_stats = {}
for u in factory_dict:
for f in factory_dict[u]:
basic = all_stats.get(f.id,None)
if basic:
if u in result:
result[u] += basic['new_user_run']
else:
result[u] = basic['new_user_run']
print 'end...',day
示例10: distribute_free
# 需要导入模块: from service import Service [as 别名]
# 或者: from service.Service import inst [as 别名]
def distribute_free(self):
page = int(self.get_argument('pageNum',1))
psize = int(self.get_argument('numPerPage',100))
order_field = self.get_argument('orderField','d_1')
assert order_field in ('d_1','d_10','d_20','d_30','d_minue_100')
book_ids = self.get_argument('book_ids','')
bookid_list = [i for i in book_ids.split(',') if i]
count,books = 0,[]
q = EValueFreeDistribute.mgr().get_all_data(bookid_list)
count = len(q)
res = q.orderby(order_field,'DESC')[(page-1)*psize:page*psize]
books = Service.inst().fill_book_info_by_bid(res)
self.render('data/e_value_distribute_free.html',
order_field=order_field,book_ids=book_ids,page=page,psize=psize,books=books,count=count)
示例11: get_fill_category_id
# 需要导入模块: from service import Service [as 别名]
# 或者: from service.Service import inst [as 别名]
def get_fill_category_id(self,books):
for book in books:
cate = Service.inst().extern.get_book_category(book['book_id'])
if not cate:
#print "not memcached ",book['book_id']
try:
q = Ebk5Category.mgr().get_cate_ID_by_bookid(book['book_id'])
if q:
q = q[0]
book['category_no1'] = q['category1']
book['category_no2'] = q['category2']
book['category_no3'] = q['category3']
Service.inst().extern.save_book_category(book['book_id'],q)
else:
book['category_no1'] = ''
book['category_no2'] = ''
book['category_no3'] = ''
except Exception, e:
print book['book_id'],'can not find category'
logging.error('%s\n',str(e),exc_info=True)
else:
book['category_no1'] = cate['category1']
book['category_no2'] = cate['category2']
book['category_no3'] = cate['category3']
示例12: import_toptag_bybook
# 需要导入模块: from service import Service [as 别名]
# 或者: from service.Service import inst [as 别名]
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)
示例13: distribute_pay
# 需要导入模块: from service import Service [as 别名]
# 或者: from service.Service import inst [as 别名]
def distribute_pay(self):
page = int(self.get_argument('pageNum',1))
psize = int(self.get_argument('numPerPage',100))
order_field = self.get_argument('orderField','')
assert order_field in ('','p10_usnum','p20_usnum','p30_usnum','p40_usnum','p50_usnum','p60_usnum','p70_usnum','p80_usnum','p90_usnum','p100_usnum')
book_ids = self.get_argument('book_ids','')
bookid_list = [i for i in book_ids.split(',') if i]
count,books = 0,[]
q = EValuePayDistribute.mgr().get_all_data(bookid_list)
count = len(q)
if order_field is '':
res = q[(page-1)*psize:page*psize]
else:
res = q.orderby(order_field,'DESC')[(page-1)*psize:page*psize]
books = Service.inst().fill_book_info_by_bid(res)
self.render('data/e_value_distribute_pay.html',
order_field=order_field,book_ids=book_ids,page=page,psize=psize,books=books,count=count)
示例14: refer
# 需要导入模块: from service import Service [as 别名]
# 或者: from service.Service import inst [as 别名]
def refer(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))
pkey = self.get_argument('pkey','1S1')
#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)
count,tags = 0,[]
if scope:
q = BookReferStat.mgr().Q(time=yest).filter(scope_id=scope.id,mode='day',time=yest,p_key=pkey)
count = q.count()
books = q.orderby('uv','DESC')[(page-1)*psize:page*psize]
books = Service.inst().fill_book_info(books)
# pagination
page_count = (count+psize-1)/psize
self.render('data/book_refer.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, pkey=pkey
)
示例15: recommendation
# 需要导入模块: from service import Service [as 别名]
# 或者: from service.Service import inst [as 别名]
def recommendation(self):
page = int(self.get_argument('pageNum',1))
psize = int(self.get_argument('numPerPage',100))
tody = self.get_date(1) + datetime.timedelta(days=1)
start = self.get_argument('start','')
appid = self.get_argument('appid','')
action = self.get_argument('action','')
type = self.get_argument('type','')
yest = tody - datetime.timedelta(days=1)
if not start:
start = tody - datetime.timedelta(days=7)
else:
start = datetime.datetime.strptime(start,'%Y-%m-%d')
end = yest
count,stats = 0,[]
stats = []
_start,days = start,[]
while _start <= end:
_end = _start + datetime.timedelta(days=1)
stat, appids = Recommendation.mgr().get_recommendation_one_day_stat(_start,appid)
stat = self.data_process(stat,appids,_start)
stat = self.bubblesort(stat,'download')
stats.extend(stat)
days.append(_start)
_start = _end
for stat in stats:
stat['time'] = stat['time'].strftime('%Y-%m-%d')
stats = Service.inst().fill_app_info(stats)
count = len(stats)
if action == 'export':
title = [('time','时间'),('appid','appid'),('appname','app名字'),('download','下载'),('install','安装')]
xls = Excel().generate(title,stats,1)
filename = 'recommendation_%s.xls' % (yest.strftime('%Y-%m-%d'))
self.set_header('Content-Disposition','attachment;filename=%s'%filename)
self.finish(xls)
else:
stats = stats[(page-1)*psize:page*psize]
self.render('data/recommendation.html',appid=appid,type=type,
date=yest.strftime('%Y-%m-%d'),start=start.strftime('%Y-%m-%d'),page=page,psize=psize,count=count,stats=stats)