Exemplo n.º 1
0
def benchmark(f, acurate_time=1):
    """Checks how much time does function f work. It runs it as
    many times as needed for avoiding inaccuracy"""

    runs = 1
    while True:
        start_time = time_func()
        for _ in xrange(runs):
            f()
        dt = time_func() - start_time
        if dt >= acurate_time:
            break
        runs *= 2
    return dt / runs
Exemplo n.º 2
0
def benchmark(f, acurate_time=1):
    """Checks how much time does function f work. It runs it as
    many times as needed for avoiding inaccuracy"""

    runs = 1
    while True:
        start_time = time_func()
        for _ in xrange(runs):
            f()
        dt = time_func() - start_time
        if dt >= acurate_time:
            break
        runs *= 2
    return dt / runs
Exemplo n.º 3
0
def time(name=None):
    from time import time as time_func
    if name is None:
        name = 'DEFAULT'
    print(f'[Timer::{name}] Start...')
    start = time_func()
    yield
    print(f'[Timer::{name}] End. Time elapsed = {time_func() - start}')
Exemplo n.º 4
0
 def pre_schedule(self):
     now = time_func()
     while self.tasks:
         D, task, T = heappop(self.tasks)
         if now - T >= D:
             self.schedule.install(task)
         else:
             heappush(self.tasks, (D, task, T))
             break
     self.active = len(self.tasks) > 0
Exemplo n.º 5
0
 def pre_schedule(self):
     now = time_func()
     while self.tasks:
         D,task,T = heappop(self.tasks)
         if now - T >= D:
             self.schedule.install(task)
         else:
             heappush(self.tasks, (D,task,T))
             break 
     self.active = len(self.tasks) > 0
Exemplo n.º 6
0
 def handle(self, T, task):
     heappush(self.tasks, (float(T), task, time_func()))
     self.active = True
Exemplo n.º 7
0
 def handle(self, T, task):
     heappush(self.tasks, (float(T),task,time_func()))
     self.active = True
Exemplo n.º 8
0
import sys
import serial

path_BEIDOU = os.path.join(
    os.path.dirname(os.path.dirname(os.path.dirname(
        os.path.abspath(__file__)))), "beidou")
sys.path.append(path_BEIDOU)
from beidou import TXA

serial_BEIDOU = serial.Serial("/dev/ttyUSB1", 115200)
txa = TXA(user_address='0247718', serial=serial_BEIDOU, transfer_method='1')
txa.read()

_DEBUG_ = False

time_old = time_func()

values = {}
names = ['PM2.5', 'CO', 'SO2', 'O3', 'HCHO', 'MQ2']

txa.send(b"$CCICI,0,00*73\r\n")

while True:

    value_pm25 = sensor_api.read_value('PM2.5')
    if value_pm25 > 0:
        # print("\t\tpm2.5 :", value_pm25)
        values['PM25'] = value_pm25

    value_CO = sensor_api.read_value('CO')
    if value_CO > 0: