Startup
This commit is contained in:
41
script/mytest/parallel.py
Normal file
41
script/mytest/parallel.py
Normal file
@@ -0,0 +1,41 @@
|
||||
#1. Example parallelizeing
|
||||
prefix="X12SA-OP-BPM6:";
|
||||
|
||||
def f2(c, v):
|
||||
print "Running ", c, " = " , v
|
||||
|
||||
def init_mod_par(prefix):
|
||||
cmd = "Erase/Start"
|
||||
parallelize((f2,(prefix + "Current1:TSControl",cmd)), \
|
||||
(f2,(prefix + "Current2:TSControl",cmd)), \
|
||||
(f2,(prefix + "Current3:TSControl",cmd)), \
|
||||
(f2,(prefix + "Current4:TSControl",cmd)) )
|
||||
|
||||
ret = parallelize((init_mod_par,("T1",)), (init_mod_par,("T2",)), (init_mod_par,("T3",)))
|
||||
|
||||
|
||||
|
||||
|
||||
#2. Parllelizing multiple modules with sequential init
|
||||
def init_module(prefix):
|
||||
start = time.time()
|
||||
caputq(prefix + "Current1:TSControl", "Erase/Start")
|
||||
caputq(prefix + "Current2:TSControl", "Erase/Start")
|
||||
caputq(prefix + "Current3:TSControl", "Erase/Start")
|
||||
caputq(prefix + "Current4:TSControl", "Erase/Start")
|
||||
print "Execution time = " + str(time.time() - start)
|
||||
init_module(pico_amp.prefix)
|
||||
|
||||
#ret = parallelize((init_module,(pico_amp.prefix,)), (init_module,(pico_amp2.prefix,)), (init_module,(pico_amp3.prefix,)))
|
||||
ret = parallelize((init_module,(pico_amp.prefix,)), (init_module,(pico_amp3.prefix,)))
|
||||
|
||||
#3,Parllelizing multiple modules with parallel init
|
||||
def init_mod_par(prefix):
|
||||
cmd = "Erase/Start"
|
||||
parallelize( (caputq,(prefix + "Current1:TSControl",cmd)), \
|
||||
(caputq,(prefix + "Current2:TSControl",cmd)), \
|
||||
(caputq,(prefix + "Current3:TSControl",cmd)), \
|
||||
(caputq,(prefix + "Current4:TSControl",cmd)) )
|
||||
|
||||
|
||||
ret = parallelize((init_mod_par,(pico_amp.prefix,)), (init_mod_par,(pico_amp2.prefix,)), (init_mod_par,(pico_amp3.prefix,)))
|
||||
77
script/mytest/test-time.py
Normal file
77
script/mytest/test-time.py
Normal file
@@ -0,0 +1,77 @@
|
||||
|
||||
import datetime
|
||||
import time
|
||||
|
||||
def now():
|
||||
return datetime.datetime.now()
|
||||
|
||||
# Prints one of the following formats*:
|
||||
# 1.58 days
|
||||
# 2.98 hours
|
||||
# 9.28 minutes # Not actually added yet, oops.
|
||||
# 5.60 seconds
|
||||
# 790 milliseconds
|
||||
# *Except I prefer abbreviated formats, so I print d,h,m,s, or ms.
|
||||
def format_delta(start,end):
|
||||
|
||||
# Time in microseconds
|
||||
one_day = 86400000000
|
||||
one_hour = 3600000000
|
||||
one_second = 1000000
|
||||
one_millisecond = 1000
|
||||
|
||||
delta = end - start
|
||||
|
||||
build_time_us = delta.microseconds + delta.seconds * one_second + delta.days * one_day
|
||||
|
||||
days = 0
|
||||
while build_time_us > one_day:
|
||||
build_time_us -= one_day
|
||||
days += 1
|
||||
|
||||
if days > 0:
|
||||
time_str = "%.2fd" % ( days + build_time_us / float(one_day) )
|
||||
else:
|
||||
hours = 0
|
||||
while build_time_us > one_hour:
|
||||
build_time_us -= one_hour
|
||||
hours += 1
|
||||
if hours > 0:
|
||||
time_str = "%.2fh" % ( hours + build_time_us / float(one_hour) )
|
||||
else:
|
||||
seconds = 0
|
||||
while build_time_us > one_second:
|
||||
build_time_us -= one_second
|
||||
seconds += 1
|
||||
if seconds > 0:
|
||||
time_str = "%.2fs" % ( seconds + build_time_us / float(one_second) )
|
||||
else:
|
||||
ms = 0
|
||||
while build_time_us > one_millisecond:
|
||||
build_time_us -= one_millisecond
|
||||
ms += 1
|
||||
time_str = "%.2fms" % ( ms + build_time_us / float(one_millisecond) )
|
||||
print time_str;
|
||||
return time_str
|
||||
|
||||
# returns the elapsed milliseconds since the start of the program
|
||||
def millis():
|
||||
dt = datetime.now() - start_time
|
||||
ms = (dt.days * 24 * 60 * 60 + dt.seconds) * 1000 + dt.microseconds / 1000.0
|
||||
return ms
|
||||
#d = datetime.now()
|
||||
#print "datetime.now", d
|
||||
def TimestampMillisec64():
|
||||
return int((datetime.datetime.utcnow() - datetime.datetime(1970, 1, 1)).total_seconds() * 1000)
|
||||
|
||||
now();
|
||||
#format_delta(1496394245,1596400000);
|
||||
ticks = time.time()
|
||||
print "Number of ticks since 12:00am, January 1, 1970:", ticks
|
||||
#print time_str;
|
||||
localtime = time.asctime( time.localtime(time.time()) )
|
||||
print "Local current time :", localtime
|
||||
|
||||
from datetime import datetime
|
||||
dt = datetime.now()
|
||||
print "datetime.now", dt
|
||||
16
script/mytest/test1.py
Normal file
16
script/mytest/test1.py
Normal file
@@ -0,0 +1,16 @@
|
||||
#rel_x = pico_bpm6_new_x.read()
|
||||
rel_x = pico_bpm6_ts_x.read()
|
||||
|
||||
class SensorXAxis(ReadableArray):
|
||||
def __init__(self, sensor):
|
||||
self.sensor = sensor
|
||||
def read(self):
|
||||
return [x + self.sensor.getTimestamp() for x in rel_x]
|
||||
def getSize(self):
|
||||
return len(rel_x) #only reads if cache is None
|
||||
|
||||
|
||||
x_axis = SensorXAxis(pico_bpm6_ts_sumall)
|
||||
|
||||
#plot(x_axis.read())
|
||||
plot(x_axis)
|
||||
Reference in New Issue
Block a user