Example #1
0
def plot_data(timeseries, relevant_bidders, lgc_data):

    # from bokeh.sampledata.stocks import AAPL

    def datetime(x):
        return np.array(x, dtype=np.datetime64)

    plottable = {p: [] for p in relevant_bidders}
    lgc_prices = []
    for time in sorted(timeseries.keys()):
        for participant in relevant_bidders:
            if participant in timeseries[time]:
                plottable[participant].append(timeseries[time][participant])
            else:
                plottable[participant].append(float("nan"))

        lgc_prices.append(-1.0 * lgc_data.get(time, 'price'))

    p1 = figure(x_axis_type="datetime", title="Spot Bids")
    p1.grid.grid_line_alpha = 0.3
    p1.xaxis.axis_label = 'Date'
    p1.yaxis.axis_label = 'Price'

    # participant_meta = ParticipantService().participant_metadata
    for i, participant in enumerate(relevant_bidders):
        fuel_source_primary = ParticipantService(
        ).participant_metadata[participant][
            'fuel_source_primary'] if participant in ParticipantService(
            ).participant_metadata else ""
        # Get rid of irrelevant gen types.
        if fuel_source_primary not in ["Hydro", "Fossil"]:
            color = palette.hex_colors[i % len(palette.hex_colors)]
            p1.line(datetime(sorted(timeseries.keys())),
                    plottable[participant],
                    color=color,
                    legend=participant + " " + fuel_source_primary)
    p1.line(datetime(sorted(timeseries.keys())),
            lgc_prices,
            legend="LGC Price",
            line_width=2,
            line_dash='dashed')

    p1.legend.location = "top_left"

    window_size = 30

    show(gridplot([[p1]], plot_width=1200, plot_height=500))  # open a browser
Example #2
0
from application.model.participants import ParticipantService
from application.model.demand import Demand
from application.model.price import Price
participant_service = ParticipantService()
import pendulum
from application import config

from application.model.bidstack import BidStack, DoesNotExist, bid_to_dict, bid_to_list

dates = BidStack.objects().distinct('trading_period')
dates = [
    date for date in dates if (pendulum.instance(date).minute == 0
                               or pendulum.instance(date).minute == 30)
]
states = ['NSW', 'QLD', 'VIC', 'QLD', 'TAS']

participants = {}
for state in states:
    participants[state] = [
        p for p in participant_service.participant_metadata
        if participant_service.participant_metadata[p]['state'] == state
    ]

for state in states:
    for date in dates:
        if not Price.objects(date_time=date, region=state, price_type='BASIC'):
            print('Adding', state, date)
            # Basic settlement.
            rounded_time = pendulum.instance(date, tz=config.TZ)
            if rounded_time.minute > 30:
                rounded_time = rounded_time.start_of('hour').add(hours=1)