コード例 #1
0
ファイル: signature.py プロジェクト: pauloborges/tg
    def status_init(self):
        super(SignatureShowOption, self).init()
        self.build_gui()

        try:
            with open(self.signature_file, 'r') as f:
                file_content = json.loads(f.read())
        except (IOError, ValueError):
            file_content = {}

        for k, v in file_content.iteritems():
            print k
            states = v["states"]

            for n, pos in states.iteritems():
                if n.lower() == "off":
                    continue
                self.power_scatter.addPoints(
                        brush=qt.brush(255, 255, 255, 255),
                        pos=[pos], size=10)
                text = qt.text(k+'/'+n, anchor=(0.5, 0))
                text.setPos(pos[0], pos[1]-0.5)
                self.power_plot.addItem(text)

        self.status = self.STATUS.WAIT
コード例 #2
0
ファイル: disaggregate.py プロジェクト: pauloborges/tg
    def build_gui(self):
        self.sign_plot = self.build_plot("VAr", "W",
            title=u"Possíveis transições")
        self.sign_scatter = qt.scatter(unicolor=True)
        self.sign_plot.addItem(self.sign_scatter)

        self.next_row()

        self.power_plot = self.build_plot("VAr", "W",
            title=u"Tempo real")
        self.power_scatter = qt.scatter(unicolor=True)
        self.power_plot.addItem(self.power_scatter)

        self.reac_power_data = deque(maxlen=self.POWER_SIZE_LEN)
        self.real_power_data = deque(maxlen=self.POWER_SIZE_LEN)

        self.power_scatter_brushes = qt.mk_brushes(
                            self.POWER_SIZE_LEN, 255, 255, 255)

        self.status_text = qt.text("", anchor=(0.0, 1.0))
        self.status_text.setPos(0, 0)
        self.power_plot.addItem(self.status_text)
コード例 #3
0
ファイル: disaggregate.py プロジェクト: pauloborges/tg
    def update_classifier(self):
        self.classifier_instances = []
        self.classifier_labels = []
        self.classifier_texts = []

        for appliance, data in self.signatures.iteritems():
            self.classifier_instances.extend([
                t[2] if t[0] == self.current_status[appliance]
                else [-t[2][0], -t[2][1]]
                for t in data["transitions"]
                if t[0] == self.current_status[appliance]
                or t[1] == self.current_status[appliance]
            ])

            self.classifier_labels.extend([
                (appliance,
                t[0] if t[1] == self.current_status[appliance]
                else t[1])
                for t in data["transitions"]
                if t[0] == self.current_status[appliance]
                or t[1] == self.current_status[appliance]
            ])

            self.classifier_texts.extend([
                qt.text(appliance + '/' + label, anchor=(0, 0.5))
                for app, label in self.classifier_labels
                if app == appliance
            ])

        for i, text in enumerate(self.classifier_texts):
            text.setPos(*self.classifier_instances[i])

        self.classifier_classes = range(
                                len(self.classifier_instances))

        self.classifier = KNeighborsClassifier(n_neighbors=1)
        self.classifier.fit(self.classifier_instances,
                            self.classifier_classes)
コード例 #4
0
ファイル: signature.py プロジェクト: pauloborges/tg
    def button_tag_clicked(self):
        self.labels = []

        arrow = qt.arrow(angle=-160, tipAngle=60,
                            headLen=40, tailLen=40, tailWidth=20,
                            pen={'color': 'w', 'width': 3})
        self.power_plot.addItem(arrow)

        try:
            for i, prototype in enumerate(self.prototypes):
                arrow.setPos(prototype[0]-0.2, prototype[1]+0.2)
                qt.update_gui()

                current_state = qt.input_dialog("Nome do estado", "")
                self.labels.append(current_state)

                text = qt.text(current_state, anchor=(0.5, 0))
                text.setPos(prototype[0], prototype[1]-0.5)
                self.power_plot.addItem(text)
        except qt.UserCancelError:
            return
        
        self.power_plot.removeItem(arrow)

        self.transitions = []

        l = len(self.prototypes)
        for i in xrange(l):
            for j in xrange(i+1, l):
                self.transitions.append((
                    self.labels[j], self.labels[i], (
                    self.prototypes[i][0] - self.prototypes[j][0],
                    self.prototypes[i][1] - self.prototypes[j][1]
                )))

        self.button_cluster.setEnabled(False)
        self.button_tag.setEnabled(False)
        self.button_save.setEnabled(True)