def run(self): startTime = QDateTime.currentMSecsSinceEpoch() try: self.result = simulate_fmu( self.filename, stop_time=self.stopTime, solver=self.solver, step_size=self.stepSize, relative_tolerance=self.relativeTolerance, output_interval=self.outputInterval, fmi_type=self.fmiType, start_values=self.startValues, apply_default_start_values=self.applyDefaultStartValues, input=self.input, output=self.output, debug_logging=self.debugLogging, visible=True, fmi_call_logger=self.logFMICall if self.fmiLogging else None, logger=self.logFMUMessage, step_finished=self.stepFinished) except Exception as e: self.messageChanged.emit('error', str(e)) stopTime = QDateTime.currentMSecsSinceEpoch() totalTime = ((stopTime - startTime) / 1000.) if self.stopped: self.messageChanged.emit( 'info', 'Simulation stopped after %s s' % totalTime) else: self.messageChanged.emit('info', 'Simulation took %s s' % totalTime)
def __init__(self): self.lslrec = Lslrecorder() if (self.lslrec.findStream() == -1): return self.lslrec.startRec() app = QApplication(sys.argv) presentation = StimulusPresentation() # init speller-mode with image path and inter-stimulus-interval, presentation.initialize('speller_images/', 120, PresentationMode.SPELLER_MODE) # show window presentation.show() # simulate waiting time to demonstrate startup-feature #curr_time = QDateTime.currentMSecsSinceEpoch() #while QDateTime.currentMSecsSinceEpoch() < curr_time + 1000: # QCoreApplication.processEvents(QEventLoop.AllEvents, 100) # show target with text #presentation.show_target(1, 'Search for this Target') # execute subtrial and save flash-sequence _flash_sequence = presentation.execute_sub_trial() curr_time = QDateTime.currentMSecsSinceEpoch() while QDateTime.currentMSecsSinceEpoch() < curr_time + 1000: QCoreApplication.processEvents(QEventLoop.AllEvents, 100) # show target, and afterwards highlight target in matrix before next keypress #presentation.show_target(5, 'This is multi-\nline text', show_matrix=True) #_flash_sequence = presentation.execute_sub_trial() print(_flash_sequence) self.getDataSnippets(_flash_sequence) sys.exit(app.exec_())
def run(self): startTime = QDateTime.currentMSecsSinceEpoch() try: # TODO: pass fmi_type self.result = simulate_fmu( self.filename, stop_time=self.stopTime, solver=self.solver, step_size=self.stepSize, relative_tolerance=self.relativeTolerance, output_interval=self.outputInterval, start_values=self.startValues, input=self.input, output=self.output, logger=self.logFMUMessage, step_finished=self.stepFinished) except Exception as e: self.messageChanged.emit('error', str(e)) stopTime = QDateTime.currentMSecsSinceEpoch() totalTime = ((stopTime - startTime) / 1000.) if self.stopped: self.messageChanged.emit( 'info', 'Simulation stopped after %s s' % totalTime) else: self.messageChanged.emit('info', 'Simulation took %s s' % totalTime)
def run(self, *args): self.P2Signal.emit("Running...") TimeStamp = QDateTime() Time = TimeStamp.currentMSecsSinceEpoch() ###################################### # Current Processing edit here counter = 0 while(counter < 5): counter1 = 0 while counter1 < 100000000: counter1 += 1 counter += 1 ###################################### self.P2Signal.emit(str(TimeStamp.currentMSecsSinceEpoch() - Time) + " ms")
def emitRobotSensorData(self, robot): cone = robot.view_cone() robotsInView = {} timestamp = QDateTime.currentMSecsSinceEpoch() # Special case for runner robot: He sees everything: if isinstance(robot, robots.RunnerRobot): ids = self.robots.keys() wallsInView = self.obstacles else: # Get ids of all robots that are in view, i.e. that intersect with the view cone ids = filter(lambda id: cone.intersects(self.robots[id].shape()), self.robots) wallsInView = filter(cone.intersects, self.obstacles) for id in ids: other = self.robots[id] dist = (robot.pos - other.pos).length() angle = math.degrees( math.atan2(other.y - robot.y, other.x - robot.x)) robotsInView[id] = { 'x': other.x, 'y': other.y, 'id': other.id, 'pos': QVector2D(other.x, other.y), 'dist': dist, 'angle': angle, 'timestamp': timestamp } robot.robotsInViewSignal.emit(robotsInView) robot.wallsInViewSignal.emit(list(wallsInView))
def startStop(self): if self.state == 1: #stop print("data acquisition started") self.gui.liste_sayim.append("Timestamp\tCH1 Count\tCH1 Count/sec\tCH2 Count\tCH2 Count/sec") self.gui.liste_sayim.append("Stop Acquisition") self.gui_thread.terminate() del self.gui_thread self.gui.button_stop.setText("Start Data Acquisition") self.state = 0 self.gui.interval.setEnabled(True) self.timestamp = 0 elif self.state == 0: #start print("data acquisition stopped") self.gui.interval.setEnabled(False) scan_interval = self.gui.interval.value() self.gui_thread = CloneThread(scan_interval) # This is the thread object self.gui_thread.signal.connect(self.finished) self.gui.liste_sayim.append("Interval : " + format(scan_interval)) self.gui_thread.start() self.start_time = QDateTime.currentMSecsSinceEpoch() # start time in [ms] self.gui.liste_sayim.append("Start Acquisition") self.gui.liste_sayim.append(time.strftime("%a, %d %b %Y %H:%M:%S +0000", time.gmtime())) self.gui.liste_sayim.append("Timestamp\tCH1 Count\tCH1 Count/sec\tCH2 Count\tCH2 Count/sec") self.gui.button_stop.setText("Stop Data Acquisition") self.state = 1
def refresh(self): ''' 当时间每隔1s,LCD上信息会刷新一下的。 ''' startDate = QDateTime.currentMSecsSinceEpoch() # 将其转换成当前时间到1970-01-01T00:00:00世界协调时间以来的毫秒数 endDate = QDateTime(QDate(2022, 2, 4), QTime(0, 0, 0)).toMSecsSinceEpoch() # 返回2020年2月4日0:0:0自1970-01-01T00:00:00.000世界协调时间以来的毫秒数 interval = endDate - startDate # 距离冬奥会还有多少时间 if interval > 0: days = interval // (24 * 60 * 60 * 1000) hour = (interval - days * 24 * 60 * 60 * 1000) // (60 * 60 * 1000) min = (interval - days * 24 * 60 * 60 * 1000 - hour * 60 * 60 * 1000) // (60 * 1000) sec = (interval - days * 24 * 60 * 60 * 1000 - hour * 60 * 60 * 1000 - min * 60 * 1000) // 1000 intervals = str(days) + ':' + str(hour) + ':' + str( min) + ':' + str(sec) intervals = "1000:0.00" self.lcd.display(intervals)
def start_recording(self): self.log_text("recording started") #ui behaviour self.uiTimer.start() self.ui.timeDisplay.display(0) self.ui.startStopButton.setText("Stop recording") self.elapsedTime = 0 self.ui.keyRecordingFileBrowseButton.setDisabled(True) self.ui.audioRecordingFileBrowseButton.setDisabled(True) #key recording assert self.keyFileName self.keyFile = open(self.keyFileName, "w") self.log_text("key input data will be saved to " + self.keyFileName) csv.writer(self.keyFile).writerow(("timestamp", "key_code", "up_or_down")) self.startTime = QDateTime.currentMSecsSinceEpoch() #audio recording assert self.audioFileName self.log_text("audio input data will be saved to " + self.audioFileName) self.audioStream = self.audioApi.open(format=FORMAT, channels=CHANNELS, rate=RATE, input=True, frames_per_buffer=CHUNK) self.audioFile = wave.open(self.audioFileName, 'wb') self.audioFile.setnchannels(CHANNELS) self.audioFile.setsampwidth(self.audioApi.get_sample_size(FORMAT)) self.audioFile.setframerate(RATE) self.audioRecorderTimer.start()
def __handleCtcpReply(self, match): """ Private method to handle a server message containing a CTCP reply. @param match reference to the match object """ if "!" in match.group(1): sender = match.group(1).split("!", 1)[0] try: ctcpCommand = match.group(3).split(":", 1)[1] except IndexError: ctcpCommand = match.group(3) ctcpCommand = ctcpCommand[1:].split("\x01", 1)[0] if " " in ctcpCommand: ctcpReply, ctcpArg = ctcpCommand.split(" ", 1) else: ctcpReply, ctcpArg = ctcpCommand, "" ctcpReply = ctcpReply.upper() if ctcpReply == "PING" and ctcpArg.startswith("Eric IRC "): # it is a response to a ping request pingDateTime = int(ctcpArg.split()[-1]) latency = QDateTime.currentMSecsSinceEpoch() - pingDateTime self.networkWidget.addServerMessage( self.tr("CTCP"), self.tr( "Received CTCP-PING response from {0} with latency" " of {1} ms.").format(sender, latency)) else: self.networkWidget.addServerMessage( self.tr("CTCP"), self.tr( "Received unknown CTCP-{0} response from {1}.") .format(ctcpReply, sender))
def startWebcam(self): self.exit.setEnabled = False if self.webcamEnabled == 0: self.savedir = self.cwd+"..\data\\"+self.name if not os.path.exists(self.savedir): os.mkdir(self.savedir) self.fourcc = cv2.VideoWriter_fourcc('X','V','I','D') self.outputFile = self.savedir+"\\"+str(QDateTime.currentMSecsSinceEpoch())+".avi" self.out = cv2.VideoWriter(self.outputFile, self.fourcc, 30.0, (640,480)) self.capture = cv2.VideoCapture(0) self.capture.set(cv2.CAP_PROP_FRAME_WIDTH,640) self.capture.set(cv2.CAP_PROP_FRAME_HEIGHT,480) self.webcamEnabled = 1 self.timer = QTimer(self) self.timer.timeout.connect(self.updateFrame) self.start_webcam.setText(self.playStatus) if self.playStatus=='Play': self.playStatus = 'Pause' self.mediaPlayer.pause() self.timer.stop() self.recording = False else: self.playStatus = 'Play' self.mediaPlayer.play() self.timer.start(5) self.recording = True self.stop_webcam.setEnabled(True)
def run(self): while True: data = 0 # reset the counter wiringpi.digitalWrite(reset, 0) wiringpi.delayMicroseconds(1) # wiringpi.delayMicroseconds(1) wiringpi.digitalWrite(reset, 1) # print(self.interval) #wiringpi.delay(self.interval-2) # Delay for interval ms time.sleep(((self.interval)/1000)) #time.sleep(0.99838) ## store the count value into internal storage register #wiringpi.digitalWrite(rclk, 1) ##wiringpi.delayMicroseconds(1) #wiringpi.digitalWrite(rclk, 0) wiringpi.digitalWrite(byteSelect[0], 0) # select the first byte #data1 = wiringpi.digitalReadByte() # read the first 8 bits #data5 = wiringpi.digitalRead(8) # read the first 8 bits data1 = self.read(0) # read first counter data5 = self.read(1) # read second counter wiringpi.digitalWrite(byteSelect[0], 1) wiringpi.digitalWrite(byteSelect[1], 0) # select the second byte #data2 = wiringpi.digitalReadByte()# read data #data6 = wiringpi.digitalReadByte2() # data2 = self.read(0) # read first counter data6 = self.read(1) # read second counter wiringpi.digitalWrite(byteSelect[1], 1) wiringpi.digitalWrite(byteSelect[2], 0) # select the third byte #data3 = wiringpi.digitalReadByte() # read data #data7 = wiringpi.digitalReadByte2() # data3 = self.read(0) # read first counter data7 = self.read(1) # read second counter wiringpi.digitalWrite(byteSelect[2], 1) wiringpi.digitalWrite(byteSelect[3], 0) # select the forth byte #data4 = wiringpi.digitalReadByte() # read data #data8 = wiringpi.digitalReadByte2() # data4 = self.read(0) # read first counter data8 = self.read(1) # read second counter wiringpi.digitalWrite(byteSelect[3], 1) data_cnt1 = (data4<<24) | (data3<<16) | (data2<<8) | (data1) data_cnt2 = (data8<<24) | (data7<<16) | (data6<<8) | (data5) countms_cnt1 = str(data_cnt1*(1000/self.interval)) countms_cnt2 = str(data_cnt2*(1000/self.interval)) #print("data = ", countms_cnt1, data_cnt1, data4, data3, data2, data1, countms_cnt2, data_cnt2, data8, data7, data6, data5) #count = str(bin(data)) self.signal.emit([data_cnt1, countms_cnt1, data_cnt2, countms_cnt2, QDateTime.currentMSecsSinceEpoch()])
def serial_update_signal_callback(self, data): self.ax.clear() self.ax.set_ylim(ymin=0, ymax=4096) # Shift data buffers left, add new data to rightmost slot, then redraw self.timeIndexes = np.roll(self.timeIndexes, -1) if not self.hasReceivedData: self.startTime = QDateTime.currentMSecsSinceEpoch() self.timeIndexes[-1:] = 0 self.hasReceivedData = True else: self.timeIndexes[-1:] = ( QDateTime.currentMSecsSinceEpoch() - self.startTime ) self.ax.set_xlim(self.timeIndexes[0], self.timeIndexes[-1]) self.dataBuffer = np.roll(self.dataBuffer, -1) self.dataBuffer[-1:] = data self.ax.plot(self.timeIndexes, self.dataBuffer, color='r') self.ax.figure.canvas.draw()
def log_key(self, key, isUp): if not self.running: return assert self.startTime time = QDateTime.currentMSecsSinceEpoch() - self.startTime logText = str(time) + ":" + str(key.key()) + "(" + key.text() + ") " if isUp: logText = logText + "pressed" else: logText = logText + "released" self.log_text(logText) assert self.keyFile csv.writer(self.keyFile).writerow((time, key.key(), "up" if isUp else "down"))
def updateLastSighting(self): # if the last sighting is older than 2 seconds, return to Searching current_time = QDateTime.currentMSecsSinceEpoch() if current_time > self.lastSighting['timestamp'] + 2000: self.state = "Searching" if self.targetId in self.robotsInView: self.state = "Chasing" newSighting = self.robotsInView[self.targetId] # id this sighting is newer than the old one if newSighting['timestamp'] > self.lastSighting['timestamp']: self.previousSighting = self.lastSighting self.lastSighting = newSighting
def refresh(self): startDate = QDateTime.currentMSecsSinceEpoch() endDate = QDateTime(QDate(2022, 2, 4), QTime(0, 0, 0)).toMSecsSinceEpoch() interval = endDate - startDate if interval > 0: days = interval // (24 * 60 * 60 * 1000) hour = (interval - days * 24 * 60 * 60 * 1000) // (60 * 60 * 1000) min = (interval - days * 24 * 60 * 60 * 1000 - hour * 60 * 60 * 1000) // (60 * 1000) sec = (interval - days * 24 * 60 * 60 * 1000 - hour * 60 * 60 * 1000 - min * 60 * 1000) // 1000 intervals = str(days) + ':' + str(hour) + ':' + str( min) + ':' + str(sec) self.lcd.display(intervals)
def refresh(self): #正计时 self.startDate_up = QDateTime( QDate.currentDate(), self.time_start_up).toMSecsSinceEpoch() #显示正计时 self.endDate_up = QDateTime.currentMSecsSinceEpoch() interval_up = self.endDate_up - self.startDate_up + self.interval if interval_up > 0: hour = interval_up // (60 * 60 * 1000) min = (interval_up - hour * 60 * 60 * 1000) // (60 * 1000) sec = (interval_up - hour * 60 * 60 * 1000 - min * 60 * 1000) // 1000 intervals = '0' * (2 - len(str(hour))) + str( hour) + ':' + '0' * (2 - len(str(min))) + str( min) + ':' + '0' * (2 - len(str(sec))) + str(sec) self.lcd1.display(intervals) #倒计时 self.startDate_fall = QDateTime.currentMSecsSinceEpoch() #显示倒计时 self.endDate_fall = QDateTime( self.time_start_data, self.time_start_fall).toMSecsSinceEpoch() interval_fall = self.endDate_fall - self.startDate_fall - self.interval if interval_fall > 0: hour = interval_fall // (60 * 60 * 1000) min = (interval_fall - hour * 60 * 60 * 1000) // (60 * 1000) sec = (interval_fall - hour * 60 * 60 * 1000 - min * 60 * 1000) // 1000 intervals = '0' * (2 - len(str(hour))) + str( hour) + ':' + '0' * (2 - len(str(min))) + str( min) + ':' + '0' * (2 - len(str(sec))) + str(sec) self.lcd2.display(intervals) if hour == 0 and min == 0 and sec == 0: mixer.init() self.sound = mixer.music.load( "./sound/My Soul,Your Beats!.mp3") mixer.music.play(-1, 0.0)
def breakTimerSlot(self): interval = QDateTime.currentMSecsSinceEpoch() - self.breakStartMoment remainder = self.breakInterval - interval if 0 <= remainder: self.displayLCD(remainder) else: self.breakTimer.stop() self.parent.show() self.hide() if(self.parent.cyclesNum>1): self.parent.startWorkTimer(self.parent.workInterval - 1000) elif(self.parent.cyclesNum == 1): self.parent.startWorkTimer(self.parent.remainderTime[0]) else: self.parent.isOnBtnStart = False self.parent.cyclesNum -= 1
def refresh(self): startDate = QDateTime.currentMSecsSinceEpoch() endDate = QDateTime( QDate(2020, 2, 4), QTime(0, 0, 0) ).toMSecsSinceEpoch( ) # 假设是0:0:0开始的,我们创建一个QDatetime对象,并使用toMSecsSinceEpoch()返回2020年2月4日0:0:0自1970-01-01T00:00:00.000世界协调时间以来的毫秒数。 interval = endDate - startDate if interval > 0: days = interval // (24 * 60 * 60 * 1000) hour = (interval - days * 24 * 60 * 60 * 1000) // (60 * 60 * 1000) min = (interval - days * 24 * 60 * 60 * 1000 - hour * 60 * 60 * 1000) // (60 * 1000) sec = (interval - days * 24 * 60 * 60 * 1000 - hour * 60 * 60 * 1000 - min * 60 * 1000) // 1000 intervals = str(days) + ':' + str(hour) + ':' + str( min) + ':' + str(sec) self.lcd.display(intervals)
def __sendCtcpRequest(self, receiver, request, arguments): """ Private slot to send a CTCP request. @param receiver nick name of the receiver @type str @param request CTCP request to be sent @type str @param arguments arguments to be sent @type str """ request = request.upper() if request == "PING": arguments = "Eric IRC {0}".format( QDateTime.currentMSecsSinceEpoch()) self.__send("PRIVMSG {0} :\x01{1} {2}\x01".format( receiver, request, arguments))
def clear(self, period=0): """ Public slot to clear the complete history. @param period history period in milliseconds to be cleared (integer) """ if period == 0: self.__history = [] self.historyReset.emit() else: breakMS = QDateTime.currentMSecsSinceEpoch() - period while self.__history and (QDateTime(self.__history[0].dateTime).toMSecsSinceEpoch() > breakMS): itm = self.__history.pop(0) self.entryRemoved.emit(itm) self.__lastSavedUrl = "" self.__saveTimer.changeOccurred() self.__saveTimer.saveIfNeccessary() self.historyCleared.emit()
def clear(self, period=0): """ Public slot to clear the complete history. @param period history period in milliseconds to be cleared (integer) """ if period == 0: self.__history = [] self.historyReset.emit() else: breakMS = QDateTime.currentMSecsSinceEpoch() - period while self.__history and \ (QDateTime(self.__history[0].dateTime).toMSecsSinceEpoch() > breakMS): itm = self.__history.pop(0) self.entryRemoved.emit(itm) self.__lastSavedUrl = "" self.__saveTimer.changeOccurred() self.__saveTimer.saveIfNeccessary() self.historyCleared.emit()
def paintEvent(self, event): qp = QPainter() qp.begin(self) qp.setRenderHint(QPainter.Antialiasing) elapsed = self._elapsed_timer.restart() if elapsed > 100: elapsed = 100 self._t += 0.0002 * elapsed x = self._offset_x + self._ampl_x * math.sin(self._coeff_x * self._t + self._coeff_delta) y = self._offset_y + self._ampl_y * math.sin(self._coeff_y * self._t) qp.setPen(self._pen) qp.setBrush(self._brush) qp.drawEllipse(QPointF(x, y), self._circle_size, self._circle_size) qp.end() self.cursorPos.emit(x, y, QDateTime.currentMSecsSinceEpoch())
def run(self): if self.state == States.DELAY: self.last_color = self.current_color = self.next_color = random.choice( self.colors) for window in self.windows: window.showFullScreen() window.update() self.timer.start(1000 * self.delay) self.state = States.NEXT_COLOR elif self.state == States.NEXT_COLOR: self.timer.stop() self.last_color, self.next_color = self.next_color, self._another_color( self.next_color) self.current_color = self.last_color self.repeat_count = GradientWindowController.get_repeat_count( self.last_color, self.next_color) repaint_interval_msec = int(1000 * self.repeat_interval / self.repeat_count) self.timer.start(repaint_interval_msec) self.repeated_count = 0 self.state = States.REPEAT print(QDateTime.currentMSecsSinceEpoch()) elif self.state == States.REPEAT: if self.repeated_count <= self.repeat_count: self.current_color = GradientWindowController.mix_colors( self.last_color, self.next_color, self.repeated_count / self.repeat_count) for window in self.windows: window.update() self.repeated_count += 1 else: self.repeated_count = 0 self.state = States.NEXT_COLOR
def paintEvent(self, event): qp = QPainter() qp.begin(self) qp.setRenderHint(QPainter.Antialiasing) elapsed = self._elapsed_timer.restart() if elapsed > 100: elapsed = 100 self._t += 0.0002 * elapsed x = self._offset_x + \ self._ampl_x * math.sin(self._coeff_x * self._t + self._coeff_delta) y = self._offset_y + \ self._ampl_y * math.sin(self._coeff_y * self._t) qp.setPen(self._pen) qp.setBrush(self._brush) qp.drawEllipse(QPointF(x, y), self._circle_size, self._circle_size) qp.end() self.cursorPos.emit(x, y, QDateTime.currentMSecsSinceEpoch())
def startBreak(self, time): self.breakStartMoment = QDateTime.currentMSecsSinceEpoch() self.displayLCD(time) self.breakInterval = time + 1000 self.breakTimer.start() self.showFullScreen()
def _currentTime(self): epochTime = QDateTime.currentMSecsSinceEpoch() return epochTime
def test(self): while(True): v = np.zeros((1, 1)) v[:] = np.sin(QDateTime.currentMSecsSinceEpoch() / 1000) self.signal_serial_update.emit(v) QThread.msleep(100)