def updateProblemData(prevFile, newFile, force):
    """
    Update problem_data.csv
    prevFile: name of local file containing problem data
    newFile: name of new file name with new problem data. Should be set to be the same as the prevFile for appending, unless currently debuggin
    """
    df_prev = pd.read_csv(prevFile, index_col=None, engine='c')

    cur_contests = api.getContestList()
    max_prev_contests = max(df_prev.contestID)

    new_contests = [c for c in cur_contests if c > max_prev_contests]

    dflist = []
    cnt = 0
    for contestID in new_contests:
        print "   contest", contestID
        try:
            contestProblems = api.getProblemDataFromContest(contestID)
            contestProblems = contestProblems.rename(
                index=str, columns={'index': 'problemID'})
            contestProblems = contestProblems.drop('contestId', 1)
            dflist.append(contestProblems)
            cnt += 1
        except api.ContestNotFound:
            sys.stderr.write(
                str(contestID) + ', api returned contest not found error.')

    if not dflist:
        print "   Problem ratings file up to date."
        return
    problemData = pd.concat(dflist)
    writeFile(problemData, newFile, force)
    sys.stderr.write("Successfully wrote problem data from " + str(cnt) +
                     " contests.")
def updateProblemRating(prevFile, newFile, force):
    """
    Update problem_ratings.csv
    prevFile: name of local file containing problem ratings.
    newFile: name of new file name with new problem ratings. Should be set to be the same as the prevFile for appending, unless currently debuggin
    """
    df_prev = pd.read_csv(prevFile, index_col=None, engine='c')

    cur_contests = api.getContestList()
    max_prev_contests = max(df_prev.contestID)

    new_contests = [c for c in cur_contests if c > max_prev_contests]

    dflist = []
    cnt = 0
    for contestID in new_contests:
        print "   contest", contestID
        df = elo.get_contest_elo(contestID)
        dflist.append(df)
        cnt += 1

    if not dflist:
        print "   Problem ratings file up to date."
        return
    try:
        problemRatings = pd.concat(dflist)
        writeFile(problemRatings, newFile, force)
        sys.stderr.write("Successfully wrote problem data from " + str(cnt) +
                         " contests.")
    except:
        print "     Error updating this round. Most likely because all rounds were unrated."
Exemplo n.º 3
0
def updateProblemRating(prevFile, newFile, force):
    """
    Update problem_ratings.csv
    prevFile: name of local file containing problem ratings.
    newFile: name of new file name with new problem ratings. Should be set to be the same as the prevFile for appending, unless currently debuggin
    """
    df_prev = pd.read_csv(prevFile, index_col=None, engine='c')
    
    cur_contests = api.getContestList()
    max_prev_contests = max(df_prev.contestID)
    
    new_contests = [c for c in cur_contests if c > max_prev_contests]
    
    dflist = []
    cnt = 0
    for contestID in new_contests:
	print "   contest", contestID
	df = elo.get_contest_elo(contestID)
	dflist.append(df)
	cnt += 1

    if not dflist:
	print "   Problem ratings file up to date."
	return
    try:
        problemRatings = pd.concat(dflist)
        writeFile(problemRatings, newFile, force)
        sys.stderr.write("Successfully wrote problem data from " + str(cnt) + " contests.")
    except:
        print "     Error updating this round. Most likely because all rounds were unrated."
Exemplo n.º 4
0
def updateProblemData(prevFile, newFile, force):
    """
    Update problem_data.csv
    prevFile: name of local file containing problem data
    newFile: name of new file name with new problem data. Should be set to be the same as the prevFile for appending, unless currently debuggin
    """
    df_prev = pd.read_csv(prevFile, index_col=None, engine='c')
    
    cur_contests = api.getContestList()
    max_prev_contests = max(df_prev.contestID)
    
    new_contests = [c for c in cur_contests if c > max_prev_contests]
    
    dflist = []
    cnt = 0
    for contestID in new_contests:
	print "   contest", contestID
        try:
            contestProblems = api.getProblemDataFromContest(contestID)
            contestProblems = contestProblems.rename(index=str, columns={'index': 'problemID'})
            contestProblems = contestProblems.drop('contestId', 1)
            dflist.append(contestProblems)
            cnt += 1
        except api.ContestNotFound:
            sys.stderr.write(str(contestID) + ', api returned contest not found error.')
    
    if not dflist:
	print "   Problem ratings file up to date."
	return
    problemData = pd.concat(dflist)
    writeFile(problemData, newFile, force)
    sys.stderr.write("Successfully wrote problem data from " + str(cnt) + " contests.")
