@ohuoy/easymap 1.0.29 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/data/sys_log.sql +41 -0
- package/dist/example/create_report.py +326 -0
- package/index.js +5 -0
- package/package.json +1 -1
package/data/sys_log.sql
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Navicat Premium Data Transfer
|
|
3
|
+
|
|
4
|
+
Source Server : 80
|
|
5
|
+
Source Server Type : PostgreSQL
|
|
6
|
+
Source Server Version : 120000 (120000)
|
|
7
|
+
Source Host : 192.168.11.80:5432
|
|
8
|
+
Source Catalog : sdgydb
|
|
9
|
+
Source Schema : public
|
|
10
|
+
|
|
11
|
+
Target Server Type : PostgreSQL
|
|
12
|
+
Target Server Version : 120000 (120000)
|
|
13
|
+
File Encoding : 65001
|
|
14
|
+
|
|
15
|
+
Date: 16/09/2025 13:57:56
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
-- ----------------------------
|
|
20
|
+
-- Table structure for sys_log
|
|
21
|
+
-- ----------------------------
|
|
22
|
+
DROP TABLE IF EXISTS "public"."sys_log";
|
|
23
|
+
CREATE TABLE "public"."sys_log" (
|
|
24
|
+
"sl_id" int4 NOT NULL DEFAULT nextval('sys_log_sl_id_seq'::regclass),
|
|
25
|
+
"sl_time" timestamptz(6) NOT NULL,
|
|
26
|
+
"sl_machine_name" varchar(200) COLLATE "pg_catalog"."default" NOT NULL,
|
|
27
|
+
"sl_process_name" varchar(200) COLLATE "pg_catalog"."default" NOT NULL,
|
|
28
|
+
"sl_level" varchar(20) COLLATE "pg_catalog"."default" NOT NULL,
|
|
29
|
+
"sl_logger" varchar(8000) COLLATE "pg_catalog"."default",
|
|
30
|
+
"sl_message" varchar(8000) COLLATE "pg_catalog"."default",
|
|
31
|
+
"sl_call_site" varchar(8000) COLLATE "pg_catalog"."default",
|
|
32
|
+
"sl_thread" varchar(50) COLLATE "pg_catalog"."default",
|
|
33
|
+
"sl_exception" varchar(8000) COLLATE "pg_catalog"."default",
|
|
34
|
+
"sl_stacktrace" text COLLATE "pg_catalog"."default"
|
|
35
|
+
)
|
|
36
|
+
;
|
|
37
|
+
|
|
38
|
+
-- ----------------------------
|
|
39
|
+
-- Primary Key structure for table sys_log
|
|
40
|
+
-- ----------------------------
|
|
41
|
+
ALTER TABLE "public"."sys_log" ADD CONSTRAINT "sys_log_pkey" PRIMARY KEY ("sl_id");
|
|
@@ -0,0 +1,326 @@
|
|
|
1
|
+
import numpy as np
|
|
2
|
+
from sklearn.cluster import MeanShift
|
|
3
|
+
import datetime
|
|
4
|
+
import os
|
|
5
|
+
import math
|
|
6
|
+
import json
|
|
7
|
+
|
|
8
|
+
def read_SN(pols):
|
|
9
|
+
if pols == '': # 文件无法读取时,返回空
|
|
10
|
+
raise FileExistsError('该文件不存在或无法读取')
|
|
11
|
+
SN=pols[0]['lidarSN']
|
|
12
|
+
thetime=datetime.datetime.strptime(pols[0]['date'], '%Y-%m-%d %H:%M:%S')
|
|
13
|
+
DATE=thetime.strftime("%Y%m%d")
|
|
14
|
+
return SN,DATE
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
#从文件中读取污染源极坐标和时间
|
|
18
|
+
def read_xyz(pols,lng0,lat0):
|
|
19
|
+
if pols == '': # 文件无法读取时,返回空
|
|
20
|
+
raise FileExistsError('该文件不存在或无法读取')
|
|
21
|
+
#MINDISTANCE=1000
|
|
22
|
+
allx = []
|
|
23
|
+
alltime = []
|
|
24
|
+
ally = []
|
|
25
|
+
for k in pols:
|
|
26
|
+
n = 0
|
|
27
|
+
if 'lng' in k:
|
|
28
|
+
lng=k['lng']
|
|
29
|
+
if 'lat' in k:
|
|
30
|
+
lat=k['lat']
|
|
31
|
+
if 'Lng' in k:
|
|
32
|
+
lng=k['Lng']
|
|
33
|
+
if 'Lat' in k:
|
|
34
|
+
lat=k['Lat']
|
|
35
|
+
if 'date' in k:
|
|
36
|
+
date=k['date']
|
|
37
|
+
if 'Date' in k:
|
|
38
|
+
date=k['Date']
|
|
39
|
+
x,y=lnglat2xy(lng,lat,lng0,lat0)
|
|
40
|
+
allx.append(x)
|
|
41
|
+
ally.append(y)
|
|
42
|
+
atime=datetime.datetime.strptime(date, '%Y-%m-%d %H:%M:%S')
|
|
43
|
+
alltime.append(atime)
|
|
44
|
+
#print('国耀量子 版权所有')
|
|
45
|
+
return allx, ally, alltime
|
|
46
|
+
|
|
47
|
+
#把污染源空间聚类
|
|
48
|
+
def pts_cluster(x, y, polar=False, bandwidth=500):
|
|
49
|
+
# 转为np数组
|
|
50
|
+
x = np.array(x)
|
|
51
|
+
y = np.array(y)
|
|
52
|
+
if polar: # 输入为极坐标数据, x 为r, y为theta, 正北为0, 顺时针.
|
|
53
|
+
x0 = x * np.sin(np.radians(y))
|
|
54
|
+
y0 = x * np.cos(np.radians(y))
|
|
55
|
+
d = np.c_[x0, y0]
|
|
56
|
+
else: # 笛卡尔坐标
|
|
57
|
+
d = np.c_[x, y]
|
|
58
|
+
# 调用sklearn中的均值偏移函数
|
|
59
|
+
ms = MeanShift(bandwidth=bandwidth, bin_seeding=True)
|
|
60
|
+
# 训练数据
|
|
61
|
+
ms.fit(d)
|
|
62
|
+
# 数据集中每个点被各自bandwidth内中心点的访问次数来进行分类
|
|
63
|
+
output_label = ms.labels_
|
|
64
|
+
# 中心点坐标集合,该集合为数据形式[x,y]
|
|
65
|
+
cluster_centers = ms.cluster_centers_
|
|
66
|
+
if polar: # 输入为极坐标, 输出时将center转为极坐标输出
|
|
67
|
+
r = np.sqrt(cluster_centers[:, 0]**2 + cluster_centers[:, 1]**2)
|
|
68
|
+
theta = np.degrees(np.arctan2(cluster_centers[:, 0], cluster_centers[:, 1]))
|
|
69
|
+
theta[theta < -90] = theta[theta < -90] + 360 # [-180, 180] -> [-90, 270]
|
|
70
|
+
cluster_centers = np.c_[r, theta].round(3)
|
|
71
|
+
return output_label, cluster_centers
|
|
72
|
+
|
|
73
|
+
#把聚类后的污染区域的时间排出来
|
|
74
|
+
def label_time(label,time):
|
|
75
|
+
combinenumber=max(label)
|
|
76
|
+
polcombine=[[]for i in range(combinenumber+1)]
|
|
77
|
+
|
|
78
|
+
i=0
|
|
79
|
+
for polpoint in label:
|
|
80
|
+
polcombine[polpoint].append(time[i])
|
|
81
|
+
i=i+1
|
|
82
|
+
i=0
|
|
83
|
+
for polpoint in polcombine:
|
|
84
|
+
polcombine[i]=sorted(polpoint)
|
|
85
|
+
i=i+1
|
|
86
|
+
polcombine=sorted(polcombine,key=len,reverse=True)
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
return polcombine
|
|
91
|
+
|
|
92
|
+
#生成每个污染区域的污染时间段
|
|
93
|
+
def pol_time(polcombine,maxdiff=3600,mintime=1800):
|
|
94
|
+
pn=len(polcombine)
|
|
95
|
+
poltimequantum = [[] for i in range(pn)]
|
|
96
|
+
polintensity = [[] for i in range(pn)]
|
|
97
|
+
polintensity_fr = [[] for i in range(pn)]
|
|
98
|
+
poltime = [[] for i in range(pn)]
|
|
99
|
+
poltimequantum_fr = [[] for i in range(pn)]
|
|
100
|
+
poltime_fr = [[] for i in range(pn)]
|
|
101
|
+
j=0;
|
|
102
|
+
for point in polcombine:
|
|
103
|
+
i=0
|
|
104
|
+
for atime in point:
|
|
105
|
+
#poltime_fr[j].append(atime.strftime('%Y%m%d%H%M'))
|
|
106
|
+
if i==0:
|
|
107
|
+
k = 1 # 初始化排放量
|
|
108
|
+
start=atime
|
|
109
|
+
if i>0:
|
|
110
|
+
d=atime-lasttime
|
|
111
|
+
k=k+1
|
|
112
|
+
if i == len(point) - 1:
|
|
113
|
+
if d.seconds<=maxdiff:
|
|
114
|
+
lasttime = atime
|
|
115
|
+
k=k+1
|
|
116
|
+
|
|
117
|
+
if (lasttime-start).seconds>mintime or k>3:
|
|
118
|
+
|
|
119
|
+
polstart = start-datetime.timedelta(minutes=(start.minute)%5+30)
|
|
120
|
+
polstop = lasttime+datetime.timedelta(minutes=5-(lasttime.minute)%5)
|
|
121
|
+
poltimequantum[j].append([polstart,polstop])
|
|
122
|
+
polintensity[j].append(k-1)
|
|
123
|
+
start = atime
|
|
124
|
+
k = 1
|
|
125
|
+
|
|
126
|
+
elif d.seconds>=maxdiff:
|
|
127
|
+
if (lasttime-start).seconds>mintime or k>3:
|
|
128
|
+
polstart = start-datetime.timedelta(minutes=(start.minute)%5+30)
|
|
129
|
+
polstop = lasttime+datetime.timedelta(minutes=5-(lasttime.minute)%5)
|
|
130
|
+
poltimequantum[j].append([polstart,polstop])
|
|
131
|
+
polintensity[j].append(k-1)
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
start=atime
|
|
135
|
+
k = 1
|
|
136
|
+
i=i+1
|
|
137
|
+
lasttime = atime
|
|
138
|
+
poltimequantum[j],poltimequantum_fr[j],polintensity_fr[j]=time_combine(poltimequantum[j],polintensity[j])
|
|
139
|
+
[poltime[j].append(x) for x in polcombine[j] if time_just(poltimequantum[j],x)]
|
|
140
|
+
[poltime_fr[j].append(x.strftime('%Y%m%d%H%M%S')) for x in polcombine[j] if time_just(poltimequantum[j],x)]
|
|
141
|
+
j=j+1
|
|
142
|
+
return poltimequantum,polintensity_fr,poltime,poltimequantum_fr,poltime_fr
|
|
143
|
+
|
|
144
|
+
#生成每个污染区域的污染时间段
|
|
145
|
+
def pol_time2(polcombine):
|
|
146
|
+
pn = len(polcombine)#聚合数量
|
|
147
|
+
poltimequantum = [[] for i in range(pn)]
|
|
148
|
+
polintensity = [[] for i in range(pn)]
|
|
149
|
+
polintensity_fr = [[] for i in range(pn)]
|
|
150
|
+
poltime = [[] for i in range(pn)]
|
|
151
|
+
poltimequantum_fr = [[] for i in range(pn)]
|
|
152
|
+
poltime_fr = [[] for i in range(pn)]
|
|
153
|
+
j=0
|
|
154
|
+
for point in polcombine:
|
|
155
|
+
|
|
156
|
+
n2=len(point)#聚合内报警次数
|
|
157
|
+
start=point[0]
|
|
158
|
+
stop=point[-1]
|
|
159
|
+
polstart = start-datetime.timedelta(minutes=(start.minute)%5+30)
|
|
160
|
+
polstop = stop+datetime.timedelta(minutes=5-(stop.minute)%5)
|
|
161
|
+
poltimequantum[j].append([polstart,polstop])
|
|
162
|
+
polintensity[j].append(n2)
|
|
163
|
+
poltimequantum[j],poltimequantum_fr[j],polintensity_fr[j]=time_combine(poltimequantum[j],polintensity[j])
|
|
164
|
+
[poltime[j].append(x) for x in polcombine[j] if time_just(poltimequantum[j],x)]
|
|
165
|
+
[poltime_fr[j].append(x.strftime('%Y%m%d%H%M%S')) for x in polcombine[j] if time_just(poltimequantum[j],x)]
|
|
166
|
+
j=j+1
|
|
167
|
+
return poltimequantum,polintensity_fr,poltime,poltimequantum_fr,poltime_fr
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
def time_just(timelist,atime):
|
|
171
|
+
just=0
|
|
172
|
+
for timeq in timelist:
|
|
173
|
+
if atime>timeq[0] and atime<timeq[1]:
|
|
174
|
+
just=1
|
|
175
|
+
return just
|
|
176
|
+
|
|
177
|
+
#多个时间段若密集则合并
|
|
178
|
+
def time_combine(timelist,polintensity):
|
|
179
|
+
n=len(timelist)
|
|
180
|
+
if n==0:
|
|
181
|
+
return [],[],[]
|
|
182
|
+
combine=[timelist[0]]
|
|
183
|
+
combine_fr=[[timelist[0][0].strftime('%Y%m%d%H%M%S'),timelist[0][1].strftime('%Y%m%d%H%M%S')]]
|
|
184
|
+
polintensity_fr=[polintensity[0]]
|
|
185
|
+
if n<2:
|
|
186
|
+
return combine,combine_fr,polintensity
|
|
187
|
+
j=0
|
|
188
|
+
for i in range(n-1):
|
|
189
|
+
just=time_combine_just(timelist[i],timelist[i+1])
|
|
190
|
+
if just:
|
|
191
|
+
combine[j][1]=timelist[i+1][1]
|
|
192
|
+
combine_fr[j][1]=timelist[i+1][1].strftime('%Y%m%d%H%M%S')
|
|
193
|
+
polintensity_fr[j]=polintensity_fr[j]+polintensity[i+1]
|
|
194
|
+
else:
|
|
195
|
+
combine.append(timelist[i+1])
|
|
196
|
+
combine_fr.append([timelist[i + 1][0].strftime('%Y%m%d%H%M%S'),timelist[i + 1][1].strftime('%Y%m%d%H%M%S')])
|
|
197
|
+
polintensity_fr.append(polintensity[i+1])
|
|
198
|
+
j=j+1
|
|
199
|
+
return combine,combine_fr,polintensity_fr
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
#判断是否要合并区间
|
|
205
|
+
def time_combine_just(time1,time2):
|
|
206
|
+
start1 = time1[0]
|
|
207
|
+
stop1 = time1[1]
|
|
208
|
+
start2 = time2[0]
|
|
209
|
+
stop2 = time2[1]
|
|
210
|
+
if (stop1-start1+stop2-start2)>0.8*(stop2-start1):
|
|
211
|
+
return True
|
|
212
|
+
return False
|
|
213
|
+
|
|
214
|
+
|
|
215
|
+
#角度转弧度
|
|
216
|
+
def radian_list(degree):
|
|
217
|
+
radian=[]
|
|
218
|
+
for i in degree:
|
|
219
|
+
radian.append(math.radians(i))
|
|
220
|
+
return radian
|
|
221
|
+
|
|
222
|
+
#生成报告
|
|
223
|
+
def final_report(center,poltimequantum,polintensity,poltime,lng0,lat0):
|
|
224
|
+
i=0
|
|
225
|
+
finalreport=[]
|
|
226
|
+
|
|
227
|
+
for point in center:
|
|
228
|
+
if poltimequantum[i]:
|
|
229
|
+
polone={}
|
|
230
|
+
xy=point.tolist()
|
|
231
|
+
x=xy[0]
|
|
232
|
+
y=xy[1]
|
|
233
|
+
lng,lat=xy2lnglat(x,y,lng0,lat0)
|
|
234
|
+
polone['x'] = x
|
|
235
|
+
polone['y'] = y
|
|
236
|
+
polone['lng']=lng
|
|
237
|
+
polone['lat']=lat
|
|
238
|
+
polone['intensity']=polintensity[i]
|
|
239
|
+
polone['timequantum']=poltimequantum[i]
|
|
240
|
+
polone['time']=poltime[i]
|
|
241
|
+
#print(json.dumps(polreport))
|
|
242
|
+
finalreport.append(polone)
|
|
243
|
+
|
|
244
|
+
i=i+1
|
|
245
|
+
|
|
246
|
+
|
|
247
|
+
#with open("write_json.json", "w", encoding='utf-8') as f:
|
|
248
|
+
# json.dump(finalreport, f, ensure_ascii=False)
|
|
249
|
+
#json.dumps(finalreport)
|
|
250
|
+
return finalreport
|
|
251
|
+
|
|
252
|
+
|
|
253
|
+
|
|
254
|
+
|
|
255
|
+
|
|
256
|
+
|
|
257
|
+
|
|
258
|
+
# def create_path(ppath):
|
|
259
|
+
# if os.path.exists(ppath):
|
|
260
|
+
# pass
|
|
261
|
+
# else:
|
|
262
|
+
# os.mkdir(ppath)
|
|
263
|
+
# return 1
|
|
264
|
+
|
|
265
|
+
def lnglat2xy(lng,lat,lng0,lat0):
|
|
266
|
+
#lng0=117.148978#雷达经度
|
|
267
|
+
#lat0=36.689944#雷达纬度
|
|
268
|
+
ra = 6378140 # ⾚道半径
|
|
269
|
+
rb = 6356755 # 极半径
|
|
270
|
+
#flatten = (ra - rb) / ra # Partial rate of the earth
|
|
271
|
+
# change angle to radians
|
|
272
|
+
radlat = math.radians(lat)
|
|
273
|
+
radlng = math.radians(lng)
|
|
274
|
+
radlat0 = math.radians(lat0)
|
|
275
|
+
radlng0 = math.radians(lng0)
|
|
276
|
+
x=ra*math.cos(radlat0)*(radlng-radlng0)
|
|
277
|
+
y=ra*(radlat-radlat0)
|
|
278
|
+
return x,y
|
|
279
|
+
|
|
280
|
+
def xy2lnglat(x,y,lng0,lat0):
|
|
281
|
+
#lng0=117.148978#雷达经度
|
|
282
|
+
#lat0=36.689944#雷达纬度
|
|
283
|
+
ra = 6378140 # ⾚道半径
|
|
284
|
+
radlat0 = math.radians(lat0)
|
|
285
|
+
lat=lat0+math.degrees(y/ra)
|
|
286
|
+
lng=lng0+math.degrees(x/ra/math.cos(radlat0))
|
|
287
|
+
lng6=round(lng,6)
|
|
288
|
+
lat6=round(lat,6)
|
|
289
|
+
return lng6,lat6
|
|
290
|
+
|
|
291
|
+
def save_data(finalreport,filename='write_json.json'):
|
|
292
|
+
|
|
293
|
+
with open(filename, "w", encoding='utf-8') as f:
|
|
294
|
+
json.dump(finalreport, f, ensure_ascii=False)
|
|
295
|
+
return 1
|
|
296
|
+
|
|
297
|
+
|
|
298
|
+
def main_loop(lng0, lat0, windfilter, jsonstr=""):
|
|
299
|
+
raw = json.loads(jsonstr)
|
|
300
|
+
allx, ally, time = read_xyz(raw,lng0,lat0)
|
|
301
|
+
#SN,DATE=read_SN(raw)
|
|
302
|
+
#print(SN+DATE)
|
|
303
|
+
alllabel, allcenter = pts_cluster(allx, ally, bandwidth=500, polar=False)
|
|
304
|
+
polcombine = label_time(alllabel, time)
|
|
305
|
+
# ax = plt.subplot(111, projection='polar') \
|
|
306
|
+
# rootpath = 'E:\\version3.7test\POL_report2\\'
|
|
307
|
+
# lidarpath = rootpath + SN + '\\'
|
|
308
|
+
# datepath = lidarpath + DATE + '\\'
|
|
309
|
+
# create_path(rootpath)
|
|
310
|
+
# create_path(lidarpath)
|
|
311
|
+
# create_path(datepath)
|
|
312
|
+
|
|
313
|
+
poltimequantum, polintensity_fr,poltime, poltimequantum_fr,poltime_fr= pol_time(polcombine)
|
|
314
|
+
#finalreport = final_report(allcenter, poltimequantum, poltime)
|
|
315
|
+
finalreport_fr = final_report(allcenter, poltimequantum_fr, polintensity_fr,poltime_fr,lng0,lat0)
|
|
316
|
+
#printfinalreport=json.dumps(finalreport_fr)
|
|
317
|
+
#print(printfinalreport)
|
|
318
|
+
#save_data(finalreport_fr)
|
|
319
|
+
printfinalreport = json.dumps(finalreport_fr)
|
|
320
|
+
if len(finalreport_fr) == 0 and not windfilter:
|
|
321
|
+
poltimequantum, polintensity_fr, poltime, poltimequantum_fr, poltime_fr = pol_time2(polcombine)
|
|
322
|
+
# finalreport = final_report(allcenter, poltimequantum, poltime)
|
|
323
|
+
finalreport_fr = final_report(allcenter, poltimequantum_fr, polintensity_fr, poltime_fr,lng0,lat0)
|
|
324
|
+
return json.dumps(finalreport_fr)
|
|
325
|
+
else:
|
|
326
|
+
return printfinalreport
|
package/index.js
CHANGED
|
@@ -124,6 +124,11 @@ export class EasyMap {
|
|
|
124
124
|
})
|
|
125
125
|
}
|
|
126
126
|
|
|
127
|
+
|
|
128
|
+
setStyle(url){
|
|
129
|
+
this.map.setStyle(url)
|
|
130
|
+
this.map.theme.value = this.map.style.stylesheet.theme
|
|
131
|
+
}
|
|
127
132
|
addScale(postion="bottom-right"){
|
|
128
133
|
if(this.ScaleControl){
|
|
129
134
|
this.map.addControl(this.ScaleControl,postion);
|