示例#1
0
    for i in range(0, len(stations)):
        s = stations[i]
        col = 1 + 5 * i
        print "    ", s

        # add headers
        ws.write(PERIOD_START - 1, col, "Installed Capacity")
        ws.write(PERIOD_START - 1, col + 1, "RO Certificates")
        ws.write(PERIOD_START - 1, col + 2, "RO Factor")
        ws.write(PERIOD_START - 1, col + 3, "REGO Certificates")
        ws.write(PERIOD_START - 1, col + 4, "REGO Factor")

        capacity = {}
        for scheme in ['RO','REGO']:
            offset = 1 if scheme == 'RO' else 3
            ss = StationSearch()
            ss.for_wind()
            ss.set_scheme(scheme)
            ss.station = s
            if not ss.get_data():
                print "Unable to find any station with a name %s" % s
                continue

            station = None
            if len(ss) > 1:
                for st in ss.stations:
 #                   print st.as_string()
                    if 'wind' in st.technology.lower():
                        station = st
                        break
            else:
示例#2
0
# -*- coding: utf-8 -*-

# Copyright 2013 david reid <*****@*****.**>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from pywind.ofgem import StationSearch
ss = StationSearch()
ss.filter_name('Novar')
ss.get_data()
print(ss.stations[0].as_string())
示例#3
0
def main():
    """ Function that actually does the work :-) """
    parser = commandline_parser('Download bulk information from Ofgem to produce an Excel spreadsheet')
    parser.add_argument('start', type=int, help='Period to start (YYYYMM)')
    parser.add_argument('end',  type=int, help='Period to finish (YYYYMM)')
    parser.add_argument('--filename',
                        default='certificates.xls',
                        help='Filename to export to')
    parser.add_argument('--stations', nargs='*', help='Stations to search for')
    args = parser.parse_args()
    print(args)

    if not args.filename.endswith('.xls'):
        args.filename += '.xls'

    periods = []
    start_dt = _convert_type(args.start, 'period')
    end_dt = _convert_type(args.end, 'period')
    for yyy in range(start_dt.year, end_dt.year + 1):
        mmm = start_dt.month if start_dt.year == yyy else 1
        mm2 = end_dt.month if end_dt.year == yyy else 12
        for mon in range(mmm, mm2+1):
            periods.append(date(yyy, mon, 1))

    print("Period covered will be {} to {}. A total of {} periods".
          format(start_dt.strftime("%b-%Y"),
                 end_dt.strftime("%b-%Y"),
                 len(periods)))

    stations = []
    station_names = args.stations or []

    if args.input is not None:
        with open(args.input) as fh:
            for line in fh.readlines():
                station = line.strip()
                if '#' in station:
                    (station, dummy_junk) = station.split('#', 1)
                station_names.append(station)

    if len(station_names) > 0:
        print("Station names to be searched for:")
        for stat in station_names:
            print("    - {}".format(stat))

    while True:
        station = raw_input("Enter a station name (or blank to finish)")
        if station.strip() == '':
            break
        if ',' in station:
            for s in station.strip().split(','):
                station_names.append(s)
        else:
            station_names.append(station)

    if len(station_names) == 0:
        print("No stations to process. Exiting...")
        sys.exit(0)

    print("\nSearching for stations...")
    for name in station_names:
        print("    - {}".format(name))
        sss = StationSearch()
        sss.start()
        if sss.filter_name(name) and sss.get_data():
            stations.extend(sss.stations)
            print("        found")
        else:
            print("        no stations found")

    print("A total of {} stations will be recorded".format(len(stations)))

    wbb = Workbook()
    add_station_sheet(wbb, stations)

    print("\nGetting certificate data (this is quicker)...")
    certificates = {}
    for station in stations:
        print("    - {}".format(station.name))
        ocs = CertificateSearch()
        ocs.start()
        if ocs.filter_generator_id(station.generator_id) and \
                ocs.set_start_month(start_dt.month) and \
                ocs.set_start_year(start_dt.year) and \
                ocs.set_finish_month(end_dt.month) and \
                ocs.set_finish_year(end_dt.year) and \
                ocs.get_data():
            certificates[station.name] = ocs.cert_list
            add_certificate_sheet(wbb, station, ocs.certificates)
            print("        added to spreadsheet")
        else:
            print("        nothing to add")

    wbb.save(args.filename)
    print("\nData saved to {}".format(args.filename))
