Thank you very much
The script is completed.
My BTC Address is 12tSquEBTgs2WsHXgh5kKD8hNwvsrvo7o1
Running the code on the sample produces
./parse_file.py Workbook1.xlsx
--------------------------------------------------------------------------
Loading XLS File: Workbook1.xlsx
--------------------------------------------------------------------------
Question 1:
0
--------------------------------------------------------------------------
Ignoring Cells:
--------------------------------------------------------------------------
Reading Team 1 Stats: Rows 1, 11
--------------------------------------------------------------------------
Column A1. Key: Por. Incrementing Counter and adding value: 6.0
Column A2. Key: DsCs. Incrementing Counter and adding value: 5.5
Column A3. Key: Dc. Incrementing Counter and adding value: 5.0
Column A4. Key: Dc. Incrementing Counter and adding value: 6.0
Column A5. Key: DdDsCdCs. Incrementing Counter and adding value: 6.0
Column A7. Key: Mcc. Incrementing Counter and adding value: 6.0
--------------------------------------------------------------------------
Reading Team 2 Stats: Rows 13 - 23
--------------------------------------------------------------------------
Column A13. Key: Por. Incrementing Counter and adding value: 6.0
Column A14. Key: DsDcCs. Incrementing Counter and adding value: 6.0
Column A15. Key: Dc. Incrementing Counter and adding value: 6.0
Column A16. Key: Dc. Incrementing Counter and adding value: 5.0
Column A17. Key: DdDsCdCs. Incrementing Counter and adding value: 5.5
Column A19. Key: Mcc. Incrementing Counter and adding value: 5.0
Column A20. Key: Mcc. Incrementing Counter and adding value: 6.5
Difference is Negative, Adding 5 * 1 to Team 0
--------------------------------------------------------------------------
Team One Total: 39.5
Team Two Total: 40.0
Team Difference: -0.5
--------------------------------------------------------------------------
The code is as follows
#!/usr/bin/env python
import xlrd
import sys
if len(sys.argv) < 0:
print("XLS File Not Specified")
sys.exit(-1)
file = sys.argv[1]
print("--------------------------------------------------------------------------")
print("Loading XLS File: {0}".format(file))
print("--------------------------------------------------------------------------")
stats = {0: {'Count': 0, 'Total': 0}, 1: {'Count': 0, 'Total': 0}}
required_values = ['por', 'ds', 'dc', 'dd', 'mcc', 'dscs', 'ddcd', 'ddcddscs', 'dsdc', 'dddc', 'dsdddc', 'dddscdcs', 'dsdccs']
other_values = ['dc', 'ds', 'dd', 'cd', 'cs']
ignored_cells = []
def load_sheet(file, sheet):
workbook = xlrd.open_workbook(file)
worksheet = workbook.sheet_by_index(0)
return worksheet
def read_stats(start_row, end_row, stats={'Count': 0, 'Total': 0}):
for i in range(start_row, end_row):
if i in ignored_cells:
continue
value = sheet.cell(i, 0).value
if value.lower() in required_values or any(item in value.lower() for item in other_values):
amount = sheet.cell(i, 3).value
if type(amount) == unicode and amount.strip() == '-':
amount = float(0)
if type(amount) != float and not amount.isdigit():
amount = amount.replace(',', '.')
amount = float(amount)
stats['Count'] += 1
stats['Total'] += amount
print("Column A{0}. Key: {1}. Incrementing Counter and adding value: {2}".format(i+1, value, amount))
while True:
print("Question 1: ")
ignored_cell = raw_input()
if not ignored_cell.isdigit():
print("Value was not a number")
continue
ignored_cell = int(ignored_cell)
if ignored_cell == 0:
break
if ignored_cell > 23 or number < 0:
print("Number Out of Range")
continue
print("Ignoring Cell: {0}".format(ignored_cell))
ignored_cells.append(ignored_cell)
print("--------------------------------------------------------------------------")
print("Ignoring Cells: {0}".format(",".join((str(i) for i in ignored_cells))))
sheet = load_sheet(file, 0)
print("--------------------------------------------------------------------------")
print("Reading Team 1 Stats: Rows 1, 11")
print("--------------------------------------------------------------------------")
read_stats(0, 11, stats[0])
print("--------------------------------------------------------------------------")
print("Reading Team 2 Stats: Rows 13 - 23")
print("--------------------------------------------------------------------------")
read_stats(12, 23, stats[1])
difference = stats[0]['Count'] - stats[1]['Count']
if difference > 0:
stats[1]['Total'] += (5 * difference)
print("Difference is Negative, Adding 5 * {0} to Team 1".format(difference))
elif difference < 0:
stats[0]['Total'] += (5 * -difference)
print("Difference is Negative, Adding 5 * {0} to Team 0".format(-difference))
print("--------------------------------------------------------------------------")
print("Team One Total: {0}".format(stats[0]['Total']))
print("Team Two Total: {0}".format(stats[1]['Total']))
print("Team Difference: {0}".format(stats[0]['Total'] - stats[1]['Total']))
print("--------------------------------------------------------------------------")