示例#1
0
def gspDemand(supplyPoint, m, d):
    electricalData = process_data_normal(
        (electricalGSP.objects.filter(GSP=supplyPoint)), electricalGSP, 3)
    electricalData = electricalData[0:, 2] / 2
    dS = pd.date_range(start='2015-04-01', end='2016-04-01', freq='H')
    proData = pd.DataFrame({'Time': dS[0:8784], 'Data': electricalData})
    data = proData.set_index('Time')
    d1, d2, S = month(m, data)
    elec = S['Data']
    elec = elec.iloc[0:(24 * d)]

    return elec
示例#2
0
def plot_charge_demand(request):

    supplyPoint = request.GET['supplyPoint']
    m = int(request.GET['month'])
    d = request.GET['days']

    gspName = GSP.objects.filter(idx=supplyPoint)
    na0 = ([p.name for p in gspName])
    gspAuthority = gspLocalAuthority.objects.filter(gsp=na0[0])
    na1 = ([p.localAuthority for p in gspAuthority])

    mediumEV = request.GET['mediumEV']
    smallEV = request.GET['smallEV']
    geographicArea = int(request.GET['geographicArea'])

    if geographicArea == 1:
        gA = 'Urban'
    else:
        gA = 'Rural'

    if d == '':
        d = int(0)
    else:
        d = int(d)

    if m == 13:
        d = 366

    if mediumEV == '':
        mediumEV = int(0)
    else:
        mediumEV = int(mediumEV)

    if smallEV == '':
        smallEV = int(0)
    else:
        smallEV = int(smallEV)

    electricalData = process_data(
        (electricalGSP.objects.filter(GSP=supplyPoint)), electricalGSP, 3)
    chargeDataSmall = process_data((Journey.objects.filter(
        localAuthority=na1[0], Area=gA, typeEV='Economy')), Journey, 7)
    chargeDataMedium = process_data((Journey.objects.filter(
        localAuthority=na1[0], Area=gA, typeEV='Midsize')), Journey, 7)

    # good to here
    electricalData = electricalData[0:, 2] / 2
    chargeDataSmall = chargeDataSmall[0:, 0:4]
    chargeDataMedium = chargeDataMedium[0:, 0:4]

    profileSmall = formatChargeDemand(smallEV, chargeDataSmall, 'Economy', d)
    profileMedium = formatChargeDemand(mediumEV, chargeDataMedium, 'Midsize',
                                       d)

    profileTotal = np.zeros([len(profileSmall), 1])
    profileTotal[0:, 0] = (profileSmall['Charge'].as_matrix() +
                           profileMedium['Charge'].as_matrix()) / 1000

    dS = pd.date_range(start='2015-04-01', end='2016-04-01', freq='H')
    proData = pd.DataFrame({'Time': dS[0:8784], 'Data': electricalData})
    data = proData.set_index('Time')
    d1, d2, S = month(m, data)

    elec = S['Data']
    baseData = np.zeros([(24 * d), 1])
    baseData[0:, 0] = elec.iloc[0:(24 * d)]

    newData = baseData + profileTotal

    fmax = max(baseData)[0]
    newDemandMax = max(newData)[0]
    fMax = round(fmax, 2)
    newDemandMax = round(newDemandMax, 2)

    statHP = process_data_normal((gspStats.objects.filter(index=supplyPoint)),
                                 gspStats, 16)
    rating = statHP[0, 1]

    if d == 1:
        formatter = DateFormatter('%H-%M')
        rule = rrulewrapper(HOURLY, interval=6)
    elif d < 4:
        formatter = DateFormatter('%d-%m-%y')
        rule = rrulewrapper(DAILY, interval=1)
    elif d < 10:
        formatter = DateFormatter('%d-%m-%y')
        rule = rrulewrapper(DAILY, interval=2)
    elif d > 9 and d < 16:
        formatter = DateFormatter('%d-%m-%y')
        rule = rrulewrapper(DAILY, interval=3)
    elif d > 15 and d < 32:
        formatter = DateFormatter('%d-%m')
        rule = rrulewrapper(DAILY, interval=5)

    if m == 13:
        formatter = DateFormatter('%b-%Y')
        rule = rrulewrapper(MONTHLY, interval=3)

    loc = RRuleLocator(rule)
    delta = datetime.timedelta(hours=1)
    dates = drange(d1, d2, delta)
    finalDates = dates[0:(24 * d)]
    fig, ax = plt.subplots()

    ax.plot_date(finalDates, baseData, linestyle='-', marker='None')
    ax.plot_date(finalDates, newData, linestyle='-', marker='None')
    ax.xaxis.set_major_formatter(formatter)
    ax.xaxis.set_major_locator(loc)
    plt.ylabel('Electrical Demand (MWh)')
    plt.grid(True)

    buffer = BytesIO()
    canvas = pylab.get_current_fig_manager().canvas
    canvas.draw()
    pilImage = PIL.Image.frombytes("RGB", canvas.get_width_height(),
                                   canvas.tostring_rgb())
    pilImage.save(buffer, "PNG")
    pylab.close()

    image_png = buffer.getvalue()
    graphic = base64.b64encode(image_png)
    graphic = graphic.decode('utf-8')
    ##
    return render(
        request, 'transport/show_plot.html', {
            'graphic': graphic,
            'fMax': fMax,
            'newDemandMax': newDemandMax,
            'rating': rating
        })
