本文整理汇总了Python中helpers.queryhelper.QueryHelper.get_all_terminals_by_cid方法的典型用法代码示例。如果您正苦于以下问题:Python QueryHelper.get_all_terminals_by_cid方法的具体用法?Python QueryHelper.get_all_terminals_by_cid怎么用?Python QueryHelper.get_all_terminals_by_cid使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类helpers.queryhelper.QueryHelper
的用法示例。
在下文中一共展示了QueryHelper.get_all_terminals_by_cid方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get
# 需要导入模块: from helpers.queryhelper import QueryHelper [as 别名]
# 或者: from helpers.queryhelper.QueryHelper import get_all_terminals_by_cid [as 别名]
def get(self):
"""Show information of a terminal.
"""
status = ErrorCode.SUCCESS
try:
if self.current_user.oid == UWEB.DUMMY_OID: # enterprise
terminals = QueryHelper.get_all_terminals_by_cid(self.current_user.cid, self.db)
else: # operator
terminals = QueryHelper.get_all_terminals_by_oid(self.current_user.oid, self.db)
res = []
for terminal in terminals:
res.append(dict(tid=terminal.tid,
tmobile=terminal.mobile))
self.write_ret(status,
dict_=dict(res=res))
except Exception as e:
logging.exception("[UWEB] Get terminal info failed. "
" cid:%s, Exception: %s",
self.current_user.cid, e.args)
status = ErrorCode.SERVER_BUSY
self.write_ret(status)
示例2: post
# 需要导入模块: from helpers.queryhelper import QueryHelper [as 别名]
# 或者: from helpers.queryhelper.QueryHelper import get_all_terminals_by_cid [as 别名]
def post(self):
"""Provide some statistics about terminals.
"""
status = ErrorCode.SUCCESS
try:
data = DotDict(json_decode(self.request.body))
page_size = UWEB.LIMIT.PAGE_SIZE
page_number = int(data.pagenum)
start_time = data.start_time
end_time = data.end_time
query_type = data.query_type
tids = str_to_list(data.tids)
logging.info("[UWEB] mileage request: %s, cid: %s, oid: %s",
data, self.current_user.cid, self.current_user.oid)
except Exception as e:
status = ErrorCode.ILLEGAL_DATA_FORMAT
logging.exception("[UWEB] Invalid data format. Exception: %s",
e.args)
self.write_ret(status)
self.finish()
return
# NOTE: prepare
try:
# the interval between start_time and end_time is one week
# no checks for enterprise
if self.current_user.cid != UWEB.DUMMY_CID:
pass
elif (int(end_time) - int(start_time)) > UWEB.QUERY_INTERVAL:
self.write_ret(ErrorCode.QUERY_INTERVAL_EXCESS)
self.finish()
return
statistic_mode = 'single'
if not tids: # all terminals
statistic_mode = 'all'
if self.current_user.oid == UWEB.DUMMY_OID: # enterprise
terminals = QueryHelper.get_all_terminals_by_cid(
self.current_user.cid, self.db)
else: # operator
terminals = QueryHelper.get_all_terminals_by_oid(
self.current_user.oid, self.db)
tids = [terminal.tid for terminal in terminals]
except Exception as e:
logging.exception("[UWEB] cid:%s, oid:%s get mileage report failed. Exception: %s",
self.current_user.cid, self.current_user.oid, e.args)
status = ErrorCode.SERVER_BUSY
self.write_ret(status)
self.finish()
return
def _on_finish(db):
self.db = db
page_count = int(data.pagecnt)
if statistic_mode == 'all': # all
if page_count == -1:
count = len(tids)
d, m = divmod(count, page_size)
page_count = (d + 1) if m else d
reports = []
dis_count = Decimal()
for item, tid in enumerate(tids):
seq = item + 1
# NOTE: It's amazing: In database, distance's type is long. sum(distance)'s type is Decimal
mileage_log = self.db.get("SELECT SUM(distance) AS distance"
" FROM T_MILEAGE_LOG"
" WHERE tid = %s"
" AND (timestamp BETWEEN %s AND %s)",
tid, start_time,
end_time + 60 * 60 * 24)
if mileage_log and mileage_log['distance']:
dis_sum = '%0.1f' % (mileage_log['distance'] / 1000,)
else:
dis_sum = 0
alias = QueryHelper.get_alias_by_tid(
tid, self.redis, self.db)
dct = dict(seq=seq,
alias=alias,
distance=float(dis_sum))
reports.append(dct)
dis_count += Decimal(dis_sum)
counts = [float(dis_count), ]
# orgnize and store the data to be downloaded
m = hashlib.md5()
m.update(self.request.body)
hash_ = m.hexdigest()
mem_key = self.KEY_TEMPLATE % (self.current_user.uid, hash_)
self.redis.setvalue(
mem_key, (statistic_mode, reports, counts), time=UWEB.STATISTIC_INTERVAL)
reports = reports[
(page_number * page_size):((page_number + 1) * page_size)]
self.write_ret(status,
dict_=DotDict(res=reports,
pagecnt=page_count,
#.........这里部分代码省略.........