Example #1
0
 def _ensure_headers_exist(self, sample_headers, row_offset=0):
     """Returns the index at which provided headers are found, otherwise
     an exception is raised.
     """
     index = XlSheet.find_headers(self.ws, sample_headers, row_offset)
     if index == -1:
         raise Exception("Headers not found: %s" % sample_headers)
     return index
Example #2
0
 def _ensure_headers_exist(self, sample_headers, row_offset=0):
     """Returns the index at which provided headers are found, otherwise
     an exception is raised.
     """
     index = XlSheet.find_headers(self.ws, sample_headers, row_offset)
     if index == -1:
         raise Exception("Headers not found: %s" % sample_headers)
     return index
Example #3
0
def reorder_distss(db, wb):
    assets = {}
    
    # read in dist stations from excel
    ws = XlSheet(wb, 'DStations-11KV')
    reader = Reader(ws, DISTRIBUTION)
    for asset in reader.get_assets():
        sf = asset['source_feeder']
        if sf not in assets:
            assets[sf] = []
        assets[sf].append(asset)
        
    # read in feeders order
    ws2 = XlSheet(wb, 'Sheet1')
    hdrs = ['is.code', 'is.name', 'fdr.name', 'fdr.code']
    if not XlSheet.find_headers(ws2, hdrs, 0):
        raise Exception('Headers not found: %s' % hdrs)
    
    # iterate rows and extract asset in nested-for
    not_found, counter = [], 0
    filename = os.path.join(DATA_DIR, 'dist-ss.txt')
    with open(filename, 'w') as f:
        for fname in [(r[2] or '').strip() for r in ws2]:
            if fname not in assets:
                not_found.append(fname)
                continue
            
            feeders = assets[fname]
            feeder = feeders[0]
            counter += 1
            f.write('{},11,{},{},{}\n'.format(
                counter,
                feeder.source_feeder,
                feeder.name,
                feeder.transformers[0].capacity
            ))
            
            for feeder in feeders[1:]:
                f.write(',,,{},{}\n'.format(
                    feeder.name,
                    feeder.transformers[0].capacity
                ))
        f.flush()
Example #4
0
def reorder_distss(db, wb):
    assets = {}

    # read in dist stations from excel
    ws = XlSheet(wb, 'DStations-11KV')
    reader = Reader(ws, DISTRIBUTION)
    for asset in reader.get_assets():
        sf = asset['source_feeder']
        if sf not in assets:
            assets[sf] = []
        assets[sf].append(asset)

    # read in feeders order
    ws2 = XlSheet(wb, 'Sheet1')
    hdrs = ['is.code', 'is.name', 'fdr.name', 'fdr.code']
    if not XlSheet.find_headers(ws2, hdrs, 0):
        raise Exception('Headers not found: %s' % hdrs)

    # iterate rows and extract asset in nested-for
    not_found, counter = [], 0
    filename = os.path.join(DATA_DIR, 'dist-ss.txt')
    with open(filename, 'w') as f:
        for fname in [(r[2] or '').strip() for r in ws2]:
            if fname not in assets:
                not_found.append(fname)
                continue

            feeders = assets[fname]
            feeder = feeders[0]
            counter += 1
            f.write('{},11,{},{},{}\n'.format(counter, feeder.source_feeder,
                                              feeder.name,
                                              feeder.transformers[0].capacity))

            for feeder in feeders[1:]:
                f.write(',,,{},{}\n'.format(feeder.name,
                                            feeder.transformers[0].capacity))
        f.flush()