示例#3
0
def plot_electrical(request):
    supplyPoint = request.GET['supplyPoint']
    m = int(request.GET['month'])
    d = request.GET['days']
    gspName = GSP.objects.get(idx=supplyPoint)

    if d == '':
        d = int(0)
    else:
        d = int(d)

    if m == 13:
        d = 366

    electricalData = electricalGSP.objects.filter(GSP=supplyPoint)
    vlqs = electricalData.values_list()
    r = np.core.records.fromrecords(
        vlqs, names=[f.name for f in electricalGSP._meta.fields])
    l = np.array(r)
    process = np.zeros([len(l), 3])

    for i in range(
            0, len(process)):  # extract the information we need for inputs.
        change = l[i]
        for j in range(1, 4):
            process[i, (j - 1)] = change[j]

    g = np.array(process)

    dS = pd.date_range(start='2015-04-01', end='2016-04-01', freq='H')
    proData = pd.DataFrame({'Time': dS[0:8784], 'Data': g[0:, 2]})
    data = proData.set_index('Time')
    d1, d2, S = month(m, data)

    elec = S['Data']
    finalData = elec.iloc[0:(24 * d)] / 2
    if max(finalData) > abs(min(finalData)):
        maxGSP_proxy = max(finalData)
    else:
        maxGSP_proxy = min(finalData)

    maxGSP = round(maxGSP_proxy, 2)

    statHP = process_data_normal((gspStats.objects.filter(index=supplyPoint)),
                                 gspStats, 16)
    rating = statHP[0, 1]

    if d == 1:
        formatter = DateFormatter('%H-%M')
        rule = rrulewrapper(HOURLY, interval=6)
    elif d < 4:
        formatter = DateFormatter('%d-%m-%y')
        rule = rrulewrapper(DAILY, interval=1)
    elif d < 10:
        formatter = DateFormatter('%d-%m-%y')
        rule = rrulewrapper(DAILY, interval=2)
    elif d > 9 and d < 16:
        formatter = DateFormatter('%d-%m-%y')
        rule = rrulewrapper(DAILY, interval=3)
    elif d > 15 and d < 32:
        formatter = DateFormatter('%d-%m')
        rule = rrulewrapper(DAILY, interval=5)

    if m == 13:
        formatter = DateFormatter('%b-%Y')
        rule = rrulewrapper(MONTHLY, interval=3)

    loc = RRuleLocator(rule)
    delta = datetime.timedelta(hours=1)
    dates = drange(d1, d2, delta)
    finalDates = dates[0:(24 * d)]
    fig, ax = plt.subplots()

    ax.plot_date(finalDates,
                 finalData,
                 linestyle='-',
                 marker='None',
                 label='Demand')

    ##    if (finalData<0).any() == True and (finalData>0).any() == False:
    ##        ax.plot_date(finalDates,ratingNeg, linestyle='-', marker='None', color='r', label='GSP Rating')
    ##    elif (finalData<0).any() == False and (finalData>0).any() == True:
    ##        ax.plot_date(finalDates,rating, linestyle='-', marker='None', color='r', label='GSP Rating')
    ##    elif (finalData<0).any() == True and (finalData>0).any() == True:
    ##        ax.plot_date(finalDates,ratingNeg, linestyle='-', marker='None', color='r', label='GSP Rating')
    ##        ax.plot_date(finalDates,rating, linestyle='-', marker='None', color='r')

    ax.xaxis.set_major_formatter(formatter)
    ax.xaxis.set_major_locator(loc)
    plt.ylabel('Electrical Demand (MWh)')
    plt.title('Electrical Demand Plot for ' + gspName.name + ' GSP')
    plt.grid(True)

    buffer = BytesIO()
    canvas = pylab.get_current_fig_manager().canvas
    canvas.draw()
    pilImage = PIL.Image.frombytes("RGB", canvas.get_width_height(),
                                   canvas.tostring_rgb())
    pilImage.save(buffer, "PNG")
    pylab.close()

    image_png = buffer.getvalue()
    graphic = base64.b64encode(image_png)
    graphic = graphic.decode('utf-8')
    ##
    return render(request, 'electrical/show_plot.html', {
        'graphic': graphic,
        'maxGSP': maxGSP,
        'rating': rating
    })
