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


merkblatt_katal_pn16 = ['merkblatt_katal_pn16.csv']



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



with open(merkblatt_katal_pn16[-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 = 'di'
nazev_osy_y = 'hF_provozBB'
nazev_osy_y1 = 'hF_montazBB'
nazev_osy_y3 = 'hF_provozAA'
nazev_osy_y4 = 'hF_montazAA'
nazev_osy_y2 = 'hF'

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

sloupec_promenna_y4 = 0
for promenne in nazvy_promennych:
    if promenne == nazev_osy_y4:
        break
    else:
        sloupec_promenna_y4 += 1

hodnoty_x_merkblatt_katal_pn16 = []
hodnoty_y_merkblatt_katal_pn16 = []
hodnoty_y1_merkblatt_katal_pn16 = []
hodnoty_y2_merkblatt_katal_pn16 = []
hodnoty_y3_merkblatt_katal_pn16 = []
hodnoty_y4_merkblatt_katal_pn16 = []

with open(merkblatt_katal_pn16[-1],'rb') as csvsoubor:
    cteni_radku = csv.reader(csvsoubor, delimiter=';')
    for radky in cteni_radku:
        hodnoty_x_merkblatt_katal_pn16.append(radky[sloupec_promenna_x])
        hodnoty_y_merkblatt_katal_pn16.append(radky[sloupec_promenna_y])
        hodnoty_y1_merkblatt_katal_pn16.append(radky[sloupec_promenna_y1])
        hodnoty_y2_merkblatt_katal_pn16.append(radky[sloupec_promenna_y2])
        hodnoty_y3_merkblatt_katal_pn16.append(radky[sloupec_promenna_y3])
        hodnoty_y4_merkblatt_katal_pn16.append(radky[sloupec_promenna_y4])



fig, ax = plt.subplots(figsize=(15,8))
ax.plot(hodnoty_x_merkblatt_katal_pn16[2:-1], hodnoty_y3_merkblatt_katal_pn16[2:-1], 'o-', label='$h_F,provoz(A-A)$')
ax.plot(hodnoty_x_merkblatt_katal_pn16[2:-1], hodnoty_y4_merkblatt_katal_pn16[2:-1], 'o-', label='$h_F,montaz(A-A)$')
ax.plot(hodnoty_x_merkblatt_katal_pn16[2:-1], hodnoty_y_merkblatt_katal_pn16[2:-1], 'o-', label='$h_F,provoz(B-B)$')
ax.plot(hodnoty_x_merkblatt_katal_pn16[2:-1], hodnoty_y1_merkblatt_katal_pn16[2:-1], 'o-', label='$h_F,montaz(B-B)$')
ax.plot(hodnoty_x_merkblatt_katal_pn16[2:-1], hodnoty_y2_merkblatt_katal_pn16[2:-1], 'o-', label='$h_F$')
ax.grid()

ax.set_xlabel('$d_i [mm]$', fontsize=20)
ax.set_ylabel('$h_F $ $[mm]$', fontsize=20)
ax.legend(loc='upper left', shadow=False)
plt.title('Merkblatt (PN16)', fontsize=20)
plt.savefig('zavislost_'+nazev_osy_x+'_na_'+nazev_osy_y+'.png',dpi=300)
plt.show()