示例#4
0
    for i in range(0, len(stations)):
        s = stations[i]

        col = 1 + 5 * i
        print "    ", s

        # add headers
        #        ws.write(PERIOD_START - 1, col, "Installed Capacity")
        #        ws.write(PERIOD_START - 1, col + 1, "RO Certificates")
        #        ws.write(PERIOD_START - 1, col + 2, "RO Factor")
        #        ws.write(PERIOD_START - 1, col + 3, "REGO Certificates")
        #        ws.write(PERIOD_START - 1, col + 4, "REGO Factor")

        #        capacity = {}

        ss = StationSearch()
        ss.filter_name(s)
        if not ss.get_data():
            print "Unable to get station data for %s" % s
            continue
        if len(ss) == 0:
            print "No stations found matching %s" % s
            continue
        if len(ss) > 1:
            print "More than one station matches!"
            for st in ss.stations:
                print "    ", st['name']
            continue

        station = ss.stations[0]
        records = StationRecords(station)
示例#5
0
def test(theseargs):

    parser = argparse.ArgumentParser(description='Download bulk information from Ofgem to produce an Excel spreadsheet')
    parser.add_argument('--start', action='store', required=True, help='Period to start from (MMM-YYYY)')
    parser.add_argument('--end', action='store', required=True, help='Period to finish on (MMM-YYYY)')
    parser.add_argument('--scheme', action='store', default='RO', help='Scheme to get certificates for')
    parser.add_argument('--filename', action='store', default='certificates.xls', help='Filename to export to')
    parser.add_argument('--name', action='store', default=None, help='Part of a name of generation station (or name fragments for several stations, separated by commas)')
    args = parser.parse_args(args=theseargs)

    (start_year, start_month) = get_period(args.start)
    (end_year, end_month) = get_period(args.end)
    if not args.filename.endswith('.xls'):
        args.filename += '.xls'

    periods = []
    for yy in range(start_year, end_year + 1):
        mm = start_month if start_year == yy else 1
        mm2 = end_month if end_year == yy else 12
        for m in range(mm, mm2+1):
            periods.append(date(yy,m,1).strftime("%b-%Y"))

    station = args.name
    if station is None:
        stations = []
        while (True):
            station = input("Enter a station name (or blank to finish)")
            if station.strip() == '':
                break
            if ',' in station:
                for s in station.strip().split(','):
                    s = s.strip()
                    if s in stations:
                        continue
                    stations.append(s)
            else:
                station = station.strip()
                if station in stations:
                    continue
                stations.append(station)
    else:
        stations = station.strip().split(',')
        
    if len(stations) == 0:
        print("No stations to process. Exiting...")
        sys.exit(0)

    wb = Workbook()
    ws = wb.add_sheet('Certificate Data', cell_overwrite_ok=True)
    ws.write(PERIOD_START - 1,0,"Period")
    for i in range(0, len(periods)):
        ws.write(PERIOD_START + i, 0, periods[i])

    al = Alignment()
    al.horz = Alignment.HORZ_CENTER
    al.vert = Alignment.VERT_CENTER

    title_style = XFStyle()
    title_style.alignment = al

    print("\nTotal of %d stations to process\n" % len(stations))
    for i in range(0, len(stations)):
        s = stations[i]
        col = 1 + 5 * i
        print("    "+ s)

        # add headers
        ws.write(PERIOD_START - 1, col, "Installed Capacity")
        ws.write(PERIOD_START - 1, col + 1, "RO Certificates")
        ws.write(PERIOD_START - 1, col + 2, "RO Factor")
        ws.write(PERIOD_START - 1, col + 3, "REGO Certificates")
        ws.write(PERIOD_START - 1, col + 4, "REGO Factor")

        capacity = {}
        for scheme in ['RO','REGO']:
            offset = 1 if scheme == 'RO' else 3
            ss = StationSearch()
            ss.filter_scheme(scheme)
            ss.filter_name(s)
            if not ss.get_data():
                print("Unable to find any station with a name %s" % s)
                continue

            station = None
            # if more than one generator has matched, use the first WIND one 
            if len(ss.stations) > 1:
                print('Several stations found that match %s:' % s)
                print(list(st.name for st in ss.stations))
                print('The first wind station will be selected')
                for st in ss.stations:
                    if 'wind' in st.technology.lower():
                        station = st
                        break
            else:
                station = ss.stations[0]

            if station is None:
                print("Unable to get station data for '%s'" % s)
                continue

            # Write name
            ws.write_merge(PERIOD_START - 4, PERIOD_START - 4, col, col + 4,
                           station.name, title_style)
            # add accreditation #
            if scheme == 'RO':
                ws.write_merge(PERIOD_START - 2, PERIOD_START - 2, col, col + 4,
                               'RO: ' + station.accreditation + '  [' + station.commission_dt.strftime("%d %b %Y") + ']',
                               title_style)
            elif scheme == 'REGO':
                ws.write_merge(PERIOD_START - 3, PERIOD_START - 3, col, col + 4,
                               'REGO: ' + station.accreditation + '  [' + station.commission_dt.strftime("%d %b %Y") + ']',
                               title_style)
            cs = CertificateSearch()

            cs.set_start_month(start_month)
            cs.set_start_year(start_year)
            cs.set_finish_month(end_month)
            cs.set_finish_year(end_year)
            cs.filter_accreditation(station.accreditation)
            #cs.filter_scheme(scheme) # seems to work ok without this, and REGOs break with it
            #cs.filter_status(['Issued','Redeemed','Expired']) # this doesn't work. And arguable whether expired should count
            
            if not cs.get_data():
                print("Unable to get any certificate data :-(")
                continue

            data = {}
            for c in cs.certificates:
                # print(c.as_string())
                if c.status in ['Revoked','Retired','Expired']:
                    continue

                row = periods.index(c.period) + PERIOD_START
                if not c.period in capacity:
                    ws.write(row, col, c.capacity)
                    capacity[c.period] = True

                data[c.period] = data.get(c.period,0) + c.certs
                ws.write(row, col + offset + 1, c.factor)

            for p,val in viewitems(data):
                row = periods.index(p) + PERIOD_START
                ws.write(row, col + offset, val)

    print("\nComplete. Excel spreadsheet %s" % args.filename)
    wb.save(args.filename)
