本文整理汇总了Python中level.Level.gql方法的典型用法代码示例。如果您正苦于以下问题:Python Level.gql方法的具体用法?Python Level.gql怎么用?Python Level.gql使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类level.Level
的用法示例。
在下文中一共展示了Level.gql方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get
# 需要导入模块: from level import Level [as 别名]
# 或者: from level.Level import gql [as 别名]
def get(self):
while True:
new = db.get(LevelStatistics.all(keys_only=True).filter("new =", True).fetch(1000))
if len(new) == 0:
break
levels = {}
for id in set([n.levelid for n in new]):
l = Level.gql("WHERE id = :1", id).get()
if l is None:
continue
levels[id] = l
updated = []
for n in new:
n.new = False
updated.append(n)
try:
l = levels[n.levelid]
l.ratings += 1
l.ratingsum += n.rating
l.rated = True
except KeyError:
continue
for l in levels.values():
l.rating = float(l.ratingsum) / float(l.ratings)
updated.append(l)
logging.debug("%s: %f sum=%d ratings=%d" % (l.name, l.rating, l.ratingsum, l.ratings))
db.put(updated)
示例2: do
# 需要导入模块: from level import Level [as 别名]
# 或者: from level.Level import gql [as 别名]
def do(self):
levelid = self.request.get("levelid")
l = Level.gql("WHERE id = :1", levelid).get()
if l is None:
return self.set_error("Level %s does not exist." % levelid)
udid = self.request.get("udid")
if l.udid == udid:
return self.set_error("Sorry, you can't rate your own levels.")
levelstat = LevelStatistics.gql("WHERE levelid = :1 AND udid = :2",
levelid, udid).get()
if levelstat is not None:
return self.set_error("Sorry, this level has already been rated from this device.")
rating = self.request.get_range("rating", 0, 5)
s = LevelStatistics(levelid=levelid,
udid=udid,
rating=rating,
solvetime=self.request.get_range("solvetime", 0, 1000000),
pushes=self.request.get_range("pushes", 0, 1000000),
moves=self.request.get_range("moves", 0, 1000000),
new=True)
# make it appear as rated immediately
if not l.rated:
s.new = False
l.ratings = 1
l.ratingsum = rating
l.rating = float(rating)
l.rated = True
l.put()
s.put()
self.value = "ok"