示例#4
0
def plot_gsp_storage(request):
    supplyPoint=request.GET['supplyPoint']
    m=int(request.GET['month'])
    d=request.GET['days']
    gspName=GSP.objects.get(idx=supplyPoint)
    esCap=int(request.GET['esCap'])

    if d =='':
        d=int(0)
    else:
        d = int(d)

    if m == 13:
        d=366
    
    electricalData = electricalGSP.objects.filter(GSP = supplyPoint)
    vlqs = electricalData.values_list()
    r = np.core.records.fromrecords(vlqs, names=[f.name for f in electricalGSP._meta.fields])
    l=np.array(r)
    process = np.zeros([len(l),3])

    for i in range(0,len(process)): # extract the information we need for inputs.
        change = l[i]
        for j in range(1,4):
            process[i,(j-1)] = change[j]

    g=np.array(process)/2

    dS=pd.date_range(start='2015-04-01', end='2016-04-01', freq='H')
    proData=pd.DataFrame({'Time':dS[0:8784], 'Data':g[0:,2]})
    data=proData.set_index('Time')
    d1, d2, S = month(m, data)

    elec=S['Data']

    fProxy=np.zeros([24, d])
    cProxy=np.zeros([24, d])
    disProxy=np.zeros([24, d])
    newDemandProxy=np.zeros([24, d])
    
    for i in range(1,(d+1)):
        model, sol, flo, cha, dis, nD = runSolutionBalance(esCap, (elec.iloc[(24*i)-24:(24*i)]))
        fProxy[0:,(i-1)]=flo
        cProxy[0:,(i-1)]=cha
        disProxy[0:,(i-1)]=dis
        newDemandProxy[0:,(i-1)]=nD

    f=fProxy.reshape((d*24), order='F')
    c=cProxy.reshape((d*24),order='F')
    dis=disProxy.reshape((d*24),order='F')
    newDemand=newDemandProxy.reshape((d*24),order='F')

    check=all(i > 0 for i in f)

    if np.absolute(np.amax(f)) > np.absolute(np.amin(f)):
        fMax = np.amax(f)
        newDemandMax = np.amax(newDemand)
        peakReduction = 100 - round(((newDemandMax/fMax)*100),2)
        headroom = round((fMax - newDemandMax), 2)

    else:
        fMax = np.amin(f)
        newDemandMax = np.amin(newDemand)
        peakReduction = 100 - round(((newDemandMax/fMax)*100),2)
        headroom = round((newDemandMax- fMax), 2)

    statHP = process_data_normal((gspStats.objects.filter(index=supplyPoint)), gspStats, 16)
    rating=statHP[0,1]
    
    ####Plotting####
    if d == 1:
        formatter = DateFormatter('%H-%M')
        rule = rrulewrapper(HOURLY, interval=6)
    elif d < 4:
        formatter = DateFormatter('%d-%m-%y')
        rule = rrulewrapper(DAILY, interval=1)
    elif d < 10:
         formatter = DateFormatter('%d-%m-%y')
         rule = rrulewrapper(DAILY, interval=2)
    elif d > 9 and d < 16:
        formatter = DateFormatter('%d-%m-%y')
        rule = rrulewrapper(DAILY, interval=3)
    elif d > 15:
        formatter = DateFormatter('%d-%m')
        rule = rrulewrapper(DAILY, interval=5)

    if m==13:
        formatter = DateFormatter('%b-%Y')
        rule = rrulewrapper(MONTHLY, interval=3)

    loc = RRuleLocator(rule)
    delta = datetime.timedelta(hours=1)
    dates = drange(d1, d2, delta)
    finalDates=dates[0:(24*d)]
    fig, ax =plt.subplots()

    ax.plot_date(finalDates, f, linestyle='-', marker='None', label='Base Case (no BES)')
    ax.plot(finalDates, newDemand, linestyle='-', marker='None', label='With BES')
    ax.xaxis.set_major_formatter(formatter)
    ax.xaxis.set_major_locator(loc)
    ax.legend()
    plt.ylabel('Electrical Demand (MWh)')
    plt.title('Electrical Demand Plot for '+ gspName.name + ' GSP' + ' with ' + str(esCap)+ ' MWh BES')
    plt.grid(True)

    buffer = BytesIO()
    canvas = pylab.get_current_fig_manager().canvas
    canvas.draw()
    pilImage = PIL.Image.frombytes("RGB", canvas.get_width_height(), canvas.tostring_rgb())
    pilImage.save(buffer, "PNG")
    pylab.close()

    image_png = buffer.getvalue()
    graphic = base64.b64encode(image_png)
    graphic = graphic.decode('utf-8')

    return render(request, 'energyStorage/show_plot.html', {'graphic':graphic, 'fMax':fMax, 'newDemandMax': newDemandMax, 'peakReduction':peakReduction,'esCap':esCap, 'headroom':headroom, 'rating':rating})