示例#6
0
def main():
    """ Function that actually does the work :-) """
    parser = commandline_parser(
        'Download bulk information from Ofgem to produce an Excel spreadsheet')
    parser.add_argument('start', type=int, help='Period to start (YYYYMM)')
    parser.add_argument('end', type=int, help='Period to finish (YYYYMM)')
    parser.add_argument('--filename',
                        default='certificates.xls',
                        help='Filename to export to')
    parser.add_argument('--stations', nargs='*', help='Stations to search for')
    args = parser.parse_args()
    print(args)

    if not args.filename.endswith('.xls'):
        args.filename += '.xls'

    periods = []
    start_dt = _convert_type(args.start, 'period')
    end_dt = _convert_type(args.end, 'period')
    for yyy in range(start_dt.year, end_dt.year + 1):
        mmm = start_dt.month if start_dt.year == yyy else 1
        mm2 = end_dt.month if end_dt.year == yyy else 12
        for mon in range(mmm, mm2 + 1):
            periods.append(date(yyy, mon, 1))

    print("Period covered will be {} to {}. A total of {} periods".format(
        start_dt.strftime("%b-%Y"), end_dt.strftime("%b-%Y"), len(periods)))

    stations = []
    station_names = args.stations or []

    if args.input is not None:
        with open(args.input) as fh:
            for line in fh.readlines():
                station = line.strip()
                if '#' in station:
                    (station, dummy_junk) = station.split('#', 1)
                station_names.append(station)

    if len(station_names) > 0:
        print("Station names to be searched for:")
        for stat in station_names:
            print("    - {}".format(stat))

    while True:
        station = raw_input("Enter a station name (or blank to finish)")
        if station.strip() == '':
            break
        if ',' in station:
            for s in station.strip().split(','):
                station_names.append(s)
        else:
            station_names.append(station)

    if len(station_names) == 0:
        print("No stations to process. Exiting...")
        sys.exit(0)

    print("\nSearching for stations...")
    for name in station_names:
        print("    - {}".format(name))
        sss = StationSearch()
        sss.start()
        if sss.filter_name(name) and sss.get_data():
            stations.extend(sss.stations)
            print("        found")
        else:
            print("        no stations found")

    print("A total of {} stations will be recorded".format(len(stations)))

    wbb = Workbook()
    add_station_sheet(wbb, stations)

    print("\nGetting certificate data (this is quicker)...")
    certificates = {}
    for station in stations:
        print("    - {}".format(station.name))
        ocs = CertificateSearch()
        ocs.start()
        if ocs.filter_generator_id(station.generator_id) and \
                ocs.set_start_month(start_dt.month) and \
                ocs.set_start_year(start_dt.year) and \
                ocs.set_finish_month(end_dt.month) and \
                ocs.set_finish_year(end_dt.year) and \
                ocs.get_data():
            certificates[station.name] = ocs.cert_list
            add_certificate_sheet(wbb, station, ocs.certificates)
            print("        added to spreadsheet")
        else:
            print("        nothing to add")

    wbb.save(args.filename)
    print("\nData saved to {}".format(args.filename))
