def __init__(self, type):
     self.dc = DataController()
     self.drc = RepresentationControl()
     self.flowData = self.dc.abstractionData
     pos = self.drc.getAvailableAlgorithms().keys().index(type)
     self.drc.selectAlgorithm(pos)
예제 #2
0
 def __init__(self, type):
     self.dc = DataController()
     self.fec = FeatureExtractionControl()
     self.flowData = self.dc.dimrecprocData
     pos = self.fec.getAvailableAlgorithms().keys().index(type)
     self.fec.selectAlgorithm(pos)
class Ui_Form(object):
    def __init__(self, type):
        self.dc = DataController()
        self.drc = RepresentationControl()
        self.flowData = self.dc.abstractionData
        pos = self.drc.getAvailableAlgorithms().keys().index(type)
        self.drc.selectAlgorithm(pos)


    def setupUi(self, Form):
        Form.setObjectName(_fromUtf8("Form"))
        Form.resize(536, 384)
        self.tableWidget = QtGui.QTableWidget(Form)
        self.tableWidget.setGeometry(QtCore.QRect(90, 261, 221, 121))
        if self.dc.getCurrentLabels() is None:
            QtGui.QMessageBox.warning(Form, "No Features Found", "Please select Feature Extraction Method first",
                                      QtGui.QMessageBox.Ok)
        self.tableWidget.setObjectName(_fromUtf8("tableWidget"))
        self.tableWidget.setColumnCount(2)
        self.tableWidget.setRowCount(len(list(set(self.dc.getCurrentLabels()))))

        self.pushButton = QtGui.QPushButton(Form)
        self.pushButton.setGeometry(QtCore.QRect(0, 360, 75, 23))
        self.pushButton.setObjectName(_fromUtf8("pushButton"))

        self.label = QtGui.QLabel(Form)
        self.label.setGeometry(QtCore.QRect(10, 10, 521, 211))
        self.label.setText("The state figure will be saved")
        self.widget = QtGui.QWidget()
        self.widget.setGeometry(QtCore.QRect(10, 10, 521, 211))
        self.widget.setObjectName(_fromUtf8("widget"))
        self.dialog = CurveDialog(edit=False, toolbar=False, parent=self.widget)
        self.plot = self.dialog.get_plot()
        self.plot.set_antialiasing(True)
        self.plot.setAxisTitle(Qwt5.Qwt.QwtPlot.xBottom, 'Time')
        self.plot.setAxisTitle(Qwt5.Qwt.QwtPlot.yLeft, 'Value')
        self.manager = PlotManager(self)
        self.manager.add_plot(self.plot)
        ly = QtGui.QVBoxLayout()
        ly.addWidget(QtGui.QLabel(self.widget))
        ly.addWidget(QtGui.QLabel(self.plot))
        self.widget.setLayout(ly)


        #   item = QtGui.QTableWidgetItem()
        #   self.tableWidget.setHorizontalHeaderItem(0, item)
        #   item = QtGui.QTableWidgetItem()
        #   self.tableWidget.setItem(0, 0, item)
        #   item = QtGui.QTableWidgetItem()
        #   self.tableWidget.setItem(0, 1, item)

        #        item = self.tableWidget.horizontalHeaderItem(0)
        #       item.setText(_translate("Form", "Attribute", None))

        c = 0
        for it in list(set(self.dc.getCurrentLabels())):
        # item = QtGui.QTableWidgetItem()
        # item.setText(_translate("Form", "Id" + str(c), None))
        # self.tableWidget.setVerticalHeaderItem(c, item)

            item = QtGui.QTableWidgetItem()
            item.setText(str(it))
            self.tableWidget.setItem(c, 0, item)
            #print "jgaboo timeig", it
            #print it, self.drc.getRequiredParameters()[it]
            item = QtGui.QTableWidgetItem()
            item.setText("States!")
            self.tableWidget.setItem(c, 1, item)

            #print c
            c += 1

        self.retranslateUi(Form)
        QtCore.QMetaObject.connectSlotsByName(Form)

    def retranslateUi(self, Form):
        Form.setWindowTitle(_translate("Form", "Form", None))

        __sortingEnabled = self.tableWidget.isSortingEnabled()
        self.tableWidget.setSortingEnabled(False)
        self.tableWidget.setSortingEnabled(__sortingEnabled)
        self.pushButton.setText(_translate("Form", "Picture It!", None))

        Form.connect(self.pushButton, QtCore.SIGNAL('clicked()'), self.processor)

    def processor(self):
        print "in process"
        params = {}
        for i in range(self.tableWidget.rowCount()):
            a = self.tableWidget.item(i, 0)
            b = self.tableWidget.item(i, 1)
            params[str(a.text())] = str(b.text())
        #print "paramsjo", params
        #print "paramsjo2", self.dc.params
        self.drc.represent(None,{"states":self.dc.params})
