Esempio n. 1
0
def update_users():
    rundb = RunDb()

    info = {}
    for u in rundb.userdb.get_users():
        username = u['username']
        info[username] = {
            'username': username,
            'cpu_hours': 0,
            'games': 0,
            'tests': 0,
            'tests_repo': u.get('tests_repo', ''),
            'last_updated': datetime.datetime.min,
            'games_per_hour': 0.0,
        }

    for run in rundb.get_runs():
        if 'deleted' in run:
            continue
        if 'username' in run['args']:
            username = run['args']['username']
            info[username]['tests'] += 1

        tc = parse_tc(run['args']['tc'])
        for task in run['tasks']:
            if 'worker_info' not in task:
                continue
            username = task['worker_info'].get('username', None)
            if username == None:
                continue

            if 'stats' in task:
                stats = task['stats']
                num_games = stats['wins'] + stats['losses'] + stats['draws']
            else:
                num_games = task['num_games']

            info[username]['last_updated'] = max(
                task['last_updated'], info[username]['last_updated'])
            info[username]['cpu_hours'] += float(num_games * tc / (60 * 60))
            info[username]['games'] += num_games

    machines = rundb.get_machines()
    for machine in machines:
        games_per_hour = (machine['nps'] / 1200000.0) * (3600.0 / parse_tc(
            machine['run']['args']['tc'])) * int(machine['concurrency'])
        info[machine['username']]['games_per_hour'] += games_per_hour

    users = []
    for u in info.keys():
        user = info[u]
        user['last_updated'] = delta_date(user['last_updated'])
        users.append(user)

    users = [u for u in users if u['games'] > 0 or u['tests'] > 0]

    rundb.userdb.user_cache.remove()
    rundb.userdb.user_cache.insert(users)
Esempio n. 2
0
def update_users():
  rundb = RunDb()

  info = {}
  for u in rundb.userdb.get_users():
    username = u['username']
    info[username] = {'username': username,
                      'cpu_hours': 0,
                      'games': 0,
                      'tests': 0,
                      'tests_repo': u.get('tests_repo', ''),
                      'last_updated': datetime.datetime.min,
                      'games_per_hour': 0.0,}

  for run in rundb.get_runs():
    if 'deleted' in run:
      continue
    if 'username' in run['args']:
      username = run['args']['username']
      info[username]['tests'] += 1

    tc = parse_tc(run['args']['tc'])
    for task in run['tasks']:
      if 'worker_info' not in task:
        continue
      username = task['worker_info'].get('username', None)
      if username == None:
        continue

      if 'stats' in task:
        stats = task['stats']
        num_games = stats['wins'] + stats['losses'] + stats['draws']
      else:
        num_games = task['num_games']

      info[username]['last_updated'] = max(task['last_updated'], info[username]['last_updated'])
      info[username]['cpu_hours'] += float(num_games * tc / (60 * 60))
      info[username]['games'] += num_games

  machines = rundb.get_machines()
  for machine in machines:
    games_per_hour = (machine['nps'] / 1200000.0) * (3600.0 / parse_tc(machine['run']['args']['tc'])) * int(machine['concurrency'])
    info[machine['username']]['games_per_hour'] += games_per_hour

  users = []
  for u in info.keys():
    user = info[u]
    user['last_updated'] = delta_date(user['last_updated'])
    users.append(user)

  users = [u for u in users if u['games'] > 0 or u['tests'] > 0]

  rundb.userdb.user_cache.remove()
  rundb.userdb.user_cache.insert(users)
Esempio n. 3
0
def process_run(run, info):
  if 'deleted' in run:
    return
  if 'username' in run['args']:
    username = run['args']['username']
    info[username]['tests'] += 1

  tc = parse_tc(run['args']['tc'])
  for task in run['tasks']:
    if 'worker_info' not in task:
      continue
    username = task['worker_info'].get('username', None)
    if username == None:
      continue

    if 'stats' in task:
      stats = task['stats']
      num_games = stats['wins'] + stats['losses'] + stats['draws']
    else:
      num_games = task['num_games']

    try:
      info[username]['last_updated'] = max(task['last_updated'], info[username]['last_updated'])
    except:
      info[username]['last_updated'] = task['last_updated']

    info[username]['cpu_hours'] += float(num_games * int(run['args'].get('threads', 1)) * tc / (60 * 60))
    info[username]['games'] += num_games
Esempio n. 4
0
def build_users(machines, info):
  for machine in machines:
    games_per_hour = (machine['nps'] / 1200000.0) * (3600.0 / parse_tc(machine['run']['args']['tc'])) * int(machine['concurrency'])
    info[machine['username']]['games_per_hour'] += games_per_hour

  users = []
  for u in info.keys():
    user = info[u]
    try:
      user['last_updated'] = delta_date(user['last_updated'])
    except:
      pass
    users.append(user)

  users = [u for u in users if u['games'] > 0 or u['tests'] > 0]
  return users
def process_run(run, info, deltas=None):
    global skip
    if deltas and (skip or str(run['_id']) in deltas):
        skip = True
        return
    if deltas != None and str(run['_id']) in new_deltas:
        print('Warning: skipping repeated run!')
        return
    if 'username' in run['args']:
        username = run['args']['username']
        if username not in info:
            print('not in info: ', username)
            return
        else:
            info[username]['tests'] += 1

    tc = parse_tc(run['args']['tc'])
    for task in run['tasks']:
        if 'worker_info' not in task:
            continue
        username = task['worker_info'].get('username', None)
        if username == None:
            continue
        if username not in info:
            print('not in info: ', username)
            continue

        if 'stats' in task:
            stats = task['stats']
            num_games = stats['wins'] + stats['losses'] + stats['draws']
        else:
            num_games = 0

        try:
            info[username]['last_updated'] = max(
                task['last_updated'], info[username]['last_updated'])
        except:
            info[username]['last_updated'] = task['last_updated']

        info[username]['cpu_hours'] += float(
            num_games * int(run['args'].get('threads', 1)) * tc / (60 * 60))
        info[username]['games'] += num_games
    if deltas != None:
        new_deltas.update({str(run['_id']): None})
Esempio n. 6
0
def update_users():
    rundb = RunDb()

    info = {}
    for u in rundb.userdb.get_users():
        username = u["username"]
        info[username] = {
            "username": username,
            "cpu_hours": 0,
            "games": 0,
            "tests": 0,
            "tests_repo": u.get("tests_repo", ""),
            "last_updated": datetime.datetime.min,
            "games_per_hour": 0.0,
        }

    for u in rundb.userdb.old_user_cache.find():
        info[u["username"]] = u

    for run in rundb.get_runs():
        if "deleted" in run:
            continue
        if "username" in run["args"]:
            username = run["args"]["username"]
            info[username]["tests"] += 1

        tc = parse_tc(run["args"]["tc"])
        for task in run["tasks"]:
            if "worker_info" not in task:
                continue
            username = task["worker_info"].get("username", None)
            if username == None:
                continue

            if "stats" in task:
                stats = task["stats"]
                num_games = stats["wins"] + stats["losses"] + stats["draws"]
            else:
                num_games = task["num_games"]

            try:
                info[username]["last_updated"] = max(task["last_updated"], info[username]["last_updated"])
            except:
                info[username]["last_updated"] = task["last_updated"]

            info[username]["cpu_hours"] += float(num_games * tc / (60 * 60))
            info[username]["games"] += num_games

    machines = rundb.get_machines()
    for machine in machines:
        games_per_hour = (
            (machine["nps"] / 1200000.0)
            * (3600.0 / parse_tc(machine["run"]["args"]["tc"]))
            * int(machine["concurrency"])
        )
        info[machine["username"]]["games_per_hour"] += games_per_hour

    users = []
    for u in info.keys():
        user = info[u]
        try:
            user["last_updated"] = delta_date(user["last_updated"])
        except:
            pass
        users.append(user)

    users = [u for u in users if u["games"] > 0 or u["tests"] > 0]

    rundb.userdb.user_cache.remove()
    rundb.userdb.user_cache.insert(users)