def get_products(): conf = ut.getConfig() da = DataAccess(conf) query = "select * from products" result = da.select_row(query) return result
def render(self): env = Environment(loader=FileSystemLoader('templates'), autoescape=select_autoescape(['html', 'xml']), trim_blocks=True, lstrip_blocks=True) dataAccess = DataAccess() data = dataAccess.get_formatted_location_data() template = env.get_template('template.html') rendered_output = template.render(locations=data) return rendered_output
def move_time(): da = DataAccess() name_1 = input("距離計算の場所を一つ入力してください") name_2 = input("距離計算の場所を、もう一つ入力してください") spot_list = da.get_latitude_longitude(name_1) x = da.get_latitude_longitude(name_2) a = np.array([]) b = np.array([]) for spot, i in zip(spot_list, x): a = np.append(a, spot, axis=0) b = np.append(b, i, axis=0) move_time = space_calc(a[1], a[0], b[1], b[0]) print(move_time / 4.0)
def createProduct(): try: p_name = request.json['name'] p_desc = request.json['description'] p_price = request.json['price'] p_int_price = float(p_price) conf = ut.getConfig() da = DataAccess(conf) query = "INSERT INTO products (`name`, `description`, `price`) VALUES ('{0}', '{1}', {2})".format( p_name, p_desc, str(p_price)) print query da.execute_query(query) p_obj = dict(success=True, error="") except Exception as ex: p_obj = dict(success=False, error=str(ex)) return json.dumps(p_obj)
def post(self): element_idelement = DataAccess.getLastElementId() element_name = self.request.get("name") element_price = self.request.get("price") element_photo = self.request.get("photo") element_type = self.request.get("type") # STORE ELEMENT element = DataAccess.Elemento.query(element_idelement == DataAccess.Elemento.idElement) if element.count() == 0: e = DataAccess.Elemento() e.idElement = element_idelement e.name = element_name e.type = element_type e.price = element_price e.photo = element_photo e.put()
def __init__(self,config): self._procs = {} self._tracking = {} self._newkey = 0 self._done = False self._nextpid = 0 self._hostname = 'localhost' self._modulepath = "%s/proc/" % environ['STARSPATH'] self._data_access = DataAccess( environ['STARSPATH'] + '/stars.config' ) if not config == None: if 'root_path' in config: self._modulepath = '%s/proc/' % config['root_path'] if 'hostname' in config: self._hostname = config['hostname'] self.display( OUTPUT_VERBOSE, 'initialized with modulepath of %s' % (self._modulepath) )
def getElementsOfType(self, type): username = self.request.cookies.get("username") name = DataAccess.Usuario.name usuario = DataAccess.Usuario.query(name == username) useradmin = False if usuario.count() == 1: for aux in usuario: useradmin = aux.admin elemts = DataAccess.getElements(type) for ele in elemts: self.response.out.write('<table name="table' + ele.idElement + '"><tr>') self.response.out.write('<tr><td>' + ele.name + '</td><td>' + ele.price + '</td></tr>') self.response.out.write('<tr><td><img src="' + ele.photo + '"/></td>') if useradmin == "admin": self.response.out.write("<td><input type='button' class='button' value='Delete' onclick=\"deleteElement(\'" + ele.idElement + "\')\"/>") elif useradmin: self.response.out.write("<td><input type='button' class='button' value='-' onclick=\"minusElement(\'" + ele.idElement + "\')\"/>") self.response.out.write('<input type="text" id="element" value=0') self.response.out.write("<td><input type='button' class='button' value='+' onclick=\"plusElement(\'" + ele.idElement + "\')\"/>") self.response.out.write('<td></tr></table>')
def proc(raw): dataaccess = DataAccess(raw) elements = dataaccess.get_level_data() evals = dataaccess.get_evals() classes = dataaccess.get_classes() relative_weights = dataaccess.get_weight_result() mem_grades = calculate_membership_grade(evals, classes) tree = ElementTree(elements) tree.set_membership_grade(mem_grades) weights = calculate_weight(relative_weights, tree.get_pids(), tree.get_nodes()) tree.set_weight(weights) final_weight = tree.fuzzy_synthetic_evaluation() final_score = calculate_final_score(final_weight, classes) res = {} res["_result"] = final_score res["_errorno"] = 0 return res
from dataaccess import DataAccess import numpy as np da = DataAccess() x = da.get_distance() a = np.array([]) for i in x: a = np.append(a,i,axis=0) a = a.reshape(5,3) print(a)
from dataaccess import DataAccess import itertools import math hoge = DataAccess() count = 0 list_latitude = {} list_longitude = {} #赤道、極半径 red_rad = 6378.137 pol_rad = 6356.752 name = {} name_ex = {} name_box = [] time_box = [] #化成緯度、経度それぞれ辞書型に格納 for id_n in range(1, 11): x = list(itertools.chain.from_iterable(hoge.get_spots(id_n))) #化成緯度のリスト list_latitude[count] = x[2] list_longitude[count] = x[3] name[count] = x[0] name_ex[count] = x[0] name_box.append(x[0]) count += 1 def make_dist(point_A, point_B): #print(point_A + "から" + point_B + "までの時間") #適当なidを取得
from dataaccess import DataAccess import numpy as np da = DataAccess() #意味的計算(内積) spot_list = da.get_impression() a = np.array([]) for spot in spot_list: a = np.append(a,spot, axis=0) a = a.reshape(5,4) print(a) c = 3 print(c) b = np.zeros(c) x = input("その場所に歴史がありますか?(あればはいでなければいいえ)") if x == "はい": b[0] = 1 y = input("その場所に自然がありますか?(あればはいでなければいいえ)") if y == "はい": b[1] = 1 z = input("その場所に景観がありますか?(あればはいでなければいいえ)") if z == "はい": b[2] = 1 kekka = [] for item in a: kekka.append([item[0], np.sum(item[1:].astype(np.int) * b)]) kekka.sort(reverse=True) print(kekka)
def __init__(self): self.data = DataAccess() self.location_data = None
class Scraper: def __init__(self): self.data = DataAccess() self.location_data = None def get_class(self, soup_content, tag, class_to_search): mydivs = soup_content.findAll(tag, {"class": class_to_search}) return mydivs def load_location_data(self): with open(location_data_file) as f: file_data = json.load(f) self.location_data = file_data print('File read Location data:') print(self.location_data) for location in self.location_data: self.data.add_location(location) def parse_category(self, content, location): burgers = list() current_burger_name = None description_text = [] html_category_name = None category_title_content = self.get_class(content, 'h5', 'et_pb_toggle_title') for result in category_title_content: for title_children in result.children: if 'NavigableString' in str(type(title_children)): # Parse CategoryName html_category_name = title_children category_content = self.get_class(content, 'div', 'et_pb_toggle_content') for result in category_content: for burger_children in result.children: if 'Tag' in str(type(burger_children)): if burger_children.name == 'h3': if burger_children.contents: if 'NavigableString' in str( type(burger_children.contents[0])): # Parse Burger Name burger_name = burger_children.contents[0] if not current_burger_name == burger_name: if current_burger_name and ( not current_burger_name.isspace() ) and description_text: burgers.append({ 'burger_name': current_burger_name, 'description': description_text, 'category': html_category_name, 'location': location }) current_burger_name = burger_name description_text = [] if burger_children.name == 'p' or burger_children.name == 'span' or burger_children.name == 'em': for description_children in burger_children.children: if 'NavigableString' in str( type(description_children)): if description_children and ( not description_children.isspace()): description_text.append( description_children) if 'Tag' in str(type(description_children)): description_child_text = description_children.get_text( ) if description_child_text and ( not description_child_text.isspace()): description_text.append( description_child_text) if current_burger_name and ( not current_burger_name.isspace()) and description_text: burgers.append({ 'burger_name': current_burger_name, 'description': description_text, 'category': html_category_name, 'location': location }) return burgers def parse_page(self, content, location): print(f'Getting burgers from {location}.') burgers = list() soup = BeautifulSoup(content, 'lxml') rotating_burgers_divs = self.get_class(soup, 'div', rotating_burgers_class) for rotating_burgers_div in rotating_burgers_divs: burgers_retrieved = self.parse_category(rotating_burgers_div, location) burgers.extend(burgers_retrieved) classic_burgers_divs = self.get_class(soup, 'div', classic_burgers_class) for classic_burgers_div in classic_burgers_divs: burgers_retrieved = self.parse_category(classic_burgers_div, location) burgers.extend(burgers_retrieved) fries_divs = self.get_class(soup, 'div', fries_class) for fries_div in fries_divs: fries_retrieved = self.parse_category(fries_div, location) burgers.extend(fries_retrieved) pp.pprint(burgers) return burgers def remove_useless_items(self, menu_items): filtered_menu_items = list() for menu_item in menu_items: if not menu_item['burger_name'] in items_to_ignore: filtered_menu_items.append(menu_item) return filtered_menu_items def recategorize_rotating_fries(self, menu_items): for menu_item in menu_items: if menu_item['category'] == 'Fries': menu_item['category'] = 'Rotating Fries' return menu_items def populate_burgers(self, url, location): burgers = self.read_page(url, location) burgers = self.remove_useless_items(burgers) burgers = self.group_classics(burgers) burgers = self.recategorize_rotating_fries(burgers) if burgers: self.data.bulk_insert(burgers) else: print('No burgers found.') def populate_all_burgers(self): all_burgers = list() if self.location_data: for location in self.location_data: if 'url' in location: print(f'Reading Page {location}') burgers = self.read_page(location['url'], location['locationName']) burgers = self.remove_useless_items(burgers) burgers = self.group_classics(burgers) burgers = self.recategorize_rotating_fries(burgers) if burgers: self.data.bulk_insert(burgers) burgers.extend(burgers) else: print( f"No burgers found for location {location['locationName']}" ) return all_burgers def group_classics(self, burgers): for burger in burgers: if burger['category'] == 'Classic Burgers': burger['location'] = 'All Locations' return burgers def read_all_pages(self): for location in self.location_data: print(f'Reading Page {location}') self.read_page(location['url'], location['locationName']) def read_page(self, url, location): http = urllib3.PoolManager() headers = { 'User-Agent': 'whatsatabes.com bot', } r = http.request('GET', url, headers=headers) page_content = str(r.data.decode('utf-8')) r.release_conn() return self.parse_page(page_content, location)
from dataaccess import DataAccess from Genetic_Algorithm import Genetic_Algorithm import numpy as np da = DataAccess() # GA = Genetic_Algorithm() # spot_list = da.get_name_latitude_longitude() # a = np.array([]) # for spot in spot_list: # a = np.append(a,spot, axis=0) # a = a.reshape(5,3) # print(a[:,0]) space = np.array([]) name_x = input("調べたい場所を入力してください") space_x = da.get_spots_by_space_name(name) sapce = np.append(sapce, space_x) name_y = input("調べたい場所を入力してください") space_y = da.get_spots_by_space_name(name) sapce = np.append(sapce, space_y) name_z = input("調べたい場所を入力してください") space_z = da.get_spots_by_space_name(name) sapce = np.append(sapce, space_z) print(space) time = np.array(time) spot_list = da.get_time() a = np.array([]) for spot in spot_list: a = np.append(a, spot, axis=0) a = a.reshape(5, 3)
from dataaccess import DataAccess from Genetic_Algorithm import Genetic_Algorithm import numpy as np da = DataAccess() # GA = Genetic_Algorithm() spot_list = da.get_name_latitude_longitude() a = np.array([]) for spot in spot_list: a = np.append(a, spot, axis=0) a = a.reshape(5, 3) print(a[:, 0]) spot_name = a[:, 0] spot_list = a[:, 1:].astype(np.float) GA = Genetic_Algorithm(len(spot_list), spot_list, spot_name) GA.main()
from dataaccess import DataAccess from db import DB da = DataAccess() print("----") spot_list = da.get_spots_by_area("神奈川") for spot in spot_list: print(spot) # spot_list = da.get_spots("神奈川") # for spot in spot_list: # print(spot)
from dataaccess import DataAccess from db import DB da = DataAccess() spot_list = da.get_spots() for spot in spot_list: print(spot) print("----") spot_list = da.get_spots_by_area("神奈川") for spot in spot_list: print(spot) print("----") spot_list = da.get_latlng_by_spot_name("皇居") for spot in spot_list: print(spot) print("----") spot_list = da.get_openclose_by_spot_name("皇居") for spot in spot_list: print(spot) print("----") spot_list = da.get_spot_by_features(1, 0, 1, 1, 0) for spot in spot_list: print(spot) print("----") spot_list = da.get_spot_by_branch(22) for spot in spot_list: print(spot)
from dataaccess import DataAccess from Genetic_Algorithm import Genetic_Algorithm import numpy as np da = DataAccess() # GA = Genetic_Algorithm() # spot_list = da.get_name_latitude_longitude() # a = np.array([]) # for spot in spot_list: # a = np.append(a,spot, axis=0) # a = a.reshape(5,3) # print(a[:,0]) space = np.array([]) name_x = input("調べたい場所を入力してください") space_x = da.get_spots_by_space_name(name_x) space = np.append(space, space_x) name_y = input("調べたい場所を入力してください") space_y = da.get_spots_by_space_name(name_y) space = np.append(space, space_y) name_z = input("調べたい場所を入力してください") space_z = da.get_spots_by_space_name(name_z) space = np.append(space, space_z) space = space.reshape(3, 3) print(space) # a = np.array([]) # for spot in space: # a = np.append(a,spot, axis=0) # a = a.reshape(3,3) # kekka = []
class ProcessManager(object): _procs = None _tracking = None _modulepath = None _newkey = None _done = False _nextpid = None _hostname = None _data_access = None def __init__(self,config): self._procs = {} self._tracking = {} self._newkey = 0 self._done = False self._nextpid = 0 self._hostname = 'localhost' self._modulepath = "%s/proc/" % environ['STARSPATH'] self._data_access = DataAccess( environ['STARSPATH'] + '/stars.config' ) if not config == None: if 'root_path' in config: self._modulepath = '%s/proc/' % config['root_path'] if 'hostname' in config: self._hostname = config['hostname'] self.display( OUTPUT_VERBOSE, 'initialized with modulepath of %s' % (self._modulepath) ) def done(self): return self._done and len(self._procs) == 0 def newProc(self,config): self.display( OUTPUT_VERBOSE, 'attemping to create new process' ) result = None if 'general' in config: pid = self._nextpid while pid in self._procs: pid = pid + 1 if not pid in self._procs: break self._nextpid = pid + 1 self.display( OUTPUT_VERBOSE, 'found free pid of %d' % pid ) proc = self._createProc(pid,config) if not proc == None: try: self.display( OUTPUT_MINOR, 'starting process %d' % ( pid ) ) self._procs[pid] = proc self._tracking[pid] = { 'out':{}, 'ref':{}, 'started':time(), 'config':config,'issued':0, 'priority':0, 'workers':0, 'state':proc.state, 'notask':False, 'name':'' } if 'workers' in config['general']: self.setWorkers( pid, config['general']['workers'] ) if 'priority' in config['general']: self.setPriority( pid, config['general']['priority'] ) self._tracking[pid]['name'] = config['general']['modulename'] if 'name' in config['general']: self._tracking[pid]['name'] = config['general']['name'] result = pid except: displayExcept() self.delProc( pid ) pid = None return result def delProc(self,pid): result = None if pid in self._tracking: cwd = getcwd() chdir( self._modulepath ) rmtree( str(pid), ignore_errors = True ) chdir( cwd ) self.display( OUTPUT_LOGIC, 'process %d modules deleted' % pid ) result = pid del self._tracking[pid] if pid in self._procs: result = pid del self._procs[pid] if result == pid: self.display( OUTPUT_MINOR, 'process %d deleted' % result ) return result def _createProc(self,pid,config): proc = None procpath = None cwd = getcwd() load = True try: if 'resources' in config['general'] and 'modulepath' in config['general']: self.display( OUTPUT_LOGIC, 'setting up python modules for process %d from: %s::%s' % ( pid, config['general']['resources'], config['general']['modulepath'] ) ) #self.display('setting up process modules') cwd = getcwd() chdir( self._modulepath ) self.display( OUTPUT_DEBUG, 'set current working directory to %s' % getcwd() ) rmtree( str(pid), ignore_errors=True ) mkdir( str(pid) ) chdir( str(pid) ) self.display( OUTPUT_DEBUG, 'set current working directory to %s' % getcwd() ) temp = config['general']['resources'].split(':') srcHost = None srcPath = None fileName = None if len( temp ) == 1: srcPath = dirname(temp[0]) fileName = split(temp[0])[1] elif len( temp ) == 2: srcHost = temp[0] srcPath = dirname(temp[1]) fileName = split(temp[1])[1] if self._data_access.collect( getcwd(), fileName, srcHost, srcPath, fileName ): fname = split( config['general']['resources'] )[1] self.display( OUTPUT_DEBUG, 'trying to decompress %s' % fname ) #self.display( OUTPUT_DEBUG, 'files in process directory' ) #system( 'ls -al' ) if 0 == system( 'tar zxf %s' % fname ): #self.display( OUTPUT_DEBUG, 'files in process directory' ) #system( 'ls -al' ) config['general']['localresources'] = '%s/%s' % ( getcwd(), split( config['general']['resources'] )[1] ) files = listdir( config['general']['modulepath'] ) if path.count( getcwd() ) == 0: procpath = getcwd() + '/' + config['general']['modulepath'] path.insert( 0, procpath ) self.display( OUTPUT_DEBUG, 'updated module path to include %s' % procpath ) #for f in files: # if f.endswith( '.py' ): # move( config['general']['modulepath'] + '/' + f, './' ) # self.display( OUTPUT_DEBUG, 'moved %s into process cache' % f ) #self.display( OUTPUT_DEBUG, 'files in process directory' ) #system( 'ls -al' ) # reload the module so we have the latest copy for f in files: if f.endswith( '.py' ): #print path #print getcwd() #print f.split('.')[0] module = __import__( f.split('.')[0] ) reload( module ) self.display( OUTPUT_DEBUG, 'loaded module %s' % f.split('.')[0] ) #rmtree( dirname(config['general']['modulepath']), ignore_errors = True ) #self.display( OUTPUT_DEBUG, 'files in process directory' ) #system( 'ls -al' ) else: self.display( OUTPUT_ERROR, 'failed to extract resources' ) chdir( self._modulepath ) rmtree( str(pid), ignore_errors = True ) load = False else: self.display( OUTPUT_ERROR, 'failed to setup resources' ) chdir( self._modulepath ) rmtree( str(pid), ignore_errors = True ) load = False if load and 'modulename' in config['general']: self.display( OUTPUT_DEBUG, 'creating process %d as: %s' % ( pid, config['general']['modulename'] ) ) module = __import__( config['general']['modulename'].lower() ) reload(module) context = {'config':config} proc = eval( 'module.%s( context, pid )' % config['general']['modulename'] ) else: self.display( OUTPUT_ERROR, 'failed to start process' ) chdir( self._modulepath ) rmtree( str(pid), ignore_errors = True ) except: displayExcept() rmtree( str(pid), ignore_errors=True ) chdir( cwd ) proc = None self.display( OUTPUT_ERROR, 'failed to create process' ) if not load and not procpath == None: if path.count( procpath ) > 0: display( OUTPUT_DEBUG, 'removing path from process' ) path.remove( procpath ) return proc def nextControlTask(self): ctask = None for pid in self._tracking: info = self._tracking[pid] if info['state'] == PROC_READY: self.display( OUTPUT_VERBOSE, 'process %d is running, checking for control task' % pid ) ctask = self._procs[pid].nextControlTask() if not ctask == None: self.display( OUTPUT_LOGIC, 'process %d gave control task %s' % (pid,str(ctask)) ) ctask.pid = pid break return ctask def nextTask(self,pid): task = None if pid in self._tracking: info = self._tracking[pid] if info['state'] == PROC_READY: self.display( OUTPUT_VERBOSE, 'process %d is running, asking for task' % pid ) task = self._task( pid ) return task def firstDoneProc(self): result = None for pid in self._tracking.keys(): info = self._tracking[pid] if info['state'] == PROC_DONE: self.display( OUTPUT_VERBOSE, 'process %d is the first done' % pid ) result = pid break return result def nextProc(self): self.display( OUTPUT_VERBOSE, 'selecting next process' ) result = None try: maxP = -1 maxW = -1 minS = -1 for pid in self._tracking.keys(): info = self._tracking[pid] self._procs[pid].determineState() if self._procs[pid].state == PROC_DONE: self.stopProc( pid ) info = self._tracking[pid] if not self._procs[pid].state == PROC_READY: continue if info['notask']: info['notask'] = False continue if info['state'] == PROC_READY: pri = info['priority'] wai = info['workers'] - len(info['out']) ser = info['issued'] #print 'p%d - pri %d (%d) wai %d (%d) ser %d (%d)' % ( pid, pri, maxP, wai, maxW, ser, minS ) # seed the search if minS == -1: #print 'a' self.display( OUTPUT_VERBOSE, 'chose pid %d as default.' % pid ) maxP = pri maxW = wai minS = ser result = pid # higher priority and ( needs to fill quota or turn in line ) elif pri > maxP and ( wai > 0 or wai >= maxW ): self.display( OUTPUT_VERBOSE, 'chose pid %d because it has higher priority and gets next worker' % pid ) maxP = pri maxW = wai minS = ser result = pid # equal priority needing more resources elif pri == maxP and wai > maxW: self.display( OUTPUT_VERBOSE, 'chose pid %d because it needs more workers' % pid ) maxP = pri maxW = wai minS = ser result = pid # equal standing, pick the one least chosen elif pri == maxP and wai == maxW and ser < minS: self.display( OUTPUT_VERBOSE, 'chose pid %d because it is under-serviced' % pid ) maxP = pri maxW = wai minS = ser result = pid elif info['state'] == PROC_STOP: self.endProc( pid ) except: displayExcept() result = None if not result == None: self.display( OUTPUT_DEBUG, 'process %d is the next in line' % result ) return result def _task(self,pid): task = None if pid in self._procs: info = self._tracking[pid] try: task = self._procs[pid].task() if isinstance( task, Task ): task.pid = pid task.key = self._newkey self._newkey = self._newkey + 1 if task.key in info['out'] or task.key in info['ref'] : self.display( OUTPUT_ERROR, 'non-unique task key! %s' % str(task.key) ) info['out'][ task.key ] = time() info['ref'][ task.key ] = task info['issued'] = info['issued'] + 1 if task.recover(): if task.state == SUCCESS or task.state == ERROR: self.returnTask( task ) task = None elif not task == None: self.endProc(pid) except: displayExcept() self.display( OUTPUT_ERROR, 'encountered error getting task from process %d' % pid ) info['state'] = PROC_ERROR if not task == None: self.returnTask( task ) self.endProc( pid ) if task == None: info['notask'] = True else: self.display( OUTPUT_ERROR, 'requested task for unknown process %d' % pid ) return task def peekTask(self,pid): task = None if pid in self._procs: task = self._procs[pid].peek() else: self.display( OUTPUT_ERROR, 'requested peek for unknown process %d' % pid ) return task def getProcConfig(self,pid): result = None if pid in self._tracking: result = self._tracking[pid]['config'] return result def endProc(self,pid): self.display( OUTPUT_VERBOSE, 'checking if process %d is done.' % pid ) if pid in self._tracking: info = self._tracking[pid] if len(info['out']) == 0 and info['state'] == PROC_ERROR: self.display( OUTPUT_LOGIC, 'process %d had error and is ready to shutdown' % pid ) info['state'] = PROC_STOP if len(info['out']) == 0 and info['state'] == PROC_STOP: self.display( OUTPUT_LOGIC, 'process %d is done.' % pid ) info['state'] = PROC_DONE def stopProc(self,pid): if pid in self._tracking and self._tracking[pid]['state'] == PROC_READY: self.display( OUTPUT_MINOR, 'stopping process %d' % pid ) self._tracking[pid]['state'] = PROC_STOP self.endProc( pid ) def shutdown(self): self.display( OUTPUT_MAJOR, 'received shutdown request' ) for pid in self._tracking.keys(): self.stopProc( pid ) self._done = True def setPriority(self,pid,priority): try: priority = int( priority ) if pid in self._tracking: self.display( OUTPUT_MINOR, 'setting process %d to priority %d' % ( pid, priority ) ) self._tracking[pid]['priority'] = priority except: self.display( OUTPUT_ERROR, 'invalid priority %s' % str(priority) ) def setWorkers(self,pid,workers): try: workers = int(workers) if pid in self._tracking: self.display( OUTPUT_MINOR, 'setting process %d to workers %d' % ( pid, workers ) ) self._tracking[pid]['workers'] = workers except: self.display( OUTPUT_ERROR, 'invalid workers %s' % str(workers) ) def returnTask(self,task): if isinstance( task, Task ): self.display( OUTPUT_VERBOSE, 'received task' ) if task.pid in self._tracking: self.display( OUTPUT_DEBUG, 'task is known' ) info = self._tracking[task.pid] if task.key in info['out']: del info['out'][ task.key ] if task.key in info['ref']: del info['ref'][ task.key ] try: if not task.store(): self.display( OUTPUT_ERROR, 'task %s for process %d failed to store results' % (task.id(),task.pid) ) info['state'] = PROC_ERROR self.display( OUTPUT_LOGIC, 'gave process %d task %s' % (task.pid,task.id()) ) self._procs[task.pid].handle( task ) except: displayExcept() self.display( OUTPUT_ERROR, 'process %d encountered an error handling task %s' % (task.pid,task.id()) ) info['state'] = PROC_ERROR self.endProc(task.pid) def display(self, level, text): display( level, 'Process Manager: %s' % text )
from dataaccess import DataAccess import numpy as np da = DataAccess() # spot_list = da.get_spots() # for spot in spot_list: # print(x) # print("----") # spot_list = da.get_spots_by_area("長野") # for spot in spot_list: # print(spot) # print("----") # spot_list = da.get_latlng_by_spot_name("白馬五竜スキー場") # for spot in spot_list: # print(spot) # print("----") # spot_list = da.get_openclose_by_spot_name("白馬五竜スキー場") # for spot in spot_list: # print(spot) # print("----") # # spot_list = da.get_spot_by_features(0, 1, 1, 1, 1) # # for spot in spot_list: # # print(spot) # # print("----") # spot_list = da.get_spot_by_branch(22) # for spot in spot_list: # print(spot) # print("----") # ##ここから追記 # spot_list = da.get_temperature("白馬五竜スキー場")
from dataaccess import DataAccess import numpy as np da = DataAccess() #時間的計算(内積) name = input("調べたい場所を入力してください") time = da.get_spots_by_time(name) time = np.array(time) spot_list = da.get_time() a = np.array([]) for spot in spot_list: a = np.append(a, spot, axis=0) a = a.reshape(5, 3) kekka = [] for item in a: kekka.append( [item[0], np.sum(item[1:].astype(np.float) * time.astype(np.float))]) print(kekka)
from dataaccess import DataAccess import numpy as np from distance_movetime import space_calc da = DataAccess() #空間的計算(ユークリッド) name = input("調べたい場所を入力してください") space = da.get_spots_by_space(name) space = np.array(space) spot_list = da.get_space() a = np.array([]) for spot in spot_list: a = np.append(a, spot, axis=0) a = a.reshape(5, 3) print(a[1, 1:]) print(space[0, 0]) kekka = [] for item in a: # kekka.append([item[0], np.linalg.norm(item[1:].astype(np.float) - space.astype(np.float))]) kekka.append([ item[0], space_calc(item[1].astype(np.float), item[2].astype(np.float), space[0, 0].astype(np.float), space[0, 1].astype(np.float)) ]) print(kekka)