Пример #1
0
    def format_teams(self):
        teamParser = CSVParser(self.teamMap)
        self.team_dict = teamParser.csv_to_teamDict()
        print(self.team_dict)

        split = self.vs_team.split(' ')
        isHome = (split[0] == 'vs')

        self.player_team = self.team_dict[self.player_team][1]
        self.vs_team = self.team_dict[split[1]][1]

        if isHome:
            return f"{self.vs_team.lower()}mlb_{self.player_team.lower()}mlb_1"
        else:
            return f"{self.player_team.lower()}mlb_{self.vs_team.lower()}mlb_1"
Пример #2
0
 def process(self):
     path, options = self.getOptions()
     parser = CSVParser(path, self.parent().PROJECT['STRUCTURE'])
     self.progressBar.setMaximum(parser.csv_row_count -
                                 options['have_header'])
     counter = 0
     for row in parser.parse_all(**options):
         if counter % 100 == 0:
             self.parent().DB.set_values(row, commit=True)
         else:
             self.parent().DB.set_values(row, commit=False)
         counter += 1
         self.progressBar.setValue(counter)
     self.parent().DB.hard_commit()
     self.accept()
Пример #3
0
def main(argv):
    user_arguments = {}
    try:
        opts, args = getopt.getopt(argv, "i:u:p:o:f:", [
            "in=", "user="******"password="******"log-path=", "log", "log-all",
            "log-device", "out=", "out-all", "out-device", "out-format="
        ])
    except getopt.GetoptError:
        #usage()
        sys.exit(2)
    for opt, args in opts:
        print "opt: " + opt
        print "args: " + args
        if opt in ("-h", "--help"):
            #usage()
            sys.exit()
        elif opt in ("-i", "--in"):
            user_arguments["CSV File Path"] = args
        elif opt in ("-u", "--user"):
            user_arguments["Username"] = args
        elif opt in ("-p", "--password"):
            user_arguments["Password"] = args
        elif opt in ("-o", "--out"):
            user_arguments["Output Path"] = args
        elif opt == "--log-path":
            user_arguments["Log Path"] = args
        elif opt == "--log":
            user_arguments["Log"] = "Log"
        elif opt == "--log-device":
            user_arguments["Log"] = "Log Device"
        elif opt == "--log-all":
            user_arguments["Log"] = "Log All"
        elif opt == "--out-all":
            user_arguments["Output"] = "Output All"
        elif opt == "--out-device":
            user_arguments["Output"] = "Output Device"
        elif opt == "--out-format":
            user_arguments["Format"] = args
        else:
            print "Invalid Command"
            #usage()
    csv_parser = CSVParser()
    connection_data = csv_parser.parse(user_arguments)
    network = L1NetworkFlow()
    network.get_network_flow(connection_data)
Пример #4
0
def main(argv):
	user_arguments = {}
	try:
		opts, args = getopt.getopt(argv, "i:u:p:o:f:", ["in=", "user="******"password="******"log-path=","log","log-all","log-device","out=","out-all","out-device","out-format="])
	except getopt.GetoptError:
		#usage()
		sys.exit(2)
	for opt,args in opts:
		print "opt: "+ opt
		print "args: "+args
		if opt in ("-h", "--help"):
			#usage()
			sys.exit()
		elif opt in ("-i","--in"):
			user_arguments["CSV File Path"] = args
		elif opt in ("-u","--user"):
			user_arguments["Username"] = args
		elif opt in ("-p","--password"):
			user_arguments["Password"] = args
		elif opt in ("-o","--out"):
			user_arguments["Output Path"] = args
		elif opt == "--log-path":
			user_arguments["Log Path"] = args
		elif opt == "--log":
			user_arguments["Log"] = "Log"
		elif opt == "--log-device":
			user_arguments["Log"] = "Log Device"
		elif opt == "--log-all":
			user_arguments["Log"] = "Log All"
		elif opt == "--out-all":
			user_arguments["Output"] = "Output All"
		elif opt == "--out-device":
			user_arguments["Output"] = "Output Device"
		elif opt == "--out-format":
			user_arguments["Format"] = args
		else:
			print "Invalid Command"
			#usage()
	csv_parser = CSVParser()
	connection_data = csv_parser.parse(user_arguments)
	network = L1NetworkFlow()
	network.get_network_flow(connection_data)
