Exemplo n.º 1
0
def delete_art_tests_files(path_to_data_dir, file_names):
    """
	file_names is a list of files to be deleted in the final art tests directory
	"""
    path_to_central_atom_list = os.path.join(path_to_data_dir,
                                             "central_atom_list.json")
    central_atom_list = json.load(open(path_to_central_atom_list, 'r'))
    i = 0
    for central_atom in central_atom_list:
        for each_file in file_names:
            path_to_file = os.path.join(path_to_data_dir, str(central_atom),
                                        each_file)
            if os.path.isfile(path_to_file):
                if i >= 1:
                    print "deleting the file %s" % path_to_file
                    os.remove(path_to_file)
                else:
                    print "deleting the file %s" % path_to_file
                    print "confirm deleting (y/n):"
                    if prompt_yes_no() is True:
                        os.remove(path_to_file)
            else:
                print "%s" % each_file, "does not exist in %s" % os.path.join(
                    path_to_data_dir, str(central_atom))
        i = i + 1
def generate_correlation_table_mp(path_to_data_dir, input_param):
    list_of_test_id = input_param["list_of_test_id"]
    num_of_proc = input_param["num_of_proc"]
    atom_list = input_param["atom_list"]
    print "if atom_list is local or pn, voronoi volume calculation only act on atom_list from init to sad"
    print "confirm if voronoi_index_results.json is corresponding to the atom_list you just specified:", atom_list
    if not prompt_yes_no():
        raise Exception(
            "quitting, re_calc the voronoi indexes for your specified atom_list by --voro --calc --re_calc --local if atom_list is local"
        )

    operation = lambda x: single_event_data_extractor(x, path_to_data_dir,
                                                      atom_list)
    result_list = operation_on_events(path_to_data_dir,
                                      list_of_test_id,
                                      operation,
                                      num_of_proc=num_of_proc)

    convert_to_csv(path_to_data_dir, result_list)
    print "All done!"
Exemplo n.º 3
0
def delete_art_tests(path_to_data_dir, central_atom_list):
    """
	file_names is a list of files to be deleted in the final art tests directory
	"""
    print "begining delete tests:", central_atom_list
    print "confirm deleting (y/n):"
    if prompt_yes_no() is True:
        for test in central_atom_list:
            try:
                path_to_test = data_dir_to_test_dir(path_to_data_dir, test)
                if os.path.isdir(path_to_test):
                    print "deleting the test %s" % path_to_test
                    shutil.rmtree(path_to_test)
                else:
                    print "test %s" % test, "does not exist in %s" % path_to_data_dir
            except Exception:
                print "test %s" % test, "does not exist in %s" % path_to_data_dir
    else:
        print "Not deleting!"
    print "done deleting all tests in specified list of tests in %s" % path_to_data_dir
Exemplo n.º 4
0
def archived_file_names(path_to_data_dir):
	path_to_final_selected_events = os.path.join(path_to_data_dir,"final_selected_events.json")
	#path_to_central_atom_list = os.path.join(path_to_data_dir,"central_atom_list.json")
	#path_to_int_atom_list = os.path.join(path_to_data_dir, "interested_atom_list.json")
	
	print "reading final_selected_events.json"
	if os.path.exists(path_to_final_selected_events):
		print "loading final_selected_events.json, ensure that you always get most updated final_selected_events.json by --filter --re_calc if you have calculated more tests"
		final_selected_events = json.load(open(path_to_final_selected_events,"r"))
	else:
		raise Exception("final_selected_events.json does not exist in %s"%path_to_data_dir)

	list_of_file_names = [["final_selected_events.json",path_to_final_selected_events]]
	
	#if os.path.exists(path_to_central_atom_list):
	#	print "archiving central_atom_list.json, ensure central_atom_list.json is updated by --update_input if using --art --run_more"
	#	central_file = ["central_atom_list.json",path_to_central_atom_list]
	#	list_of_file_names.append(central_file)
	
	#if os.path.exists(path_to_int_atom_list):
	#	print "archiving interested_atom_list.json"
	#	int_file = ["interested_atom_list.json",path_to_int_atom_list]
	#	list_of_file_names.append(int_file)
	file_dirs = os.listdir(path_to_data_dir)
	for f in file_dirs:
		if f == "final_selected_events.json" or f == "art_data_project.zip" or f == "central_atom_list.json":
			continue
		path_to_file = os.path.join(path_to_data_dir,f)
		if os.path.isfile(path_to_file):
			list_of_file_names.append([f,path_to_file])
			
	all_tests_id = []
	for event in final_selected_events:
		test_id = int(event[0][4:])
		all_tests_id.append(test_id)
		path_to_test_dir = data_dir_to_test_dir(path_to_data_dir,test_id)
		init, sad, fin = event[1][0],event[1][1],event[1][2]
		#path_to_init = os.path.join(path_to_test_dir,init)
		#path_to_sad = os.path.join(path_to_test_dir,sad)
		#path_to_fin = os.path.join(path_to_test_dir,fin)
		init_file = return_file_names(path_to_test_dir, init)
		sad_file = return_file_names(path_to_test_dir, sad)
		fin_file = return_file_names(path_to_test_dir, fin)
		list_of_file_names.append(init_file)
		list_of_file_names.append(sad_file)
		list_of_file_names.append(fin_file)
	
	final_tests_id = list(set(all_tests_id))
	# update the central_atom_list.json
	print "update the central_atom_list.json to be all test id saved in final_selected_events.json"
	print ">>> confirm updating central_atom_list.json file (y/n): save original central_atom_list.json if necessary"
	if prompt_yes_no() is True:
		print "response received, updating!"
		update_central_atom_list(path_to_data_dir,final_tests_id)
	else:
		print "response received, not updating"
	list_of_file_names.append(["central_atom_list.json", os.path.join(path_to_data_dir, "central_atom_list.json")])
	
	for test in final_tests_id:
		path_to_test_dir = data_dir_to_test_dir(path_to_data_dir,test)
		test_file = return_test_results_file_name(path_to_test_dir)
		list_of_file_names.extend(test_file)
	return list_of_file_names
Exemplo n.º 5
0
def create_amateur_bracket(tourney_url,
                           single_elimination,
                           losers_round_cutoff,
                           randomize_seeds,
                           associate_challonge_accounts=False,
                           incomplete=False,
                           interactive=False):
    """
    Create the amateur bracket.

    Most of the params are the same as their argparse counterpart.

    @param interactive: If this is being run on the command line and can take
        user input.

    @returns: URL of the generated amateur bracket.

    """
    # Create the info for our amateur's bracket.
    tourney_name = util_challonge.extract_tourney_name(tourney_url)
    tourney_info = challonge.tournaments.show(tourney_name)
    tourney_title = tourney_info["name"]
    amateur_tourney_title = tourney_title + " Amateur's Bracket"
    amateur_tourney_name = tourney_name + "_amateur"
    amateur_tourney_url = util_challonge.tourney_name_to_url(
        amateur_tourney_name)
    if single_elimination:
        amateur_tourney_type = "single elimination"
    else:
        amateur_tourney_type = "double elimination"

    # Make sure the tournament doesn't already exist.
    existing_amateur_tournament = util_challonge.get_tourney_info(
        amateur_tourney_name)
    if existing_amateur_tournament:
        raise AmateurBracketAlreadyExistsError(
            "Amateur tournament already exists at {}.".format(
                amateur_tourney_url))

    # Get all decided loser's matches until the cutoff.
    cutoff = losers_round_cutoff
    matches = challonge.matches.index(tourney_name)
    amateur_deciding_matches = _get_losers_matches_determining_amateurs(
        matches, cutoff)
    num_completed_deciding_matches = sum(
        1 for x in amateur_deciding_matches
        if x[_PARAMS_STATE] == _MATCH_STATE_COMPLETE)
    num_amateurs = _get_num_amateurs(tourney_info["participants_count"],
                                     cutoff)

    # If they're not all complete, we don't have enough info to create the
    # amateur bracket.
    if num_completed_deciding_matches != num_amateurs:
        matches_remaining = num_amateurs - num_completed_deciding_matches
        err = AmateurBracketRequiredMatchesIncompleteError(
            "There are still {0} matches incomplete before loser's round {1}.\n"
            "Please wait for these matches to complete before creating the\n"
            "amateur bracket.\n"
            "The last loser's round for amateur's qualification can be\n"
            "configured using the --losers_round_cutoff flag.\n".format(
                matches_remaining, cutoff + 1), matches_remaining)

        if interactive:
            print(err)

            if not incomplete:
                print("Alternatively, we can 'approximate' the amateur\n"
                      "bracket if you pass in the --incomplete flag.")
                sys.exit()
            else:
                if not util.prompt_yes_no("Create amateur bracket anyway?"):
                    sys.exit()

        elif not incomplete:
            raise err

    # Gather up all the amateurs.
    amateur_infos = get_amateur_participants(tourney_name,
                                             amateur_deciding_matches)

    # Sort them based on seeding.
    if randomize_seeds:
        seed_fn = lambda x: random.random()
    else:
        seed_fn = lambda x: x[_PARAMS_SEED]
    amateur_infos = sorted(amateur_infos, key=seed_fn)

    all_amateur_params = [
        _get_params_to_create_participant(
            amateur_info,
            associate_challonge_account=associate_challonge_accounts,
            seed=seed) for seed, amateur_info in enumerate(amateur_infos, 1)
    ]

    if interactive:
        # Confirm with the user that this is all okay.
        print("I creeped your tourney at http://challonge.com/{0}...".format(
            tourney_name))
        print((
            "Here's what I think the amateur bracket should look like, taking\n"
            "all people eliminated before Loser's Round {0}:".format(cutoff +
                                                                     1)))
        print()
        print("Title: {0}".format(amateur_tourney_title))
        print("URL: {0}".format(amateur_tourney_url))
        print("Elimination Type: {0}".format(amateur_tourney_type))
        print()
        print("Seeds:")
        need_to_send_at_least_one_invite = any(
            x.get(_PARAMS_CHALLONGE_USERNAME) for x in all_amateur_params)
        if need_to_send_at_least_one_invite:
            # I really don't want people accidentally sending email invites, so
            # we're very explicit about email invites and how to turn them off.
            print(
                "(to disable invites, use --associate_challonge_accounts=False)"
            )
        for amateur_params in all_amateur_params:
            print("\t{0}. {1}".format(amateur_params[_PARAMS_SEED],
                                      amateur_params[_PARAMS_NAME]))
            if amateur_params.get(_PARAMS_CHALLONGE_USERNAME):
                print("\t\t- Challonge account will receive email invite.")
        print()
        if not util.prompt_yes_no(
                "Is it okay to create this amateur's bracket?"):
            print("Aw man. Alright, I'm not creating this amateur's bracket.")
            print(random.choice(puns.AMATEUR_PUNS))
            print("( Feel free to report bugs and request features at "
                  "https://github.com/akbiggs/challonge-tools/issues )")
            sys.exit(1)

    # We've got confirmation. Go ahead and create the amateur bracket.
    tourney, subdomain = util_challonge.tourney_name_to_parts(
        amateur_tourney_name)
    challonge.tournaments.create(amateur_tourney_title,
                                 tourney,
                                 amateur_tourney_type,
                                 subdomain=subdomain)

    for amateur_params in all_amateur_params:
        challonge.participants.create(amateur_tourney_name, **amateur_params)

    if interactive:
        print("Created {0} at {1}.".format(amateur_tourney_title,
                                           amateur_tourney_url))
        print("Start the amateur bracket at the above URL when you're ready!")

    return amateur_tourney_url
