本文整理汇总了Python中utils.utils.Utils.ranklist方法的典型用法代码示例。如果您正苦于以下问题:Python Utils.ranklist方法的具体用法?Python Utils.ranklist怎么用?Python Utils.ranklist使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类utils.utils.Utils
的用法示例。
在下文中一共展示了Utils.ranklist方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_utils
# 需要导入模块: from utils.utils import Utils [as 别名]
# 或者: from utils.utils.Utils import ranklist [as 别名]
def test_utils(self):
testlist = [1, 2, 3, 3, 4, 5, 1, 1, 1, 2]
rankedlist = Utils.ranklist(testlist)
self.assertEqual(rankedlist,
[(1, 4), (2, 2), (3, 2), (4, 1), (5, 1)])
pass
示例2: get_likely_vehicles
# 需要导入模块: from utils.utils import Utils [as 别名]
# 或者: from utils.utils.Utils import ranklist [as 别名]
def get_likely_vehicles(self, nexttrip):
prevtrips = []
self._connect()
self.cur.execute('SELECT date, vehicle FROM VEHICLES where trip=? ORDER BY date DESC', [nexttrip])
date_vehicles = self.cur.fetchall()
for d, v in date_vehicles:
self.cur.execute('SELECT trip FROM VEHICLES where date=? and vehicle=? order by time asc', [d, v])
ts = self.cur.fetchall()
if len(ts)> 1:
# find the trip just before our trip
prevtrip = None
for triplist in ts:
trip = triplist[0]
if trip == nexttrip:
# previous trip (if any) led to this one
if prevtrip:
prevtrips.append(prevtrip)
else:
prevtrip = trip
ranked_prev_trips = Utils.ranklist(prevtrips)
vehicles = []
for trip, count in ranked_prev_trips:
# get the latest vehicle for each trip
self.cur.execute('SELECT vehicle FROM VEHICLES where trip=? ORDER BY date DESC', [trip])
vehicle = self.cur.fetchone()
vehicles.append((vehicle, count))
return vehicles