def generate_nodes(filename, nodes_filename, optimize=True): print("Generating nodes to", nodes_filename) node_list = {} for shp in load_list(filename): for passage in shp.passages: for key, value in split_passage(passage).items(): if key not in node_list: node_list[key] = Node(key, node_list) node_list[key].add_passage(passage, value) # Remove if node has fewer than x samples removed_nodes = [] for key, val in node_list.items(): if len(val.passages) < 20: #print("Del", key, len(val.passages)) removed_nodes.append(key) for key in removed_nodes: del node_list[key] optimize_k(node_list, nodes_filename, optimize)
def recommend(): my_list = mylist.load_list() database_list = database.load_list() mylist_note = [] for i in range(len(my_list)): # mylist에 저장한 모든 향수들의 노트를 합친 리스트 mylist_note = mylist_note + my_list[i][4].split(',') # 노트 네임 수 mylist_count = {} for i in mylist_note: try: mylist_count[i] += 1 except: mylist_count[i] = 1 # 노트 Name을 count에 따라 내림차순으로 정렬 mylist_rank = sorted(mylist_count.items(), key=(lambda x: x[1]), reverse=True) myfavorite = mylist_rank[0][0] html_recommend_list = [] for i in range(len(database_list)): if myfavorite in database_list[i][4].split(','): html_recommend_list.append(database_list[i]) html_recommend_list = random.sample(html_recommend_list, 5) return render_template("recommend.html", html_recommend_list=html_recommend_list)
def _get_entity_type(self, entity_dict): head = entity_dict["root_lemma"].split(' ')[-1] s = database.load_list('scene-nouns.txt') if entity_dict["root_lemma"] in s or head in s: entity_dict['type'] = 'scene' else: entity_dict['type'] = 'unknown' return entity_dict
def list(): house_list = database.load_list() length = len(house_list) return render_template("list.html", house_list = house_list, length = length)
import pandas as pd import route import ship as sh import constants as c import database as db import numpy as np import pandas as pd from route import route_in_area from map import Map from alphashape import alphashape from descartes import PolygonPatch #nodes = db.load_list(c.NODES_FILENAME) ships = db.load_list(c.SHIPS_FILENAME) def draw_reach_area(start_date, end_date): dates = [r for r in pd.date_range(start_date, end_date)] # parallel processing for unix if sys.platform == 'linux': print(sys.platform) with Pool() as pool: points = pool.map(points_reaching_measurement_area, dates) pool.close() pool.join() else: points = [points_reaching_measurement_area(r) for r in dates]
import random import numpy as np from scipy import stats import matplotlib.pyplot as plt import constants as c from node import Node from database import load_list, save_list from map import Map from predict import new_passage, center_cogs, feature_preparation from sklearn.neighbors import KNeighborsClassifier, NearestNeighbors BOOTSTRAP_SAMPLES = 200 nodes = load_list(c.NODES_FILENAME) tnodes = load_list(c.TEST_NODES_FILENAME) #n = nodes[11] #for i, na in enumerate(nodes): # print(i, na.reach_k, na.reach_percentage()) def pick_random_passage(node, n): labeleds = [i for i in range(0, len(node.label))] size = len(labeleds) if len(labeleds) < n else n return random.sample(labeleds, size)
if t == 2: attrib = "reach_k" label = "Optimoitu K" check = reach_k scale = c.MAX_K if t == 3: attrib = "alpha" label = "Optimoitu painotuskerroin (suunta=1, nopeus=0)" scale = 1 def ToNearest(n, to_nearest): x = (n + (to_nearest / 2)) % to_nearest return np.around(n + 0.1 - x, 2) nodes = db.load_list(c.NODES_FILENAME) x1 = (79323, 6431055, 1530041717) x2 = (348298, 6620462, 1530070027) #print("Drawing reach percentages...") #node.draw_reach_percentages(db.load_list(c.NODES_FILENAME), limit=0.95) colormap = "RdYlGn" cmap = cm.get_cmap(colormap) values = [] for n in nodes: attrib_value = getattr(n, attrib)
def list(): house_list = database.load_list() length = len(house_list) # html에서 length를 사용하기 위해서 받아서 넘김 return render_template("list.html", house_list=house_list, length=length)
from map import Map from database import load_list import node as nd import route from util import get_closest import pandas as pd import predict import numpy as np from constants import NODES_FILENAME, TEST_NODES_FILENAME nodes = load_list(NODES_FILENAME) x1 = (79323, 6431055, 1530041717) x2 = (348298, 6620462, 1530070027) #print(util.get_velocity(x1, x2)) #print(len(noude.passages)) x1 = (230846, 6598117, 0) x2 = (235846, 6642117, 100) pas, exits = predict.predict_path(nodes, x1, x2) print("Arrives in", exits, "h") noude = get_closest(nodes, x1[0], x1[1]) #predict.test_case(noude) noude.draw('green') #print(noude.accuracy_score, noude.optimal_k)
from util import readable_time def pick_random_passage(nodefile): while True: testnode = random.choice(nodefile) rand = random.randint(0, len(testnode.passages) - 1) testpassage = testnode.passages[rand] if bool(testnode.label[rand]) is True: if testpassage.reaches[0] < 60: return testpassage n_train = load_list(c.NODES_FILENAME) n_test = load_list(c.TEST_NODES_FILENAME) testpassage = pick_random_passage(n_test) testpassage.plot() Map.draw_circle(testpassage.x[0], testpassage.y[0], 3000, "yellow") #Map.draw_circle(testpassage.x[20], testpassage.y[20], 3000, "purple") print(testpassage.reaches, " reaches") #print(testpassage.enters_meas_area() / 3600, " - ", testpassage.time[0] / 3600) real_arrival = testpassage.enters_meas_area() - testpassage.time[0] #real_arrival2 = testpassage.enters_meas_area() - testpassage.time[22] predict_p, predict_t = predict.predict_path( n_train, (testpassage.x[0], testpassage.y[0], testpassage.time[0]),