Exemplo n.º 6
0
def delete_unused_events_data(path_to_data_dir, input_param):
    """
	this function delete the configuration files of un-used events data
	inside each test of an art data project to save disk space, especially
	when users has not used WRITE_REJECTED_EVENTS = .False. option in bart.sh
	
	First, it will read the final_selected_events.json, which stores all useful events.
	
	Second, it will delete all configuration files that are not saved
	in the final_selected_events.json
	"""
    path_to_final_selected_events = os.path.join(path_to_data_dir,
                                                 "final_selected_events.json")
    if os.path.isfile(path_to_final_selected_events):
        print "reading final_selected_events.json, ensure that you always get most updated final_selected_events.json by --filter --re_calc if you have calculated more tests"
        final_selected_events = json.load(
            open(path_to_final_selected_events, "r"))
    else:
        raise Exception("final_selected_events.json does not exist in %s" %
                        path_to_data_dir)

    all_tests_events = dict()
    for event in final_selected_events:
        test_id = int(event[0][4:])
        init, sad, fin = event[1][0], event[1][1], event[1][2]
        if test_id in all_tests_events:
            all_tests_events[test_id].extend([init, sad, fin])
        else:
            all_tests_events[test_id] = [init, sad, fin]
            #all_tests_id.append(test_id)

    print "confirm deleting (y/n):"
    if prompt_yes_no() is False:
        print "response received, not deleting"
        return None
    else:
        print "response received, begin deleting"

    path_to_central_atom_list = os.path.join(path_to_data_dir,
                                             "central_atom_list.json")
    if os.path.isfile(
            path_to_central_atom_list) or "central_atom_list" in input_param:
        if os.path.isfile(path_to_central_atom_list):
            print "reading central_atom_list.json"
            central_atom_list = json.load(open(path_to_central_atom_list, 'r'))
        elif "central_atom_list" in input_param:
            print "reading central_atom_list from input SETTINGs file"
            central_atom_list = input_param['central_atom_list']
        delete_tests_list = []
        saved_tests_list = []
        for test_id in central_atom_list:
            if test_id not in all_tests_events:
                delete_tests_list.append(test_id)
            else:
                saved_tests_list.append(test_id)
        delete_art_tests(path_to_data_dir, delete_tests_list)
        print ">>> confirm updating central_atom_list.json file (y/n): save original central_atom_list.json if necessary"
        if prompt_yes_no() is True:
            print "response received, updating!"
            update_central_atom_list(path_to_data_dir, saved_tests_list)
        else:
            print "response received, not updating"
    else:
        print "central_atom_list.json does not exist in %s" % path_to_data_dir
        print "central_atom_list key does not exist in input SETTING file"
        print ">>> only deleting unused events for all tests stored in final_selected_events.json"

    print "\n Now begin deleting unused events configuration files for all tests stored in final_selected_events.json"
    for test_id in all_tests_events:
        path_to_test_dir = data_dir_to_test_dir(path_to_data_dir, test_id)
        for f in os.listdir(path_to_test_dir):
            is_match_config = re.match(r"min[0-9]+", f) or re.match(
                r"sad[0-9]+", f) or re.match(r"min[0-9]+.dump", f) or re.match(
                    r"sad[0-9]+.dump", f)
            path_to_file = os.path.join(path_to_test_dir, f)
            is_file = os.path.isfile(path_to_file)
            if is_match_config and is_file:
                if f.endswith('.dump'):
                    config_id = f[:-5]
                else:
                    config_id = f
                if config_id not in all_tests_events[test_id]:
                    print "deleting the file %s" % path_to_file
                    os.remove(path_to_file)
    print "done deleting unused events data!"