Script with max for dances
You are cute <3unknown
python
3 years ago
2.7 kB
2
Indexable
Never
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,0,0] dance_count_max = [39,39,39,29,19,39,39,14,19,29,19] # dances that clash: Latin (4) and Swag Hip Hop (9); Zumba Step(10) and Jazz Funk (3); # and Bollywood Fusion (1) and Sultry Jazz (8) unassigned_dances = 0 offsets = [] data = [] output = [] clashes = [] with open('latest.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 == 4 and 9 in clashes[index]) or (top == 9 and 4 in clashes[index]) or (top == 10 and 3 in clashes[index]) or (top == 3 and 10 in clashes[index]) or (top == 1 and 8 in clashes[index]) or (top == 8 and 1 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: 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] > dance_count_max[top] 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)