Brackets

Check-in [69a933c607]
Login

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

Overview
Comment:made it work
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256:69a933c6079004a670dda57e1900d1de0f4c621235d307d46e37612beb0f5609
User & Date: scott 2018-03-22 01:15:18
Context
2018-03-22
03:12
add div name to div sheets check-in: 461ec95f53 user: scott tags: trunk
01:15
made it work check-in: 69a933c607 user: scott tags: trunk
2018-03-21
16:24
working code check-in: 5ffa5ced86 user: scott tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to Bracket-Builder.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
110
111
112
'''
Created on Oct 20, 2017

@author: Scott
'''
### Functions

import sys
#import dataset
#import time



def nested_count(lst, x):
    return lst.count(x) + sum(nested_count(l,x) for l in lst if isinstance(l,list))


def csv_import(csv_fname):
    # This function will import the data from the CSV file and return it as a global variable as well as other instantiations
    import csv    
    divisions = []
    div_count = []

# This section reads in a CSV file
    with open(csv_fname, 'r') as f:
        csv_input = csv.reader(f, dialect='excel', delimiter=",")
        csv_data = tuple(csv_input)
    # this section sets all of the divisions into a tuple  
    for aclass in csv_data:
            t = aclass[0] 
            if t not in divisions:
                divisions.append(t)
    divisions = tuple(divisions)
    # Identify Divisions and Athlete Count
    for div_num in divisions:
        x = csv_data.count(div_num)
        n = div_num, x
        div_count.append(n)
    div_count = tuple(div_count)
    print("div count", div_count)
    '''
    # This section counts how many are in each division
    for div_num in divisions:
            # below is division, number of athletes per division, Remainder, and # of heats required to get all athletes into a heat
            x = div_num.split("_")
            x = x[0]
            y = nested_count(csv_data, x)
            n = div_num, y, y % 4, y//4 
            div_count.append(n)
    div_count = tuple(div_count)
    print("div_count: ", div_count)
    '''
    return csv_data, divisions, div_count



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'
    csv_data, divisions, div_count = csv_import(csv_fname)
    doc = sheet_build(csv_data, divisions, div_count)

    return 0 

def sheet_build(csv_data, divisions, div_count):
    import pyoo
    # Stuff around opening up a sheet and feeding in data
    desktop = pyoo.Desktop('localhost', 2002)
    doc = desktop.open_spreadsheet('F:\Python-Dev\Brackets-Nationals\Bracket-template.ods')
    #doc = desktop.create_spreadsheet()

    # Create all of the worksheets and populate with basic information
    get_sheet_name = pyoo.NameGenerator()

    for dname in divisions:
        doc.sheets.copy('Bracket-Template', get_sheet_name(dname))
        # libreoffice tab length is 31 characters, this will correct this but still put in full name
        sheetNames = []
        if len(dname) > 31:
            dshort = dname[:31]
            tlist = doc.sheets[dshort]
            tlist[0,1].value = dname
            #Collect the sheet names for returning to later !!! broken
            sheetNames.append(dshort)
        else:
            tlist = doc.sheets[dname]
            tlist[0,1].value = dname
            # collect the sheet names for returning to later !!! broken
            sheetNames.append(dname)

    '''  Broken above, not getting the counts in the nested list
    # Enter all of the divisions with # of athletes into the DivCounts Sheet
    DivCountsSheet = doc.sheets['DivCounts']
    rstart = 1
    cstart = 0
    rstop = len(div_count)
    cstop = len(div_count[0])
    DivCountsSheet[rstart:rstop, cstart,cstop].values = div_count
    '''

    alist = doc.sheets[1]
    # Feed the athlete list
    # Geometry set for putting data in the startlist (counting starts at 0; r is row and c is column)
    rstart = 3
    cstart = 0
    rstop = len(csv_data) + rstart
    cstop = len(csv_data[0]) + cstart
    alist[rstart:rstop, cstart:cstop].values = csv_data

    return doc

def wavecount():
    #This will identify how many waves for the # of athletes including how many LCQ spots
    pass


|
<
<


<
|
<
<

<
>


>



<

<
>
|


|

|



|

|
|
|
|
|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
>
>








|
|



|








>



<
<
|
<
<
<
|
<
<
<
<
<
>
|




|
|
|
<
|





|
|
|







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
'''
Created week of 3-17 by Scott Sawyer


'''
### Functions

import sys, itertools, collections, csv




'''
def nested_count(lst, x):
    return lst.count(x) + sum(nested_count(l,x) for l in lst if isinstance(l,list))
'''

def csv_import(csv_fname):
    # This function will import the data from the CSV file and return it as a global variable as well as other instantiations

    divisions = []

    athleteCountByDivision = []
    # This section reads in a CSV file
    with open(csv_fname, 'r') as f:
        csv_input = csv.reader(f, dialect='excel', delimiter=",")
        athlete_feed_data_csv = tuple(csv_input)
    # this section sets all of the divisions into a tuple  
    for aclass in athlete_feed_data_csv:
            t = aclass[0] 
            if t not in divisions:
                divisions.append(t)
#    divisions = tuple(divisions)
    # Identify Divisions and Athlete Count
    counter = collections.Counter(itertools.chain(*athlete_feed_data_csv))
    for div_name in divisions:
        c = counter[div_name]
        x = [div_name, c]
        athleteCountByDivision.append(x)















    return athlete_feed_data_csv, divisions, athleteCountByDivision

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'
    athlete_feed_data_csv, divisions, athleteCountByDivision = csv_import(csv_fname)
    docbuild = sheet_build(athlete_feed_data_csv, divisions, athleteCountByDivision)

    return 0 

def sheet_build(athlete_feed_data_csv, divisions, athleteCountByDivision):
    import pyoo
    # Stuff around opening up a sheet and feeding in data
    desktop = pyoo.Desktop('localhost', 2002)
    doc = desktop.open_spreadsheet('F:\Python-Dev\Brackets-Nationals\Bracket-template.ods')
    #doc = desktop.create_spreadsheet()

    # Create all of the worksheets and populate with basic information
    get_sheet_name = pyoo.NameGenerator()
    sheetNames = []
    for dname in divisions:
        doc.sheets.copy('Bracket-Template', get_sheet_name(dname))
        # libreoffice tab length is 31 characters, this will correct this but still put in full name


        t = dname[:31]



        sheetNames.append(t)






    #Broken above, not getting the counts in the nested list
    # Enter all of the divisions with # of athletes into the DivCounts Sheet
    DivCountsSheet = doc.sheets['DivCounts']
    rstart = 1
    cstart = 0
    rstop = len(athleteCountByDivision) + rstart
    cstop = len(athleteCountByDivision[0]) + cstart
    DivCountsSheet[rstart:rstop, cstart:cstop].values = athleteCountByDivision

    
    alist = doc.sheets[1]
    # Feed the athlete list
    # Geometry set for putting data in the startlist (counting starts at 0; r is row and c is column)
    rstart = 3
    cstart = 0
    rstop = len(athlete_feed_data_csv) + rstart
    cstop = len(athlete_feed_data_csv[0]) + cstart
    alist[rstart:rstop, cstart:cstop].values = athlete_feed_data_csv

    return doc

def wavecount():
    #This will identify how many waves for the # of athletes including how many LCQ spots
    pass

Changes to Bracket-template.ods.

cannot compute difference between binary files