├── .gitignore ├── README.md ├── atcoder ├── getScores.sh ├── getranks.py ├── gp-100_scores.txt ├── ranksToScore.py └── scrape.py ├── codeforces ├── getScores.sh ├── gp-100_scores.txt ├── ranksToScore.py └── resultCalculator.py └── filter.py /.gitignore: -------------------------------------------------------------------------------- 1 | __pycache__ 2 | *.csv 3 | *.json -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Result Calculators for the Sport Programmer of the Month Challenge 2 | 3 | ## Usage 4 | 5 | 1. Download the list of students registered for the contest in the form of a `.csv` file and place it in `./`. 6 | 7 | 2. run `filter.py` with : 8 | 9 | ```python 10 | python3 filter.py 11 | ``` 12 | ### You are now setup for the whole month ! 13 | 3. Contests : 14 | - move into the folder for the respective competition using `cd`. 15 | - ### AtCoder : 16 | - enter your atcoder credenntials in lines `12` and `13` of `scrape.py` 17 | - Then run the following command to get the scores: 18 | ``` 19 | ./getScores.sh 20 | ``` 21 | Example: `./getScores.sh abc171` 22 | - ### Codeforces : 23 | - Run the following command to get the scores: 24 | ``` 25 | ./getScores.sh 26 | ``` 27 | Example: `./getScores.sh 1397` 28 | - The results are calculated and stored in the file `scores.csv` of the respective directories 29 | 30 | ## Contributors : 31 | 32 | The following students were involved in writing the programs: 33 | 34 | - Atcoder Rank Calculator: [namangup](https://github.com/namangup) 35 | - Codeforces Rank Calculator: [abhimanyusethia12](https://github.com/abhimanyusethia12) 36 | - Ranks to Score Convertor: [AthaSSiN](https://github.com/AthaSSiN) 37 | - Input file filter : [Pramodh-G](https://github.com/Pramodh-G) 38 | 39 | ## Managers : 40 | 41 | The following students were involved in the management of the challenge: 42 | 43 | - August: [Pramodh-G](https://github.com/Pramodh-G) and [rohanblueboybaijal](https://github.com/rohanblueboybaijal) 44 | - September: [rockstar2514](https://github.com/rockstar2514) and [SomTambe](https://github.com/SomTambe) 45 | - October: [Zark84010](https://github.com/Zark84010) and [SarthakRout](https://github.com/SarthakRout) 46 | - November: [shubh101295](https://github.com/shubh101295) and [yatharth0610](https://github.com/yatharth0610) 47 | - December: [namangup](https://github.com/namangup) and [abhimanyusethia12](https://github.com/abhimanyusethia12) 48 | -------------------------------------------------------------------------------- /atcoder/getScores.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | python3 getranks.py input.csv $1 3 | python3 ranksToScore.py 4 | cat scores.csv 5 | -------------------------------------------------------------------------------- /atcoder/getranks.py: -------------------------------------------------------------------------------- 1 | import json 2 | import csv 3 | from scrape import gen_json 4 | from sys import argv 5 | 6 | usernames = [] 7 | dictOfHandles = {} 8 | with open(argv[1],'r') as f: 9 | fr = csv.reader(f, delimiter=',') 10 | for row in fr: 11 | usernames.append(row[1].strip()) 12 | dictOfHandles[row[1].strip()] = row[0].strip() 13 | 14 | print(dictOfHandles) 15 | contest = argv[2] 16 | gen_json(contest) 17 | 18 | with open('ranklist.json', 'r') as f: 19 | data = json.load(f) 20 | 21 | 22 | handlesInOrder = [] 23 | ranksInOrder = [] 24 | 25 | ranks = [] 26 | 27 | data = data["StandingsData"] 28 | for i in data: 29 | if (i['UserScreenName'] in usernames): 30 | handlesInOrder += [i['UserScreenName']] 31 | ranksInOrder += [i['Rank']] 32 | 33 | doneRolls = [] 34 | 35 | with open('ranks_for_contest.csv', mode='w') as final_file: 36 | file_writer = csv.writer(final_file, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL) 37 | rank = 1 38 | count = 0 39 | for handle in handlesInOrder: 40 | if(count==0): 41 | file_writer.writerow([1, dictOfHandles[handle]]) 42 | count+=1 43 | doneRolls.append(dictOfHandles[handle]) 44 | del dictOfHandles[handle] 45 | else: 46 | if(ranksInOrder[count]>ranksInOrder[count-1]): 47 | rank+=1 48 | file_writer.writerow([rank, dictOfHandles[handle]]) 49 | count+=1 50 | doneRolls.append(dictOfHandles[handle]) 51 | del dictOfHandles[handle] 52 | for handle, roll_no in dictOfHandles.items(): 53 | if roll_no not in doneRolls: 54 | doneRolls.append(roll_no) 55 | file_writer.writerow([10000, roll_no]) 56 | -------------------------------------------------------------------------------- /atcoder/gp-100_scores.txt: -------------------------------------------------------------------------------- 1 | Place Score 2 | 1 1000 3 | 2 706 4 | 3 575 5 | 4 497 6 | 5 443 7 | 6 403 8 | 7 371 9 | 8 346 10 | 9 325 11 | 10 307 12 | 11 291 13 | 12 277 14 | 13 265 15 | 14 254 16 | 15 244 17 | 16 235 18 | 17 226 19 | 18 218 20 | 19 211 21 | 20 204 22 | 21 198 23 | 22 192 24 | 23 186 25 | 24 181 26 | 25 176 27 | 26 171 28 | 27 166 29 | 28 161 30 | 29 157 31 | 30 153 32 | 31 149 33 | 32 145 34 | 33 142 35 | 34 138 36 | 35 135 37 | 36 131 38 | 37 128 39 | 38 125 40 | 39 122 41 | 40 119 42 | 41 116 43 | 42 113 44 | 43 110 45 | 44 107 46 | 45 105 47 | 46 102 48 | 47 99 49 | 48 97 50 | 49 94 51 | 50 92 52 | 51 90 53 | 52 87 54 | 53 85 55 | 54 83 56 | 55 80 57 | 56 78 58 | 57 76 59 | 58 74 60 | 59 72 61 | 60 70 62 | 61 68 63 | 62 66 64 | 63 63 65 | 64 62 66 | 65 60 67 | 66 58 68 | 67 56 69 | 68 54 70 | 69 52 71 | 70 50 72 | 71 48 73 | 72 46 74 | 73 45 75 | 74 43 76 | 75 41 77 | 76 39 78 | 77 37 79 | 78 36 80 | 79 34 81 | 80 32 82 | 81 31 83 | 82 29 84 | 83 27 85 | 84 26 86 | 85 24 87 | 86 22 88 | 87 21 89 | 88 19 90 | 89 17 91 | 90 16 92 | 91 14 93 | 92 13 94 | 93 11 95 | 94 10 96 | 95 8 97 | 96 7 98 | 97 5 99 | 98 4 100 | 99 2 101 | 100 1 -------------------------------------------------------------------------------- /atcoder/ranksToScore.py: -------------------------------------------------------------------------------- 1 | import csv 2 | import operator 3 | 4 | f = open("gp-100_scores.txt") 5 | 6 | scores = [] 7 | for line in f: 8 | line = line.split() 9 | scores.append(line) 10 | 11 | f.close() 12 | 13 | records = [] 14 | 15 | with open("ranks_for_contest.csv") as csvFile: 16 | csvReader = csv.reader(csvFile, delimiter = ',') 17 | for row in csvReader: 18 | record = {} 19 | record['Roll No'] = row[1] 20 | record['Rank'] = row[0] 21 | if row[0]=='10000': 22 | record['Rank']='NA' 23 | if int(row[0]) > 100: 24 | record['Score'] = 0 25 | else: 26 | record['Score'] = int(scores[int(row[0])][1]) 27 | records.append(record) 28 | records = sorted(records, key=operator.itemgetter('Roll No')) 29 | filename = 'scores.csv' 30 | with open(filename, 'w') as f: 31 | w = csv.DictWriter(f,['Roll No', 'Rank', 'Score']) 32 | w.writeheader() 33 | for record in records: 34 | w.writerow(record) 35 | -------------------------------------------------------------------------------- /atcoder/scrape.py: -------------------------------------------------------------------------------- 1 | import requests 2 | from bs4 import BeautifulSoup 3 | 4 | def gen_json(contest): 5 | loginurl = f'https://atcoder.jp/login' 6 | ranklist = f'https://atcoder.jp/contests/{contest}/standings/json' 7 | s = requests.Session() 8 | r = s.get(loginurl) 9 | soup = BeautifulSoup(r.content, 'html.parser') 10 | csrf = soup.find('input', attrs={'name':'csrf_token'})['value'] 11 | 12 | # Supply an AtCoder account details 13 | user = 'username' 14 | password = 'password' 15 | 16 | r = s.post(loginurl, data={'username':user, 'password':password, 'csrf_token':csrf}) 17 | r = s.get(ranklist) 18 | 19 | data = r.text 20 | with open('ranklist.json', 'w') as f: 21 | f.write(data) 22 | s.close() 23 | -------------------------------------------------------------------------------- /codeforces/getScores.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | python3 resultCalculator.py input.csv $1 3 | python3 ranksToScore.py 4 | cat scores.csv 5 | -------------------------------------------------------------------------------- /codeforces/gp-100_scores.txt: -------------------------------------------------------------------------------- 1 | Place Score 2 | 1 1000 3 | 2 706 4 | 3 575 5 | 4 497 6 | 5 443 7 | 6 403 8 | 7 371 9 | 8 346 10 | 9 325 11 | 10 307 12 | 11 291 13 | 12 277 14 | 13 265 15 | 14 254 16 | 15 244 17 | 16 235 18 | 17 226 19 | 18 218 20 | 19 211 21 | 20 204 22 | 21 198 23 | 22 192 24 | 23 186 25 | 24 181 26 | 25 176 27 | 26 171 28 | 27 166 29 | 28 161 30 | 29 157 31 | 30 153 32 | 31 149 33 | 32 145 34 | 33 142 35 | 34 138 36 | 35 135 37 | 36 131 38 | 37 128 39 | 38 125 40 | 39 122 41 | 40 119 42 | 41 116 43 | 42 113 44 | 43 110 45 | 44 107 46 | 45 105 47 | 46 102 48 | 47 99 49 | 48 97 50 | 49 94 51 | 50 92 52 | 51 90 53 | 52 87 54 | 53 85 55 | 54 83 56 | 55 80 57 | 56 78 58 | 57 76 59 | 58 74 60 | 59 72 61 | 60 70 62 | 61 68 63 | 62 66 64 | 63 63 65 | 64 62 66 | 65 60 67 | 66 58 68 | 67 56 69 | 68 54 70 | 69 52 71 | 70 50 72 | 71 48 73 | 72 46 74 | 73 45 75 | 74 43 76 | 75 41 77 | 76 39 78 | 77 37 79 | 78 36 80 | 79 34 81 | 80 32 82 | 81 31 83 | 82 29 84 | 83 27 85 | 84 26 86 | 85 24 87 | 86 22 88 | 87 21 89 | 88 19 90 | 89 17 91 | 90 16 92 | 91 14 93 | 92 13 94 | 93 11 95 | 94 10 96 | 95 8 97 | 96 7 98 | 97 5 99 | 98 4 100 | 99 2 101 | 100 1 -------------------------------------------------------------------------------- /codeforces/ranksToScore.py: -------------------------------------------------------------------------------- 1 | import csv 2 | import operator 3 | 4 | f = open("gp-100_scores.txt") 5 | 6 | scores = [] 7 | for line in f: 8 | line = line.split() 9 | scores.append(line) 10 | 11 | f.close() 12 | 13 | records = [] 14 | 15 | with open("ranks_for_contest.csv") as csvFile: 16 | csvReader = csv.reader(csvFile, delimiter = ',') 17 | for row in csvReader: 18 | record = {} 19 | record['Roll No'] = row[1] 20 | record['Rank'] = row[0] 21 | if row[0]=='10000': 22 | record['Rank']='NA' 23 | if int(row[0]) > 100: 24 | record['Score'] = 0 25 | else: 26 | record['Score'] = int(scores[int(row[0])][1]) 27 | records.append(record) 28 | records = sorted(records, key=operator.itemgetter('Roll No')) 29 | filename = 'scores.csv' 30 | with open(filename, 'w') as f: 31 | w = csv.DictWriter(f,['Roll No', 'Rank', 'Score']) 32 | w.writeheader() 33 | for record in records: 34 | w.writerow(record) 35 | -------------------------------------------------------------------------------- /codeforces/resultCalculator.py: -------------------------------------------------------------------------------- 1 | #importing required libraries 2 | import requests 3 | import csv 4 | import sys 5 | 6 | #PART 1- input CSV -> string of handles (for parameter of API) 7 | #and- input CSV -> dictOfHandles 8 | with open(sys.argv[1], mode='r') as csv_file: 9 | stringOfHandles = '' 10 | dictOfHandles = {} #with key = handle; value = roll no. 11 | csv_reader = csv.reader(csv_file, delimiter=',') 12 | flag = 0 13 | for row in csv_reader: 14 | lowerCaseHandle = row[1].lower().strip() 15 | if(flag==0): 16 | stringOfHandles += lowerCaseHandle 17 | flag=1 18 | dictOfHandles[lowerCaseHandle] = row[0] 19 | else: 20 | stringOfHandles += ';' 21 | stringOfHandles += lowerCaseHandle 22 | dictOfHandles[lowerCaseHandle] = row[0] 23 | 24 | #PART 2- API -> handles in order of their relative ranks 25 | parameters= { 26 | "contestId": sys.argv[2], 27 | "handles" : stringOfHandles, 28 | "showUnofficial": 'true' 29 | } 30 | URL = "https://codeforces.com/api/contest.standings" 31 | page = requests.get(URL, params=parameters) 32 | 33 | import json 34 | tp = page.json()['result']['rows'] 35 | 36 | handlesInOrder = [] 37 | ranksInOrder = [] 38 | 39 | for person in tp: 40 | if person['party']['participantType'] not in ['OUT_OF_COMPETITION', 'CONTESTANT']: 41 | continue 42 | members_list = (person['party'])['members'] 43 | handle = (members_list[0])['handle'] 44 | absolute_rank = person['rank'] 45 | handlesInOrder += [handle.lower()] 46 | ranksInOrder += [absolute_rank] 47 | #print(handlesInOrder) 48 | 49 | #Part 3- handlesInOrder + dictOfHandles -> CSV file with relative rank and roll no. 50 | with open('ranks_for_contest.csv', mode='w') as final_file: 51 | file_writer = csv.writer(final_file, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL) 52 | rank = 1 53 | count = 0 54 | for handle in handlesInOrder: 55 | if(count==0): 56 | file_writer.writerow([1, dictOfHandles[handle]]) 57 | count+=1 58 | del dictOfHandles[handle] 59 | else: 60 | if(ranksInOrder[count]>ranksInOrder[count-1]): 61 | rank+=1 62 | file_writer.writerow([rank, dictOfHandles[handle]]) 63 | count+=1 64 | del dictOfHandles[handle] 65 | for handle, roll_no in dictOfHandles.items(): 66 | file_writer.writerow([10000, roll_no]) 67 | -------------------------------------------------------------------------------- /filter.py: -------------------------------------------------------------------------------- 1 | import pandas as pd 2 | 3 | df = pd.read_csv('input.csv') 4 | ans = df[['Roll Number','Codeforces Username']] 5 | ans.to_csv('./codeforces/input.csv',index=False,header=False) 6 | ans = df[['Roll Number','AtCoder Username']] 7 | ans.to_csv('./atcoder/input.csv',index=False,header=False) --------------------------------------------------------------------------------