Brackets

Check-in [61d471ded0]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:rewrite2
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | trunk
Files: files | file ages | folders
SHA3-256:61d471ded07e78f99450f4c6dde41e051740dbe2b62f5ba85eb9b24042e5441c
User & Date: scott 2018-03-22 17:14:51
Context
2018-03-22
17:14
rewrite2 Leaf check-in: 61d471ded0 user: scott tags: trunk
06:23
starting next section check-in: ebb1395d47 user: scott tags: trunk
Changes
Hide Diffs Unified Diffs Show Whitespace Changes Patch

Added Bracket-template-sample-output.ods.

cannot compute difference between binary files

Added V2-bracketbuilder.py.



























































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
''' 
Cleanup of old bracket builder with a division map built up front
Developed by Scott Sawyer for the USASA to do BX/SX brackets
'''

import sys, itertools, collections, csv

def csv_import(csv_fname):
    '''
    This function takes in the competitors list and then cleans it up.  
    This means shortening all of the names in such a way as to be recognizable but not break anything
    Especially the greater than 31 characters for tab names and the & sign for breaking in weird places
    * Snowboard is shortened to SB
    * Intellectually Disabled is shortened to I D
    * Freeski is shortened to FS
    * & is changed to and
    '''
    #define lists, tuples, etc. for the function 
    athlete_feed_data_csv = []
    athleteCleanDivNames = []
    with open(csv_fname, 'r') as f:
        csv_input = csv.reader(f, dialect='excel', delimiter=",")
        athlete_feed_data_csv = tuple(csv_input)
    for divchange in athlete_feed_data_csv:
        newdiv = divchange[0]
        newdiv = newdiv.split(" ")
        if '&' in newdiv:
            newdiv[newdiv.index('&')] = 'and'
        if 'Intellectually' in newdiv:
            newdiv[newdiv.index('Intellectually')] = 'I'
            newdiv[newdiv.index('Disabled')] = 'D'
        else:
            pass
        if 'Snowboard' in newdiv:
            newdiv[newdiv.index('Snowboard')] = 'SB'
        if 'Freeski' in newdiv:
            newdiv[newdiv.index('Freeski')] = 'FS'
        newdiv = " ".join(newdiv)
        divchange = [newdiv] + divchange[1:]
        athleteCleanDivNames.append(divchange)
    return athleteCleanDivNames

def athleteCount(athleteCleanDivNames):
    '''
    This function gets a list of how many athletes are in each division and outputs number of competitors and 
    the number of waves for that number of competitors
    '''
    athleteCountByDivision = []
    counter = collections.Counter(itertools.chain(*athleteCleanDivNames))
    for div_name in athleteCleanDivNames:
        div_only = div_name[0]
        c = counter[div_only]
        x = [div_only, c]
        if x not in athleteCountByDivision:
            athleteCountByDivision.append(x)
    return athleteCountByDivision

def data_injection(doc, SheetName, startRow, StartColumn, injectData):
    rowStop = len(injectData) + startRow
    columnStop = len(injectData[0]) + StartColumn
    tsheet = doc.sheets[SheetName]
    tsheet[startRow:rowStop, StartColumn:columnStop].values = injectData
    return 0

def bracketSheetCreation(doc, sheetlist):
    import pyoo
    get_sheet_name = pyoo.NameGenerator()
    for div_name in sheetlist:
        sheet_name = div_name[0]
        I_sheet_name = 'I-' + sheet_name
        doc.sheets.copy('SeedTemplate', get_sheet_name(I_sheet_name))
        doc.sheets.copy('Bracket-Template', get_sheet_name(sheet_name))
    return 0

def sheet_build(athleteCleanDivNames, athleteCountByDivision):
    '''
    This function controlls all of the interactions with libreoffice by roughly doing the following
        First it opens up the document and creates the connection
        it will inject the bulk data
        Then it will create all of the sheets
        then it will feed the seed sheets (prefaced with an I-)
        Then it will build the heat layouts
    '''
    import pyoo
    desktop = pyoo.Desktop('localhost', 2002)
    doc = desktop.open_spreadsheet('F:\Python-Dev\Brackets-Nationals\Bracket-template.ods')
    #create division list
    divisions = []
    for div_name in athleteCountByDivision:
        divisions.append(div_name[0])
    #Inject Data
    data_injection(doc, 'DivCounts', 1, 0, athleteCountByDivision)
    data_injection(doc, 'Full Rider List', 3, 0, athleteCleanDivNames)
    #Create Sheets
    bracketSheetCreation(doc, athleteCleanDivNames)

def main(args):
    #the main program that makes everything work
    #feed in filename of csv file in base path
    csv_fname = input("Enter the name of the CSV File: ")
    if csv_fname == "":
        csv_fname = 'F:\Python-Dev\Brackets-Nationals\sample1-bxlist.csv'
    athleteCleanDivNames = csv_import(csv_fname)
    athleteCountByDivision = athleteCount(athleteCleanDivNames)
    docbuild = sheet_build(athleteCleanDivNames, athleteCountByDivision)
    return 0 
    
if __name__ == '__main__':
    sys.exit(main(sys.argv))

Added pylaunch.bat.



>
1
F:\Program-Files\LibreOffice\program\python F:\Python-Dev\Brackets-Nationals\$1