示例#7
0
    parser.add_argument(
        '--scheme',
        action='store',
        default='REGO',
        help='Scheme to search (ignored for accreditation) [default REGO]')
    parser.add_argument('--organisation',
                        action='store',
                        help='Organisation to search for')
    parser.add_argument('--output',
                        action='store',
                        help='Filename to output data into (as CSV)')

    args = parser.parse_args()

    print("Connecting with Ofgem website and preparing the search...")
    osd = StationSearch()

    crit = "Searching for Ofgem Stations where:\n\tscheme is %s" % args.scheme

    osd.filter_scheme(args.scheme)

    if args.name:
        osd.filter_name(args.name)
        crit += "\n\tname contains '%s'" % args.name

    if args.organisation:
        osd['organisation'] = args.organisation
        crit += "\n\torganisation is '%s'" % args.organisation

    if args.generator:
        if args.generator.upper()[0] == 'R':
示例#8
0
def main():
    parser = commandline_parser('Search ofgem database for matching stations')
    parser.add_argument('--generator',
                        action='store',
                        help='Generator ID to search for')
    parser.add_argument('--organisation',
                        action='store',
                        help='Organisation to search for')

    args = parser.parse_args()

    if args.station is None and \
                    args.generator is None and \
                    args.organisation is None:
        print("You must specify either a name, generator id or organisation")
        sys.exit(0)

    setup_logging(args.debug, request_logging=args.request_debug)

    print("Connecting with Ofgem website and preparing the search...")
    osd = StationSearch()
    osd.start()

    print("Setting up filters:")

    if args.station is not None:
        osd.filter_name(args.station)
        print("    - station name contains {}".format(args.station))

    if args.organisation:
        osd.filter_organisation(args.organisation)
        print("    -  organisation contains {}".format(args.organisation))

    if args.generator:
        if args.generator.upper()[0] in ['R', 'P']:
            osd.filter_scheme('RO')
        elif args.generator.upper()[0] == 'G':
            osd.filter_scheme('REGO')
        osd.filter_generator_id(args.generator.upper())
        print("    - generator ID is {}".format(args.generator.upper()))

    print("\nGetting results from Ofgem...\n")

    if osd.get_data() is False:
        print("Search returned no data")
        sys.exit(0)

    print("Query returned {} result{}".format(len(osd),
                                              '' if len(osd) == 0 else 's'))

    fmt = StdoutFormatter("35s", "13s", "12.2f", "20s", "20s", "15s")
    print(
        fmt.titles("Station Name", "Commission Dt", "Capacity", "Technology",
                   "Country", "Generator ID"))

    for stat in osd.rows():
        # The rows() output is intended for exporting, so fields will have '@' prepended
        # if they are attributes.
        # This could also be done by using osd.stations
        station = stat.get('Station')
        if station is None:
            continue
        cdt = station.get('@commission_dt')
        print(
            fmt.row(station.get('@name'),
                    cdt.strftime("%Y-%m-%d") if cdt else 'n/a',
                    station.get('@capacity'), station.get('@technology'),
                    station.get('@country'), station.get('@generator_id')))
