# -*- coding: utf-8 -*-
"""
Created on Fri Jul 21 16:57:53 2023

@author: stani
"""

# -*- coding: utf-8 -*-
"""
Created on Thu Jul 20 15:52:15 2023

@author: stani
"""

# -*- coding: utf-8 -*-
"""
Created on Thu Jul 20 12:52:44 2023

@author: stani
"""
#import streamlit as st
import pandas as pd
import matplotlib.pyplot as plt
#import numpy as np
#import datetime
#from datetime import date
#import seaborn as sns
#x=['2019', '2020', '2021']
data = pd.read_excel(r'C:\Users\stani\Desktop\Webapp\st_zagora\data_for_python2.xlsx') 
df = pd.DataFrame(data)
df['year'] = pd.DatetimeIndex(df['data']).year
#print(df['year'].unique())
#year_t = df['year']




choice_value=[2019, 2021]

#returnMatches=list(set(choice_value).intersection(set(year))))

#lista =set(choice_value)
#listb =set(year)   
#returnMatches=listb.intersection(lista)   
#print " ".join(str(return) for return in returnMatches ) # remove the set()   
#print(returnMatches)
#set_year = list(returnMatches)

#for i in range(0, len(set_year)):
 #   set_year[i] = int(set_year[i])

#print(type(set_year))
#print(df['year'])



#df[df['year'].isin([2019, 2021])]
df1=df[df['year'].isin(choice_value)]
year_float=df1['year'].unique()
year=list(map(str,year_float))

percent_profit = (round(df1.groupby(df1.data.dt.year)['profit_mount'].sum()/df1.groupby(df1.data.dt.year)['total_income'].sum()*100))
#print(percent_profit)


plt.xlabel("Year")
plt.ylabel("Percent")
plt.title("Year profit in percent")

#for index, value in enumerate(percent_profit):
 #   plt.text(value, index,
  #           str(value))

plt.bar(year, percent_profit) 

