def calculate(self): try: self.client = float(self.client_line_edit.text()) self.client_delta = float(self.client_delta_line_edit.text()) self.op1_m = float(self.op1_m_line_edit.text()) self.op1_delta = float(self.op1_delta_line_edit.text()) self.op2_m = float(self.op2_m_line_edit.text()) self.op2_delta = float(self.op2_delta_line_edit.text()) self.op3_m = float(self.op3_m_line_edit.text()) self.op3_delta = float(self.op3_delta_line_edit.text()) self.comp1 = float(self.comp1_m_line_edit.text()) self.comp2 = float(self.comp2_m_line_edit.text()) self.dt = float(self.dt_line_edit.text()) self.n = int(self.n_line_edit.text()) except ValueError as exc: print(exc) return self.system = system.System( client_law=UniformDistributionLaw(a=self.client-self.client_delta, b=self.client+self.client_delta), op1_law=UniformDistributionLaw(a=self.op1_m-self.op1_delta, b=self.op1_m+self.op1_delta), op2_law=UniformDistributionLaw(a=self.op2_m-self.op2_delta, b=self.op2_m+self.op2_delta), op3_law=UniformDistributionLaw(a=self.op3_m-self.op3_delta, b=self.op3_m+self.op3_delta), comp1_law=ConstantDistributionLaw(c=self.comp1), comp2_law=ConstantDistributionLaw(c=self.comp2), n=self.n, dt=self.dt, method=self.method ) result = self.system.calculate() self.generated_count_line_edit.setText(str(result['generated_count'])) self.processed_count_line_edit.setText(str(result['processed_count'])) self.rejected_count_line_edit.setText(str(result['rejected_count'])) self.rejected_probability_line_edit.setText(str(round(result['rejected_count'] / (result['generated_count'] + result['rejected_count']), 4)))
def __init__(self): self.qapp = QApplication([]) super().__init__() self.setFixedSize(700, 800) self.move(100, 10) self.setWindowTitle( 'Лабораторная работа №1 по моделированию, вариант №14. ' 'Шилов ИУ7-72' ) self.uniform_label = QLabel('Равномерное\nраспределение', self) self.uniform_label.setFixedSize(200, 100) self.uniform_label.move(100, 100) self.a = -1 self.a_label = QLabel('a =', self) self.a_label.setFixedSize(100, 100) self.a_label.move(100, 200) self.a_line_edit = QLineEdit(str(self.a), self) self.a_line_edit.setFixedSize(100, 100) self.a_line_edit.move(200, 200) self.b = 1 self.b_label = QLabel('b =', self) self.b_label.setFixedSize(100, 100) self.b_label.move(100, 300) self.b_line_edit = QLineEdit(str(self.b), self) self.b_line_edit.setFixedSize(100, 100) self.b_line_edit.move(200, 300) self.uniform_n = 100 self.uniform_n_label = QLabel('n =', self) self.uniform_n_label.setFixedSize(100, 100) self.uniform_n_label.move(100, 400) self.uniform_n_line_edit = QLineEdit(str(self.uniform_n), self) self.uniform_n_line_edit.setFixedSize(100, 100) self.uniform_n_line_edit.move(200, 400) self.normal_label = QLabel('Нормальное\nраспределение', self) self.normal_label.setFixedSize(200, 100) self.normal_label.move(400, 100) self.nu = 0 self.nu_label = QLabel('nu =', self) self.nu_label.setFixedSize(100, 100) self.nu_label.move(400, 200) self.nu_line_edit = QLineEdit(str(self.nu), self) self.nu_line_edit.setFixedSize(100, 100) self.nu_line_edit.move(500, 200) self.sigma = 1 self.sigma_label = QLabel('sigma =', self) self.sigma_label.setFixedSize(100, 100) self.sigma_label.move(400, 300) self.sigma_line_edit = QLineEdit(str(self.sigma), self) self.sigma_line_edit.setFixedSize(100, 100) self.sigma_line_edit.move(500, 300) self.normal_n = 100 self.normal_n_label = QLabel('n =', self) self.normal_n_label.setFixedSize(100, 100) self.normal_n_label.move(400, 400) self.normal_n_line_edit = QLineEdit(str(self.normal_n), self) self.normal_n_line_edit.setFixedSize(100, 100) self.normal_n_line_edit.move(500, 400) self.uniform_distribution_law = UniformDistributionLaw( a=self.a, b=self.b ) self.normal_distribution_law = NormalDistributionLaw( nu=self.nu, sigma=self.sigma ) self.button = QPushButton('Провести рассчет', self) self.button.setFixedSize(500, 100) self.button.clicked.connect(self.calculate) self.button.move(100, 600)
class View(QMainWindow): def __init__(self): self.qapp = QApplication([]) super().__init__() self.setFixedSize(700, 800) self.move(100, 10) self.setWindowTitle( 'Лабораторная работа №1 по моделированию, вариант №14. ' 'Шилов ИУ7-72' ) self.uniform_label = QLabel('Равномерное\nраспределение', self) self.uniform_label.setFixedSize(200, 100) self.uniform_label.move(100, 100) self.a = -1 self.a_label = QLabel('a =', self) self.a_label.setFixedSize(100, 100) self.a_label.move(100, 200) self.a_line_edit = QLineEdit(str(self.a), self) self.a_line_edit.setFixedSize(100, 100) self.a_line_edit.move(200, 200) self.b = 1 self.b_label = QLabel('b =', self) self.b_label.setFixedSize(100, 100) self.b_label.move(100, 300) self.b_line_edit = QLineEdit(str(self.b), self) self.b_line_edit.setFixedSize(100, 100) self.b_line_edit.move(200, 300) self.uniform_n = 100 self.uniform_n_label = QLabel('n =', self) self.uniform_n_label.setFixedSize(100, 100) self.uniform_n_label.move(100, 400) self.uniform_n_line_edit = QLineEdit(str(self.uniform_n), self) self.uniform_n_line_edit.setFixedSize(100, 100) self.uniform_n_line_edit.move(200, 400) self.normal_label = QLabel('Нормальное\nраспределение', self) self.normal_label.setFixedSize(200, 100) self.normal_label.move(400, 100) self.nu = 0 self.nu_label = QLabel('nu =', self) self.nu_label.setFixedSize(100, 100) self.nu_label.move(400, 200) self.nu_line_edit = QLineEdit(str(self.nu), self) self.nu_line_edit.setFixedSize(100, 100) self.nu_line_edit.move(500, 200) self.sigma = 1 self.sigma_label = QLabel('sigma =', self) self.sigma_label.setFixedSize(100, 100) self.sigma_label.move(400, 300) self.sigma_line_edit = QLineEdit(str(self.sigma), self) self.sigma_line_edit.setFixedSize(100, 100) self.sigma_line_edit.move(500, 300) self.normal_n = 100 self.normal_n_label = QLabel('n =', self) self.normal_n_label.setFixedSize(100, 100) self.normal_n_label.move(400, 400) self.normal_n_line_edit = QLineEdit(str(self.normal_n), self) self.normal_n_line_edit.setFixedSize(100, 100) self.normal_n_line_edit.move(500, 400) self.uniform_distribution_law = UniformDistributionLaw( a=self.a, b=self.b ) self.normal_distribution_law = NormalDistributionLaw( nu=self.nu, sigma=self.sigma ) self.button = QPushButton('Провести рассчет', self) self.button.setFixedSize(500, 100) self.button.clicked.connect(self.calculate) self.button.move(100, 600) def start_application(self): self.update() self.show() self.qapp.exec_() def get_input(self): try: self.a = float(self.a_line_edit.text()) self.b = float(self.b_line_edit.text()) self.uniform_n = int(self.uniform_n_line_edit.text()) self.nu = float(self.nu_line_edit.text()) self.sigma = float(self.sigma_line_edit.text()) self.normal_n = int(self.normal_n_line_edit.text()) except ValueError: return 'Неверный формат входных данных' if ( self.b <= self.a or not (10 <= self.uniform_n <= 10000) or self.sigma <= 0 or not (10 <= self.normal_n <= 10000) ): return 'Нарушены ограничения на входные данные' def calculate(self): error = self.get_input() if error: return self.uniform_distribution_law = UniformDistributionLaw( a=self.a, b=self.b ) self.normal_distribution_law = NormalDistributionLaw( nu=self.nu, sigma=self.sigma ) plt.subplot(221) plt.plot( self.uniform_distribution_law.x_list, self.uniform_distribution_law.F_list ) uniform_sample = self.uniform_distribution_law.sample(self.uniform_n) plt.plot( ( [self.uniform_distribution_law.left_border] + uniform_sample + [self.uniform_distribution_law.right_border] ), ( [i / self.uniform_n for i in range(self.uniform_n + 1)] + [1] ) ) plt.grid(True) plt.title('Равномерное распределение') plt.xlabel('x') plt.ylabel('F(x)') plt.subplot(222) plt.plot( self.normal_distribution_law.x_list, self.normal_distribution_law.F_list ) normal_sample = self.normal_distribution_law.sample(self.normal_n) plt.plot( ( [self.normal_distribution_law.left_border] + normal_sample + [self.normal_distribution_law.right_border] ), ( [i / self.normal_n for i in range(self.normal_n + 1)] + [1] ) ) plt.grid(True) plt.title('Нормальное распределение') plt.xlabel('x') plt.subplot(223) plt.plot( self.uniform_distribution_law.x_list, self.uniform_distribution_law.f_list, ) plt.hist(uniform_sample, hist_steps(uniform_sample), density=True, alpha=0.5) plt.grid(True) plt.xlabel('x') plt.ylabel('f(x)') plt.subplot(224) plt.plot( self.normal_distribution_law.x_list, self.normal_distribution_law.f_list, ) plt.hist(normal_sample, hist_steps(normal_sample), density=True, alpha=0.5) plt.grid(True) plt.xlabel('x') plt.show()
def calculate(self): error = self.get_input() if error: return self.uniform_distribution_law = UniformDistributionLaw( a=self.a, b=self.b ) self.normal_distribution_law = NormalDistributionLaw( nu=self.nu, sigma=self.sigma ) plt.subplot(221) plt.plot( self.uniform_distribution_law.x_list, self.uniform_distribution_law.F_list ) uniform_sample = self.uniform_distribution_law.sample(self.uniform_n) plt.plot( ( [self.uniform_distribution_law.left_border] + uniform_sample + [self.uniform_distribution_law.right_border] ), ( [i / self.uniform_n for i in range(self.uniform_n + 1)] + [1] ) ) plt.grid(True) plt.title('Равномерное распределение') plt.xlabel('x') plt.ylabel('F(x)') plt.subplot(222) plt.plot( self.normal_distribution_law.x_list, self.normal_distribution_law.F_list ) normal_sample = self.normal_distribution_law.sample(self.normal_n) plt.plot( ( [self.normal_distribution_law.left_border] + normal_sample + [self.normal_distribution_law.right_border] ), ( [i / self.normal_n for i in range(self.normal_n + 1)] + [1] ) ) plt.grid(True) plt.title('Нормальное распределение') plt.xlabel('x') plt.subplot(223) plt.plot( self.uniform_distribution_law.x_list, self.uniform_distribution_law.f_list, ) plt.hist(uniform_sample, hist_steps(uniform_sample), density=True, alpha=0.5) plt.grid(True) plt.xlabel('x') plt.ylabel('f(x)') plt.subplot(224) plt.plot( self.normal_distribution_law.x_list, self.normal_distribution_law.f_list, ) plt.hist(normal_sample, hist_steps(normal_sample), density=True, alpha=0.5) plt.grid(True) plt.xlabel('x') plt.show()
def __init__(self): self.qapp = QApplication([]) super().__init__() self.setFixedSize(1080, 700) self.move(100, 10) self.setWindowTitle( 'Лабораторная работа №5 по моделированию.' 'Жарова ИУ7-73Б' ) self.normal_label = QLabel('Параметры\nклиентов', self) self.normal_label.setFixedSize(300, 50) self.normal_label.move(50, 50) self.client = 10 self.client_label = QLabel('average =', self) self.client_label.setFixedSize(100, 50) self.client_label.move(50, 100) self.client_line_edit = QLineEdit(str(self.client), self) self.client_line_edit.setFixedSize(100, 50) self.client_line_edit.move(120, 100) self.client_delta = 2 self.client_delta_label = QLabel(' +-', self) self.client_delta_label.setFixedSize(100, 50) self.client_delta_label.move(220, 100) self.client_delta_line_edit = QLineEdit(str(self.client_delta), self) self.client_delta_line_edit.setFixedSize(100, 50) self.client_delta_line_edit.move(250, 100) self.op_label = QLabel('Параметры\nоператоров', self) self.op_label.setFixedSize(300, 100) self.op_label.move(380, 20) self.op1_m = 20 self.op1_m_label = QLabel('average1 =', self) self.op1_m_label.setFixedSize(100, 50) self.op1_m_label.move(380, 100) self.op1_m_line_edit = QLineEdit(str(self.op1_m), self) self.op1_m_line_edit.setFixedSize(100, 50) self.op1_m_line_edit.move(460, 100) self.op1_delta = 5 self.op1_delta_label = QLabel(' +-', self) self.op1_delta_label.setFixedSize(100, 50) self.op1_delta_label.move(560, 100) self.op1_delta_line_edit = QLineEdit(str(self.op1_delta), self) self.op1_delta_line_edit.setFixedSize(100, 50) self.op1_delta_line_edit.move(590, 100) self.op2_m = 40 self.op2_m_label = QLabel('average2 =', self) self.op2_m_label.setFixedSize(100, 50) self.op2_m_label.move(380, 160) self.op2_m_line_edit = QLineEdit(str(self.op2_m), self) self.op2_m_line_edit.setFixedSize(100, 50) self.op2_m_line_edit.move(460, 160) self.op2_delta = 10 self.op2_delta_label = QLabel(' +-', self) self.op2_delta_label.setFixedSize(100, 50) self.op2_delta_label.move(560, 160) self.op2_delta_line_edit = QLineEdit(str(self.op2_delta), self) self.op2_delta_line_edit.setFixedSize(100, 50) self.op2_delta_line_edit.move(590, 160) self.op3_m = 40 self.op3_m_label = QLabel('average3 =', self) self.op3_m_label.setFixedSize(100, 50) self.op3_m_label.move(380, 220) self.op3_m_line_edit = QLineEdit(str(self.op3_m), self) self.op3_m_line_edit.setFixedSize(100, 50) self.op3_m_line_edit.move(460, 220) self.op3_delta = 20 self.op3_delta_label = QLabel(' +-', self) self.op3_delta_label.setFixedSize(100, 50) self.op3_delta_label.move(560, 220) self.op3_delta_line_edit = QLineEdit(str(self.op3_delta), self) self.op3_delta_line_edit.setFixedSize(100, 50) self.op3_delta_line_edit.move(590, 220) self.comp_label = QLabel('Параметры\nкомпьютеров', self) self.comp_label.setFixedSize(300, 100) self.comp_label.move(720, 20) self.comp1 = 15 self.comp1_label = QLabel('const1 =', self) self.comp1_label.setFixedSize(100, 50) self.comp1_label.move(720, 100) self.comp1_m_line_edit = QLineEdit(str(self.comp1), self) self.comp1_m_line_edit.setFixedSize(100, 50) self.comp1_m_line_edit.move(785, 100) self.comp2 = 30 self.comp2_label = QLabel('const2 =', self) self.comp2_label.setFixedSize(100, 50) self.comp2_label.move(720, 160) self.comp2_m_line_edit = QLineEdit(str(self.comp2), self) self.comp2_m_line_edit.setFixedSize(100, 50) self.comp2_m_line_edit.move(785, 160) self.method_label = QLabel('Метод рассчета', self) self.method_label.setFixedSize(200, 100) self.method_label.move(920, 14) self.method_box = QComboBox(self) self.method_box.addItems(['delta t', 'events']) self.method_box.setFixedSize(140, 60) self.method_box.move(920, 90) self.method_box.currentTextChanged.connect(self.select_method) self.dt = 0.01 self.dt_label = QLabel('dt =', self) self.dt_label.setFixedSize(200, 100) self.dt_label.move(920, 135) self.dt_line_edit = QLineEdit(str(self.dt), self) self.dt_line_edit.setFixedSize(100, 50) self.dt_line_edit.move(960, 160) self.select_method() self.n = 300 self.n_label = QLabel('Обработать \nзаявок (n) = ', self) self.n_label.setFixedSize(100, 50) self.n_label.move(50, 200) self.n_line_edit = QLineEdit(str(self.n), self) self.n_line_edit.setFixedSize(100, 50) self.n_line_edit.move(140, 200) self.system = system.System( client_law=UniformDistributionLaw(a=8, b=12), op1_law=UniformDistributionLaw(a=15, b=25), op2_law=UniformDistributionLaw(a=30, b=50), op3_law=UniformDistributionLaw(a=20, b=60), comp1_law=ConstantDistributionLaw(c=15), comp2_law=ConstantDistributionLaw(c=30), n=self.n, dt=1, method='delta t' ) result = self.system.calculate() self.button = QPushButton('Провести рассчет', self) self.button.setFixedSize(500, 100) self.button.clicked.connect(self.calculate) self.button.move(100, 500) self.result_label = QLabel('Результаты рассчета', self) self.result_label.setFixedSize(200, 100) self.result_label.move(760, 280) self.generated_count_label = QLabel('Количество\nобработанных заявок =', self) self.generated_count_label.setFixedSize(300, 50) self.generated_count_label.move(720, 420) #self.generated_count_label.hide() self.generated_count_line_edit = QLineEdit(str(result['generated_count']), self) self.generated_count_line_edit.setFixedSize(100, 50) self.generated_count_line_edit.move(880, 420) #self.generated_count_line_edit.hide() self.processed_count_label = QLabel('Количество\nобработанных заявок =', self) self.processed_count_label.setFixedSize(300, 50) self.processed_count_label.move(720, 420) self.processed_count_label.hide() self.processed_count_line_edit = QLineEdit(str(result['processed_count']), self) self.processed_count_line_edit.setFixedSize(100, 50) self.processed_count_line_edit.move(880, 420) self.processed_count_line_edit.hide() self.rejected_count_label = QLabel('Количество\nпропущенных заявок =', self) self.rejected_count_label.setFixedSize(300, 50) self.rejected_count_label.move(720, 480) self.rejected_count_line_edit = QLineEdit(str(result['rejected_count']), self) self.rejected_count_line_edit.setFixedSize(100, 50) self.rejected_count_line_edit.move(880, 480) self.rejected_probability_label = QLabel('Вероятность\nотказа =', self) self.rejected_probability_label.setFixedSize(300, 50) self.rejected_probability_label.move(720, 540) self.rejected_probability_line_edit = QLineEdit(str(round(result['rejected_count'] / (result['generated_count'] + result['rejected_count']), 4)), self) self.rejected_probability_line_edit.setFixedSize(100, 50) self.rejected_probability_line_edit.move(880, 540)