예제 #4
0
class Ui_Form(object):
    def __init__(self, type):
        self.dc = DataController()
        self.fec = FeatureExtractionControl()
        self.flowData = self.dc.dimrecprocData
        pos = self.fec.getAvailableAlgorithms().keys().index(type)
        self.fec.selectAlgorithm(pos)


    def setupUi(self, Form):
        Form.setObjectName(_fromUtf8("Form"))
        Form.resize(536, 384)
        self.Form=Form
        self.tableWidget = QtGui.QTableWidget(Form)
        self.tableWidget.setGeometry(QtCore.QRect(90, 261, 221, 121))
        self.tableWidget.setObjectName(_fromUtf8("tableWidget"))
        self.tableWidget.setColumnCount(2)
        self.tableWidget.setRowCount(len(self.fec.getRequiredParameters()))

        item = QtGui.QTableWidgetItem()
        self.tableWidget.setVerticalHeaderItem(0, item)
        item = QtGui.QTableWidgetItem()
        self.tableWidget.setHorizontalHeaderItem(0, item)
        item = QtGui.QTableWidgetItem()
        self.tableWidget.setHorizontalHeaderItem(1, item)
        item = QtGui.QTableWidgetItem()
        self.tableWidget.setItem(0, 0, item)
        item = QtGui.QTableWidgetItem()
        self.tableWidget.setItem(0, 1, item)

        self.pushButton = QtGui.QPushButton(Form)
        self.pushButton.setGeometry(QtCore.QRect(0, 300, 75, 23))
        self.pushButton.setObjectName(_fromUtf8("pushButton"))

        self.widget = QtGui.QWidget(Form)
        self.widget.setGeometry(QtCore.QRect(10, 10, 521, 211))
        self.widget.setObjectName(_fromUtf8("widget"))

        self.pushButton_3 = QtGui.QPushButton(Form)
        self.pushButton_3.setGeometry(QtCore.QRect(0, 360, 75, 23))
        self.pushButton_3.setObjectName(_fromUtf8("pushButton_3"))

        self.dialog = CurveDialog(edit=False, toolbar=False, parent=self.widget)
        self.plot = self.dialog.get_plot()
        self.plot.set_antialiasing(True)
        self.plot.setAxisTitle(Qwt5.Qwt.QwtPlot.xBottom, 'Time')
        self.plot.setAxisTitle(Qwt5.Qwt.QwtPlot.yLeft, 'Value')
        self.manager = PlotManager(self)
        self.manager.add_plot(self.plot)
        legend = make.legend('TL')
        self.plot.add_item(legend)
        ly = QtGui.QVBoxLayout()
        ly.addWidget(self.plot)
        self.widget.setLayout(ly)

        #   item = QtGui.QTableWidgetItem()
        #   self.tableWidget.setHorizontalHeaderItem(0, item)
        #   item = QtGui.QTableWidgetItem()
        #   self.tableWidget.setItem(0, 0, item)
        #   item = QtGui.QTableWidgetItem()
        #   self.tableWidget.setItem(0, 1, item)

        #        item = self.tableWidget.horizontalHeaderItem(0)
        #       item.setText(_translate("Form", "Attribute", None))

        c = 0
        for it in self.fec.getRequiredParameters():
        # item = QtGui.QTableWidgetItem()
        # item.setText(_translate("Form", "Id" + str(c), None))
        # self.tableWidget.setVerticalHeaderItem(c, item)

            item = QtGui.QTableWidgetItem()
            item.setText(it)
            self.tableWidget.setItem(c, 0, item)

            print it, self.fec.getRequiredParameters()[it]
            item = QtGui.QTableWidgetItem()
            item.setText(str(self.fec.getRequiredParameters()[it]))
            self.tableWidget.setItem(c, 1, item)

            print c
            c += 1

        self.retranslateUi(Form)
        QtCore.QMetaObject.connectSlotsByName(Form)

    def retranslateUi(self, Form):
        Form.setWindowTitle(_translate("Form", "Form", None))

        __sortingEnabled = self.tableWidget.isSortingEnabled()
        self.tableWidget.setSortingEnabled(False)
        self.tableWidget.setSortingEnabled(__sortingEnabled)
        self.pushButton.setText(_translate("Form", "Process", None))
        Form.connect(self.pushButton, QtCore.SIGNAL('clicked()'), self.process)
        self.pushButton_3.setText(_translate("Form", "Save", None))
        Form.connect(self.pushButton_3, QtCore.SIGNAL('clicked()'),self.saveDialog)

    def process(self):
        params = {}
        for i in range(self.tableWidget.rowCount()):
            a = self.tableWidget.item(i, 0)
            b = self.tableWidget.item(i, 1)
            params[str(a.text())] = int(b.text())
        print "params", params
        outpN = self.tableWidget.item(0, 0)
        #params = {"none": "none", "output_length": outpN}


        r = np.array(range(len(self.dc.dimrecprocData))).reshape(len(self.dc.dimrecprocData), 1)
        s = np.array(self.dc.dimrecprocData).reshape(len(self.dc.dimrecprocData), 1)
        rs = np.hstack((s, s))

        labels = self.fec.extractFeature(rs, params)
        print labels
        self.plot.del_all_items()
        self.plot.replot()
        self.plot.add_item(
            make.curve(range(0, len(self.dc.dimrecprocData)), self.dc.dimrecprocData))

        from guiqwt.styles import AnnotationParam

        i = 0
        i_beg = 0
        i_end = 0
        while i < len(labels):
            cur = labels[i_end]

            if i < len(labels) - 1:
                if labels[i_end + 1] != cur:
                    i_end = i
                    from guiqwt.annotations import AnnotatedRectangle

                    param = AnnotationParam()
                    param.title = str(labels[int(i_beg)])
                    param.show_computations = False

                    anno = AnnotatedRectangle(r[int(i_beg)], self.dc.dimrecprocData[int(i_beg)], int(i_end), self.dc.dimrecprocData[r[int(i_end)]], param) #TODO: y axis scaling
                    self.plot.add_item(anno)
                    i_beg = i_end
                    print "s1"
                else:
                    i_end = i
                    print "s2"
                print "s3"
            print "s4", i_end, len(labels)
            i += 1

        self.rangeSelection = make.range(-2, 2)
        disp0 = make.range_info_label(self.rangeSelection, 'BR', u"x = %.1f +- %.1f cm",
                                      title="Range infos")
        #self.plot.add_item(self.rangeSelection)
        #self.plot.add_item(disp0)
        #self.dc.setCurrentDataFlowObject(self.flowData)
        self.dc.featureexData = self.flowData
        self.dc.setCurrentLabels(labels)
        print(self.dc.setCurrentLabels)
        #ToDo: Check that following line, make property in data controller
        self.dc.dimrecprocData = rs
        self.plot.replot()
        self.currentdata = np.reshape(labels, (-1, 1))

    def saveDialog(self):
        path = QtGui.QFileDialog.getSaveFileName(self.Form, 'Save File', '', 'CSV(*.csv)')
        if not path.isEmpty():
            with open(unicode(path), 'wb') as stream:
                writer = csv.writer(stream)
                [a,b]=self.currentdata.shape
                print(a)
                print(b)
                for row in range(a):
                    rowdata = []
                    for column in range(b):
                        item = self.currentdata.item(row, column)
                        if item is not None:
                            rowdata.append(item)
                        else:
                            rowdata.append('')
                    writer.writerow(rowdata)