Commit 33c4c36b authored by liyuanhong's avatar liyuanhong

修改了里程和油耗和时长累加的问题

parent 2df27cb9
{"time": {"dateTime": "2020-04-17 17:53:51", "date": "2020-04-17", "time": "17:53:51"}, "curDayTravel": {"todayTotalMilleage": 139860, "todayTotalOil": 770, "todayTotalTime": 350, "theMilleage": 73815, "theOil": 396, "theTime": 180}, "travelData": {"totalMilleage": 243524, "totalOil": 921, "totalTime": 501}} {"time": {"dateTime": "2020-04-20 15:57:07", "date": "2020-04-20", "time": "15:57:07"}, "curDayTravel": {"todayTotalMilleage": 686578, "todayTotalOil": 2422, "todayTotalTime": 1153, "theMilleage": 760393, "theOil": 2818, "theTime": 1333}, "travelData": {"totalMilleage": 930102, "totalOil": 3343, "totalTime": 1654}}
\ No newline at end of file \ No newline at end of file
...@@ -93,7 +93,7 @@ class AutoCarService(): ...@@ -93,7 +93,7 @@ class AutoCarService():
def sendVersionMsg(self): def sendVersionMsg(self):
versionObj = VersionReport_protocol(msgCount=1,WATER_CODE=self.sn,DEV_ID=self.carId) versionObj = VersionReport_protocol(msgCount=1,WATER_CODE=self.sn,DEV_ID=self.carId)
versionMsg = versionObj.generateVersionMsg() versionMsg = versionObj.generateVersionMsg()
self.sendMsg(versionMsg, ) self.sendMsg(versionMsg)
self.sn = self.sn + 1 self.sn = self.sn + 1
info = self.getCurTime() + " 发送了版本信息" info = self.getCurTime() + " 发送了版本信息"
print(info) print(info)
...@@ -127,7 +127,7 @@ class AutoCarService(): ...@@ -127,7 +127,7 @@ class AutoCarService():
longitude = self.gpsLine[self.gpsLineIndex]["lng"] longitude = self.gpsLine[self.gpsLineIndex]["lng"]
gpsMsg = self.genGPSMsg(latitude, longitude) gpsMsg = self.genGPSMsg(latitude, longitude)
self.gpsLineIndex = self.gpsLineIndex + 1 self.gpsLineIndex = self.gpsLineIndex + 1
info = self.getCurTime() + " 度:" + str(latitude).replace("\n","") + " 经度:" + str(longitude).replace("\n","") info = self.getCurTime() + " 度:" + str(latitude).replace("\n","") + " 经度:" + str(longitude).replace("\n","")
info.replace("\n","") info.replace("\n","")
print(info) print(info)
self.writeToFile("result.txt", info + "\n", 1) self.writeToFile("result.txt", info + "\n", 1)
...@@ -144,6 +144,12 @@ class AutoCarService(): ...@@ -144,6 +144,12 @@ class AutoCarService():
print(info) print(info)
self.writeToFile("result.txt", info + "\n", 1) self.writeToFile("result.txt", info + "\n", 1)
time.sleep(self.changeGPSLineTime) time.sleep(self.changeGPSLineTime)
endTime = int(time.time())
if (endTime - startTime) > self.serviceTime:
info = self.getCurTime() + " 本次车机模拟程序跑完(间隔时间产生的时间用完)........"
print(info)
self.writeToFile("result.txt", info + "\n", 1)
exit()
self.connectService() self.connectService()
self.serviceStatus = 1 self.serviceStatus = 1
self.travelStatus = 1 self.travelStatus = 1
...@@ -209,9 +215,6 @@ class AutoCarService(): ...@@ -209,9 +215,6 @@ class AutoCarService():
with open("data/protocolTools/carData/" + self.carId + ".json", "r", encoding="utf-8") as fi: with open("data/protocolTools/carData/" + self.carId + ".json", "r", encoding="utf-8") as fi:
content = fi.read() content = fi.read()
conJson = json.loads(content) conJson = json.loads(content)
# conJson["curDayTravel"]["theMilleage"] = 0 # 今日行驶总里程
# conJson["curDayTravel"]["theOil"] = 0 # 今日行驶总油耗
# conJson["curDayTravel"]["theTime"] = 0 # 今日行驶总时间
timeStamp = time.time() timeStamp = time.time()
timeArray = time.localtime(timeStamp) timeArray = time.localtime(timeStamp)
dateTimeM = time.strftime("%Y-%m-%d %H:%M:%S", timeArray) dateTimeM = time.strftime("%Y-%m-%d %H:%M:%S", timeArray)
...@@ -221,26 +224,28 @@ class AutoCarService(): ...@@ -221,26 +224,28 @@ class AutoCarService():
self.carDataObj = ProtocolSimulaterDataService("data/protocolTools/carData/", dataFile) self.carDataObj = ProtocolSimulaterDataService("data/protocolTools/carData/", dataFile)
self.carDataObj.setData(conJson) self.carDataObj.setData(conJson)
if dateM == conJson["time"]["date"]: if dateM == conJson["time"]["date"]:
pass self.OBDdata["totailMileage"] = conJson["travelData"]["totalMilleage"]
self.OBDdataOri["totailMileage"] = conJson["travelData"]["totalMilleage"]
self.OBDdata["totalOilExpen"] = conJson["travelData"]["totalOil"]
self.OBDdataOri["totalOilExpen"] = conJson["travelData"]["totalOil"]
self.OBDdata["totalRunTime"] = conJson["travelData"]["totalTime"]
self.OBDdataOri["totalRunTime"] = conJson["travelData"]["totalTime"]
else: #如果不是当天日期,则将日期设置为当天,并写入车辆数据文件 else: #如果不是当天日期,则将日期设置为当天,并写入车辆数据文件
# conJson["time"]["dateTime"] = dateTimeM conJson["curDayTravel"]["todayTotalMilleage"] = 0 # 今日行驶总里程
# conJson["time"]["date"] = dateM conJson["curDayTravel"]["todayTotalOil"] = 0 # 今日行驶总油耗
# conJson["time"]["time"] = timeM conJson["curDayTravel"]["todayTotalTime"] = 0 # 今日行驶总时间
# conJson["curDayTravel"]["todayTotalMilleage"] = 0 # 今日行驶总里程
# conJson["curDayTravel"]["todayTotalOil"] = 0 # 今日行驶总油耗
# conJson["curDayTravel"]["todayTotalTime"] = 0 # 今日行驶总时间
self.carDataObj.setTodayTotalMilleage(0) self.carDataObj.setTodayTotalMilleage(0)
self.carDataObj.setTodayTodayTotalOil(0) self.carDataObj.setTodayTodayTotalOil(0)
self.carDataObj.setTodayTodayTotalTime(0) self.carDataObj.setTodayTodayTotalTime(0)
self.carDataObj.setDateTime2file(dateTimeM) self.carDataObj.setDateTime2file(dateTimeM)
self.carDataObj.setData2file(dateM) self.carDataObj.setData2file(dateM)
self.carDataObj.setTime2file(timeM) self.carDataObj.setTime2file(timeM)
self.OBDdata["totailMileage"] = self.carDataObj["travelData"]["totalMilleage"] self.OBDdata["totailMileage"] = conJson["travelData"]["totalMilleage"]
self.OBDdataOri["totailMileage"] = self.carDataObj["travelData"]["totalMilleage"] self.OBDdataOri["totailMileage"] = conJson["travelData"]["totalMilleage"]
self.OBDdata["totalOilExpen"] = self.carDataObj["travelData"]["totalOil"] self.OBDdata["totalOilExpen"] = conJson["travelData"]["totalOil"]
self.OBDdataOri["totalOilExpen"] = self.carDataObj["travelData"]["totalOil"] self.OBDdataOri["totalOilExpen"] = conJson["travelData"]["totalOil"]
self.OBDdata["totalRunTime"] = self.carDataObj["travelData"]["totalTime"] self.OBDdata["totalRunTime"] = conJson["travelData"]["totalTime"]
self.OBDdataOri["totalRunTime"] = self.carDataObj["travelData"]["totalTime"] self.OBDdataOri["totalRunTime"] = conJson["travelData"]["totalTime"]
self.carData = conJson self.carData = conJson
fireOnEventObj = EventReport_protocol(DEV_ID=self.carId,WATER_CODE=self.sn) fireOnEventObj = EventReport_protocol(DEV_ID=self.carId,WATER_CODE=self.sn)
gpsData = self.genGPSData(self.gpsLine[0]["lat"], self.gpsLine[0]["lng"]) gpsData = self.genGPSData(self.gpsLine[0]["lat"], self.gpsLine[0]["lng"])
...@@ -254,7 +259,9 @@ class AutoCarService(): ...@@ -254,7 +259,9 @@ class AutoCarService():
self.sendMsg(gpsMsg) self.sendMsg(gpsMsg)
self.sn = self.sn + 1 self.sn = self.sn + 1
time.sleep(0.1) time.sleep(0.1)
OBDMsg = self.genOBDMsg() OBDMsg = self.genOBDMsg(self.OBDdata["fireStatus"],1,self.OBDdata["engineSpeed"], \
self.OBDdata["speed"],self.OBDdata["meterMileage"],self.OBDdata["totailMileage"], \
self.OBDdata["totalOilExpen"],self.OBDdata["totalRunTime"])
self.sendMsg(OBDMsg) self.sendMsg(OBDMsg)
self.sn = self.sn + 1 self.sn = self.sn + 1
info = self.getCurTime() + " 发送了点火事件" info = self.getCurTime() + " 发送了点火事件"
......
[2020-04-17 18:20:28] 建立了连接 [2020-04-20 18:02:05] 建立了连接
[2020-04-17 18:20:28] 进行了登录操作 [2020-04-20 18:02:05] 进行了登录操作
[2020-04-17 18:20:29] 发送了版本信息 [2020-04-20 18:02:05] 发送了版本信息
[2020-04-17 18:20:29] 当前设置了GPS轨迹:6_先涛的车轨迹(短).txt [2020-04-20 18:02:06] 当前设置了GPS轨迹:1_sample(短).json
[2020-04-17 18:20:29] 发送了点火事件 [2020-04-20 18:02:06] 发送了点火事件
[2020-04-17 18:20:31] 维度:29.585448 经度:106.279711 [2020-04-20 18:02:08] 纬度:29.569133 经度:106.586571
[2020-04-17 18:20:37] 维度:29.585448 经度:106.279711 [2020-04-20 18:02:09] 纬度:29.569215 经度:106.586935
[2020-04-17 18:20:42] 维度:29.585448 经度:106.279711 [2020-04-20 18:02:10] 纬度:29.569215 经度:106.587114
[2020-04-17 18:20:47] 维度:29.585448 经度:106.279711 [2020-04-20 18:02:11] 纬度:29.569231 经度:106.587424
[2020-04-17 18:20:52] 维度:29.585448 经度:106.279711 [2020-04-20 18:02:12] 纬度:29.569278 经度:106.587685
[2020-04-17 18:20:57] 维度:29.585448 经度:106.279711 [2020-04-20 18:02:13] 纬度:29.569298 经度:106.587981
[2020-04-17 18:21:02] 维度:29.585448 经度:106.279711 [2020-04-20 18:02:14] 纬度:29.569341 经度:106.588098
[2020-04-17 18:21:07] 维度:29.585448 经度:106.279711 [2020-04-20 18:02:15] 纬度:29.569392 经度:106.588287
[2020-04-17 18:21:12] 维度:29.585448 经度:106.279711 [2020-04-20 18:02:17] 纬度:29.569439 经度:106.588435
[2020-04-17 18:21:17] 维度:29.585448 经度:106.279711 [2020-04-20 18:02:18] 纬度:29.569506 经度:106.588565
[2020-04-17 18:21:22] 维度:29.585448 经度:106.279711 [2020-04-20 18:02:19] 纬度:29.569565 经度:106.588646
[2020-04-17 18:21:28] 维度:29.586623 经度:106.287903 [2020-04-20 18:02:20] 纬度:29.569651 经度:106.588763
[2020-04-17 18:21:33] 维度:29.586608 经度:106.289041 [2020-04-20 18:02:21] 纬度:29.569745 经度:106.588884
[2020-04-17 18:21:38] 维度:29.586631 经度:106.293958 [2020-04-20 18:02:22] 纬度:29.569832 经度:106.589073
[2020-04-17 18:21:43] 维度:29.586603 经度:106.296643 [2020-04-20 18:02:23] 纬度:29.569977 经度:106.589374
[2020-04-17 18:21:48] 维度:29.586588 经度:106.29702 [2020-04-20 18:02:24] 纬度:29.570114 经度:106.589688
[2020-04-17 18:21:53] 维度:29.586625 经度:106.297076 [2020-04-20 18:02:25] 纬度:29.570228 经度:106.589993
[2020-04-17 18:21:58] 发送了熄火事件: [2020-04-20 18:02:27] 纬度:29.570271 经度:106.590146
[2020-04-17 18:21:58] 执行了停止行驶服务 [2020-04-20 18:02:28] 纬度:29.570291 经度:106.590357
[2020-04-17 18:21:58] gps轨迹跑完,自动停止行驶! [2020-04-20 18:02:29] 纬度:29.570264 经度:106.590573
[2020-04-20 18:02:30] 纬度:29.570248 经度:106.590802
[2020-04-20 18:02:31] 纬度:29.570205 经度:106.59095
[2020-04-20 18:02:32] 纬度:29.570256 经度:106.59108
[2020-04-20 18:02:33] 纬度:29.570421 经度:106.591273
[2020-04-20 18:02:34] 纬度:29.570578 经度:106.591507
[2020-04-20 18:02:35] 纬度:29.570703 经度:106.591673
[2020-04-20 18:02:37] 纬度:29.570774 经度:106.591772
[2020-04-20 18:02:38] 纬度:29.570943 经度:106.591974
[2020-04-20 18:02:39] 纬度:29.57108 经度:106.592145
[2020-04-20 18:02:40] 纬度:29.571261 经度:106.592342
[2020-04-20 18:02:41] 纬度:29.571332 经度:106.592383
[2020-04-20 18:02:42] 纬度:29.571493 经度:106.592527
[2020-04-20 18:02:43] 纬度:29.571642 经度:106.592679
[2020-04-20 18:02:44] 纬度:29.571748 经度:106.592765
[2020-04-20 18:02:45] 纬度:29.571834 经度:106.592877
[2020-04-20 18:02:47] 纬度:29.571901 经度:106.593007
[2020-04-20 18:02:48] 纬度:29.571936 经度:106.593182
[2020-04-20 18:02:49] 纬度:29.571936 经度:106.593308
[2020-04-20 18:02:50] 纬度:29.571874 经度:106.593407
[2020-04-20 18:02:51] 纬度:29.571815 经度:106.593591
[2020-04-20 18:02:52] 纬度:29.571795 经度:106.593784
[2020-04-20 18:02:53] 纬度:29.571862 经度:106.593847
[2020-04-20 18:02:54] 发送了熄火事件:
[2020-04-20 18:02:54] 执行了停止行驶服务
[2020-04-20 18:02:54] gps轨迹跑完,自动停止行驶!
------------------------------------------------------------------------ ------------------------------------------------------------------------
[2020-04-17 18:21:58] 请稍后240秒,正在切换轨迹行驶... [2020-04-20 18:02:54] 请稍后120秒,正在切换轨迹行驶...
[2020-04-17 18:25:58] 建立了连接 [2020-04-20 18:04:54] 本次车机模拟程序跑完(间隔时间产生的时间用完)........
[2020-04-17 18:25:59] 进行了登录操作
[2020-04-17 18:26:00] 发送了版本信息
[2020-04-17 18:26:00] 当前设置了GPS轨迹:6_先涛的车轨迹(短).txt
[2020-04-17 18:26:01] 发送了点火事件
[2020-04-17 18:26:06] 维度:29.585448 经度:106.279711
[2020-04-17 18:26:11] 维度:29.585448 经度:106.279711
[2020-04-17 18:26:16] 维度:29.585448 经度:106.279711
[2020-04-17 18:26:21] 维度:29.585448 经度:106.279711
[2020-04-17 18:26:26] 维度:29.585448 经度:106.279711
[2020-04-17 18:26:31] 维度:29.585448 经度:106.279711
[2020-04-17 18:26:36] 维度:29.585448 经度:106.279711
[2020-04-17 18:26:41] 维度:29.585448 经度:106.279711
[2020-04-17 18:26:47] 维度:29.585448 经度:106.279711
[2020-04-17 18:26:52] 维度:29.585448 经度:106.279711
[2020-04-17 18:26:57] 维度:29.586623 经度:106.287903
[2020-04-17 18:27:02] 维度:29.586608 经度:106.289041
[2020-04-17 18:27:07] 维度:29.586631 经度:106.293958
[2020-04-17 18:27:12] 维度:29.586603 经度:106.296643
[2020-04-17 18:27:17] 维度:29.586588 经度:106.29702
[2020-04-17 18:27:22] 维度:29.586625 经度:106.297076
[2020-04-17 18:27:28] 发送了熄火事件:
[2020-04-17 18:27:28] 执行了停止行驶服务
[2020-04-17 18:27:28] gps轨迹跑完,自动停止行驶!
------------------------------------------------------------------------
[2020-04-17 18:27:28] 请稍后240秒,正在切换轨迹行驶...
[2020-04-17 18:31:28] 建立了连接
[2020-04-17 18:31:29] 进行了登录操作
[2020-04-17 18:31:29] 发送了版本信息
[2020-04-17 18:31:30] 当前设置了GPS轨迹:6_先涛的车轨迹(短).txt
[2020-04-17 18:31:30] 发送了点火事件
[2020-04-17 18:31:35] 发送了熄火事件:
[2020-04-17 18:31:35] 执行了停止行驶服务
[2020-04-17 18:31:35] 本次车机模拟程序跑完........
...@@ -10,8 +10,8 @@ def startSimulaterService(): ...@@ -10,8 +10,8 @@ def startSimulaterService():
autoCarObj.setCarId("M202003060520") #设置车机号 autoCarObj.setCarId("M202003060520") #设置车机号
autoCarObj.setSendDur(5) # 设置发送消息的间隔时间 autoCarObj.setSendDur(5) # 设置发送消息的间隔时间
autoCarObj.setTimeout(30) # 设置socket超时时间 autoCarObj.setTimeout(30) # 设置socket超时时间
autoCarObj.setChangeGPSLineTime(1 * 4 * 60) # 设置跑完一条轨迹后,进入下一条轨迹的时间(请设置至少大于4分钟的时间) autoCarObj.setChangeGPSLineTime(1 * 10 * 60) # 设置跑完一条轨迹后,进入下一条轨迹的时间(请设置至少大于4分钟的时间)
autoCarObj.setServiceTime(1 * 10 * 60) # 设置整个服务的持续时间 autoCarObj.setServiceTime(12 * 60 * 60) # 设置整个服务的持续时间
autoCarObj.setOilExpend(10) # 设置1L 油跑多少公里 autoCarObj.setOilExpend(10) # 设置1L 油跑多少公里
autoCarObj.setSpeed(80) #设置车速,每小时多少公里 autoCarObj.setSpeed(80) #设置车速,每小时多少公里
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment