def get_analysis_data(self, index, analyse_type): from utils.database_utils import DatabaseConnect db = DatabaseConnect() analysis_dict = db.get_index_analysis(index=index, analyse_type=analyse_type, window=self.temp_window) return analysis_dict
def btn_analyse_clicked(self): self.statusbar.showMessage("Analysing " + self.selected_timeseries + "...") from utils.database_utils import DatabaseConnect db = DatabaseConnect() self.time_series_data = db.get_timeseries_details( timeseries_id=self.selected_timeseriesId, window=self.temp_window) self.analysed_data = [] if "source_file" in self.time_series_data.keys( ) and self.time_series_data["source_file"]: import os if os.path.exists(self.time_series_data["source_file"]): for index in range(1, 11): self.create_graph( source_file=self.time_series_data["source_file"], time_series_type=self.time_series_data["file_type"], index=index) self.show_graph(show=True) self.statusbar.showMessage("", 1) else: QtWidgets.QMessageBox.about(self.temp_window, "Info", "Invalid source file !!!") else: QtWidgets.QMessageBox.about(self.temp_window, "Info", "No source file found !!!")
def get_products(self): """ Get the list of all products in the database :return: products_list """ from utils.database_utils import DatabaseConnect db = DatabaseConnect() self.products_list, self.productId_list = db.get_products(window=self.temp_window) return self.products_list
def get_questions(self): """ GET ALL THE QUESTIONS FROM DATABASE :return: questions """ from utils.database_utils import DatabaseConnect db = DatabaseConnect() questions = db.get_all_questions(window=self.temp_window) return questions
def get_models(self): """ Get the list of all models in the database :return: models_list """ from utils.database_utils import DatabaseConnect db = DatabaseConnect() self.models_list, self.modelId_list = db.get_models( window=self.temp_window) return self.models_list
def delete_model_byId(self, id): """ Delete the models from the database on the basis of id :param id: :return: status i.e, Model deleted or not """ from utils.database_utils import DatabaseConnect db = DatabaseConnect() result = db.delete_model(id, window=self.temp_window) return result
def get_model_details(self, id): """ get details of the Time series from the database. :return: string, dictionary """ from utils.database_utils import DatabaseConnect db = DatabaseConnect() model_string, self.model_detail_dict = db.get_model_details( id, window=self.temp_window) return model_string, self.model_detail_dict
def delete_timeseries(self, id): """ Calls a function delete_timeseries from database_util.py class to delete the Time series. :param id: :return: """ from utils.database_utils import DatabaseConnect db = DatabaseConnect() deleted = db.delete_timeseries(id=id, window=self.temp_window) return deleted
def get_timeseries_details(self): """ Get details of the Time series from the database. :return: timeseries_info """ from utils.database_utils import DatabaseConnect db = DatabaseConnect() self.timeseries_info = db.get_timeseries_details( self.selected_timeseriesId, window=self.temp_window) return self.timeseries_info
def auth_user(self, un, password): """ Matches the username and password in the database and returns the response as the user is authorised or not :param un: :param password: :return: """ from utils.database_utils import DatabaseConnect db = DatabaseConnect() return db.auth_user(un, password)
def get_product_details(self, id): """ Get the details of the Product from the database on the basis of provided id :param id: :return: string, dictionary """ from utils.database_utils import DatabaseConnect db = DatabaseConnect() product_string, self.product_detail_dict = db.get_product_details(id, window=self.temp_window) return product_string, self.product_detail_dict
def create_evaluation(self, attachment_one, attachment_two): """ Save gthe evaluation with attachment paths in the database :param attachment_one: :param attachment_two: :return: """ from utils.database_utils import DatabaseConnect conn = DatabaseConnect() self.evaluation_id = conn.create_evaluation(self.selected_productId, attachment_one, attachment_two, window=self.temp_window)
def save_answers(self, question, answer, dimension): """ Save the answers of the evaluation in the database :param question: :param answer: :param dimension: :return: """ from utils.database_utils import DatabaseConnect conn = DatabaseConnect() conn.save_answers(answer=answer, question=question, dimension=dimension, evaluation_id=self.evaluation_id, window=self.temp_window)
def delete_product_byId(self, id): """ Delete the products from the database on the basis of id :param id: :return: status i.e, Product deleted or not """ from utils.database_utils import DatabaseConnect db = DatabaseConnect() status = db.delete_product(id) if not status: QtWidgets.QMessageBox.about(self.temp_window, "Warning", "Database Error !!!") return status
def get_users(self): """ This function returns the list of all users in the database :return: """ from utils.database_utils import DatabaseConnect db = DatabaseConnect() user_list = db.get_users() if type(user_list) == bool: QtWidgets.QMessageBox.about(self.temp_window, "Warning", "Database Error !!!") return [] return user_list
def timeseries_list_view(self): from utils.database_utils import DatabaseConnect db = DatabaseConnect() self.timeseries_list, self.timeseriesId_list = db.get_timeserieses( window=self.temp_window) self.timeseries_listWidget = QtWidgets.QListWidget() index = 0 for item in self.timeseriesId_list: listitem = QtWidgets.QListWidgetItem() listitem.setText(self.timeseries_list[index]) listitem.setData(1, item) index += 1 self.timeseries_listWidget.addItem(listitem) self.timeseries_listWidget.currentItemChanged.connect( self.timeseries_list_item_event) self.scrollArea_timeseries.setWidget(self.timeseries_listWidget)
def update_product(self): """ Updates the product record in the database. :return: """ from utils.database_utils import DatabaseConnect conn = DatabaseConnect() name = self.txt_name.text() code = self.txt_code.text() categorya = self.combo_category_A.currentText() categoryb = self.combo_category_B.currentText() info1 = self.txt_info1.text() info2 = self.txt_info_2.text() info3 = self.txt_info_3.text() info4 = self.txt_info_4.text() info5 = self.txt_info_5.text() info6 = self.txt_info_6.text() info7 = self.txt_info_7.toPlainText() id = self.product_id if name and code: updated = conn.update_product_record(id=id, name=name, code=code, categorya=categorya, categoryb=categoryb, info1=info1, info2=info2, info3=info3, info4=info4, info5=info5, info6=info6, info7=info7) if updated: self.temp_window.parent_win.ui.get_products() self.temp_window.parent_win.ui.load_products_list() self.temp_window.parent_win.ui.txt_overview.clear() QMessageBox.about(self.temp_window, "info", "Product is updated Successfully !!!") return True else: QMessageBox.about(self.temp_window, "Warning", "Database Error !!!") return False else: QMessageBox.about(self.temp_window, "warning", "name and code field is mendetory !!!") return False
def load_record(self): tabs = self.tab.children()[0].children() from utils.database_utils import DatabaseConnect db = DatabaseConnect() answer_list = db.get_answers_by_evaluation(self.selected_productId) attachments = db.get_attachments(window=self.temp_window, product_id=self.selected_productId) if attachments: if attachments["attachment_one"] and attachments["attachment_one"] != 'None' and attachments["attachment_one"] != "": self.attachment1_path = attachments["attachment_one"] file_path = self.attachment1_path self.btn_attachment1.setText(file_path.split("/")[-1][:10]+"..") self.btn_attachment1.setAutoFillBackground(True) self.btn_attachment1.clicked.disconnect(self.btn_attachment1_clicked) self.btn_attachment1.clicked.connect(self.show_attachment1) self.btn_attachment1.show() self.btn_attachment1.installEventFilter(self.temp_window) if attachments["attachment_two"] and attachments["attachment_two"] != 'None' and attachments["attachment_two"] != "": self.attachment2_path = attachments["attachment_two"] file_path = self.attachment2_path self.btn_attachment2.setAutoFillBackground(True) self.btn_attachment2.setText(file_path.split("/")[-1][:10]+"..") self.btn_attachment2.show() self.btn_attachment2.clicked.disconnect(self.btn_attachment2_clicked) self.btn_attachment2.clicked.connect(self.show_attachment2) self.btn_attachment2.installEventFilter(self.temp_window) for tab in tabs: if tab and "tab_" in tab.objectName() and tab.objectName() != "tab_overview": tab_name = str(tab.objectName()) dimension = int((tab_name).replace("tab_", "")) for quesbox in tab.children(): for d in answer_list: if d["question"] == quesbox.title() and d["dimension"] == dimension: final_answer = str(d["answer"]) for option in quesbox.children()[1:]: if str(option.text()) == str(final_answer): option.setChecked(True) quesbox.setDisabled(True) self.btn_reset.setDisabled(True) self.btn_save.setDisabled(True) self.btn_return.setDisabled(True)
def get_scores(product_id): """ Calculate the score of all dimensions :param product_id: :return: Dictionary containing the dimention as a key and score as a value. """ from utils.database_utils import DatabaseConnect db = DatabaseConnect() dimension_scores = {} answers = db.get_answers_by_evaluation( product_id) # Get all the answers of an evaluation if answers: formatted_answers = format_answer_to_get_score(answers) for dimension, answers in formatted_answers.items(): d_score = get_dimension_score(answers) dimension_scores.update({dimension: d_score}) return dimension_scores
def models_list_view(self): """ add the models into the list widget of the window """ from utils.database_utils import DatabaseConnect db = DatabaseConnect() self.models_list, self.modelId_list = db.get_models( window=self.temp_window) self.listWidget_model.clear() index = 0 for item in self.modelId_list: listitem = QtWidgets.QListWidgetItem() listitem.setText(self.models_list[index]) listitem.setData(1, item) index += 1 self.listWidget_model.addItem(listitem) self.listWidget_model.itemClicked.connect(self.model_list_item_event)
def timeseries_list_view(self): """ creates the items of list widget to display the list of Time-series on the window """ from utils.database_utils import DatabaseConnect db = DatabaseConnect() self.timeseries_list, self.timeseriesId_list = db.get_timeserieses( window=self.temp_window) self.listWidget_timeseries.clear() index = 0 for item in self.timeseriesId_list: listitem = QtWidgets.QListWidgetItem() listitem.setText(self.timeseries_list[index]) listitem.setData(1, item) index += 1 self.listWidget_timeseries.addItem(listitem) self.listWidget_timeseries.itemClicked.connect( self.timeseries_list_item_event)
def btn_unbind_clicked(self): """ Remove the id of the product from the selected time-series :return: """ from utils.database_utils import DatabaseConnect db = DatabaseConnect() updated = db.update_timeseries_productId(self.selected_timeseriesId, "NULL", window=self.temp_window) if updated: self.btn_bind.setDisabled(True) self.btn_unbind.setDisabled(True) QtWidgets.QMessageBox.about( self.temp_window, "info", "Successfully unbind the product from time series !!!") self.timeseries_list_view() self.load_products_list()
def btn_export_prediction_clicked(self): """ Export the Prediction data as a CSV file """ try: initial_data = ({ "Time Series": self.selected_timeseries, "Model": self.selected_model, "Param 1": self.param_one.text(), "Param 2": self.param_two.text(), "Param 3": self.param_three.text() }) initial_data.update(PREDICTION_DATA) col1 = list(initial_data.keys()) col2 = list(initial_data.values()) from utils.database_utils import DatabaseConnect db = DatabaseConnect() timeseries_data = db.get_timeseries_details( self.selected_timeseriesId, self.temp_window) source_file = timeseries_data["source_file"] import pandas as pd prediction_data = {} source_file_data = pd.read_excel(source_file, header=None).to_dict() if source_file_data: dates = dict(list(source_file_data.values())[0]).values() values = self.time_series_prediction( dict(list(source_file_data.values())[1]).values()) col1.extend([None, "Date"]) col2.extend([None, "Predicted-values"]) col1.extend(list(dates)) col2.extend(list(values)) prediction_data.update({"Column 1": col1, "Column 2": col2}) from utils.window_utils import export_file export_file(window=self.temp_window, export_data=prediction_data) except Exception as ex: QtWidgets.QMessageBox.about(self.temp_window, "Error", str(ex))
def reset_evaluation(self, id): """ Reset the evaluation by calling a function delete_evaluation from database_util file :param id: :return: """ buttonReply = QtWidgets.QMessageBox.question( self.temp_window, "Message", 'Do you really want to reset this evaluation ?', QtWidgets.QMessageBox.Yes | QtWidgets.QMessageBox.No, QtWidgets.QMessageBox.No) if buttonReply == QtWidgets.QMessageBox.Yes: from utils.database_utils import DatabaseConnect db = DatabaseConnect() deleted = db.delete_evaluation(product_id=id, window=self.temp_window) if deleted: self.temp_window.show() return True else: return False
def save_product(self): """ Creates a product in a database :return: """ from utils.database_utils import DatabaseConnect conn = DatabaseConnect() name = self.txt_name.text() code = self.txt_code.text() category_a = self.combo_category_A.currentText() category_b = self.combo_category_B.currentText() info_1 = self.txt_info1.text() info_2 = self.txt_info_2.text() info_3 = self.txt_info_3.text() info_4 = self.txt_info_4.text() info_5 = self.txt_info_5.text() info_6 = self.txt_info_6.text() info_7 = self.txt_info_7.toPlainText() if name and code: saved = conn.save_product_record(name, code, category_a, category_b, info_1, info_2, info_3, info_4, info_5, info_6, info_7) if saved: self.temp_window.parent_win.ui.get_products() self.temp_window.parent_win.ui.load_products_list() QMessageBox.about(self.temp_window, "info", "Product is added Successfully !!!") return True else: QMessageBox.about(self.temp_window, "Warning", "Database Error !!!") return False else: if not name: self.txt_name.setFocusPolicy(QtCore.Qt.StrongFocus) self.txt_name.setFocus() elif not code: self.txt_code.setFocus()
def load_products_list(self): """ Creates the items of list widget to display the list of products on the window :return: """ db = DatabaseConnect() self.products_list, self.productId_list, self.isEvaluated_list, self.products_dict_list = db.get_products( evaluate=True, window=self.temp_window) self.listWidget = QListWidget() self.btn_reset.setDisabled(True) index = 0 for item in self.productId_list: listitem = QListWidgetItem() listitem.setText(self.products_list[index]) listitem.setData(3, item) listitem.setData(4, self.isEvaluated_list[index]) index += 1 self.listWidget.addItem(listitem) self.listWidget.itemActivated.connect(self.list_item_event) self.listWidget.itemClicked.connect(self.list_item_event) self.scrollArea.setWidget(self.listWidget)
def save_model(self, update=False): """ Save the model in the database ( Create or update a Model) :param update: """ from utils.database_utils import DatabaseConnect db = DatabaseConnect() try: name = str(self.txt_name.text()) type = str(self.comboBox_type.currentText()) me1 = float(str(self.txt_me1.text())) me2 = float(str(self.txt_me2.text())) me3 = float(str(self.txt_me3.text())) me4 = float(str(self.txt_me4.text())) me5 = float(str(self.txt_me5.text())) me6 = float(str(self.txt_me6.text())) me7 = float(str(self.txt_me7.text())) me8 = float(str(self.txt_me8.text())) me9 = float(str(self.txt_me9.text())) me10 = float(str(self.txt_me10.text())) me11 = float(str(self.txt_me11.text())) me12 = float(str(self.txt_me12.text())) me13 = float(str(self.txt_me13.text())) me14 = float(str(self.txt_me14.text())) me15 = float(str(self.txt_me15.text())) me16 = float(str(self.txt_me16.text())) param1 = str(self.txt_param1.text()) param2 = str(self.txt_param2.text()) param3 = str(self.txt_param3.text()) description = str(self.txt_memo.toPlainText()) time_series_ID = self.selected_timeseriesId if (name and type and me1 and me2 and me3 and me4 and me5 and me6 and me7 and me8 and me9 and me10 and me11 and me12 and me13 and me14 and me15 and me16 and param1 and param2 and param3): if not update: saved = db.save_model_record(name=name, type=type, me1=me1, me2=me2, me3=me3, me4=me4, me5=me5, me6=me6, me7=me7, me8=me8, me9=me9, me10=me10, me11=me11, me12=me12, me13=me13, me14=me14, me15=me15, me16=me16, param1=param1, param2=param2, param3=param3, description=description, time_series_ID=time_series_ID, window=self.temp_window) else: saved = db.update_model_record( name=name, type=type, me1=me1, me2=me2, me3=me3, me4=me4, me5=me5, me6=me6, me7=me7, me8=me8, me9=me9, me10=me10, me11=me11, me12=me12, me13=me13, me14=me14, me15=me15, me16=me16, param1=param1, param2=param2, param3=param3, description=description, time_series_ID=time_series_ID, model_id=self.selected_modelId, window=self.temp_window) if saved: QtWidgets.QMessageBox.about( self.temp_window, "info!", "Successfully saved the model !!!") self.temp_window.parent_window.ui.models_list_view() return saved else: QtWidgets.QMessageBox.about( self.temp_window, "Error!!!", "Fill the mendetory fields on window !!!") return False except Exception as ex: QtWidgets.QMessageBox.about(self.temp_window, "Error!!!", str(ex))