Exemplo n.º 5
0
def updateProblemData(prevFile, newFile, force):
    """
    Update problem_data.csv
    prevFile: name of local file containing problem data
    newFile: name of new file name with new problem data. Should be set to be the same as the prevFile for appending, unless currently debuggin
    """
    df_prev = pd.read_csv(prevFile, index_col=None, engine='c')
    
    cur_contests = api.getContestList()
    
    tmp_list = dict(df_prev.contestID)
    tmp_list = set([tmp_list[key] for key in tmp_list])
    
    good = []
    for key in tmp_list:
      try:
        int(key)
        good.append(int(key))
      except:
        continue
    
    tmp_list = set(good)
    
    bad_contests = {}
    with open('bad_contests.txt', 'r') as f:
      l = [int(x) for x in f.read().split()]
      for x in l:
        bad_contests[x] = 1
    
    new_contests = []
    for c in cur_contests:
      if c not in tmp_list and c not in bad_contests:
        new_contests.append(c)
    
    dflist = []
    cnt = 0
    for contestID in new_contests:
      print "   contest", contestID
      try:
          contestProblems = api.getProblemDataFromContest(contestID)
          contestProblems = contestProblems.rename(index=str, columns={'index': 'problemID'})
          contestProblems = contestProblems.drop('contestId', 1)
          dflist.append(contestProblems)
          cnt += 1
      except api.ContestNotFound:
          sys.stderr.write(str(contestID) + ', api returned contest not found error.')
  
    if not dflist:
      print "   Problem ratings file up to date."
      return
    
    problemData = pd.concat(dflist)
    writeFile(problemData, newFile, force)
    sys.stderr.write("Successfully wrote problem data from " + str(cnt) + " contests.")
Exemplo n.º 6
0
def updateProblemRating(prevFile, newFile, force):
    """
    Update problem_ratings.csv
    prevFile: name of local file containing problem ratings.
    newFile: name of new file name with new problem ratings. Should be set to be the same as the prevFile for appending, unless currently debuggin
    """
    df_prev = pd.read_csv(prevFile, index_col=None, engine='c')
    
    cur_contests = api.getContestList()
    
    tmp_list = dict(df_prev.contestID)
    tmp_list = set([tmp_list[key] for key in tmp_list])
    
    bad_contests = {}
    with open('bad_contests.txt', 'r') as f:
      l = [int(x) for x in f.read().split()]
      for x in l:
        bad_contests[x] = 1
    
    new_contests = []
    for c in cur_contests:
      if c not in tmp_list and c not in bad_contests:
        new_contests.append(c)
    
    dflist = []
    cnt = 0
    for contestID in new_contests:
      print "   contest", contestID
      df = elo.get_contest_elo(contestID)
      dflist.append(df)
      cnt += 1

    if not dflist:
      print "   Problem ratings file up to date."
      return
    try:
        problemRatings = pd.concat(dflist)
        writeFile(problemRatings, newFile, force)
        sys.stderr.write("Successfully wrote problem data from " + str(cnt) + " contests.")
    except:
        print "     Error updating this round. Most likely because all rounds were unrated."
Exemplo n.º 7
0
        if args.forceUpdate:
            sys.stderr.write(args.outputFile +
                             " found, -f flag set, overwriting...\n")
            fh = open(args.outputFile, 'w')
        else:
            sys.stderr.write(args.outputFile +
                             " found, opening in append mode...\n")
            fh = open(args.outputFile, 'a')
    else:
        sys.stderr.write(args.outputFile +
                         " not found, creating new file...\n")
        fh = open(args.outputFile, 'w')

    if contestID != "0":  # calculate problem ratings for a specific competition
        df = get_contest_elo(contestID)
        df.to_csv(fh, header=True, index=False)

    else:  # calculate problem ratings for all currently available contests

        for cid in af.getContestList():
            sys.stderr.write("Calculating ELO for contest " + str(cid) + ".\n")

            contest_elos = get_contest_elo(cid)

            if contest_elos is not None:
                contest_elos.to_csv(fh, header=True, index=False)
                sys.stderr.write("Got " + str(contest_elos.shape[0]) +
                                 " new rows.\n")

            sys.stderr.flush()