import streamlit as st
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
import datetime
from datetime import date

start_date = st.sidebar.date_input('start date', datetime.date(2019,1,1))

st.write(start_date)
end_date = st.sidebar.date_input('end date', datetime.date(2022,1,1))

st.write(start_date)





#df = ld.load_data_projet()

#st.title("Date range")

#min_date = datetime.datetime(2019,5,1)
#max_date = datetime.date(2021,1,1)

#a_date = st.date_input("Pick a date", (min_date, max_date))

##this uses streamlit 'magic'!!!!
#"The date selected:", a_date
#"The type", type(a_date)
#"Singling out a date for dataframe filtering", a_date[0]
#"Singling out a date for dataframe filtering 2", a_date[1]
data = pd.read_excel(r'C:\Users\stani\Desktop\Webapp\st_zagora\data_for_python2.xlsx') 
df = pd.DataFrame(data)

#df['data'].map(datetime.datetime.date) 
#df['data'] = df['data'].apply(lambda x: x.strftime('%Y-%m-%d'))
#df['data'] = pd.to_datetime(df['data'], format="%Y-%d-%m")
#dates = (df['data'])
df['data'] = pd.to_datetime(df['data']).dt.date

dates=df[(df['data'] >= start_date) & (df['data'] <= end_date)]
x = np.arange(len(dates))
st.write(df[(df['data'] >= start_date) & (df['data'] <= end_date)])
df_res=df[(df['data'] >= start_date) & (df['data'] <= end_date)]
#st.write(df,dates)
production_cost =  df_res['production cost'] 
#plot(dates, production_cost)
average_production_cost= production_cost.mean()
st_dev=df_res['production cost'].std()
st.write('average_production_cost=', round(average_production_cost,2))
st.write('standart deviation =', round(st_dev,2))
st.line_chart(production_cost)
