Untitled
Dance script 2022unknown
python
4 years ago
2.6 kB
5
Indexable
import csv import sys dance_names = ["Bhangra", "Bollywood Fusion", "Hip Hop", "Jazz Funk", "Latin", "Latin Salsa", "Sassy Jazz", "Street", "Sultry Jazz", "Swag Hip Hop", "Zumba Step"] dance_count = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0] # dances that clash: Latin (1) and Swag Hip Hop (0), Zumba Step(3) and Jazz Funk (2) unassigned_dances = 0 offsets = [] data = [] output = [] clashes = [] with open('2022.csv') as csv_file: csv_reader = csv.reader(csv_file, delimiter=',') line_count = 0 for row in csv_reader: row = row[:14] # print(row) if line_count < 3: line_count += 1 continue if line_count == 3: # print(f'Column names are {", ".join(row)}') line_count += 1 else: data.append(row) output.append(row[0]) dance_rankings = row[3:14] highest_rating = min(i for i in dance_rankings if int(i) > 0) offsets.append(int(highest_rating)) line_count += 1 clashes.append([]) unassigned_dances += int(row[1]) index = 0 def isClashing(top, index): if ((top == 1 and 0 in clashes[index]) or (top == 0 and 1 in clashes[index]) or (top == 2 and 3 in clashes[index]) or (top == 3 and 2 in clashes[index])): # print("Clashing!!!", data[index]) return True return False while unassigned_dances > 0: index = 0 for row in data: # try: no_of_dances = int(row[1]) if no_of_dances == 0 : index += 1 continue dance_rankings = row[3:] offset = offsets[index] if str(offset) not in dance_rankings: # print("Bypassing...", row[0]) unassigned_dances -= no_of_dances index += 1 continue top = dance_rankings.index(str(offset)) # print(row[0]) # print(dance_rankings) # print(offset) # print(top) skip = False while ( dance_count[top] > 31 or isClashing(top, index)): offset += 1 if str(offset) not in dance_rankings: # print("Bypassing...", row[0]) unassigned_dances -= no_of_dances skip = True break top = dance_rankings.index(str(offset)) if skip: # print("Bypassing...", row[0]) unassigned_dances -= no_of_dances index += 1 continue dance_count[top] += 1 row[1] = no_of_dances - 1 output[index] = output[index] + ", " + dance_names[top] clashes[index].append(top) offsets[index] = offset + 1 index += 1 unassigned_dances -= 1 # except: # print("Exception:", row[0], dance_rankings, sys.exc_info()[0]) for row in output: print(row)
Editor is loading...