def setUp(self): t = datetime.now() ts = [] for i in range(3): ts.append(t+timedelta(0,i)) self.testSymbol1 = symbol(value=4,bars=[bar(False),bar(True),bar(False),bar(True,wide=True),bar(False),bar(True),bar(False),bar(False)],pulses=ts) self.symbols = generateSymbols()
def makec(self,symbols,time): real_symbols = [] #for every symbol for symbol in symbols: if symbol.value!=None: value = symbol.value else: value = random.randint(0,99) #if not, create a random one for realSymbol in self.symbols: #find the corresponding real symbol appended = False if (value==realSymbol.value): #and the val match real_symbols.append(realSymbol) #keep the real symbol appended = True break #quit when you're done if not appended: for identifier in self.identifiers: #find the corresponding real symbol appended = False if (value==identifier.value): #and the val match real_symbols.append(identifier) #keep the real symbol appended = True break #quit when you're done if not appended: raise ValueError('Could not find a defined symbol with value,',value) #now let's take care of the timeStamps final_symbols = [] new_time = time for c in range(len(real_symbols)): new_time new_symbol = copy(real_symbols[c]) new_symbol.timeStamp = copy(new_time) final_symbols.append(new_symbol) new_time = new_time + timedelta(0,len(real_symbols[c])*self.modulus) #for real_symbol in real_symbols: # print "!!",real_symbol return final_symbols
def make(system_symbols, symbols, time_stamp, modulus=0.5, ratio=2.0, debug=True): newSymbols = [] for s in symbols: #create random symbols if their values aren't defined if s.value is not None: newSymbols.append(s) else: newSymbols.append(system_symbols[random.randint(0, 99)]) bars = [] for nS in newSymbols: #accumulate all of the bars bars.extend(nS.bars) pulses = [] #print bars first_found = False first = None for b in bars: #iterate through the bars, creating pulses where needed time = modulus if b.wide: time = modulus * 2.0 if b.peak: if first_found is False and first is not None: first_found = True first += timedelta(0, time / ratio) if first is None: first_found = True first = timedelta(0, time / ratio) pulses.append(time_stamp + timedelta(0, time / ratio)) if first_found is False and first is not None: first += timedelta(0, time) if first is None: first = timedelta(0, time) time_stamp += timedelta(0, time) for i in range(len(pulses)): pulses[i] = pulses[i] - first return pulses, time_stamp
def make(self,symbols,timeStamp,modulus=0.5,ratio=2.0,debug=False): newSymbols = [] for s in symbols: #create random symbols if their values aren't defined if s.value is not None: newSymbols.append(s) else: newSymbols.append(self.symbols[random.randint(0,99)]) bars = [] for nS in newSymbols: #accumulate all of the bars bars.extend(nS.bars) pulses = [] #print bars first_found = False first = None for b in bars: #iterate through the bars, creating pulses where needed time = modulus if b.wide: time = modulus*2.0 if b.peak: if first_found is False and first is not None: first_found = True first += timedelta(0,time/ratio) if first is None: first_found = True first = timedelta(0,time/ratio) #pdb.set_trace() pulses.append(pulse(timeStamp=timeStamp+timedelta(0,time/ratio))) if first_found is False and first is not None: first += timedelta(0,time) if first is None: first = timedelta(0,time) timeStamp += timedelta(0,time) for i in range(len(pulses)): pulses[i].timeStamp = pulses[i].timeStamp - first return pulses,timeStamp
def setup(self): rightNow = datetime.now() later = rightNow + timedelta(0,1) self.beforePulse = pulse(timeStamp=rightNow) self.afterPulse = pulse(timeStamp=later) self.testPulse = pulse(timeStamp=rightNow,amplitude=100,d2x=50)
#we need to work with floats for comparison from helper import smart_datetime as datetime from helper import smart_timedelta as timedelta #not sure why this is still here def to_float(dt): return float(dt.hour * 60 * 60) + float(dt.minute * 60) + float( dt.second) + float(dt.microsecond / 1000000.0) modulus = 0.5 toDelta = lambda t: timedelta(0, t) system_symbols = generateSymbols() system_identifiers = generateIdentifiers() def make(system_symbols, symbols, time_stamp, modulus=0.5, ratio=2.0, debug=True): newSymbols = [] for s in symbols: #create random symbols if their values aren't defined if s.value is not None:
from copy import copy from symbol_generation import generateSymbols, generateIdentifiers #we need to work with floats for comparison from helper import smart_datetime as datetime from helper import smart_timedelta as timedelta #not sure why this is still here def to_float(dt): return float(dt.hour*60*60) + float(dt.minute*60) + float(dt.second) + float(dt.microsecond/1000000.0) modulus = 0.5 toDelta = lambda t: timedelta(0,t) system_symbols = generateSymbols() system_identifiers = generateIdentifiers() def make(system_symbols,symbols,time_stamp,modulus=0.5,ratio=2.0,debug=True): newSymbols = [] for s in symbols: #create random symbols if their values aren't defined if s.value is not None: newSymbols.append(s) else: newSymbols.append(system_symbols[random.randint(0,99)]) bars = [] for nS in newSymbols: #accumulate all of the bars