def randomize(self): self.__class__.curDepth += 1 while True: self.type = randomizer.getRandom(self.probabilities) if self.type == 0: self.prefixedNonTypeName = prefixed_non_type_name() self.prefixedNonTypeName.randomize() elif self.type == 1: self.lvalue = l_value() self.member = member() self.member.randomize() elif self.type == 2: self.lvalue = l_value() self.expression = expression() self.expression.randomize() elif self.type == 3: self.lvalue = l_value() self.expression = expression() self.expression.randomize() self.expression2 = expression() self.expression2.randomize() if self.__class__.curDepth < self.__class__.maxDepth: if self.lvalue is not None: self.lvalue.randomize() if not self.filter(): break else: self.__class__.curDepth -= 1 self.__class__.curDepth -= 1
def test_unitaire_10(visible=False): print("*** expression: test_unitaire_10 ***") a = ex.expression("3 * ( x + 1 ) / (x - 20)") if visible: print("a =", a) b = ex.expression("x - 1") if visible: print("b =", b) x = a + b if visible: print("a + b = {}\n".format(x)) x = a - b if visible: print("a - b = {}\n".format(x)) x = a * b if visible: print("a * b = {}\n".format(x)) x = a / b if visible: print("a / b = {}\n".format(x)) a = ex.expression("x + 1") if visible: print("a =", a) n = ex.expression("4") if visible: print("n =", n) x = a**n if visible: print("a ** n = {}\n".format(x)) ok = True return ok
def get_expression(token_list): root, flag = expression.expression(token_list) if flag == False: raise exceptions.SyntaxNotMatched return root
def randomize(self): self.type_name = type_name() self.type_name.randomize() if self.type_name.prefixed_type is not None: self.expression = expression() self.expression.randomize() else: self.type_name = None
def test_unitaire_5(visible=False): print("*** expression: test_unitaire_5 ***") e = ex.expression("a + b") if visible: print(e) ok = e.est_valide() return ok
def test_unitaire_3(visible=False): print("*** expression: test_unitaire_3 ***") e = ex.expression("3") if visible: print(e) ok = (e.lire_valeur().lire_num().valuation() == ra.rationnel(3)) return ok
def test_unitaire_12(visible=False): print("*** expression: test_unitaire_12 ***") e = ex.expression("(2+1)/(x*x*x*x*x+1)") if visible: print(e) ok = e.est_valide() return ok
def test_unitaire_9(visible=False): print("*** expression: test_unitaire_9 ***") e = ex.expression("(a + b)/(x)") if visible: print(e) ok = e.est_valide() return ok
def test_unitaire_4(visible=False): print("*** expression: test_unitaire_4 ***") e = ex.expression("3 * ( 1/2 + 1 )") if visible: print(e) ok = e.est_valide() return ok
def randomize(self): from statement import statement common.usedRandomize() self.expression = expression() self.expression.randomize() self.if_statement = statement() self.if_statement.randomize() self.else_statement = statement() self.else_statement.randomize()
def test_unitaire_11(visible=False): print("*** expression: test_unitaire_11 ***") e = ex.expression("3 / ( (19 + 1) - 20 )") if visible: print("e =", e) e.afficher_erreur() ok = (not e.est_valide()) return ok
def test_unitaire_0(visible=False): print("*** expression: test_unitaire_0 ***") e = ex.expression("{5 * {x / 3} + [x - 1]}") if visible: print(e) print(repr(e)) f = frac.fraction() if visible: print(f) ok = e.est_valide() and f.est_valide() return ok
def randomize(self): self.type = randomizer.getRandom(self.probabilities) if self.type == 0: self.value = expression() elif self.type == 1: self.value = default_literal() elif self.type == 2: self.value = dontcare_literal() elif self.type == 3: self.value = mask_expression() elif self.type == 4: self.value = range_expression() self.value.randomize()
def reconstitute(filename, ref_gene, ref_sample): # assumes headings: Well Sample Cq Target # further assume that line ends may have been munged by Excel 2011 f = open(filename, 'r') buf = f.read().replace('\r', '\n').split('\n') norm = lambda line: [line[3], line[1], float(line[2])] buf = [norm(line.split('\t')) for line in buf[1:] if len(line) > 1] # now each line in buf looks like: ['Gapdh', 'Sample1', 20.95] sample_d, ignored_genes, ignored_samples = expression(buf, ref_gene, ref_sample) if ignored_genes: print >> sys.stderr, 'ignored genes:', ignored_genes if ignored_samples: print >> sys.stderr, 'ignored samples:', ignored_samples print 'Target\tSample\tValues' for target in sorted(sample_d.keys()): for sample in sorted(sample_d[target].keys()): print '%s\t%s\t%s' % (target, sample, '\t'.join([str(i) for i in sample_d[target][sample]]))
def reconstitute(filename, ref_gene, ref_sample): # assumes headings: Well Sample Cq Target # further assume that line ends may have been munged by Excel 2011 f = open(filename, 'r') buf = f.read().replace('\r', '\n').split('\n') norm = lambda line: [line[3], line[1], float(line[2])] buf = [norm(line.split('\t')) for line in buf[1:] if len(line) > 1] # now each line in buf looks like: ['Gapdh', 'Sample1', 20.95] sample_d, ignored_genes, ignored_samples = expression( buf, ref_gene, ref_sample) if ignored_genes: print >> sys.stderr, 'ignored genes:', ignored_genes if ignored_samples: print >> sys.stderr, 'ignored samples:', ignored_samples print 'Target\tSample\tValues' for target in sorted(sample_d.keys()): for sample in sorted(sample_d[target].keys()): print '%s\t%s\t%s' % (target, sample, '\t'.join( [str(i) for i in sample_d[target][sample]]))
def randomize(self): common.usedRandomize() self.expression = expression() self.expression.randomize() self.switch_casses = switch_casses() self.switch_casses.randomize()
def randomize(self): common.usedRandomize() self.left_expression = expression() self.left_expression.randomize() self.right_expression = expression() self.right_expression.randomize()
def randomize(self): rnd = randomizer.randint(self.min_list_size, self.max_list_size) for x in range(0, rnd): _expression = expression() _expression.randomize() self.exp_list.append(_expression)
def randomize(self): common.usedRandomize() self.value = expression() self.value.randomize()
def handle_message(self, message, bot_handler): content = False text = message['content'] # detects help message if "help" in text: content = """ Name: Randy Synopsis: {curly braces define optional input} ------------ Coin; @randy {<times> }c{oins weight <heads>:<tails>:<clumsy>} Examples; long:- `@randy 20 coin weight 20:10:30`, short:- `@randy 20cw2:1:3` ------------ Dice; @randy {<times> }d{ice <faces>,<stop>,<step> weight <number> <load>:<rest>:<clumsy> <operand>} Examples; long:- `@randy 20 dice 16,24,2 weight 16 20:10:30 +89`, short:- `@randy 20d16,24,2w16 20:10:30+89` ------------ Times - the number of times the action will be performed, with dice all results will be automatically accumulated and a final result given. Coin - the command used to define a coin flip. Dice - the command used to define a dice roll. Faces - the number of faces you want the die to have, becomes dice start value when stop and step are defined, with a default of 1. Stop - defines what number to stop at when deciding the size of the dice. Both start and stop are inclusive so put the number you would expect on the dice. Step - defines what the increments on the dice should be. Weight - the command given to inform that you wish to edit the weightings. Number - the number on the dice you wish to load. This must be followed by a space and then the ratio else it will default to 2:1. Heads - the weighting you wish heads to have. Weightings should be integer ratios, larger numbers mean it is more likely lower is less likely. Load - the weighting you wish the load number to have. Tails - the weighting you wish tails to have. Rest - the weighting you wish the rest of the numbers to have. Clumsy - this is a weighting with a default of 0 that allows the potential for the item to be lost during operation. Operand - this defines an operand `+`, `-`, `/`, or `*` that you can perform upon the accumulated dice rolls. This is mostly useful for applying buffs or debuffs. """ # prints purpose elif "purpose" in text: content = "My purpose is as a random item generator, I provide coin flips and dice rolls upon request, try `help` to to learn my commands." # responds to null input so you can check it's listening elif text == "" or text == "?": content = "yes?" else: command = expression.expression() matches = command.get_message(text) if matches == None: matches = [] # detects coin input if len(matches) == 4: times = test.test(matches[0]) heads = test.test(matches[1]) tails = test.test(matches[2]) clumsy = test.test(matches[3]) operand = "" item = coin.coin() results = item.parseCoin(times, heads, tails, clumsy) slug = "You flipped a coin " + str( times.value) + " times, the result was:\n" # detects dice input elif len(matches) == 10: times = test.test(matches[0]) faces = test.test(matches[1]) stop = test.test(matches[2]) step = test.test(matches[3]) number = test.test(matches[4]) load = test.test(matches[5]) rest = test.test(matches[6]) clumsy = test.test(matches[7]) operand = matches[8] value = test.test(matches[9]) try: if stop.value is None: faces.ifExists(6) item = die.createSimpleDie(faces.value) else: faces.ifExists(1) stop.ifExists(6) step.ifExists(1) item = die.die(faces.value, stop.value, step.value) except TypeError as error: content = str(error) else: try: results = item.parseDice(times, faces, number, load, rest, clumsy) except TypeError as error: content = str(error) else: slug = "You rolled a D" + str(len( item.weights.keys())) + " " + str( times.value) + " times, the result was:\n" # catches any other kind of input else: content = "I'm sorry what was that? I don't understand.\nType `help` to see the commands I know." # parses output in message friendly way if content == False: content = "" acc = 0 for item in results: if isinstance(item, int): acc += item content += ", " + str(item) content = content[2:] content = slug + content if operand is None and len(matches) == 10: content += " = " + str(acc) elif operand is not None and len(operand) != 0: value.ifExists(1) try: if operand == "+": acc += value.value elif operand == "-": acc -= value.value elif operand == "*": acc *= value.value elif operand == "/": acc /= value.value except ZeroDivisionError: content = "divide by zero? how dumb do you think I am?!" else: content += " " + operand + " " + str( value.value) + " = " + str(acc) # sends completed message and ends bot_handler.send_reply(message, content) return
def parse_char(self): ret = expression(self.currToken) self.next() return ret
ser = serial.Serial('/dev/ttyUSB0',115200) ser.flushOutput() ser.flushInput() print ser.name #print ser.readline() # Hotword detector def hotWord(models): sensitivity = [0.5]*len(models) detector = snowboydecoder.HotwordDetector(models, sensitivity=sensitivity) # main loop word = detector.start(detected_callback=snowboydecoder.play_audio_file, sleep_time=0.03) return(word) exp = expression.expression(ser) exp.sleepy() awake = hotWord(['Tinku.pmdl']) # Listening for word 'Tinku' while sleeping if (awake == '1'): exp.blink() while(True): word = hotWord(['take a picture.pmdl', 'Exit.pmdl']) print word if (word == '1'): cam = camera.camera() cam.picture() elif (word == '2'): pyautogui.hotkey('alt','f4') break;