import csv
import numpy as np
import matplotlib.pyplot as plt
from copy import deepcopy


integralni_metoda_katal_pn10 = ['integralni_metoda_katal_pn10.csv']



with open(integralni_metoda_katal_pn10[-1],'rb') as csvsoubor:
    cteni_radku = csv.reader(csvsoubor, delimiter=';')
    pocet_radku_katal_pn10 = 0
    for radky in cteni_radku:
        pocet_radku_katal_pn10 += 1



with open(integralni_metoda_katal_pn10[-1],'rb') as csvsoubor:
    cteni_radku = csv.reader(csvsoubor, delimiter=';')
    _cteni_radku = list(cteni_radku)
    nazvy_promennych = _cteni_radku[0]
    nazvy_jednotek = _cteni_radku[1]



nazev_osy_x = 'B'
nazev_osy_y = 'sigmaTHETA_provoz'
nazev_osy_y1 = 'sigmaTHETA_montaz'
nazev_osy_y2 = 'sigmar_provoz'
nazev_osy_y3 = 'sigmaH_provoz'

sloupec_promenna_x = 0
for promenne in nazvy_promennych:
    if promenne == nazev_osy_x:
        break
    else:
        sloupec_promenna_x += 1

sloupec_promenna_y = 0
for promenne in nazvy_promennych:
    if promenne == nazev_osy_y:
        break
    else:
        sloupec_promenna_y += 1

sloupec_promenna_y1 = 0
for promenne in nazvy_promennych:
    if promenne == nazev_osy_y1:
        break
    else:
        sloupec_promenna_y1 += 1

sloupec_promenna_y2 = 0
for promenne in nazvy_promennych:
    if promenne == nazev_osy_y2:
        break
    else:
        sloupec_promenna_y2 += 1

sloupec_promenna_y3 = 0
for promenne in nazvy_promennych:
    if promenne == nazev_osy_y3:
        break
    else:
        sloupec_promenna_y3 += 1



hodnoty_x_integral_katal_pn10 = []
hodnoty_y_integral_katal_pn10 = []
hodnoty_y1_integral_katal_pn10 = []
hodnoty_y2_integral_katal_pn10 = []
hodnoty_y3_integral_katal_pn10 = []


with open(integralni_metoda_katal_pn10[-1],'rb') as csvsoubor:
    cteni_radku = csv.reader(csvsoubor, delimiter=';')
    for radky in cteni_radku:
        hodnoty_x_integral_katal_pn10.append(radky[sloupec_promenna_x])
        hodnoty_y_integral_katal_pn10.append(radky[sloupec_promenna_y])
        hodnoty_y1_integral_katal_pn10.append(radky[sloupec_promenna_y1])
        hodnoty_y2_integral_katal_pn10.append(radky[sloupec_promenna_y2])
        hodnoty_y3_integral_katal_pn10.append(radky[sloupec_promenna_y3])


fig, ax = plt.subplots(figsize=(15,8))

ax.plot(hodnoty_x_integral_katal_pn10[2:-1], hodnoty_y_integral_katal_pn10[2:-1], 'o-', label='$\sigma_\Theta$ $-$ $provoz$')
ax.plot(hodnoty_x_integral_katal_pn10[2:-1], hodnoty_y1_integral_katal_pn10[2:-1], 'o-', label='$\sigma_\Theta$ $-$ $montaz$')
ax.plot(hodnoty_x_integral_katal_pn10[2:-1], hodnoty_y3_integral_katal_pn10[2:-1], 'o-', label='$\sigma_H$ $-$ $provoz$')
ax.plot(hodnoty_x_integral_katal_pn10[2:-1], hodnoty_y2_integral_katal_pn10[2:-1], 'o:', label='$\sigma_r$ $-$ $provoz$')


ax.grid()
minimum = min(hodnoty_y_integral_katal_pn10,hodnoty_y1_integral_katal_pn10,hodnoty_y2_integral_katal_pn10,hodnoty_y3_integral_katal_pn10)
maximum = max(hodnoty_y_integral_katal_pn10,hodnoty_y1_integral_katal_pn10,hodnoty_y2_integral_katal_pn10,hodnoty_y3_integral_katal_pn10)
ax.set_ylim(-50.,450.)
ax.set_xlabel('$B [mm]$', fontsize=20)
ax.set_ylabel('$\sigma_\Theta, \sigma_r, \sigma_H $ $[MPa]$', fontsize=20)
ax.legend(loc='upper left', shadow=False)
plt.title('CSN EN 13445 (PN10)', fontsize=20)
plt.savefig('zavislost_'+nazev_osy_x+'_na_'+nazev_osy_y+'.png',dpi=400)
plt.show()
