Exemplo n.º 1
0
def get_dashboard(dashboard_id):
    redis = redis_connection()
    dashboard_value = redis.get(dashboard_id)
    if not dashboard_value:
        return
    dashboard_json = json.loads(redis.get(dashboard_id))
    dashboard = Dashboard()
    dashboard.dashboard_id = dashboard_json["dashboard_id"]
    for buddy in dashboard_json['buddies']:
        dashboard.add_buddy(Buddy(buddy["username"], buddy["color_id"]))
    return dashboard
Exemplo n.º 2
0
from utils import redis_connection

from .leaderboard import LeaderBoard

FRUIT_AVAILABLE = True
FRUIT_UN_AVILABLE = False
# There is a 10 % chance that a fruit will be
# avilable on the given step.
AVAILABLE_WEIGHT = 0.1
UN_AVAILABLE_WEIGHT = 0.9
FRUIT_CHOICES = [FRUIT_AVAILABLE, FRUIT_UN_AVILABLE]
FRUIT_WEIGHTS = [AVAILABLE_WEIGHT, UN_AVAILABLE_WEIGHT]
POINTS_PER_COLLECTION = 10

conn = redis_connection()


class Game:
    def __init__(self):
        self.game_id = str(uuid.uuid4())
        self._leaderboard = LeaderBoard()

    def start(self, username):
        if self.username:
            raise ValueError("This method can be called only once")
        if conn.exists(f"active_game:{username}"):
            raise ValueError("User can only play one game at a time")
        self.username = username
        self.steps = 0
        self.points = 0
Exemplo n.º 3
0
def set_draft_blog(uid, markdown):
    _cache = redis_connection()
    key = str("%s:draft:blog:%s" % (APP, uid))
    _cache.set(key, markdown, settings.DRAFT_BLOG_TIMEOUT)
Exemplo n.º 4
0
  def save(self):
      conn = redis_connection()
 		conn.
Exemplo n.º 5
0
def get_events(dashboard_id):
    redis = redis_connection()
    key_name = '{}-events'.format(dashboard_id)
    events = redis.lrange(key_name, 0, -1)
    return events
Exemplo n.º 6
0
def save_event(color, oldX, oldY, newX, newY, dashboard_id):
    redis = redis_connection()
    key_name = '{}-events'.format(dashboard_id)
    redis.rpush(key_name, json.dumps({'color': color, 'oldX': oldX, 'oldY': oldY, 'newX': newX, 'newY': newY}))
Exemplo n.º 7
0
 def save(self):
     redis = redis_connection()
     redis.set(self.dashboard_id, self.to_json())