예제 #1
0
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)
예제 #2
0
def randomize(tournament):
    """Randomize seeds among participants.

    Only applicable before a tournament has started.

    """
    api.fetch("POST", "tournaments/%s/participants/randomize" % tournament)
예제 #3
0
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)
예제 #4
0
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)
예제 #5
0
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)
예제 #6
0
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)
예제 #7
0
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)
예제 #8
0
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)
예제 #9
0
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)
예제 #10
0
def randomize(tournament):
    """Randomize seeds among participants.

    Only applicable before a tournament has started.

    """
    api.fetch("POST", "tournaments/%s/participants/randomize" % tournament)
예제 #11
0
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)
예제 #12
0
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)
예제 #13
0
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))
예제 #14
0
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))
예제 #15
0
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
예제 #16
0
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']
예제 #17
0
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)
예제 #18
0
def update(tournament, **params):
    """Update a tournament's attributes."""
    api.fetch("PUT", "tournaments/%s" % tournament, "tournament", **params)
예제 #19
0
def update(tournament, **params):
    """Update a tournament's attributes."""
    api.fetch("PUT", "tournaments/%s" % tournament, "tournament", **params)
예제 #20
0
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