def markRead(self): self.received = True stats.record("link_opened", simplejson.dumps({ "user": self.sender.user.user.email(), "link": self.url })) self.save()
def reconnecting_fn(self, *args, **kwargs): try: return fn(self, *args, **kwargs) except (pymysql.OperationalError, pymysql.err.InterfaceError) as err: stats.record('users.mysql-failure') self.__reconnect() return fn(self, *args, **kwargs)
def save(self): try: self.key() except db.NotSavedError: stats.record("user_added", simplejson.dumps({"user": self.user.email()})) self.put() memcache.set("user_%s_data" % self.user.user_id(), self) return self
def markRead(self): self.received = True stats.record( "link_opened", simplejson.dumps({ "user": self.sender.user.user.email(), "link": self.url })) self.save()
def save(self): try: self.key() except db.NotSavedError: stats.record("link_added", simplejson.dumps({ "user": self.sender.user.user.email(), "link": self.url })) self.put() return self
def save(self): self.put() stamp = timestamp.now() stamp = stamp.replace(day=stamp.day + 1, hour=0, minute=0, second=0, microsecond=0) self.date = stamp self.user.setExplicitImmunity(stamp) stats.record("payment", simplejson.dumps({ "user": self.user.user.email(), "item": self.item }))
def save(self): try: self.key() except db.NotSavedError: stats.record( "link_added", simplejson.dumps({ "user": self.sender.user.user.email(), "link": self.url })) self.put() return self
def save(self): try: self.key() except db.NotSavedError: stats.record("device_added", simplejson.dumps({"user": self.user.user.email(), "device": self.address})) if self.address == None: self.address = "%s/%s" % (self.user.user.email(), self.name) self.put() memcache.set("device_%s_data" % self.address, self) return self
def save(self): try: self.key() except db.NotSavedError: stats.record( "device_added", simplejson.dumps({ "user": self.user.user.email(), "device": self.address })) if self.address == None: self.address = "%s/%s" % (self.user.user.email(), self.name) self.put() memcache.set("device_%s_data" % self.address, self) return self
def save(self): self.put() stamp = timestamp.now() stamp = stamp.replace(day=stamp.day + 1, hour=0, minute=0, second=0, microsecond=0) self.date = stamp self.user.setExplicitImmunity(stamp) stats.record( "payment", simplejson.dumps({ "user": self.user.user.email(), "item": self.item }))
def test_record(self): self.game.rules.add(RuleCard.objects.get(ref_name = 'HAG10')) # 5 different colors => +10 points self.game.rules.add(RuleCard.objects.get(ref_name = 'HAG12')) # most red cards double their value self.game.rules.add(RuleCard.objects.get(ref_name = 'HAG13')) # 3 yellow cards doubles the value of 1 white card self.game.rules.add(RuleCard.objects.get(ref_name = 'HAG15')) # (random) more than 13 cards => removed y = Commodity.objects.get(ruleset = 1, name = 'Yellow') b = Commodity.objects.get(ruleset = 1, name = 'Blue') r = Commodity.objects.get(ruleset = 1, name = 'Red') o = Commodity.objects.get(ruleset = 1, name = 'Orange') w = Commodity.objects.get(ruleset = 1, name = 'White') mommy.make(CommodityInHand, game = self.game, player = self.loginUser, nb_cards = 3, commodity = y) mommy.make(CommodityInHand, game = self.game, player = self.loginUser, nb_cards = 2, commodity = b) mommy.make(CommodityInHand, game = self.game, player = self.loginUser, nb_cards = 3, commodity = r) mommy.make(CommodityInHand, game = self.game, player = self.loginUser, nb_cards = 2, commodity = o) mommy.make(CommodityInHand, game = self.game, player = self.loginUser, nb_cards = 2, commodity = w) mommy.make(CommodityInHand, game = self.game, player = self.alternativeUser, nb_cards = 6, commodity = y) mommy.make(CommodityInHand, game = self.game, player = self.alternativeUser, nb_cards = 1, commodity = b) mommy.make(CommodityInHand, game = self.game, player = self.alternativeUser, nb_cards = 2, commodity = r) mommy.make(CommodityInHand, game = self.game, player = self.alternativeUser, nb_cards = 6, commodity = o) trade = mommy.make(Trade) record(self.game, trade = trade) try: stats_loginUser = StatsScore.objects.get(game = self.game, player = self.loginUser) self.assertEqual(trade, stats_loginUser.trade) self.assertEqual(68, stats_loginUser.score) self.assertFalse(stats_loginUser.random) self.assertIsNotNone(stats_loginUser.date_score) except StatsScore.DoesNotExist: self.fail("StatsScore does not contain record for loginUser (test2)") try: stats_alternativeUser = StatsScore.objects.get(game = self.game, player = self.alternativeUser) self.assertEqual(trade, stats_alternativeUser.trade) self.assertTrue(stats_alternativeUser.random) self.assertIsNotNone(stats_alternativeUser.date_score) except StatsScore.DoesNotExist: self.fail("StatsScore does not contain record for alternativeUser (test5)") self.assertEqual(stats_loginUser.date_score, stats_alternativeUser.date_score)
def __init__(self, address, generate=True, override_quota=False): self.address = address if generate: self.token = memcache.get("token_%s" % self.address) if self.token is None: device = models.getDevice(self.address) if device.token and device.tokenValid(): self.token = device.token else: if models.getQuota().amount > models.getStats( 'channels').count or override_quota: self.token = channel.create_channel(self.address) stats.record("channel_created", simplejson.dumps({ "channel": self.address})) self.cached = False device.updateToken(self.token) else: raise OverQuotaError() return False memcache.set("token_%s" % self.address, self.token, time=7200)
def post(self, name="Chrome"): self.response.headers.add_header("Access-Control-Allow-Origin", "*") user = auth.getCurrentUser() device = None if user: try: user_data = models.getUser(user) except models.UserDoesNotExistError: user_data = models.UserData(user=user).save() try: device = models.getDevice("%s/%s" % (user.email(), name)) except: device = models.DeviceData(user=user_data, name=name).save() last_links = models.getUnreadLinks(device) channel = channels.Channel(device.address, False) for link in last_links: channel.queueLink(link) channel.send() stats.record("user_connected", simplejson.dumps({"user": user.email()})) self.response.out.write(device.address)
def __init__(self, address, generate=True, override_quota=False): self.address = address if generate: self.token = memcache.get("token_%s" % self.address) if self.token is None: device = models.getDevice(self.address) if device.token and device.tokenValid(): self.token = device.token else: if models.getQuota().amount > models.getStats( 'channels').count or override_quota: self.token = channel.create_channel(self.address) stats.record( "channel_created", simplejson.dumps({"channel": self.address})) self.cached = False device.updateToken(self.token) else: raise OverQuotaError() return False memcache.set("token_%s" % self.address, self.token, time=7200)
def updateQuota(level): quota = QuotaData(amount=int(level), date=timestamp.now()) quota.put() memcache.set("quota", quota) stats.record("quota_updated", str(quota.amount)) return quota
from datetime import datetime import requests import stats if __name__=="__main__": print "Starting to collect stats..." while True: t = localtime() time = ":".join([str(t) for t in [t.tm_hour,t.tm_min,t.tm_sec]]) print "Collecting stats at "+time now = str(datetime.utcnow()) date = now[:11] time = "-".join(now[-15:-7].split(":")) filename = "stats/records/"+date+"/"+time+".json" dirname = os.path.dirname(filename) if not os.path.exists(dirname): os.makedirs(dirname) # collect and record stats, silently failing if we don't have an internet connection try: stats.record(*stats.collect(), filename=filename) except requests.exceptions.ConnectionError: pass # sleep for 30 mins sleep(1800)