def createListModel(model): file_model = utility.readFileJSON(os.path.join(templatesPath, model)) list_measures = [] for model in file_model["parameters"]["filter_tag"]: if (model["tag"] != "CommunicationCode"): list_measures.append(utility.getSubstring(model["tag"], start=".")) return (list_measures)
def search_json(path, diz_xml): global environment_prefix file_list = utility.createListFile(path, ".json") diz_meters = {} environment_prefix = "" count = 0 for file in file_list: file_json = utility.readFileJSON(os.path.join(path, file)) if (count == 0): environment_prefix = file_json["parameters"]["environment_prefix"] count += 1 meter_name = file_json["parameters"]["meter_name"] for key in file_json["parameters"]["filter_tag"]: if (key["tag"] != "CommunicationCode"): if (meter_name not in diz_meters): diz_meters[meter_name] = [] diz_meters[meter_name] += [{ key["tag"][key["tag"].find(".") + 1:]: { "id": key["id"], "period": key["period"], "name": diz_xml[key["tag"]] } }] return ([diz_meters, environment_prefix])
def createListModel(model): file_model = utility.readFileJSON(templatesPath, model+".json") list_measures = [] for model in file_model["parameters"]["filter_tag"]: if(model["tag"] != "CommunicationCode"): list_measures.append(model["tag"][model["tag"].find(".")+1 :]) return(list_measures)
def searchTemplate(numberMeasures): dizMetersConfig = utility.readFileJSON( os.path.realpath(''), "\\configuration\\meterMeasuresConfiguration.json") for model_meter, diz_value in dizMetersConfig.items(): for key, value in diz_value.items(): if (key == "measuresSelected" and value == numberMeasures): return (model_meter + ".json", value)
def searchTemplate(numberMeasures): dizMetersConfig = utility.readFileJSON(os.path.realpath (''), "\\configuration\\meterMeasuresConfiguration.json") list_model = [] for model_meter, diz_value in dizMetersConfig.items(): for key, value in diz_value.items(): if(key == "measuresSelected" and value==numberMeasures): if(model_meter not in list_model): list_model.append(model_meter) return(list_model)
def add_gateway_id(string): path = os.path.join(os.path.realpath(''), "configuration\\gatewayIdConfiguration.json") list_gateway_id = utility.readFileJSON(path) if (string not in list_gateway_id and string != ''): list_gateway_id.append(string) utility.saveFileJSON(path, list_gateway_id) return True else: return False
def add_environment_prefix(string): path = os.path.join(os.path.realpath(''), "configuration\\environmentPrefixConfiguration.json") list_environment_prefix = utility.readFileJSON(path) if (string not in list_environment_prefix and string != ''): list_environment_prefix.append(string) utility.saveFileJSON(path, list_environment_prefix) return True else: return False
def count_measures_template(file_name): list_measures = JaSONx.createListModel(file_name) diz_templates = utility.readFileJSON( os.path.realpath(''), "\\configuration\\meterMeasuresConfiguration.json") if (file_name not in diz_templates): diz_templates[file_name] = { "measuressMax": len(list_measures), "measuresSelected": len(list_measures) } utility.saveFileJSON( os.path.realpath('') + "\\configuration\\", "meterMeasuresConfiguration.json", diz_templates)
def createJSON(nameMeter, folder, template): file = utility.readFileJSON(templatesPath, template) file["parameters"]["serial_number"] = serial_number file["parameters"]["model"] = template[:template.find(".")] file["parameters"]["user_name"] = user_name file["parameters"]["password"] = password key = file["parameters"]["file_name_filter"] key["match_group_value"] = name_file_hierarchy.split("_")[1]+"_"+match_group_value file["parameters"]["meter_name"] = nameMeter file["parameters"]["maker"] = nameMeter for measureMeter in file["parameters"]["filter_tag"]: if(measureMeter["tag"]!="CommunicationCode"): measureMeter["tag"] = measureMeter["tag"].replace(measureMeter["tag"][:measureMeter["tag"].find(".")], nameMeter) utility.saveFileJSON(jsonPath+folder+"\\", nameMeter+".json", file)
def createJSON(nameMeter, folder, template): file = utility.readFileJSON(os.path.join(templatesPath, template)) file["gateway_id"] = gateway_id file["parameters"]["environment_prefix"] = environment_prefix file["parameters"]["serial_number"] = serial_number file["parameters"]["model"] = template[:template.find(".")] file["parameters"]["user_name"] = user_name file["parameters"]["password"] = password key = file["parameters"]["file_name_filter"] key["match_group_value"] = name_file_hierarchy.split( "_")[1] + "_" + match_group_value file["parameters"]["meter_name"] = nameMeter file["parameters"]["maker"] = nameMeter for measureMeter in file["parameters"]["filter_tag"]: if (measureMeter["tag"] != "CommunicationCode"): measureMeter["tag"] = measureMeter["tag"].replace( measureMeter["tag"][:measureMeter["tag"].find(".")], nameMeter) utility.saveFileJSON(os.path.join(jsonPath, folder, nameMeter), file)
def search_json(path): global environment_prefix file_list = utility.createListFile(path) diz_meters = {} for file in file_list: file_json = utility.readFileJSON(path + "\\", file) meter_name = file_json["parameters"]["meter_name"] for key in file_json["parameters"]["filter_tag"]: environment_prefix = file_json["parameters"]["environment_prefix"] if (key["tag"] != "CommunicationCode"): if (meter_name not in diz_meters): diz_meters[meter_name] = [] else: diz_meters[meter_name] += [{ key["tag"][key["tag"].find(".") + 1:]: { "id": key["id"], "period": key["period"] } }] return (diz_meters)
''' @author = "Jury Francia, Simone Olivieri, Vic Zagranowski" @version = "2.1" @email = "[email protected], [email protected], [email protected]" ''' import os import utility import configuration '''Control paths exist''' configuration.control_paths() '''Configuration path, open file configuration.json''' paths = utility.readFileJSON( os.path.join(os.path.realpath(''), "configuration\\pathConfiguration.json")) templatesPath = paths["templatesPath"] jsonPath = paths["jsonPath"] hierarchyPath = paths["hierarchyPath"] templatesExcelPath = paths["templatesExcelPath"] excelPath = paths["excelPath"] '''Constant data variables''' user_name = "" password = "" match_group_value = "" name_file_hierarchy = "" dizMeters = {} serial_number = "" gateway_id = "" environment_prefix = "" '''Setting constant data, triggered by MainInterface'''
def __init__(self, parent=None): super(MainInterface, self).__init__(parent) '''Window settings''' self.setWindowTitle("JaSONx - v 1.5.1") self.setFixedSize(1050,600) scriptDir = os.path.dirname(os.path.realpath(__file__)) self.setWindowIcon(QtGui.QIcon(scriptDir + os.path.sep + 'image\\logo.png')) '''Font settings''' font = QtGui.QFont() font.setPointSize(13) fontToolbar = QtGui.QFont() fontToolbar.setPointSize(10) self.setFont(font) '''Label settings''' self.title_label = QtWidgets.QLabel() self.user_name_label = QtWidgets.QLabel() self.password_label = QtWidgets.QLabel() self.match_group_value_label = QtWidgets.QLabel() self.combo_box_hierarchy_label = QtWidgets.QLabel() self.gateway_id_label = QtWidgets.QLabel() self.combo_box_environment_prefix_label = QtWidgets.QLabel() self.title_label.setAlignment(QtCore.Qt.AlignCenter) '''Label text''' self.title_label.setPixmap(QtGui.QPixmap('image\\title.png')) self.user_name_label.setText("Username: "******"Password: "******"Hierarchy: ") self.gateway_id_label.setText("Gateway id: ") self.combo_box_environment_prefix_label.setText("Environment prefix: ") '''Textbox settings''' self.user_name_text = QtWidgets.QLineEdit(self) self.password_text = QtWidgets.QLineEdit(self) '''Combobox settings''' self.combo_box_hierarchy = QtWidgets.QComboBox() self.combo_box_hierarchy.addItems(utility.getListHierarchy()) self.combo_box_environment_prefix = QtWidgets.QComboBox() self.combo_box_environment_prefix.addItems(utility.readFileJSON(os.path.join(os.path.realpath (''), "configuration\\environmentPrefixConfiguration.json"))) self.combo_box_gateway_id = QtWidgets.QComboBox() self.combo_box_gateway_id.addItems(utility.readFileJSON(os.path.join(os.path.realpath (''), "configuration\\gatewayIdConfiguration.json"))) '''Button settings''' self.button = QtWidgets.QPushButton("Send data") self.button.setStyleSheet("background-color: #8b0000; color: white; height:50; border-radius:10") self.button.setFont(font) self.button.clicked.connect(self.on_pushButton_clicked) '''Grid layout''' grid = QtWidgets.QGridLayout() grid.addWidget(self.user_name_label, 0, 0) grid.addWidget(self.user_name_text, 0, 1) grid.addWidget(self.password_label, 1, 0) grid.addWidget(self.password_text, 1, 1) grid.addWidget(self.gateway_id_label, 2, 0) grid.addWidget(self.combo_box_gateway_id, 2, 1) grid.addWidget(self.combo_box_environment_prefix_label, 3, 0) grid.addWidget(self.combo_box_environment_prefix, 3, 1) grid.addWidget(self.combo_box_hierarchy_label, 4, 0) grid.addWidget(self.combo_box_hierarchy, 4, 1) '''Vertical layout''' vbox = QtWidgets.QVBoxLayout() vbox.addWidget(self.title_label) vbox.addLayout(grid) vbox.addWidget(self.button) '''Layout QWidget''' layout = QtWidgets.QWidget() layout.setLayout(vbox) '''Layout QMainWindow''' self.setCentralWidget(layout) '''TOOLBAR''' toolbar = self.addToolBar('Toolbar') toolbar.setMovable(False) toolbar.setIconSize(QtCore.QSize(40,40)) toolbar.setFont(fontToolbar) toolbar.setToolButtonStyle(QtCore.Qt.ToolButtonTextBesideIcon) '''Icon toolbar''' '''Exit application''' exit_act = QtWidgets.QAction(QtGui.QIcon(os.path.join(os.path.realpath(''), "image", "icon","exiticon.png")), 'Close', self) exit_act.setShortcut('Ctrl+Q') exit_act.setStatusTip('Close application') '''Add Hierarchy xml''' add_xml_hierarchy_act = QtWidgets.QAction(QtGui.QIcon(os.path.join(os.path.realpath(''), "image", "icon","xmlicon.png")), 'Add Hierarchy', self) add_xml_hierarchy_act.setShortcut('Ctrl+H') add_xml_hierarchy_act.setStatusTip('Add Hierarchy XML') '''Add template json''' add_json_template_act = QtWidgets.QAction(QtGui.QIcon(os.path.join(os.path.realpath(''), "image", "icon","jsonicon.png")), 'Add Template', self) add_json_template_act.setShortcut('Ctrl+T') add_json_template_act.setStatusTip('Add JSON Template') '''Refresh application''' refresh_act = QtWidgets.QAction(QtGui.QIcon(os.path.join(os.path.realpath(''), "image", "icon","refreshicon.png")), 'Refresh', self) refresh_act.setShortcut('Ctrl+R') refresh_act.setStatusTip('Refresh application') '''Add evironment prefix''' add_environment_prefix_act = QtWidgets.QAction(QtGui.QIcon(os.path.join(os.path.realpath(''), "image", "icon","addlisticon.png")), 'Add environment prefix', self) add_environment_prefix_act.setShortcut('Ctrl+P') add_environment_prefix_act.setStatusTip('Add environment prefix') '''Add gateway id''' add_gateway_id_act = QtWidgets.QAction(QtGui.QIcon(os.path.join(os.path.realpath(''), "image", "icon","addlisticon.png")), 'Add gateway id', self) add_gateway_id_act.setShortcut('Ctrl+Y') add_gateway_id_act.setStatusTip('Add gateway id') '''xCELL''' xCell_act = QtWidgets.QAction(QtGui.QIcon(os.path.join(os.path.realpath(''), "image", "xcell.png")), 'xCell', self) xCell_act.setShortcut('Ctrl+L') xCell_act.setStatusTip('Open xCELL Interface') '''acThing''' acThing_act = QtWidgets.QAction(QtGui.QIcon(os.path.join(os.path.realpath(''), "image", "acthing.png")), 'acThing', self) acThing_act.setShortcut('Ctrl+I') acThing_act.setStatusTip('Open acThing Interface') '''ACTION TOOLBAR''' toolbar.addAction(exit_act) toolbar.addSeparator() toolbar.addSeparator() toolbar.addAction(add_xml_hierarchy_act) toolbar.addAction(add_json_template_act) toolbar.addAction(add_environment_prefix_act) toolbar.addAction(add_gateway_id_act) toolbar.addAction(refresh_act) toolbar.addSeparator() toolbar.addSeparator() toolbar.addAction(xCell_act) toolbar.addSeparator() toolbar.addSeparator() toolbar.addAction(acThing_act) '''TOOOLBAR TRIGGERED''' exit_act.triggered.connect(self.closeFunction) add_xml_hierarchy_act.triggered.connect(self.addHierarchy) add_json_template_act.triggered.connect(self.addJsonTemplate) refresh_act.triggered.connect(self.refreshWindow) add_environment_prefix_act.triggered.connect(self.addEnvironmentPrefix) add_gateway_id_act.triggered.connect(self.addGatewayId) xCell_act.triggered.connect(self.openXcellInterface) acThing_act.triggered.connect(self.openAcThingInterface) '''MENU SETTINGS''' '''Configuration Json path''' configJsonPathAct = QtWidgets.QAction(QtGui.QIcon('exit.png'), 'Json Path Configuration', self) configJsonPathAct.setShortcut('Ctrl+J') configJsonPathAct.setStatusTip('') configJsonPathAct.triggered.connect(self.changePathJsonFile) '''Configuration Hierarchy path''' configHierarchyPathAct = QtWidgets.QAction(QtGui.QIcon('exit.png'), 'Hierarchy Path Configuration', self) configHierarchyPathAct.setShortcut('Ctrl+X') configHierarchyPathAct.setStatusTip('') configHierarchyPathAct.triggered.connect(self.changePathHierarchy) '''Configuration Excel path''' configExcelPathAct = QtWidgets.QAction(QtGui.QIcon('exit.png'), 'Excel Path Configuration', self) configExcelPathAct.setShortcut('Ctrl+E') configExcelPathAct.setStatusTip('') configExcelPathAct.triggered.connect(self.changePathExcel) '''Reset paths default''' resetPathAct = QtWidgets.QAction(QtGui.QIcon('exit.png'), 'Reset Path to Default', self) resetPathAct.setShortcut('Ctrl+D') resetPathAct.setStatusTip('') resetPathAct.triggered.connect(self.resetDefaultPath) '''Refresh template configuration''' refreshTemplateConfigAct = QtWidgets.QAction(QtGui.QIcon('exit.png'), 'Refresh template configuration', self) refreshTemplateConfigAct.setShortcut('Ctrl+C') refreshTemplateConfigAct.setStatusTip('') refreshTemplateConfigAct.triggered.connect(self.refreshTemplateConfiguration) '''User Guide''' UserGuideAct = QtWidgets.QAction(QtGui.QIcon('exit.png'), 'Open User Guide', self) UserGuideAct.setShortcut('Ctrl+G') UserGuideAct.setStatusTip('') UserGuideAct.triggered.connect(self.openUserGuide) '''Add bar menu''' menubar = self.menuBar() '''Menu path population''' fileMenu = menubar.addMenu('&Change Path') fileMenu.addAction(configJsonPathAct) fileMenu.addAction(configHierarchyPathAct) fileMenu.addAction(configExcelPathAct) fileMenu.addAction(resetPathAct) '''Menu template configuration''' fileMenu2 = menubar.addMenu('&Refresh Template Configuration') fileMenu2.addAction(refreshTemplateConfigAct) '''Menu Info - User Guide''' fileMenu3 = menubar.addMenu('&Info') fileMenu3.addAction(UserGuideAct)
def getListPrefix_mgvalue(): return(utility.readFileJSON(os.path.realpath (''), "\\configuration\\prefixMatchGroupValue.json"))