<commit_before>from __future__ import division
from misc import significant
import math
import matplotlib.pyplot as plt

# Volume Discount constant
VOLUME_CONSTANT = -0.8

CAP_PRICE_MW_2018 = 125.  # $/MW-day
CARBON_PRICE = 11.  #
REGULATION_PRICE = 60.  # $/MW/hour

# step function
p = lambda x, m, b: math.ceil(x/m)*(VOLUME_CONSTANT*math.log(math.ceil(x/m))+b)


def gini(list_of_values):
    sorted_list = sorted(list_of_values)
    height, area = 0, 0
    for value in sorted_list:
        height += value
        area += height - value / 2.
    fair_area = height * len(list_of_values) / 2
    return (fair_area - area) / fair_area


def grid_value(domain):
    """grid value in Virtual Power Plant in a mature market"""

    cap_w = domain.STC()*domain.capacity_factor()
    cap_s = domain.capacity() # w assuming 1C discharge
    e_v = domain.storage.surplus/1000. * .12

    cap_v = CAP_PRICE_MW_2018/1E6*cap_w*365.

    reg_v = REGULATION_PRICE/1E6*cap_s*365*24

    carbon_delta = sum(domain.g)/1000*.125
    results = {
        'e_v ($):': significant(e_v),
        'cap ($)': significant(cap_v),
        'reg ($):': significant(reg_v),
        'carbon delta (kg)': significant(carbon_delta)}
    return results


def scaling():
    """Scaling various system types

    This is interesting because it's step functions

    """
    fig = plt.figure(figsize=(8.5, 11))
    ax = fig.add_subplot(111)
    # ax.set_title('Storage Frequency Histogram')
    ws = range(1, 10000, 100)
    m = [p(x, 250, 1000) for x in range(1, 10000, 100)]
    ac = [p(x, 5000, 15000) for x in range(1, 10000, 100)]
    dc = [p(x, 1500, 7000) for x in range(1, 10000, 100)]
    ax.plot(ws, m, label='Micro Inverter')
    ax.plot(ws, ac,  label='AC Coupled')
    ax.plot(ws, dc, label='DC Coupled')
    ax.legend(loc='upper left')
    ax.set_ylabel('size (W)')
    ax.set_xlabel('Price (USD)')
    plt.draw()
    plt.show()
    plt.ion()
    fig.savefig('scaling.pdf')

# price of energy vs time
# plot(range(1,365),[7000./(5*2*x) for x in range(1,365)]),
# plot(range(1,365),[250./(5*.25*x) for x in range(1,365)]),
# plot(range(1,365),[17000./(5*8*x) for x in range(1,365)]),ylim(0,20)
# interesting because of when the sequences converge

# value of lost load Voll
# Loss ($/kW) = f(duration, season, time of day, notice)
# customer damage function (CDF)

if __name__ == '__main__':
    scaling()
<commit_msg>kwh not w.  silly me<commit_after>from __future__ import division
from misc import significant
import math
import matplotlib.pyplot as plt

# Volume Discount constant
VOLUME_CONSTANT = -0.8

CAP_PRICE_MW_2018 = 125.  # $/MW-day
CARBON_PRICE = 11.  #
REGULATION_PRICE = 60.  # $/MW/hour

# step function
p = lambda x, m, b: math.ceil(x/m)*(VOLUME_CONSTANT*math.log(math.ceil(x/m))+b)
# Where x is kwh, m is increment size and b is price floor constant


def gini(list_of_values):
    sorted_list = sorted(list_of_values)
    height, area = 0, 0
    for value in sorted_list:
        height += value
        area += height - value / 2.
    fair_area = height * len(list_of_values) / 2
    return (fair_area - area) / fair_area


def grid_value(domain):
    """grid value in Virtual Power Plant in a mature market"""

    cap_w = domain.STC()*domain.capacity_factor()
    cap_s = domain.capacity() # w assuming 1C discharge
    e_v = domain.storage.surplus/1000. * .12

    cap_v = CAP_PRICE_MW_2018/1E6*cap_w*365.

    reg_v = REGULATION_PRICE/1E6*cap_s*365*24

    carbon_delta = sum(domain.g)/1000*.125
    results = {
        'e_v ($):': significant(e_v),
        'cap ($)': significant(cap_v),
        'reg ($):': significant(reg_v),
        'carbon delta (kg)': significant(carbon_delta)}
    return results


def scaling():
    """Scaling various system types

    This is interesting because it's step functions

    """
    fig = plt.figure(figsize=(8.5, 11))
    ax = fig.add_subplot(111)
    # ax.set_title('Storage Frequency Histogram')
    ws = range(1, 10000, 100)
    m = [p(x, 250*1.3, 1000) for x in range(1, 10000, 100)]
    ac = [p(x, 5000*1.3, 15000) for x in range(1, 10000, 100)]
    dc = [p(x, 1500*1.3, 7000) for x in range(1, 10000, 100)]
    ax.plot(ws, m, label='Micro Inverter')
    ax.plot(ws, ac,  label='AC Coupled')
    ax.plot(ws, dc, label='DC Coupled')
    ax.legend(loc='upper left')
    ax.set_ylabel('Load (kWh)')
    ax.set_xlabel('Price (USD)')
    plt.draw()
    plt.show()
    plt.ion()
    fig.savefig('scaling.pdf')

# price of energy vs time
# plot(range(1,365),[7000./(5*2*x) for x in range(1,365)]),
# plot(range(1,365),[250./(5*.25*x) for x in range(1,365)]),
# plot(range(1,365),[17000./(5*8*x) for x in range(1,365)]),ylim(0,20)
# interesting because of when the sequences converge

# value of lost load Voll
# Loss ($/kW) = f(duration, season, time of day, notice)
# customer damage function (CDF)

if __name__ == '__main__':
    scaling()

{'fraction_non_alphanumeric': 0.1516267648864334, 'fraction_numerical': 0.06670759156947002, 'mean_word_length': 3.360392506690455, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5332391', 'n_tokens_mistral': 2087, 'n_tokens_neox': 1815, 'n_words': 474}