def thread_cal(self, start, end): patch = 1 # print(start,end) Mysql = mysql() Mysql.init() cur = Mysql.db.cursor() for rmp in range(start, end, 1): i = orgin_data[rmp] patch += 1 # print("x") try: cur.execute(string % ('\'A' + i[3] + '\'')) if patch % 100 == 0: print(patch, self.id) dj = cur.fetchall() distances = [] # print(1) for j in dj: # print(j[2],j[1],i[1],i[0]) distances.append( haversine(float(j[2]), float(j[1]), float(i[1]), float(i[0]))) wps = np.argsort(distances) sp = kp['wor'] ex = sp % (dj[wps[0]][0], distances[wps[0]], i[2]) # print(ex) cur.execute(ex) Mysql.db.commit() except Exception as e: print("?")
def select_sql(center, radios): r = cal(radios) c1 = center[0] - r c2 = center[0] + r r1 = center[1] + r r2 = center[1] - r p = mysql() p.init() cur = p.db.cursor() string = get_sql("../full/sl.json", "s_npp") cur.execute(string % (str(c1), str(c2), str(r1), str(r2))) data = cur.fetchall() data = np.array(data) return data[:, 0:2]
def get_time(): p = mysql() p.init() cur = p.db.cursor() string = "select Time from acident" cur.execute(string) time_data = cur.fetchall() time_dict = {} npc = [] for i in list(time_data): npc.append(i[0]) for i in npc: if i not in time_dict: time_dict[i] = 0 time_dict[i] += 1 print(time_dict) times = np.zeros(24 * 60) n_time = np.zeros(24 * 6) for key in time_dict.keys(): if (key != 'nan'): times[time_transform(key)] = time_dict[key] for i in range(0, 24 * 60, 10): print(i) s = 0 for x in range(10): s += times[i + x] n_time[int(i / 10)] = s x = [] for i in range(0, 24 * 6): x.append(tran_time(i, 10)) x = range(0, 24 * 6) plt.scatter(x, n_time) plt.show()
from calL.dis import haversine from sql.kmql import mysql import pandas as pd import json import threading import time import numpy as np Mysql = mysql() Mysql.init() f = open("sl.json", 'r') kp = json.loads(f.read()) map_key = {"3": "A"} cur = Mysql.db.cursor() cur.execute(kp['s_3p']) orgin_data = cur.fetchall() string = kp['s_r2p'] patch = 1 class mThread(threading.Thread): def init(self, id, start, end): self.id = id self.st = start self.end = end def run(self): self.thread_cal(self.st, self.end) def thread_cal(self, start, end):
import folium import pandas as pd from folium import plugins from sql.kmql import mysql import json import numpy as np from xixi.caculate import cal p = mysql() p.init() f = open('sql.json', 'r') sqls = json.loads(f.read()) def gnmd(result): lix = [] for i in result: lix.append(i) icd = folium.map.FeatureGroup() for i in lix: icd.add_child( folium.CircleMarker( i, radius=6, # define how big you want the circle markers to be color='yellow', fill=True, fill_color='red', fill_opacity=0.4)) return icd