from shutil import copyfile

from PyQt5.QtWidgets import QDialog
import xlrd

import image_mark
from Check_result import Ui_Dialog_Check
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
from PyQt5.QtGui import *

right_list = []
wrong_list = []
last_list = []
img_url = ''


class Check_logic(QDialog, Ui_Dialog_Check):
    def __init__(self, parent=None):
        super(Check_logic, self).__init__(parent)

    def inti_infor(self, a, b, c, url, filepath, hang):
        self.setupUi(self)
        rb = xlrd.open_workbook(filepath)
        st = rb.sheet_by_index(0)
        sf = rb.sheet_by_index(1)
        result_url = st.cell_value(1, 6) + '\\' + st.cell_value(1, 0) + '_' + str(hang) + '_Compared.jpg'
        result_url_js = st.cell_value(1, 6) + '\\' + st.cell_value(1, 0) + '_' + str(hang) + '_js.jpg'

        sz = st.cell_value(1, 5)
        self.description.setText(st.cell_value(1, 0) + '目视机视对比')
        hang = int(hang)
        self.description_3.setText('准确率:' + str(round(float(sf.cell_value(hang, 8)) * 100, 3)) +
                                   '%   误判率:' + str(round(float(sf.cell_value(hang, 9)) * 100, 3)) +
                                   '%   漏判率:' + str(round(float(sf.cell_value(hang, 10)) * 100, 3)) +
                                   '%   匹配率:' + str(round(float(sf.cell_value(hang, 11)) * 100, 3)) + '%')
        # self.description_2.setText(" ○ 为正确标记，╳ 为误判标记，■ 为漏判标记")
        global right_list, wrong_list, last_list, img_url
        right_list = eval(a)
        wrong_list = eval(b)
        last_list = eval(c)
        img_url = url
        image_mark.Image_mark.mark_function_2(right_list, wrong_list, last_list, img_url, result_url_js,sz)
        print(img_url)
        copyfile('D:/66.jpg', result_url)
        tp = QPixmap('D:/66.jpg')
        # if tp.height() * 651 / tp.width() < 1021:
        if tp.height() * 1021 / tp.width() < 651:
            self.img__.setPixmap(tp.scaled(self.img__.width(), tp.height() * self.img__.width() / tp.width()))
        else:
            self.img__.setPixmap(tp.scaled(tp.width() * self.img__.height() / tp.height(), self.img__.height()))
            self.img__.move((1021 - (tp.width() * self.img__.height() / tp.height())) / 2 + 40, 120)
