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 Side-by-Side Diffs Ignore Whitespace Patch

Added Bracket-template-sample-output.ods.

cannot compute difference between binary files

Added V2-bracketbuilder.py.

            1  +''' 
            2  +Cleanup of old bracket builder with a division map built up front
            3  +Developed by Scott Sawyer for the USASA to do BX/SX brackets
            4  +'''
            5  +
            6  +import sys, itertools, collections, csv
            7  +
            8  +def csv_import(csv_fname):
            9  +    '''
           10  +    This function takes in the competitors list and then cleans it up.  
           11  +    This means shortening all of the names in such a way as to be recognizable but not break anything
           12  +    Especially the greater than 31 characters for tab names and the & sign for breaking in weird places
           13  +    * Snowboard is shortened to SB
           14  +    * Intellectually Disabled is shortened to I D
           15  +    * Freeski is shortened to FS
           16  +    * & is changed to and
           17  +    '''
           18  +    #define lists, tuples, etc. for the function 
           19  +    athlete_feed_data_csv = []
           20  +    athleteCleanDivNames = []
           21  +    with open(csv_fname, 'r') as f:
           22  +        csv_input = csv.reader(f, dialect='excel', delimiter=",")
           23  +        athlete_feed_data_csv = tuple(csv_input)
           24  +    for divchange in athlete_feed_data_csv:
           25  +        newdiv = divchange[0]
           26  +        newdiv = newdiv.split(" ")
           27  +        if '&' in newdiv:
           28  +            newdiv[newdiv.index('&')] = 'and'
           29  +        if 'Intellectually' in newdiv:
           30  +            newdiv[newdiv.index('Intellectually')] = 'I'
           31  +            newdiv[newdiv.index('Disabled')] = 'D'
           32  +        else:
           33  +            pass
           34  +        if 'Snowboard' in newdiv:
           35  +            newdiv[newdiv.index('Snowboard')] = 'SB'
           36  +        if 'Freeski' in newdiv:
           37  +            newdiv[newdiv.index('Freeski')] = 'FS'
           38  +        newdiv = " ".join(newdiv)
           39  +        divchange = [newdiv] + divchange[1:]
           40  +        athleteCleanDivNames.append(divchange)
           41  +    return athleteCleanDivNames
           42  +
           43  +def athleteCount(athleteCleanDivNames):
           44  +    '''
           45  +    This function gets a list of how many athletes are in each division and outputs number of competitors and 
           46  +    the number of waves for that number of competitors
           47  +    '''
           48  +    athleteCountByDivision = []
           49  +    counter = collections.Counter(itertools.chain(*athleteCleanDivNames))
           50  +    for div_name in athleteCleanDivNames:
           51  +        div_only = div_name[0]
           52  +        c = counter[div_only]
           53  +        x = [div_only, c]
           54  +        if x not in athleteCountByDivision:
           55  +            athleteCountByDivision.append(x)
           56  +    return athleteCountByDivision
           57  +
           58  +def data_injection(doc, SheetName, startRow, StartColumn, injectData):
           59  +    rowStop = len(injectData) + startRow
           60  +    columnStop = len(injectData[0]) + StartColumn
           61  +    tsheet = doc.sheets[SheetName]
           62  +    tsheet[startRow:rowStop, StartColumn:columnStop].values = injectData
           63  +    return 0
           64  +
           65  +def bracketSheetCreation(doc, sheetlist):
           66  +    import pyoo
           67  +    get_sheet_name = pyoo.NameGenerator()
           68  +    for div_name in sheetlist:
           69  +        sheet_name = div_name[0]
           70  +        I_sheet_name = 'I-' + sheet_name
           71  +        doc.sheets.copy('SeedTemplate', get_sheet_name(I_sheet_name))
           72  +        doc.sheets.copy('Bracket-Template', get_sheet_name(sheet_name))
           73  +    return 0
           74  +
           75  +def sheet_build(athleteCleanDivNames, athleteCountByDivision):
           76  +    '''
           77  +    This function controlls all of the interactions with libreoffice by roughly doing the following
           78  +        First it opens up the document and creates the connection
           79  +        it will inject the bulk data
           80  +        Then it will create all of the sheets
           81  +        then it will feed the seed sheets (prefaced with an I-)
           82  +        Then it will build the heat layouts
           83  +    '''
           84  +    import pyoo
           85  +    desktop = pyoo.Desktop('localhost', 2002)
           86  +    doc = desktop.open_spreadsheet('F:\Python-Dev\Brackets-Nationals\Bracket-template.ods')
           87  +    #create division list
           88  +    divisions = []
           89  +    for div_name in athleteCountByDivision:
           90  +        divisions.append(div_name[0])
           91  +    #Inject Data
           92  +    data_injection(doc, 'DivCounts', 1, 0, athleteCountByDivision)
           93  +    data_injection(doc, 'Full Rider List', 3, 0, athleteCleanDivNames)
           94  +    #Create Sheets
           95  +    bracketSheetCreation(doc, athleteCleanDivNames)
           96  +
           97  +def main(args):
           98  +    #the main program that makes everything work
           99  +    #feed in filename of csv file in base path
          100  +    csv_fname = input("Enter the name of the CSV File: ")
          101  +    if csv_fname == "":
          102  +        csv_fname = 'F:\Python-Dev\Brackets-Nationals\sample1-bxlist.csv'
          103  +    athleteCleanDivNames = csv_import(csv_fname)
          104  +    athleteCountByDivision = athleteCount(athleteCleanDivNames)
          105  +    docbuild = sheet_build(athleteCleanDivNames, athleteCountByDivision)
          106  +    return 0 
          107  +    
          108  +if __name__ == '__main__':
          109  +    sys.exit(main(sys.argv))

Added pylaunch.bat.

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