Пример #5
0
def main():
    runs = 10
    rounds = 5
    chromosome_size = 23
    population_size = 1000
    data_set_name = 'bigfaultmatrix.txt'

    pwd = os.path.abspath(os.path.dirname(__file__))
    data_set_path = os.path.join(pwd, data_set_name)
    parser = CSVParser(data_set_path)
    test_case_fault_matrix = parser.parse_data(True)

    ga = GeneticAlgorithm(test_case_fault_matrix, chromosome_size,
                          population_size, rounds, 0.8, 0.08, 0.05, 0.75)
    ga.set_show_each_chromosome(False)
    ga.set_show_fitness_internals(False)
    ga.set_show_crossover_internals(False)
    ga.set_show_mutation_internals(False)
    ga.set_show_duplicate_internals(False)
    ga.set_silent(True)
    ga.run(runs)
    ga_fitness = ga.get_stats()

    for i in range(0, 2):
        if i == 0:
            hc = HillClimbing(test_case_fault_matrix, chromosome_size,
                              population_size, rounds, False)
        else:
            hc = HillClimbing(test_case_fault_matrix, chromosome_size,
                              population_size, rounds, True)
        hc.set_show_each_solution(False)
        hc.set_show_fitness_internals(False)
        hc.set_show_swapping_internals(False)
        hc.set_silent(True)
        hc.run(runs)
        if i == 0:
            hc_internal_fitness = hc.get_stats()
        else:
            hc_external_fitness = hc.get_stats()

    rs = RandomSearch(test_case_fault_matrix, chromosome_size, population_size,
                      rounds)
    rs.set_show_each_solution(False)
    rs.set_silent(True)
    rs.run(runs)
    rs_fitness = rs.get_stats()

    rs_data = np.array(rs_fitness)
    hs_internal = np.array(hc_internal_fitness)
    hs_external = np.array(hc_external_fitness)
    ga_data = np.array(ga_fitness)

    # test_cases_per_test_suite = np.array([5, 10, 20, 23, 30, 50, 100])
    # unique_large_apfd = np.array([0.4594736842105263, 0.6063157894736844, 0.6867105263157895, 0.6978260869565216, 0.7128947368421051, 0.7326842105263159, 0.7480263157894737])
    # full_large_apfd = np.array([0.44631578947368417, 0.6023684210526316, 0.6846052631578947, 0.6958810068649884, 0.7122807017543858, 0.7320526315789474, 0.7476578947368421])

    # plt.plot(test_cases_per_test_suite, unique_large_apfd, '-gD')
    # plt.xlabel("Test Cases per Test Suite")
    # plt.ylabel("Mean Fitness (APFD)")
    # plt.xticks(np.arange(min(test_cases_per_test_suite), max(test_cases_per_test_suite) + 1, 5.0))

    # combine these different collections into a list
    data_to_plot = [rs_data, hs_internal, hs_external, ga_data]

    # Create a figure instance
    fig = plt.figure(1, figsize=(9, 6))

    # Create an axes instance
    ax = fig.add_subplot(111)

    # add patch_artist=True option to ax.boxplot()
    bp = ax.boxplot(data_to_plot, patch_artist=True)

    # change outline color, fill color and linewidth of the boxes
    for box in bp['boxes']:
        # change outline color
        box.set(color='#7570b3', linewidth=2)
        # change fill color
        box.set(facecolor='#1b9e77')

    # change color and linewidth of the whiskers
    for whisker in bp['whiskers']:
        whisker.set(color='#7570b3', linewidth=2)

    # change color and linewidth of the caps
    for cap in bp['caps']:
        cap.set(color='#7570b3', linewidth=2)

    # change color and linewidth of the medians
    for median in bp['medians']:
        median.set(color='#b2df8a', linewidth=2)

    # change the style of fliers and their fill
    for flier in bp['fliers']:
        flier.set(marker='o', color='#e7298a', alpha=0.5)

    # Custom x-axis labels
    ax.set_xticklabels([
        'Random Search', 'HC Internal Swap', 'HC External Swap',
        'Genetic Algorithm'
    ])

    # Remove top axes and right axes ticks
    ax.get_xaxis().tick_bottom()
    ax.get_yaxis().tick_left()

    # Save the figure
    graph_path = os.path.join(pwd, 'graph.pdf')
    pdf = PdfPages(graph_path)
    plt.savefig(pdf, format='pdf', bbox_inches='tight')
    plt.show()
    pdf.close()
