def update(tournament, participant_id, **params): """Update the attributes of a tournament participant.""" api.fetch( "PUT", "tournaments/%s/participants/%s" % (tournament, participant_id), "participant", **params)
def randomize(tournament): """Randomize seeds among participants. Only applicable before a tournament has started. """ api.fetch("POST", "tournaments/%s/participants/randomize" % tournament)
def publish(tournament): """Publish a tournament, making it publically accessible. The tournament must have at least 2 participants. """ api.fetch("POST", "tournaments/publish/%s" % tournament)
def destroy(tournament): """Deletes a tournament along with all its associated records. There is no undo, so use with care! """ api.fetch("DELETE", "tournaments/%s" % tournament)
def start(tournament): """Start a tournament, opening up matches for score reporting. The tournament must have at least 2 participants. """ api.fetch("POST", "tournaments/start/%s" % tournament)
def update(tournament, match_id, **params): """Update/submit the score(s) for a match.""" api.fetch( "PUT", "tournaments/%s/matches/%s" % (tournament, match_id), "match", **params)
def reset(tournament): """Reset a tournament, clearing all of its scores and attachments. You can then add/remove/edit participants before starting the tournament again. """ api.fetch("POST", "tournaments/reset/%s" % tournament)
def destroy(tournament, participant_id): """Destroys or deactivates a participant. If tournament has not started, delete a participant, automatically filling in the abandoned seed number. If tournament is underway, mark a participant inactive, automatically forfeiting his/her remaining matches. """ api.fetch( "DELETE", "tournaments/%s/participants/%s" % (tournament, participant_id))
def dataset(): url = request.args.get('url') offset = request.args.get('offset') skip = request.args.get('skip').rstrip('+') cookie_key = 'ts_%s' % md5(url).hexdigest() start = end = None current_ts = int(time()) if not offset: ts = request.args.get(cookie_key) if not ts: ts = request.cookies.get(cookie_key) if ts: start = int(ts) while start % settings.step_size != 0: start += 1 if not start: start = current_ts - int(offset) end = current_ts records = [] keys = api.get_keys() data = api.fetch(url, start, end) for i in data: if i.get('total') > float(skip): # skip if larger than 100ms record = [int(i.get('timestamp')), '', '', ''] else: if i.get('code', 200) == 200: record = [int(i.get('timestamp')), abs(float(i.get('connect'))) * 100 if i.has_key('connect') else '', abs(float(i.get('ttfb'))) * 100 if i.has_key('ttfb') else '', abs(float(i.get('total'))) * 100 if i.has_key('total') else ''] else: record = [int(i.get('timestamp')), abs(float(i.get('connect'))) * -100 if i.has_key('connect') else '', abs(float(i.get('ttfb'))) * -100 if i.has_key('ttfb') else '', abs(float(i.get('total'))) * -100 if i.has_key('total') else ''] ts = datetime.fromtimestamp(record[0]).isoformat() record.pop(0) record.insert(0, 'new Date("%s+07:00")' % ts) records.append(record) code = render_template('data.js', records=records, url=url, keys=keys, offset=offset) resp = make_response(code) resp.set_cookie(cookie_key, int(time())) resp.headers['Content-Type'] = 'text/javascript' resp.headers['Content-Length'] = len(code) resp.headers['Cache-Control'] = 'max-age=60' return resp
def fetch_pcr(*args, **kwargs): """Wrapper for fetch to automatically parse rehttp://pennapps.com/courses-demo/sults from the PCR API.""" try: # Attempt to load the user's token kwargs['token'] = os.environ["PCR_AUTH_TOKEN"] except KeyError: # On error, use the public token kwargs['token'] = "public" return fetch(DOMAIN, *args, **kwargs)['result']
def main(): producer = KafkaProducer(bootstrap_servers='localhost:9092') chunks = api.fetch() for chunk in chunks: message = (chunk['id'] + ',' + str(chunk['parent']) + ',' + str(chunk['weight'])).encode('utf-8') producer.send('foo2', message) print("Publishing message as comma-separated line" + message)
def update(tournament, **params): """Update a tournament's attributes.""" api.fetch("PUT", "tournaments/%s" % tournament, "tournament", **params)
def dataset(): url = request.args.get('url') offset = request.args.get('offset') skip = request.args.get('skip').rstrip('+') cookie_key = 'ts_%s' % md5(url).hexdigest() start = end = None current_ts = int(time()) if not offset: ts = request.args.get(cookie_key) if not ts: ts = request.cookies.get(cookie_key) if ts: start = int(ts) while start % settings.step_size != 0: start += 1 if not start: start = current_ts - int(offset) end = current_ts records = [] keys = api.get_keys() data = api.fetch(url, start, end) for i in data: if i.get('total') > float(skip): # skip if larger than 100ms record = [int(i.get('timestamp')), '', '', ''] else: if i.get('code', 200) == 200: record = [ int(i.get('timestamp')), abs(float(i.get('connect'))) * 100 if i.has_key('connect') else '', abs(float(i.get('ttfb'))) * 100 if i.has_key('ttfb') else '', abs(float(i.get('total'))) * 100 if i.has_key('total') else '' ] else: record = [ int(i.get('timestamp')), abs(float(i.get('connect'))) * -100 if i.has_key('connect') else '', abs(float(i.get('ttfb'))) * -100 if i.has_key('ttfb') else '', abs(float(i.get('total'))) * -100 if i.has_key('total') else '' ] ts = datetime.fromtimestamp(record[0]).isoformat() record.pop(0) record.insert(0, 'new Date("%s+07:00")' % ts) records.append(record) code = render_template('data.js', records=records, url=url, keys=keys, offset=offset) resp = make_response(code) resp.set_cookie(cookie_key, int(time())) resp.headers['Content-Type'] = 'text/javascript' resp.headers['Content-Length'] = len(code) resp.headers['Cache-Control'] = 'max-age=60' return resp