import numpy as np
from scipy.optimize import curve_fit
from matplotlib import pyplot as plt
from pyscript import web, when, display

display("ready to compute")

def solver(L, R_per_L, U):
    R = L * R_per_L
    I = U / R
    P = U * I
    return P, I
    




@when("click", "#run-button")
def plot(event):
    """
    Plot.
    """

  
    
    input_text = web.page["constant_a"]
    a = float(input_text.value)
    
    
    Qcor = correlation(wind_speed, a, 0.2 )

    ####
    # wind_speed
    #
    fig, ax = plt.subplots(1)
    
    Vind = np.argsort(wind_speed)
    ax.plot(wind_speed,1000*Q_meas,"dk" , label="meas")
    ax.plot(wind_speed[Vind], 1000*Qcor[Vind],"-", label="cor a=%.2f" % a)
    
    ax.set_ylabel("Volume rate (l/s)")
    
    ax.grid(1)
    ax.set_xlabel("Wind speed (m/s)")
    ax.legend()
    
    
    
    display(fig)
    
        
    
    
    
    

