import pandas as pd
import matplotlib.pyplot as plt
import numpy as np

%matplotlib inline
# Turn interactive plotting off
plt.ioff()

"""
Explanation: Pump Curves - Ulka E5 and Fluid-o-Tech 1106
The Ulka E5 and Fluid-o-Tech 1106 are solenoid pump (aka vibration pump) models commonly used in domestic espresso machines. A pump curve reflects the achievable discharge pressure at a given flowrate, which is limited by pump power and influenced by pump speed and efficiency.
1. Setup
Import Statements
End of explanation
"""


mL_per_US_gallon = 3785.41
mL_per_L = 1000.0

sec_per_min = 60.0
sec_per_hr = 60.0 * sec_per_min

"""
Explanation: Conversion Factors
End of explanation
"""


FluidOTech = pd.read_csv(r'https://github.com/DIYCoffeeGuy/data/raw/master/Fluidotech%201106%20Pump%20Curve.csv')
Ulka = pd.read_csv(r'https://github.com/DIYCoffeeGuy/data/raw/master/Ulka%20E5%20Pump%20Curve.csv')

"""
Explanation: 2. Pump curve data
Import the data
End of explanation
"""


FluidOTech['Volumetric Flowrate (mL/s)'] = FluidOTech['Volumetric Flowrate (L/h)'] * mL_per_L / sec_per_hr
Ulka['Volumetric Flowrate (mL/s)'] = Ulka['Volumetric Flowrate (mL / min)'] / sec_per_min

"""
Explanation: Standardise the units.
End of explanation
"""


FluidOTech[['Discharge Pressure (barg)','Volumetric Flowrate (mL/s)']]

Ulka[['Discharge Pressure (barg)','Volumetric Flowrate (mL/s)']]

"""
Explanation: Take a look at the data.
End of explanation
"""


fig, axes = plt.subplots(figsize=(12,8));

"""
Explanation: 3. Plotting the Curves
End of explanation
"""


FluidOTech.plot(
    kind='line',
    x='Discharge Pressure (barg)',
    y='Volumetric Flowrate (mL/s)',
    ax=axes,
    xlim=(0,15),
    legend=True,
    linestyle='dashed',
    color='b');

Ulka.plot(
    kind='line',
    ax=axes,
    x='Discharge Pressure (barg)',
    xlim=(0,15),
    y='Volumetric Flowrate (mL/s)',
    linestyle='solid',
    color='r');

"""
Explanation: Add the pump curve data
End of explanation
"""


#Configure the legend
lines, labels = axes.get_legend_handles_labels()[0], ['Fluid-o-Tech 1106','Ulka E5']
axes.legend(lines, labels, loc='best');
axes.set_title('Comparison of Vibration Pump Curves', fontsize=20)

#Add ticks to the x-axes
axes.set_xticks(range(0,16));

#Configure LH y-axes
axes.set_yticks(range(0,13))
axes.set_ylabel('Volumetric Flowrate (mL/s)');

#Add and configure RH y-axis
axes2 = axes.twinx()
axes2.set_yticks(np.arange(0.0,0.251,0.025))
axes2.set_ylim(0,60*15/mL_per_US_gallon)
axes2.set_ylabel('Volumetric Flowrate (US gal/min)');

"""
Explanation: Configure the plot layout and labels
End of explanation
"""


fig.tight_layout()

plt.show()

"""
Explanation: Display chart
End of explanation
"""


