Exemplo n.º 1
0
    def _loadLV_network_stations(db, wb):
        # extra 11kV feeder list from db
        cursor = db.feeders\
                   .find({'voltage':11, 'name': {'$ne': ''}})\
                   .sort('name', pymongo.ASCENDING)

        feeders = {f['name']: f['code'] for f in cursor}

        # get dist. sub-stations from file
        assets, not_found, xlfeeders = [], [], set()
        ws = XlSheet(wb, 'DStations-11KV')
        reader = Reader(ws, DISTRIBUTION)
        for asset in reader.get_assets():
            assets.append(asset)

            # change feeder name to feeder code
            name = asset['source_feeder']
            xlfeeders.add(name)
            if name not in feeders:
                not_found.append(name)
            else:
                asset['source_feeder'] = feeders[name]

            # save to db
            db.stations.insert_one(asset)
        print('assets:: stations: %s' % len(assets))
Exemplo n.º 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
Exemplo n.º 3
0
 def _loadMV_network_stations_feeders(db, wb):
     args_list = ((TRANSMISSION, 'TStations+Fdrs'), (INJECTION,
                                                     'IStations+Fdrs'))
     for args in args_list:
         ws = XlSheet(wb, args[1])
         reader = Reader(ws, args[0])
         for asset in reader.get_assets():
             Loader._save_as_stations_feeders(db, asset)
Exemplo n.º 4
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
Exemplo n.º 5
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()
Exemplo n.º 6
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()