Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """"
- Qualifiers_2.py
- """
- from Qualifier_classes import Qualifier
- file_path = 'C:\\Users\\Neo\\My Documents\\Python Scripts\\FTC Scouting\\sample.txt'
- file = open(file_path, 'r')
- Data = []
- all_teams = []
- Teams_list = []
- keys = ['Team Number: ', 'Name: ','Qualifier: ']
- qualifier_keys = ['Qualifier: ', 'QP: ', 'RP: ', 'HS: ', 'Matches: ']
- team_attr = ['name','number']
- UI_options = [1,2]
- class Team:
- def __init__(self,name,number):
- self.name = name
- self.number = number
- def __repr__(self):
- return repr((self.name,self.number))
- def list_teams(n):
- tTeams = []
- for line in Data:
- check = line.find(keys[n])
- if not check == -1:
- team = line.partition(keys[n])[2]
- if team not in tTeams:
- tTeams.append(team)
- return tTeams
- #@param: team_number , team to find
- #@output: gives back line number in raw Data list
- def find_start_team(team_number):
- tcount = 0
- if str(team_number) in list_teams(0):
- for line in Data:
- if not line.find(str(team_number)) == -1:
- return tcount
- else:
- tcount += 1
- else:
- return 'not a valid team number'
- #@param: Start_team_number , the previous team next number
- #@output: the line number for the start and end of the team's acquired info
- def find_team(start_team_number):
- try:
- start_search = find_start_team(start_team_number)
- tcount = start_search
- for line in Data[start_search+1:]:
- if not line.find(keys[0]) == -1:
- return start_search, tcount
- else:
- tcount += 1
- except ValueError:
- return 'not a team number'
- def team_data(start,stop):
- temp_data = []
- for line in Data[start:stop]:
- temp_data.append(line)
- return temp_data
- #@param: qualifier_key , the name of the category you wish to find
- #@param: data , the qualifier info for some team
- #@output: returns back the data for the category
- def get_data(qualifier_key, data):
- for line in data:
- if not line.find(qualifier_key) == -1:
- return line.partition(qualifier_key)[2]
- #@param: data , the qualifier data for some team
- #@output: remaining_data , the remaining data after the first qualifier
- # note: will return -1 if there is no more qualifiers
- def just_qualifiers(data):
- tcount = 0
- for line in data:
- if not line.find(qualifier_keys[0]) == -1:
- return data[tcount:]
- tcount += 1
- return -1
- #@param: data , array of values for a single qualifier
- def update_qualifier(data):
- tqual = Qualifier()
- tqual.name = data[0]
- tqual.rp = data[1]
- tqual.hs = data[2]
- tqual.num_of_matches = tdata[3]
- return tqual
- #@param: data , the block of data for the team
- #@output: the qualifier data and remainind data
- def get_qualifier(data):
- temp_data = []
- for key in range(len(qualifier_keys)):
- temp_data.append(get_data(qualifier_keys[key],data))
- temp_qual = update_qualifier(temp_data)
- data = data[len(temp_data):]
- return temp_qual, data
- #Turns our txt file into usable data
- for line in file:
- line = line[:-1]
- Data.append(line)
- #Creates a tuple for holding the ID of all the teams
- all_teams.append(list_teams(0))
- all_teams.append(list_teams(1))
- #Makes an organized list of the ID for all the teams in a 2-tuple
- for team in range(len(list_teams(0))):
- Teams_list.append(Team(all_teams[1][team],int(all_teams[0][team])))
- """*******************
- NEW CODE
- *******************"""
- for team in range(len(all_teams[0])):
- start , stop = find_team((all_teams[0][team]))
- tdata = []
- tqual = []
- Qualifiers = []
- #maps the specific teams block of data to tdata
- for line in team_data(start, stop):
- tdata.append(line)
- tdata = just_qualifiers(tdata)
- print all_teams[0][team]
- print tdata
- while True:
- if not just_qualifiers(tdata) == -1:
- tqual , tdata = get_qualifier(tdata)
- Qualifiers.append(tqual)
- else:
- break
- # print Qualifiers
- # print 'team number\t' + all_teams[0][team]
- """*******************
- END NEW CODE
- *******************"""
- file.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement