css属性选择器诸如Class^=,Class*= ,Class$=释义

Bean的生命周期

  返回  

python获取数据

2021/8/20 14:37:54 浏览:
#!/usr/bin/python3
#--*--coding:utf-8 --*--
import socket
import xlwt
import xlrd
import json
import sys
import time
import datetime

#recv data
#bind ip and port

ip_port=('172.31.22.29',8890)
sock = socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
sock.bind(ip_port)

def main():
	i=0
	sum=0
	num_sum=0
	data_save = xlwt.Workbook() #make a data save
	sheet1 = data_save.add_sheet('sheet1') #make a sheet1
	sheet1.write(0,0,'messageType')
	sheet1.write(0,1,'region')
	sheet1.write(0,2,'type')
	sheet1.write(0,3,'id')
	sheet1.write(0,4,'lat')
	sheet1.write(0,5,'lon')

	while 1:
		data, addr = sock.recvfrom(10240)
		# data = {"crossID":"","fenceID":"","motor":[{"heading":35982,"height":184,"id":17,"lat":30.2368012,"length":495,"lon":120.2522902,"messageType":2,"motionState":1,"region":1,"relativeAngle":359.82,"relativeDistance":2032,"source":4,"speed":21,"trackStatus":1,"type":2,"width":191,"xAcceleration":0,"xSpeed":0,"yAcceleration":0,"ySpeed":0},{"heading":12996,"height":213,"id":72,"lat":30.2372427,"length":414,"lon":120.2525253,"messageType":2,"motionState":1,"region":1,"relativeAngle":129.96,"relativeDistance":7368,"source":4,"speed":302,"trackStatus":1,"type":2,"width":179,"xAcceleration":0,"xSpeed":-3,"yAcceleration":0,"ySpeed":0},{"heading":34550,"height":161,"id":364,"lat":30.2367944,"length":205,"lon":120.2524165,"messageType":2,"motionState":1,"region":1,"relativeAngle":345.5,"relativeDistance":2775,"source":4,"speed":60,"trackStatus":1,"type":2,"width":157,"xAcceleration":0,"xSpeed":0,"yAcceleration":0,"ySpeed":0},{"heading":27124,"height":207,"id":416,"lat":30.2370557,"length":464,"lon":120.2527685,"messageType":2,"motionState":1,"region":1,"relativeAngle":271.24,"relativeDistance":7270,"source":4,"speed":70,"trackStatus":1,"type":2,"width":224,"xAcceleration":0,"xSpeed":0,"yAcceleration":0,"ySpeed":0},{"heading":35156,"height":106,"id":502,"lat":30.2371838,"length":111,"lon":120.2521573,"messageType":2,"motionState":1,"region":1,"relativeAngle":351.56,"relativeDistance":5984,"source":4,"speed":142,"trackStatus":1,"type":2,"width":270,"xAcceleration":0,"xSpeed":0,"yAcceleration":0,"ySpeed":1},{"heading":17094,"height":128,"id":516,"lat":30.2374504,"length":312,"lon":120.2527906,"messageType":2,"motionState":1,"region":1,"relativeAngle":170.94,"relativeDistance":10608,"source":4,"speed":41,"trackStatus":1,"type":2,"width":162,"xAcceleration":0,"xSpeed":0,"yAcceleration":0,"ySpeed":0},{"heading":17938,"height":68,"id":527,"lat":30.2367703,"length":583,"lon":120.252395,"messageType":2,"motionState":1,"region":1,"relativeAngle":179.38,"relativeDistance":2406,"source":4,"speed":237,"trackStatus":1,"type":2,"width":89,"xAcceleration":0,"xSpeed":1,"yAcceleration":0,"ySpeed":0},{"heading":1454,"height":122,"id":590,"lat":30.2371108,"length":38,"lon":120.2527381,"messageType":2,"motionState":1,"region":1,"relativeAngle":14.54,"relativeDistance":7375,"source":4,"speed":195,"trackStatus":1,"type":2,"width":49,"xAcceleration":0,"xSpeed":-1,"yAcceleration":0,"ySpeed":0},{"heading":9575,"height":213,"id":595,"lat":30.2370285,"length":254,"lon":120.2528125,"messageType":2,"motionState":1,"region":1,"relativeAngle":95.75,"relativeDistance":7412,"source":4,"speed":36,"trackStatus":1,"type":2,"width":89,"xAcceleration":0,"xSpeed":0,"yAcceleration":0,"ySpeed":0},{"heading":16994,"height":132,"id":597,"lat":30.2376861,"length":168,"lon":120.252703,"messageType":2,"motionState":1,"region":1,"relativeAngle":169.94,"relativeDistance":12546,"source":4,"speed":932,"trackStatus":1,"type":2,"width":160,"xAcceleration":0,"xSpeed":-5,"yAcceleration":0,"ySpeed":7},{"heading":3820,"height":30,"id":609,"lat":30.236728,"length":331,"lon":120.2523574,"messageType":2,"motionState":1,"region":1,"relativeAngle":38.2,"relativeDistance":1881,"source":4,"speed":114,"trackStatus":1,"type":2,"width":87,"xAcceleration":0,"xSpeed":1,"yAcceleration":0,"ySpeed":0},{"heading":31775,"height":64,"id":614,"lat":30.2371303,"length":94,"lon":120.2523502,"messageType":2,"motionState":1,"region":1,"relativeAngle":317.75,"relativeDistance":5596,"source":4,"speed":173,"trackStatus":1,"type":2,"width":41,"xAcceleration":0,"xSpeed":0,"yAcceleration":0,"ySpeed":0}],"nonMotor":[{"heading":27863,"height":181,"id":488,"lat":30.237513,"length":213,"lon":120.2528154,"messageType":2,"motionState":1,"region":1,"relativeAngle":278.63,"relativeDistance":11334,"source":4,"speed":71,"trackStatus":1,"type":3,"width":95,"xAcceleration":0,"xSpeed":0,"yAcceleration":0,"ySpeed":0},{"heading":24128,"height":88,"id":504,"lat":30.2372041,"length":79,"lon":120.252698,"messageType":2,"motionState":1,"region":1,"relativeAngle":241.28,"relativeDistance":7893,"source":4,"speed":49,"trackStatus":1,"type":3,"width":26,"xAcceleration":0,"xSpeed":0,"yAcceleration":0,"ySpeed":0},{"heading":22175,"height":72,"id":505,"lat":30.2370122,"length":51,"lon":120.2527405,"messageType":2,"motionState":1,"region":1,"relativeAngle":221.75,"relativeDistance":6675,"source":4,"speed":116,"trackStatus":1,"type":3,"width":113,"xAcceleration":0,"xSpeed":0,"yAcceleration":0,"ySpeed":0},{"heading":34280,"height":97,"id":584,"lat":30.2377442,"length":96,"lon":120.252914,"messageType":2,"motionState":1,"region":1,"relativeAngle":342.8,"relativeDistance":14007,"source":4,"speed":102,"trackStatus":1,"type":3,"width":117,"xAcceleration":0,"xSpeed":0,"yAcceleration":0,"ySpeed":0},{"heading":322,"height":140,"id":605,"lat":30.237065,"length":191,"lon":120.2521856,"messageType":2,"motionState":1,"region":1,"relativeAngle":3.22,"relativeDistance":4664,"source":4,"speed":558,"trackStatus":1,"type":3,"width":55,"xAcceleration":0,"xSpeed":-3,"yAcceleration":0,"ySpeed":4}],"pedistrain":[{"heading":21,"height":133,"id":450,"lat":30.2370648,"length":40,"lon":120.2526991,"messageType":2,"motionState":1,"region":1,"relativeAngle":0.21,"relativeDistance":6761,"source":4,"speed":179,"trackStatus":1,"type":1,"width":48,"xAcceleration":0,"xSpeed":0,"yAcceleration":0,"ySpeed":-1}],"radarID":"","unknow":[{"heading":1150,"height":66,"id":258,"lat":30.2367413,"length":360,"lon":120.2522377,"messageType":2,"motionState":1,"region":1,"relativeAngle":11.5,"relativeDistance":1252,"source":4,"speed":90,"trackStatus":1,"type":0,"width":206,"xAcceleration":0,"xSpeed":0,"yAcceleration":0,"ySpeed":0},{"heading":22500,"height":14,"id":559,"lat":30.2367479,"length":34,"lon":120.2521774,"messageType":2,"motionState":1,"region":1,"relativeAngle":225.0,"relativeDistance":1051,"source":4,"speed":17,"trackStatus":1,"type":0,"width":36,"xAcceleration":0,"xSpeed":0,"yAcceleration":0,"ySpeed":0},{"heading":32559,"height":170,"id":578,"lat":30.2370277,"length":225,"lon":120.2523828,"messageType":2,"motionState":1,"region":1,"relativeAngle":325.59,"relativeDistance":4636,"source":4,"speed":844,"trackStatus":1,"type":0,"width":103,"xAcceleration":0,"xSpeed":1,"yAcceleration":0,"ySpeed":8}],"utc":2328217948708.424}
		innovusion_data = json.loads(data.decode())

		if ('motor' in innovusion_data):
			motor = innovusion_data['motor']

		else:
			motor = ""
		if ('nonMotor' in innovusion_data):
			nonMotor = innovusion_data['nonMotor']

		else:
			nonMotor = ""
		if ('pedistrain' in innovusion_data):
			pedistrain = innovusion_data['pedistrain']

		else:
			pedistrain = ""
		if ('unknow' in innovusion_data):
			unknow = innovusion_data['unknow']

		else:
			unknow = ""
		for i in range(len(motor)):
			x=num_sum + i
			messageType = motor[i]['messageType']
			region = motor[i]['region']
			type = motor[i]['type']
			id = motor[i]['id']
			lat = motor[i]['lat']
			lon = motor[i]['lon']

			sheet1.write(x+1,0,motor[i]['messageType'])
			sheet1.write(x+1,1,motor[i]['region'])
			sheet1.write(x+1,2,motor[i]['type'])
			sheet1.write(x+1,3,motor[i]['id'])
			sheet1.write(x+1,4,motor[i]['lat'])
			sheet1.write(x+1,5,motor[i]['lon'])
		for i in range(len(nonMotor)):
			x=num_sum + len(motor)+i
			messageType = nonMotor[i]['messageType']
			region = nonMotor[i]['region']
			type = nonMotor[i]['type']
			id = nonMotor[i]['id']
			lat = nonMotor[i]['lat']
			lon = nonMotor[i]['lon']

			sheet1.write(x+1,0,nonMotor[i]['messageType'])
			sheet1.write(x+1,1,nonMotor[i]['region'])
			sheet1.write(x+1,2,nonMotor[i]['type'])
			sheet1.write(x+1,3,nonMotor[i]['id'])
			sheet1.write(x+1,4,nonMotor[i]['lat'])
			sheet1.write(x+1,5,nonMotor[i]['lon'])
		for i in range(len(pedistrain)):
			x=num_sum + len(motor)+len(nonMotor)+i
			messageType = pedistrain[i]['messageType']
			region = pedistrain[i]['region']
			type = pedistrain[i]['type']
			id = pedistrain[i]['id']
			lat = pedistrain[i]['lat']
			lon = pedistrain[i]['lon']

			sheet1.write(x+1,0,pedistrain[i]['messageType'])
			sheet1.write(x+1,1,pedistrain[i]['region'])
			sheet1.write(x+1,2,pedistrain[i]['type'])
			sheet1.write(x+1,3,pedistrain[i]['id'])
			sheet1.write(x+1,4,pedistrain[i]['lat'])
			sheet1.write(x+1,5,pedistrain[i]['lon'])
		for i in range(len(unknow)):
			x=num_sum + len(motor)+len(nonMotor)+len(pedistrain)+i
			messageType = unknow[i]['messageType']
			region = unknow[i]['region']
			type = unknow[i]['type']
			id = unknow[i]['id']
			lat = unknow[i]['lat']
			lon = unknow[i]['lon']

			sheet1.write(x+1,0,unknow[i]['messageType'])
			sheet1.write(x+1,1,unknow[i]['region'])
			sheet1.write(x+1,2,unknow[i]['type'])
			sheet1.write(x+1,3,unknow[i]['id'])
			sheet1.write(x+1,4,unknow[i]['lat'])
			sheet1.write(x+1,5,unknow[i]['lon'])
		if sum == 3000:
			data_save.save("v2r_data.xls") 
			sys.exit()
		else:
			sum=sum + 1
			num_sum=num_sum + len(motor)+len(nonMotor)+len(pedistrain) + len(unknow)

if __name__ == '__main__':
	main()

联系我们

如果您对我们的服务有兴趣,请及时和我们联系!

服务热线:18288888888
座机:18288888888
传真:
邮箱:888888@qq.com
地址:郑州市文化路红专路93号