Пример #6
0
from flask import render_template, Blueprint, jsonify, make_response, send_from_directory
import logging
import sys
import os

sys.path.insert(0, './templates/main/python/')

import previous_starts as ps
import pitch_data as pd
from csv_parser import CSVParser
from pitch_data import PitchData

main_blueprint = Blueprint('main', __name__)
fileName = './templates/main/python/data/master.csv'
playerParser = CSVParser(fileName)
player_dict = playerParser.csv_to_playerDict()


@main_blueprint.route('/starts/<pid>', methods=["GET"])
def get_starts(pid):
    starts = ps.PrevStarts(pid)
    data = starts.get_previous_starts()
    return data


@main_blueprint.route('/graphs/<pid>/<date>/<player_team>/<opp_team>',
                      methods=['GET'])
def get_data(pid, date, player_team, opp_team):
    mlb_id = player_dict[pid][0]
    pitch_data = PitchData(mlb_id, date, player_team, opp_team)
    return pitch_data.get_pitch_data()
Пример #7
0
def get_ballots_and_names_from(
        file_name: str) -> Tuple[List[Ballot], List[str]]:
    parser = CSVParser(file_name)
    return (parser.ballots, parser.candidate_names)
Пример #8
0
def main():
    if len(sys.argv) == 1:
        usage()

    league = sys.argv[1].lower()
    ## TODO: Simple check to make sure the league is NCAA or NFL. This should
    #        be checked against a set of leagues that we are interested in.
    #        Update config.py to create the URLs for other leagues correctly.
    if league != 'ncaa' and league != 'nfl':
        usage()

    ## TODO: Make the --use-previous-files flag functional. Currently, the program
    #        will assume that a file exists with the twitter handles from a
    #        previous run and check the file to make sure it doesn't have to re-find
    #        a Twitter handle for a certain player. If the flag is not present
    #        in the command arguments, then the file should not be checked.
    parser = CSVParser(league, config)

    # Create a twapi instance that is tied to the developer account.
    api = twitter.Twitter(
        auth=twitter.OAuth(config['access_key'], config['access_secret'],
                           config['consumer_key'], config['consumer_secret']))
    twauth = tweepy.OAuthHandler(config['consumer_key'],
                                 config['consumer_secret'])
    twauth.set_access_token(config['access_key'], config['access_secret'])
    twapi = tweepy.API(twauth)

    # For each team in the given league, find the Twitter handle of each team
    # member.
    for team in config[league + '_team_codes']:
        res = team.split(':')
        team_code = res[0]
        team_name = res[1]
        print 'Starting %s' % team_name.strip()
        player_list = None
        if len(res) > 2:
            list_owner = res[2]
            list_name = res[3]
            player_list = {}
            for member in tweepy.Cursor(twapi.list_members, list_owner,
                                        list_name).items():
                user_dict = member.__dict__
                player_list[user_dict['screen_name']] = user_dict['id_str']
                player_list[user_dict['name']] = (user_dict['screen_name'],
                                                  user_dict['id_str'])

        # Write the twitter handles of the team to the output csv file.
        # The handle might be taken from the previous output file if it is present.
        write_team_csv(api,
                       team_code.strip(),
                       team_name.strip(),
                       league,
                       player_list,
                       parsed=parser)
        print 'Finished %s' % team_name.strip()

    # Go through the csv file, manually prompt the user to look at the handles
    # that were rated as low confidence (i.e. not sure if the handle is correct).
    ## TODO: Might want to make this optional, this part can take a while as you
    #        must manually interact with the program.
    clean_up_file(league, config, twapi)

    # Combine all of the team csv output files into a single league file.
    combine(league)
    os.system('cut -d, -f2 --complement output_%s.csv > %s.csv' %
              (league, league))
    os.system('rm output_%s.csv' % league)
    print 'See output in %s' % (league + '.csv')