示例#9
0
def main():
    parser = commandline_parser('Search ofgem database for matching stations')
    parser.add_argument('--generator', action='store', help='Generator ID to search for')
    parser.add_argument('--organisation', action='store', help='Organisation to search for')

    args = parser.parse_args()

    if args.station is None and \
                    args.generator is None and \
                    args.organisation is None:
        print("You must specify either a name, generator id or organisation")
        sys.exit(0)

    setup_logging(args.debug, request_logging=args.request_debug)

    print("Connecting with Ofgem website and preparing the search...")
    osd = StationSearch()
    osd.start()

    print("Setting up filters:")

    if args.station is not None:
        osd.filter_name(args.station)
        print("    - station name contains {}".format(args.station))

    if args.organisation:
        osd.filter_organisation(args.organisation)
        print("    -  organisation contains {}".format(args.organisation))

    if args.generator:
        if args.generator.upper()[0] in ['R', 'P']:
            osd.filter_scheme('RO')
        elif args.generator.upper()[0] == 'G':
            osd.filter_scheme('REGO')
        osd.filter_generator_id(args.generator.upper())
        print("    - generator ID is {}".format(args.generator.upper()))

    print("\nGetting results from Ofgem...\n")

    if osd.get_data() is False:
        print("Search returned no data")
        sys.exit(0)

    print("Query returned {} result{}".format(len(osd), '' if len(osd) == 0 else 's'))

    fmt = StdoutFormatter("35s", "13s", "12.2f", "20s", "20s", "15s")
    print(fmt.titles("Station Name", "Commission Dt", "Capacity",
                     "Technology", "Country", "Generator ID"))

    for stat in osd.rows():
        # The rows() output is intended for exporting, so fields will have '@' prepended
        # if they are attributes.
        # This could also be done by using osd.stations
        station = stat.get('Station')
        if station is None:
            continue
        cdt = station.get('@commission_dt')
        print(fmt.row(station.get('@name'),
                      cdt.strftime("%Y-%m-%d") if cdt else 'n/a',
                      station.get('@capacity'),
                      station.get('@technology'),
                      station.get('@country'),
                      station.get('@generator_id')))
示例#10
0
    for i in range(0, len(stations)):
        s = stations[i]

        col = 1 + 5 * i
        print "    ", s

        # add headers
        #        ws.write(PERIOD_START - 1, col, "Installed Capacity")
        #        ws.write(PERIOD_START - 1, col + 1, "RO Certificates")
        #        ws.write(PERIOD_START - 1, col + 2, "RO Factor")
        #        ws.write(PERIOD_START - 1, col + 3, "REGO Certificates")
        #        ws.write(PERIOD_START - 1, col + 4, "REGO Factor")

        #        capacity = {}

        ss = StationSearch()
        ss.filter_name(s)
        if not ss.get_data():
            print "Unable to get station data for %s" % s
            continue
        if len(ss) == 0:
            print "No stations found matching %s" % s
            continue
        if len(ss) > 1:
            print "More than one station matches!"
            for st in ss.stations:
                print "    ", st["name"]
            continue

        station = ss.stations[0]
        records = StationRecords(station)