test_ice.py
18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
#!/usr/bin/python
# -*- coding:utf-8 -*-
import pandas as pd
import sys,traceback,Ice
Ice.loadSlice("--all -I.. ice/bsd.ice")
Ice.loadSlice("--all -I.. ice/Hdao_gps.ice")
Ice.loadSlice("--all -I.. --underscore ice/district.ice")
Ice.loadSlice("--all -I.. --underscore ice/ipoi.ice")
Ice.loadSlice("--all -I.. --underscore ice/HDao_mile.ice")
import datetime
import BaseStationData
import HDaoGps,HDaoMile
import DISTRICT
import pymysql
import POI
fmrsDBConn = pymysql.Connect(host='192.168.5.24', port=3306, user='biz_neshield_tmp',passwd='TmM6IJAr', db='neshield', charset='utf8')
# env_host = "192.168.3.101"
# env_host = "192.168.5.31"
env_host = "192.168.5.26"
def get_distdetail_by_pos(lng,lat):
try:
with Ice.initialize(sys.argv) as communicator:
obj = communicator.stringToProxy(f'DistrictFinder:default -h {env_host} -p 10008')
obj.ice_ping()
printer = DISTRICT.IDistrictFinderPrx.checkedCast(obj)
if not printer:
raise RuntimeError("Invalid proxy")
rsp = printer.get_distdetail_by_pos(lng,lat)
print(rsp)
return rsp
except:
traceback.print_exc()
return None
def getGpsByBs(mnc,lac,cellid):
try:
with Ice.initialize(sys.argv) as communicator:
obj = communicator.stringToProxy(f'BsdObjectId:default -h {env_host} -p 10945')
obj.ice_ping()
printer = BaseStationData.BaseStationServicePrx.checkedCast(obj)
if not printer:
raise RuntimeError("Invalid proxy")
req = BaseStationData.BsDataReq()
# bsData = BaseStationData.BsData()
req.bs.mnc = int(mnc)
req.bs.lac = int(lac)
req.bs.cellid = int(cellid)
rsp = printer.GetGpsByBs(req)
print(rsp)
# print(rsp[1].gps.addr)
return rsp[1].gps.addr
except:
traceback.print_exc()
def getGpsByBsList():
try:
with Ice.initialize(sys.argv) as communicator:
obj = communicator.stringToProxy(f'BsdObjectId:default -h {env_host} -p 10945')
obj.ice_ping()
printer = BaseStationData.BaseStationServicePrx.checkedCast(obj)
if not printer:
raise RuntimeError("Invalid proxy")
req = BaseStationData.BsDataListReq()
bsList = []
# BsData = BaseStationData.BsData()
# BsData.mnc = 0
# BsData.lac = 1
# BsData.cellid = 6
# bsList.append(BsData)
for i in range(6):
BsData = BaseStationData.BsData()
BsData.mnc = 0
BsData.lac = 9278
BsData.cellid = 2
bsList.append(BsData)
req.bsList = bsList
rsp = BaseStationData.BsDataResp()
rsp = printer.GetGpsByBsList(req)
print(rsp)
except:
traceback.print_exc()
def getGpsRecords(sn,starttime,endtime):
try:
with Ice.initialize(sys.argv) as communicator:
obj = communicator.stringToProxy(f'HDaoGpsSvc:default -h {env_host} -p 23470')
obj.ice_ping()
printer = HDaoGps.DaoGpsServicePrx.checkedCast(obj)
if not printer:
raise RuntimeError("Invalid proxy")
req = HDaoGps.GpsGetRequest()
req.userID = sn
req.apType = 5
req.extraMapReq = 0
req.startTime = int(datetime.datetime.strptime(starttime,"%Y-%m-%d %H:%M:%S").timestamp())
req.endTime = int(datetime.datetime.strptime(endtime,"%Y-%m-%d %H:%M:%S").timestamp())
req.reqCount = 2000
rsp = printer.getGpsRecords(req)
print(rsp)
except:
traceback.print_exc()
def getGpsByLatestBsRecord(sn,type):
try:
with Ice.initialize(sys.argv) as communicator:
obj = communicator.stringToProxy(f'HDaoGpsSvc:default -h {env_host} -p 23469')
obj.ice_ping()
printer = HDaoGps.DaoGpsServicePrx.checkedCast(obj)
if not printer:
raise RuntimeError("Invalid proxy")
req = HDaoGps.LatestBsGetRequest()
req.userID = int(sn)
req.apType = type
rsp = printer.getGpsByLatestBsRecord(req)
print(rsp[1].gps.gpsTime)
print(rsp)
except:
traceback.print_exc()
def getLatestBsRecord(sn,type = 5):
try:
with Ice.initialize(sys.argv) as communicator:
obj = communicator.stringToProxy(f'HDaoGpsSvc:default -h {env_host} -p 23469')
obj.ice_ping()
printer = HDaoGps.DaoGpsServicePrx.checkedCast(obj)
if not printer:
raise RuntimeError("Invalid proxy")
req = HDaoGps.LatestBsGetRequest()
req.userID = int(sn)
req.apType = type
req.extraMapReq = 0
rsp = printer.getLatestBsRecord(req)
# print(rsp[1].gps.gpsTime)
print(rsp)
except:
traceback.print_exc()
def getLatestGpsRecord(sn,type = 5):
try:
with Ice.initialize(sys.argv) as communicator:
obj = communicator.stringToProxy(f'HDaoGpsSvc:default -h {env_host} -p 23469')
obj.ice_ping()
printer = HDaoGps.DaoGpsServicePrx.checkedCast(obj)
if not printer:
raise RuntimeError("Invalid proxy")
req = HDaoGps.LatestGpsGetRequest()
req.userID = int(sn)
req.apType = type
req.extraMapReq = 0
rsp = printer.getLatestGpsRecord(req)
# print(rsp[1].gps.gpsTime)
print(rsp)
except:
traceback.print_exc()
def getGpsByBsRecordsOfLatesBs(sn,type,startTime,endTime):
try:
with Ice.initialize(sys.argv) as communicator:
obj = communicator.stringToProxy(f'HDaoGpsSvc:default -h {env_host} -p 23469')
obj.ice_ping()
printer = HDaoGps.DaoGpsServicePrx.checkedCast(obj)
if not printer:
raise RuntimeError("Invalid proxy")
req = HDaoGps.BsGetRequest()
req.userID = int(sn)
req.apType = type
req.startTime = int(datetime.datetime.strptime(startTime,"%Y-%m-%d %H:%M:%S").timestamp())
req.endTime = int(datetime.datetime.strptime(endTime, "%Y-%m-%d %H:%M:%S").timestamp())
req.reqCount = -1
rsp = printer.getGpsByBsRecordsOfLatesBs(req)
print(f"{datetime.datetime.fromtimestamp(rsp[1].gps.gpsTime).strftime('%Y-%m-%d %H:%M:%S')}")
print(f"{datetime.datetime.fromtimestamp(rsp[1].gps.storeTime).strftime('%Y-%m-%d %H:%M:%S')}")
print(rsp)
except:
traceback.print_exc()
def getGeoPoiType(lng,lat):
try:
with Ice.initialize(sys.argv) as communicator:
obj = communicator.stringToProxy(f'BsdObjectId:default -h {env_host} -p 10945')
obj.ice_ping()
printer = BaseStationData.BaseStationServicePrx.checkedCast(obj)
if not printer:
raise RuntimeError("Invalid proxy")
req = BaseStationData.BsPoint()
req.lng = lng
req.lat = lat
rsp = BaseStationData.DaoPoiInfoResp()
rsp = printer.getPoiTypeFromGeo(req)
print(rsp)
except:
traceback.print_exc()
def getDeviceInfoOfRegion(lLng,lLat,rLng,rLat):
try:
with Ice.initialize(sys.argv) as communicator:
obj = communicator.stringToProxy(f'HDaoGpsSvc:default -h {env_host} -p 23479')
obj.ice_ping()
printer = HDaoGps.DaoGpsServicePrx.checkedCast(obj)
if not printer:
raise RuntimeError("Invalid proxy")
req = HDaoGps.RegionData()
req.leftLng = lLng
req.leftLat = lLat
req.rightLng = rLng
req.rightLat = rLat
rsp = printer.getDeviceInfoOfRegion(req)
print(rsp)
except:
traceback.print_exc()
def getDevicesGpsInfo(snList):
try:
with Ice.initialize(sys.argv) as communicator:
obj = communicator.stringToProxy(f'HDaoGpsSvc:default -h {env_host} -p 23470')
print(env_host,23479)
obj.ice_ping()
printer = HDaoGps.DaoGpsServicePrx.checkedCast(obj)
if not printer:
raise RuntimeError("Invalid proxy")
req = HDaoGps.BatchGpsDevInfoRequest()
req.extraMapReq = 1
req.seqNo = 0 # seqNo%6 6个中保留1个
req.userIds = snList
rsp = printer.getDevicesGpsInfo(req)
print(rsp)
except:
traceback.print_exc()
def ReverseGeocoding2(lng,lat):
try:
with Ice.initialize(sys.argv) as communicator:
obj = communicator.stringToProxy(f'PoiSearchNear:default -h 192.168.5.31 -p 10081')
obj.ice_ping()
printer = POI.IPOISearchNearPrx.checkedCast(obj)
if not printer:
raise RuntimeError("Invalid proxy")
req = POI.geopoint()
req.lng = lng
req.lat = lat
rsp = printer.ReverseGeocoding2(req)
print(rsp)
except:
traceback.print_exc()
def endUserMileStat(sn):
try:
with Ice.initialize(sys.argv) as communicator:
obj = communicator.stringToProxy(f'RtMileStatSvc:default -h {env_host} -p 23472')
obj.ice_ping()
printer = HDaoMile.DaoMileServicePrx.checkedCast(obj)
if not printer:
raise RuntimeError("Invalid proxy")
req = HDaoMile.MileStatEndRequest()
req.userID = sn
req.apType = 5
req.beginTime = int(datetime.datetime.strptime("2023-09-20 10:48:53","%Y-%m-%d %H:%M:%S").timestamp())
req.endTime = int(datetime.datetime.strptime("2023-09-20 11:08:19","%Y-%m-%d %H:%M:%S").timestamp())
req.bRetGpsTime = True
rsp = printer.endUserMileStat(req)
print(rsp)
except:
traceback.print_exc()
def getJourneyRecords(sn,bgnDate,endDate):
try:
with Ice.initialize(sys.argv) as communicator:
obj = communicator.stringToProxy(f'RtMileStatSvc:default -h {env_host} -p 23472')
obj.ice_ping()
printer = HDaoMile.DaoMileServicePrx.checkedCast(obj)
if not printer:
raise RuntimeError("Invalid proxy")
req = HDaoMile.GetJourneyRecordsReq()
req.userID = sn
req.apType = 5
req.bReqAddr = False
req.bgnDate.year = bgnDate[0]
req.bgnDate.month = bgnDate[1]
req.bgnDate.day = bgnDate[2]
req.endDate.year = endDate[0]
req.endDate.month = endDate[1]
req.endDate.day = endDate[2]
req.extraMapReq = 0
rsp = printer.getJourneyRecords(req)
print(rsp)
except:
traceback.print_exc()
class DeviceInfo:
def __init__(self,sn,count,validCount):
self.sn = sn
self.count = count
self.validCount = validCount
def add_count(self):
self.count += 1
def add_validCount(self):
self.validCount += 1
if __name__ == "__main__":
# snlist = [1510824193, 1510824194, 1510922309, 1510922324, 1510922327, 1510922330, 1510922334, 1510922335, 1510922336, 1510922337, 1510922338, 1510922339, 1510922340, 1510922341, 1510922342, 1510922345, 1510922346, 1510922347, 1510922350, 1510922352, 1510922354, 1510922369, 1510922371, 1510922372, 1510922375, 1510922376, 1510922390, 1510922391, 1510922418, 1510922425, 1510922428, 1510922430, 1510922431, 1510922433, 1510922448, 1510922449, 1510922456, 1510922458, 1510922460, 1510922464, 1510922468, 1510922472, 1510922480, 1510922492, 1510922497, 1510922514, 1510922521, 1510922522, 1510922523, 1510922524, 1510922525, 1510922526, 1510922529, 1510922533, 1510922539, 1510922542, 1510922547, 1510922549, 1510922550, 1510922555, 1510922562, 1510922564, 1510922567, 1510922569, 1510922570, 1510922571, 1510922572, 1510922577, 1510922582, 1510922583, 1510922586, 1510922590, 1510922592, 1510922595, 1510922597, 1510922608, 1510922616, 1510922620, 1510922623, 1510922624, 1510922635, 1510922637, 1510922638, 1510922639, 1510922641, 1510922642, 1510922643, 1510922645, 1510922646, 1510922650, 1510922651, 1510922652, 1510922659, 1510922661, 1510922663, 1510922664, 1510922667, 1510922668, 1510922669]
# snlist = [1190910192,1190614211,1190706000,1190910175,1190614987,1190614359,1190909435,1181127963,1190909126,1190910195,1190112152,1190909426,1190909377,1190429928,1190614984,1190112128,1190909439,1190522172,1190909633,1190624163,1190910026,1190404102,1190429919,1190112136,1190706009,1181127934,1190112131,1190112365,1190910127,1190522602,1190910158,1190706151,1190522604,1190614464,1190110673,1190522007,1190909007,1190706245,1181223028,1190706285,1190107499,1190111898,1190909006,1190404071,1190705407,1190909630,1190706291,1190909084,1180720969,1190706181,1190909635,1190706210,1181031326,1190706174,1181031332,1190705199,1190522526,1180720985,1190706307,1190909274,1190909606,1190705198,1190706170,1190909061,1190614215,1190909197,1190112135,1180720975,1190112150,1190910239,1180720989,1190403860,1190429949,1190706281,1181127927,1190429971,1190624467,1190624191,1190909645,1190706247,1190706225,1190624365,1181127908,1190429940,1190909673,1181127985,1190910321,1190706294,1190706267,1190404895,1190522947,1181127954,1190910185,1190910306,1190706289,1190522997,1190111086,1190706011,1190429030,1190403850,1190909607,1190429976,1180720963,1190112137,1190110665,1181031328,1190706458,1190615144,1181127928,1181127948,1181127901,1190909770,1190429287,1190111939,1190614777,1190910243,1190429290,1190909096,1190909611,1190910346,1190705400,1190706261,1190910297,1190910094,1190910320,1190429925,1190429934,1190112100,1190110664,1190429112,1190111431,1190910393,1190909973,1190112120,1190909617,1190112115,1181127960,1181127953,1190404370,1190112122,1181127989,1190910380,1190615411,1190522030,1190522035,1190909057,1190909726,1190909058,1190429960,1190522278,1181127996,1190910374,1190706265,1190909307,1190404955,1190429959,1190404477,1190112569,1190522577,1190429293,1190705182,1190910426,1190910359,1181127097,1190403662,1190614738,1190112347,1190706226,1190909556,1190909749,1190429936,1190909743,1190910227,1190909745,1190522356,1190910298,1190910230,1190614271,1190910394,1190909904,1180823373,1190522952,1181127994,1190522336,1190522337,1190910343,1190909767,1190522576,1190429234,1190429274,1190910488,1190615397,1190910285,1190614210,1190705936,1190910410,1181127952,1190706172,1190429311,1190910287]
# print(len(snlist))
# getDevicesGpsInfo(snList=snlist)
# startTime = datetime.datetime.now().timestamp()
# print(f"startTime = {startTime}")
# getDeviceInfoOfRegion(113989108,22585025,113994542,22589522)
# endTime = datetime.datetime.now().timestamp()
# print(f"endTime = {endTime}")
# print(f"useTime = {endTime - startTime}")
# endUserMileStat(87207270103)
#获取最后gps位置数据,
#param: sn,设备类型
getLatestGpsRecord('1570731232',5)
#获取gps信息
# getGpsRecords(15212050744,"2024-01-17 00:00:00","2024-01-18 00:00:00")
#获取里程列表
# getJourneyRecords( 15209030720,[2024,1,1],[2024,1,4])
# getLatestBsRecord('352538107542444',11)
# getLatestBsRecord('45212100445',5)
# getGpsByBs(0,18267,57061)
# getGpsByBs(0,18334,46178417)
# sir_map = {}
# deviceInfo = DeviceInfo("15212170590", 0, 0)
# sir_map["15212170590"] = deviceInfo
# with open("deviceinfo_st.txt", 'w') as f:
# for dev in sir_map.values():
# f.write(f"{dev.sn},{dev.count},{dev.validCount}")
# ghc跑的数据-在跑基站转经纬度
# df = pd.read_excel(os.getcwd() + "\\excel\\lastGPSandBs.xlsx")
# for i in df.index:
# addr = getGpsByBs(df.loc[i,'mmc'],df.loc[i,'lac'], df.loc[i,'ci'])
# df.loc[i, '基站地址'] = addr
# df.to_excel(f"\\excel\\lastGPSandBs_re.xlsx",index=False)
# 直接调用bsIcesvr
# getGpsByBsList()
#通过hdaod调用bsIceSvr获取gps
# getGpsByLatestBsRecord('1610523358',5)
#获取高德poi类型
# getGeoPoiType(113.991416,22.587527)
#原始经纬度转地址
# ReverseGeocoding2(117.634416, 38.709333)
#取一段时间内的最后一个基站转gps
# getGpsByBsRecordsOfLatesBs('1621226935',5,'2023-03-01 00:00:00','2023-03-01 17:00:00')
#通过经纬度,获取所在省市区
# for file in ["第一设备.xlsx","第二设备.xlsx"]:
# fileName = file[0:file.find('.')]
# fileEx = file[file.find('.')+1:]
# df = pd.read_excel(f"{file}")
# startTime = datetime.datetime.now().timestamp()
# for i in df.index:
# lat = df.loc[i,"activeLat"]
# lng = df.loc[i,"activeLng"]
# # lng = 118.479347
# # lat = 24.659208
# # for i in range(1000):
# # lng += random.randint(-1,1)/10.0
# # lat += random.randint(-1,1)/10.0
# # print(lng,lat)
# data = get_distdetail_by_pos(lng, lat)
# df.loc[i,'province'] = data[1]
# df.loc[i, 'city'] = data[2]
# df.loc[i, 'area'] = data[3]
# endTime = datetime.datetime.now().timestamp()
# df.to_excel(f"{fileName}_re.{fileEx}", index=False)
# print(f"useTime = {endTime - startTime}")
#获取仲利设备,判断最后位置点是否在行政区内
# startTime = datetime.datetime.now().timestamp()
# cursor = fmrsDBConn.cursor()
# sql = f"select tvd.sn from t_vehicle_device tvd left join t_vehicle tv on tv.id = tvd.vehicle_id left join t_user tu on tu.id = tv.created_by " \
# f"left join t_device td on td.sn = tvd.sn where tu.tenant_id = 44 and tv.del_flag = 0 and tvd.bind_status = 1" \
# f" and tvd.del_flag = 0 and tv.del_flag = 0 and tu.del_flag = 0"
# cursor.execute(sql)
# result = cursor.fetchall()
# print(len(result))
# for i in result:
# sn = i[0]
# getLatestGpsRecord(sn)
# endTime = datetime.datetime.now().timestamp()
# print(f"useTime = {endTime - startTime}")