def post(self): contest_dict = contest.get_contest_dict_from_request(self.request) parsed_time = time.strptime(contest_dict['time'], "%H:%M") date_and_time = datetime.datetime( year=int(contest_dict["year"]), month=list(calendar.month_name).index(contest_dict["month"]), day=int(contest_dict["day"]), hour=parsed_time.tm_hour, minute=parsed_time.tm_min) timezone = pytz.timezone(contest_dict["time_zone"]) date_and_time = timezone.localize(date_and_time) contest_dict["date_and_time"] = date_and_time contest_dict["full_name"] = contest_dict["full_name"].replace( '\n', ' ') cont = None contest_id = self.request.get("id") if contest_id: cont = contest.get_contest_by_id(contest_id) for prop in cont.properties(): setattr(cont, prop, contest_dict[prop]) if not cont: self.redirect('\error?message=No contest with given id') return else: contest_dict["full_name"] = cgi.escape(contest_dict["full_name"]) contest_dict["short_name"] = cgi.escape(contest_dict["short_name"]) contest_dict["info"] = cgi.escape(contest_dict["info"]) cont = Contest(parent=contest.PARENT_KEY, **contest_dict) cont.put() self.redirect('/')
def _get_upcoming_contest_info(upcoming_contests): ''' HACK: The codes depend on AtCoder Home page. contest_info contains below information: ignore : http://www.timeanddate.com/worldclock/fixedtime.html? iso=202xxxxxTxxxx&px=xxx contest date : 202x-xx-xx xx:xx:xx+0900 contest url : /contests/abbreviated_contest_name contest name : hogehoge ''' from contest import Contest contest_info = upcoming_contests.find_all('a', limit=2) name, start_date, url = '', '', '' for index, link in enumerate(contest_info): if index == 0: start_date = _fix_contest_date_format(link.text) elif index == 1: name = link.text url = ATCODER_BASE_URL + link['href'] contest = Contest(name=name, start_date=start_date, url=url) return contest
def get_contest(y, rounds): contest = Contest(y) for r in rounds: print('Scraping: Eurovision Song Contest {} {}'.format(y, r)) contest = scraper.scrape_year(contest, r) contest = scraper.scrape_misc(contest) return contest
def main(): input_file_name = input( "Enter the path to the voting data spreadsheet (made by create_voter_spreadsheet.py): " ) contest = Contest() contest.populate_from_spreadsheet(input_file_name) output_file_name_prefix = input( "Enter the prefix that the output spreadsheets will start with: ") num_winners = int( input("Enter the desired number of winners for the contest: ")) contest.get_winners(num_winners, output_file_name_prefix)
def add_contest(update, context): if update.message.from_user.username != 'maksim1744': update.message.reply_text('This option is not available for you') return context.bot_data.setdefault('contest', dict()) for contest in context.args: if not re.fullmatch(r'[0-9]+', contest): update.message.reply_text('Contest must be an integer') break if contest in context.bot_data['contest']: continue context.bot_data['contest'][contest] = Contest(contest) ask_contest(update, context)
def check(self): contest = Contest(self.contestId) if contest.ratingChanges(): users = contest.participants() channels = [] for user in users: if self.toFilter.count(user) > 0: print "Will send to ... " + user channels.append(fix(user) + 'Rating') print "Ratings are out!" sender = NotificationSender( 'CF Contest %d, Ratings are updated!' % self.contestId, channels) print sender.send() return True return False
def check(self): contest = Contest(self.contestId) if contest.systemTest(): users = contest.participants() channels = [] for user in users: if self.toFilter.count(user) > 0: print "Will send to ... " + user channels.append(fix(user) + 'SystemTest') print "System Test is Final" sender = NotificationSender( 'CF Contest %d, system test is over' % self.contestId, channels) print sender.send() return True return False
def minerva_pvalue(sample, popsize, alpha, Vw, Vl, null_margin): """Computes the pvalue for a one-round minerva audit with the passed values. Uses an adapted version of Grant's Minerva code in r2b2 (adapted for null margins). Parameters: sample : list of 1's (vote for winner) and 0's (vote for loser) popsize : total ballots in stratum alpha : risk limit Vw : reported votes for winner in stratum Vl : reported votes for loser in stratum null_margin : the margin in votes assumed under the null Returns: float : the minerva pvalue """ contest = Contest(popsize, { 'A': Vw, 'B': Vl }, 1, ['A'], ContestType.PLURALITY) audit = Minerva_S(alpha, 1.0, contest, null_margin) n = len(sample) audit.rounds.append(n) audit.current_dist_reported() audit.current_dist_null() k = np.sum(sample == 1) x = (popsize + null_margin) / 2 if x < k or popsize - x < np.sum(sample == 0): return 0 pvalue = audit.stopping_condition(k)['pvalue'] return min(pvalue)
from contest import Contest contest = Contest(675) print contest.systemTest() print contest.ratingChanges() res = contest.participants() for x in res: print x
def __init__(self, string, prev=None): """Initialize the activation from the string At least callsign, date, and sota reference are needed, other information is optional. If a previous activation is given then the callsign and date can be preserved from it, but new sota reference is mandatory. An asterisk instead of sota reference means a chase """ self.previous = prev # start splitting the string into words w, pos, end = find_word(string) # callsign m = call.fullmatch(w) if m: self.callsign = w.upper() w, pos, end = find_word(string, end) elif prev: self.callsign = prev.callsign else: raise LogException( "Error in activation definition, missing callsign", pos) # date m = date_reg.fullmatch(w) if m: try: self.date = date(int(m.group(1)), int(m.group(3)), int(m.group(4))) except ValueError: raise LogException( "Error in activation definition, invalid date format", pos) w, pos, end = find_word(string, end) elif prev: self.date = prev.date else: raise LogException("Error in activation definition, missing date", pos) # sota reference is mandatory m = sota_ref.fullmatch(w) if m: self.ref = w.upper() elif w == '*': self.ref = '' else: raise LogException( "Error in activation definition, invalid SOTA reference detected", pos) notes = string[end:].strip() m = contest.search(notes) if m: self.contest = Contest(m.group(1)) notes = notes[:m.start()] + notes[m.end():] else: self.contest = None self.notes = notes self.qsos = [] # TODO: other information self.wwff = None self.locator = None
'B': 49500 }, 1, ['A'], ContestType.PLURALITY) stratum2 = Contest(7500+1500, { 'A': 7500, 'B': 1500 }, 1, ['A'], ContestType.PLURALITY) overall_contest = Contest(45500+49500+7500+1500, { 'A': 45500+7500, 'B': 49500+1500 }, 1, ['A'], ContestType.PLURALITY) """ stratum1 = Contest(100000, { 'A': 60000, 'B': 40000 }, 1, ['A'], ContestType.PLURALITY) stratum2 = Contest(50000, { 'A': 32000, 'B': 18000 }, 1, ['A'], ContestType.PLURALITY) overall_contest = Contest(100000+50000, { 'A': 32000+60000, 'B': 18000+40000 }, 1, ['A'], ContestType.PLURALITY) strata = [stratum1, stratum2]
i = 1 for stratum in self.strata: stratum_lambda = stratum.contest_ballots / self.overall_contest.contest_ballots print("stratum " + str(i) + " lambda value: " + str(stratum_lambda)) lambda_.append(stratum_lambda) i += 1 print("sum of lambda values: " + str(sum(lambda_))) return lambda_ # TESTING stratum1 = Contest(45500 + 49500, { 'A': 49500, 'B': 45500 }, 1, ['A'], ContestType.PLURALITY) stratum2 = Contest(9000, { 'A': 7500, 'B': 1500 }, 1, ['A'], ContestType.PLURALITY) overall_contest = Contest(45500 + 49500 + 9000, { 'A': 45500 + 7500, 'B': 49500 + 1500 }, 1, ['A'], ContestType.PLURALITY) strata = [] strata.append(stratum1) strata.append(stratum2)
seconds = contest_cfg['duration'] % 60 minutes = contest_cfg['duration'] / 60 % 60 hours = contest_cfg['duration'] / 60 / 60 % 60 logger.debug("Duration: %02d:%02d:%02d" % (hours, minutes, seconds)) logger.debug("Problems: " + str(contest_cfg['prob_ids'])) logger.debug("Penalty: %d points / wrong submission" % contest_cfg['penalty']) problems = { prob_id: Problem(prob_id, options.contest_dir, logger) for prob_id in contest_cfg['prob_ids'] } contest = Contest(options.delay, contest_cfg['duration'], options.minutes_in, contest_cfg['prob_ids'], contest_cfg['penalty'], logger) judge = Judge(contest, problems, options.contest_dir, options.num_judges, logger) application = web.Application( [ (r'/', IndexHandler), (r'/index.html', IndexHandler), (r'/auth/login', AuthLoginHandler), (r'/auth/logout', AuthLogoutHandler), (r'/api/v1/admin/(.*)', AdminHandler), (r'/api/v1/log/(.*)', LogHandler), (r'/api/v1/metadata', MetadataHandler), (r'/api/v1/updates', UpdatesHandler), (r'/api/v1/submit/(.*)/solution', SubmitSolutionHandler),
new_arrangement[contest].append({"type": player_tuple["type"], "amount": perm[contest]}) new_arrangements.append(new_arrangement) arrangements = new_arrangements games = list() for i in range(len(arrangements)): arrangement = arrangements[i] # We now needs to create contests. # Each arrangement is a game game = dict() for contest_id in arrangement: players = arrangement[contest_id] game[contest_id] = Contest(prizes[contest_id]) game[contest_id].add_players(players) game[contest_id].calculate_inner_equilibrium() games.append(game) for game_id in range(len(games)): print game_id for contest_id in games[game_id]: print games[game_id][contest_id] print games[game_id][contest_id]._contest_result print "\n" neighbors_matrix = [] for game_id in range(len(games)): neighbors_matrix.append([])