Пример #9
0
 def __init__(self):
     self.csv_parser = CSVParser()
     self.csc = CurrencyStringConverter()
Пример #10
0
class CurrencyConvert(object):
    def __init__(self):
        self.csv_parser = CSVParser()
        self.csc = CurrencyStringConverter()

    def usage(self, prog):
        print("""
                    usage: {} <--field N> [--multiplier N] [-i input] [-o output]
                    """.format(prog)
              )

    def convert(self):
        """
        """
        # ************************* 解析命令行 ************************************
        order = {
            "field": "",
            "multiplier": "",
            "input": "",
            "output": ""
        }

        opts, args = getopt.getopt(sys.argv[3:], 'i:o:',
                                   [
                                       'field=',
                                       'multiplier=',
                                       'help'
                                   ]
                                   )

        # opts为分析出的格式信息,是一个两元组的列表。每个元素为:(选项串,附加参数)。如果没有附加参数则为空串''。
        for option, value in opts:
            if option in ["--help"]:
                self.usage(sys.argv[2])
                # 执行return后,不再执行余下所有其他语句
                return
            elif option in ["-i"]:
                order["input"] = value
            elif option in ["-o"]:
                order["output"] = value
            elif option in ["--field"]:
                order["field"] = value
            elif option in ["--multiplier"]:
                order["multiplier"] = value

        # args为不属于格式信息的剩余的命令行参数。包括那些没有"-"或"--"的参数
        # 当命令行中使用"<"和">"作为输入和输出文件的标志时
        for i in range(len(args)):
            if args[i] == "<":
                order["input"] = args[i + 1]
            elif args[i] == ">":
                order["output"] = args[i + 1]

        # print(order)
        # ************************* 解析命令行 ************************************
        # ************************* 业务流程  *************************************
        if ".csv" in order["input"]:
            # 从文件中读取
            contents_list = self.csv_parser.file_read(order["input"])
            # prices = self.csv_parser.prices_read(contents_list)
        else:
            # 从命令行直接输入
            # print(order["input"])
            #**************************处理数据本身带有逗号的情形,欧元***********************
            contents_split = order["input"].split(",")
            print(contents_split)
            contents = []
            i = 0
            while i in range(len(contents_split)):
                if "'" in contents_split[i] and "'" in contents_split[i + 1]:
                    # 如果相邻两个字符串含有"''",则将两个数据合并
                    contents_split[i] = contents_split[i] + "," + contents_split[i + 1]
                    contents.append(contents_split[i])
                    i = i + 2
                else:
                    contents.append(contents_split[i])
                    i = i + 1
            print(contents)
            contents_list = [contents]
            print("contents_list = {}".format(contents_list))
            # prices = ["Price Per Month"]
            # prices.append(self.csv_parser.prices_read(contents_list)[0])
            # print(prices)
        # ************************************************************************************
        prices = self.csv_parser.prices_read(contents_list)
        print("prices = {}".format(prices))

        # 美元换欧元
        new_prices = self.csc.dollar_to_euro(prices, float(order["multiplier"]))
        print(new_prices)

        # # 欧元换美元
        # new_prices = self.csc.euro_to_dollar(prices, float(order["multiplier"]))
        # print(new_prices)

        new_contents = self.csv_parser.contents_update(new_prices, contents_list)

        if len(order["output"]) != 0:
            # 指定输出文件,则写入输出文件中
            self.csv_parser.file_write(order["output"], new_contents)
        else:
            # 未指定输出文件, 输出new_contents,与文件显示样式相同
            content = ""
            for i in range(len(new_contents)):
                # row = new_contents[i]
                for j in range(len(new_contents[i])):
                    # 判断是否为最后一个元素
                    # 如果是最后一个元素,不再添加","
                    if j == len(new_contents[i]) - 1:
                        # 行中的某个元素,string = new_contents[i][j]
                        content += new_contents[i][j]
                    else:
                        # 不是最后一个元素,每次添加元素之后,要添加csv文件的分隔符","
                        content += new_contents[i][j] + ","
            print(content)