def query(self): query = self.maker.query() join_on = [] for x in self.xaxis: name = random_field() join_on.append(name) x = x.label(name) query.append_column(x) query = query.group_by(Column(x.name)) name = random_field() column = Visitor(self._column).visit() query.append_column(column.label(name)) field = random_field() query = query.alias(random_table()) self._query.append_column(column.label(field)) if self.attr('result_type') == 'rate': value = (Column(field) - query.columns[name]) / query.columns[name] else: value = Column(field) - query.columns[name] self.maker.add_value(value) self.maker.add_join(query, [ query.columns.get(name) == Column(self.maker.xalias[i]) for i, name in enumerate(join_on) ]) return self._query
def tryout(self, d): examplevisitor = Visitor() attracties = [5, 8, 10, 22, 26, 1, 0, 4] permutatie = examplevisitor.calculate(lijstvanattracties=attracties, dataclass=d, generations=100) print(permutatie)
def insertVisitor(self, input_file): f = open(input_file, 'r') lines = f.readlines() count = 0 for line in lines: try: # process each line info = line.strip().split(',') name = info[0].split(' ', 1) # split by first occurrence only first_name = name[0].strip() last_name = '' if (len(name) == 2): # if user has first name only last_name = name[1].strip() visitorObj = Visitor(first_name, last_name, info[1].strip(), info[2].strip(), info[3].strip(), info[4].strip()) date_of_visit = visitorObj.getDateOfVisit() if (self.__today is None or self.__today < date_of_visit): # today is the latest date self.__today = date_of_visit self.__parkStorage.insert(visitorObj) count += 1 except Exception as error: print('error occurred while insertig visitor', error) self.__output.writelines([ "\n---------- insert ----------\nTotal visitors detailed entered: ", str(count), "\n-----------------------------\n" ]) f.close()
def main(argv): input_stream = FileStream(argv[1]) lexer = c2llvmLexer(input_stream) stream = CommonTokenStream(lexer) parser = c2llvmParser(stream) tree = parser.prog() v = Visitor() v.visit(tree) if (len(argv) == 3): print(v.module, file=open(argv[2], 'w')) print(v.module)
def test(): path = os.getcwd() + "/results " if not os.path.isdir(path): os.mkdir(path) for j in os.listdir("tests"): text = open("tests/" + j, "r") i = text.read() print(i) v = Visitor() v.start(str(i)) logger = v.get_logger() logger.printx()
def register_visitor(self, name, surname, tariff, comment) -> int: """ Записывает в таблицу посетителя с именем name, фамилией surname, тарифом tariff и опционально с комментарием, возвращает идентификатор нового посетителя""" # Корректность значения tariff гарантируется. visitor = Visitor(name, surname, float(tariff), comment) insert_visit_response = self.service.spreadsheets().values().append( spreadsheetId=self.spreadsheet_id, range="A1:H1", valueInputOption="USER_ENTERED", body=self.__get_insert_visit_request(visitor)).execute() # Получение номера последней строки. last_row_index = int(insert_visit_response['updates'] ['updatedRange'].split(':')[-1][1:]) # Запрос на копирование формул. self.service.spreadsheets().batchUpdate( spreadsheetId=self.spreadsheet_id, body=self.__get_formula_expansion_request( last_row_index)).execute() # Возвращаем номер последней строки в качестве идентификатора посетителя. return last_row_index
def parse(filename, debug=False): with open(filename) as file: contents = file.read() parser = ParserPEG(calc_grammar, "start", True) parse_tree = parser.parse(contents) visitor = Visitor(debug=debug) result = visit_parse_tree(parse_tree, visitor ) #Try to get if we found anything or not if ( visitor.functions or visitor.classes): print (visitor.namespace ) return visitor print ("Empty") return None
def start_visitor(self, module_name, index_gpx): track_seg = self.gpxs[index_gpx].track.track_segment v = Visitor(track_seg) N = len(self.loaded_modules) for i in range(N): if module_name == self.active_modules[i].module_name: self.active_modules[i].accept(v)
def _run_checker(checker, mode, set_of_files): if mode == 'full': files = core.get_files(set_of_files) else: files = core.get_files(set_of_files, checker.get_pattern_hint()) if not files: cnf = 'Could not find any problem related to ' cnf += checker.get_problem_type().lower() sys.stderr.write(cnf + '\n') else: print __current_wip(checker, files) visitor = Visitor(checker) index = Index.create() for c_file in files: root = index.parse(c_file, options=TranslationUnit.PARSE_DETAILED_PROCESSING_RECORD) ReportBlocker.blocked_lines = [] visitor.visit(root.cursor, c_file)
def table(self): import copy from visitor import Visitor root = self.expr.get('root', {}) table = copy.deepcopy(root.get('from')) if table: table['key'] = 'from' return Visitor(table).visit()[0]
def xaxis(self): from visitor import Function result = [] for x in self.maker.xaxis: v = Visitor(x).visit() if not Function.accept(x): result.append(v) continue result.append(self.next_time(x)) return result
def main(ctx, **argv): verbosity = argv.pop("verbosity").upper() logging.basicConfig(format='%(asctime)s %(message)s', level=verbosity) token = argv.pop("token", None) ctx.obj = Context() ctx.obj.visitor = Visitor(token=token)
def parseRegex(str): #print(str) stream = InputStream(str) lexer = rGexLexer(stream) stream = CommonTokenStream(lexer) parser = rGexParser(stream) tree = parser.regex() printer = Visitor() walker = ParseTreeWalker() walker.walk(printer, tree) return printer.stack.pop()
def simulateVisits(self, totalvisitors, proportionthatuseapp, dataclass): # let's assume for a second that everyone arrives at 8u30 but is active at 8 listofvisitors = [ Visitor() for j in range(int(proportionthatuseapp * totalvisitors)) ] for i in listofvisitors: print(i.__class__) amountofusers = proportionthatuseapp * totalvisitors list = [0 for i in range(10)] list[0] = 1.3 list[1] = 0.6 list[2] = 0.6 list[3] = 0.5 list[4] = 0.5 list[5] = 0.6 list[6] = 0.4 list[7] = 0.4 list[8] = 0.1 list[9] = 0.1 timeline = [0 for x in range(10000)] for i in range(10): clicks = int(list[i] * amountofusers) # add clicks in random places for k in range(clicks): timeline[random.randint(i * 1000, i * 1000 + 999)] += 1 for j in range(10000): currenttime = j / 10000 * 118 for i in range(timeline[j]): # take random visitor and make him click ;) vis = listofvisitors[random.randint(0, amountofusers)] amountofattractions = random.normalvariate(15, 2) listofattractions = [] for kl in range(int(amountofattractions)): r = random.randint(0, 27) if r not in listofattractions: listofattractions.append(r) # oldstartinglocation, oldstartinghour, oldpermutation, newstartinghour currentlocation = dataclass.getcurrentlocation( vis.locatie, vis.hourofstart, vis.permutatie, currenttime) vis.calculate(locatie=currentlocation, lijstvanattracties=listofattractions, uur=currenttime, dataclass=dataclass, generations=200) return
def main(debug=False): filename = sys.argv[1] #debug = bool(sys.argv[2]) with open(filename) as file: contents = file.read() #print (contents) # # An expression we want to evaluate input_expr = """class Application extends Container implements HttpKernelInterface, TerminableInterface, ResponsePreparerInterface { """ # input_expr = input input_expr = contents if not input_expr: return None # First we will make a parser - an instance of the calc parser model. # Parser model is given in the form of PEG notation therefore we # are using ParserPEG class. Root rule name (parsing expression) is "calc". parser = ParserPEG(calc_grammar, "start", True) # Then parse tree is created out of the input_expr expression. parse_tree = parser.parse(input_expr) visitor = Visitor(debug=debug) result = visit_parse_tree(parse_tree, visitor ) print (visitor.namespace ) #print (visitor.classes ) #print (visitor.functions ) # analyseASG( parser, input, Visitor(), True, False ) # Then parse tree is created out of the input_expr expression. #parse_tree = parser.parse(input_expr) #result = parser.getASG(sem_actions) #print( parse_tree ) #print( result ) if debug: # getASG will start semantic analysis. # In this case semantic analysis will evaluate expression and # returned value will be evaluated result of the input_expr expression. # Semantic actions are supplied to the getASG function. print("{} = {}".format(input_expr, result))
def query(self): columns = Visitor({'list': self._column['operands']}).visit() for col in columns: self._query = self._query.group_by(col) count = func.count(text('1')) self._query.append_column(count.label('count_num')) self._query.append_column( case([(count > text('1'), count)], else_=text('0')).label('repeat_num')) query = select().select_from(self._query.alias('repeat_table')) for name in self.maker.xalias: query = query.group_by(Column(name)) query.append_column(Column(name)) query.append_column( func.sum(Column('repeat_num')) / func.sum(Column('count_num'))) return query
def new_visitor(sorting=False, data=None, extra_data=None): if data is None: data = {'a-b': 'ab', 'b-c': 'bc'} g = load_graph('test-visitor', data) record = AttrDict() record.visited = [] record.origins = {} def tf(d): return extra_data def vf(data, iteration, origin, steps): if data.nid in record.visited: verb("This node was already visited.") return False verb("This node not visited yet.") record.visited.append(data.nid) record.origins[data.nid] = origin return True v = Visitor(g, tf, vf, sorting=sorting) return v, g, record
def main(): parser = argparse.ArgumentParser(description='Tag Music Files.') parser.add_argument('root', help='Root path for files to tag.') parser.add_argument('--freezefile', help='Freeze the data from the initial read to this file.') parser.add_argument('--extensions', nargs='+', default=['mp3', 'm4a', 'm4p'], help="List of extensions to search for.") parser.add_argument('--logfile', help='Log for tag logging data.') args = parser.parse_args() visitor = Visitor(args.extensions) if args.freezefile and exists(args.freezefile): visitor.thaw(args.freezefile) else: visitor.find_files(args.root) print("Found a total of {} {} files.".format(visitor.count, visitor.type)) if args.logfile: with open(args.logfile, 'w') as fp: visitor.tagall(logfp=fp) else: visitor.tagall() if args.freezefile: visitor.freeze(args.freeze)
def __init__(self, replaceRootConstruct): Visitor.__init__(self) self._store = {} self._fop = None self.__currentConstructAccessor = [ (replaceRootConstruct, None) ]
def db_updatevisitor(v: Visitor): cur.execute('UPDATE Visitors SET \ fname=?, lname=?, gender=?, dob=?, mobile=?, email=? \ WHERE id = ?' ,\ (v.fname, v.lname, v.gender, v.get_strdob(), v.mobile, v.email, v.id))
cur.execute('SELECT last_insert_rowid()') v.id = cur.fetchone()[0] def db_updatevisitor(v: Visitor): cur.execute('UPDATE Visitors SET \ fname=?, lname=?, gender=?, dob=?, mobile=?, email=? \ WHERE id = ?' ,\ (v.fname, v.lname, v.gender, v.get_strdob(), v.mobile, v.email, v.id)) def db_insertvisit(d: Visit): cur.execute('INSERT INTO Visits (indate, outdate, paid, firstvisit) \ VALUES (?, ?, ?, ?)' ,\ (d.get_strin(), d.get_strout(), d.get_strpaid(), d.get_strisFirstVisit())) cur.execute('SELECT last_insert_rowid()') d.id = cur.fetchone()[0] db_init() visitor1 = Visitor('Anishka', 'Patel', datetime.today(), 'M', '87459712351', '*****@*****.**') visit1 = Visit(datetime.today(), datetime.today()) db_insertvisitor(visitor1) db_insertvisit(visit1) conn.commit() conn.close() visitor1.toConsole() visit1.toConsole()
def render(self, context): v = Visitor(context) return v.visit(self._tree)
from que import Queue from visitor import Visitor from oper import Operator, OperatorType import random queue = Queue() operator1 = Operator('Bob', [OperatorType.PAYTAX, OperatorType.OPENBIS], queue) operator2 = Operator('Bib', [OperatorType.OPENBIS, OperatorType.ASKQUESTION], queue) operator3 = Operator('Bub', [OperatorType.PAYTAX, OperatorType.ASKQUESTION], queue) for i in range(20): visitor = Visitor(OperatorType(random.randint(1, 3))) queue.addVisitor(visitor)
def db_insertvisitor(v: Visitor): cur.execute('INSERT INTO Visitors (fname, lname, gender, dob, mobile, email) \ VALUES (?, ?, ?, ?, ?, ?)' ,\ (v.fname, v.lname, v.gender, v.get_strdob(), v.mobile, v.email)) cur.execute('SELECT last_insert_rowid()') v.id = cur.fetchone()[0]
def __init__(self): self.printer = Visitor() st.beginScope('main')
if __name__ == '__main__': # adding test file name as command line argument argParser = argparse.ArgumentParser() argParser.add_argument('testFileName') args = argParser.parse_args() testFileName = args.testFileName try: with open(testFileName, 'r') as testFile: testFileData = testFile.readlines() except FileNotFoundError: print('Error: test file {} does not exist'.format(testFileName)) sys.exit() lexer = Lexer() tokens = lexer.lex(testFileData) verbose = True parser = Parser(verbose) parser.parse(tokens) ast = parser.AST print(parser.AST.equations) visiteur = Visitor() visiteur.doIt(ast) print(visiteur.Liste_variable) print("Nombre d'équations : ", visiteur.nb_eqs) visiteur.solveSystem(parser)
def function(self): from visitor import Visitor return Visitor(self.expr['operands'][0]).visit()
import os import threading from time import time, sleep import settings from log_etl import Log from visitor import Visitor start = time() log = Log(os.path.join(os.path.dirname(__file__),'data/data.txt')) v = Visitor(settings.TARGET_HOST) for data in log.etl(): elapsed = time()-start if ((data['time']-log.start) > (elapsed * settings.SPEED)): sleep((data['time']-log.start)-(elapsed * settings.SPEED)) while (threading.activeCount() > settings.THREAD_LIMIT): print "Threading limit reached. Sleeping..." sleep(settings.THREAD_LIMIT_SLEEP) v.visit(data['url']) v.close() log.close()
print("Total requests %s (aprox: %s / thread)" % (payload_size, payload_size / threads)) database_name = urlparse.urlparse(target).hostname manager = DBManager(database_name) # # Starting Manager and Payload processes # payload.daemon = True manager.daemon = True payload.start() manager.start() Visitor.set_discriminator(discriminator) Visitor.set_banned_location(autodiscriminator_location) Visitor.set_user_agent(user_agent) Visitor.set_proxy(proxy) Visitor.set_authentication(authentication) Visitor.set_requests(request_type) if size_discriminator: Visitor.set_size_discriminator(size_discriminator) if request_delay: Visitor.set_delay(request_delay) thread_pool = [] for number in range(0, threads + 1): v = Visitor(number, payload, manager.get_results_queue()) thread_pool.append(v) v.daemon = True
def addVisitor(self, visitor, trips): self.visitors.append(Visitor(visitor, trips))
database_name = urlparse.urlparse(target).hostname manager = DBManager(database_name) # # Starting Manager and Payload processes # payload.daemon = True manager.daemon = True payload.start() manager.start() # Give payload and manager time to get ready time.sleep(1) try: Visitor.set_discriminator(discriminator) Visitor.set_banned_location(autodiscriminator_location) Visitor.set_user_agent(user_agent) Visitor.set_proxy(proxy) Visitor.set_authentication(authentication) Visitor.set_requests(request_type) if size_discriminator: Visitor.set_size_discriminator(size_discriminator) if request_delay: Visitor.set_delay(request_delay) for number in range(0, threads + 1): v = Visitor(number, payload, manager.get_results_queue()) v.daemon = True v.start() while len(multiprocessing.active_children()) > 1:
def __get_insert_visit_request( self, visitor: Visitor, ): """ Возвращает тело запроса для добавления посетителя в таблицу """ return {"majorDimension": "ROWS", "values": [visitor.get_sheet_row()]}
def accept(self, visitor: Visitor): visitor.visit(self.construct_name, self)
def accept(self, visitor: Visitor, *args, **kwargs): return visitor.visit(self, *args, **kwargs)