Commit 72dfbc75 by 潘建波

12/25 提交code服务

1 parent b17c0900
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
from flask import Blueprint,request,redirect,url_for from flask import Blueprint,request,redirect,url_for
import flask import flask
import apps.gbvar.database_global as dbs import gbvar.database_global as dbs
import json,re,time,io import json,re,time,io
code_sev = Blueprint('code_sev', __name__) code_sev = Blueprint('code_sev', __name__)
......
#!/usr/bin/evn python #!/usr/bin/evn python
# coding=utf-8 # coding=utf-8
from flask import Blueprint,request,redirect,url_for from flask import Blueprint,request,redirect,url_for
import flask
from werkzeug import secure_filename from werkzeug import secure_filename
import json,re,time,io import json,re,time,io
import sys import sys
import os import os
from apps.commons.util import * import uuid
import apps.gbvar.ws_serv_global as sv_global from commons.util import *
import apps.gbvar.database_global as database import gbvar.ws_serv_global as sv_global
import apps.gbvar.dict_properties as dict_p import gbvar.database_global as database
import apps.commons.editXml as editXml import gbvar.dict_properties as dict_p
import apps.commons.event_to_local as etl import commons.editXml as editXml
import commons.event_to_local as etl
import dao.firebird_dao as dbmanipulation
import commons.data_process as proc
tx1_box = Blueprint('tx1_box', __name__) tx1_box = Blueprint('tx1_box', __name__)
#数据接收接口 #数据接收接口
@tx1_box.route('/events', methods=["POST"]) @tx1_box.route('/events', methods=["POST"])
...@@ -21,20 +23,32 @@ def dataRecv(): ...@@ -21,20 +23,32 @@ def dataRecv():
data = request.get_data() data = request.get_data()
dataDic = json.loads(data) dataDic = json.loads(data)
if type(dataDic) is dict: if type(dataDic) is dict:
res = etl.eventToLocal.saveEventToLocal(dataDic) # res = etl.eventToLocal.saveEventToLocal(dataDic)
print(res) # print(res)
send_all_data(sv_global.get_value(),data) send_all_data(sv_global.get_value(),data)
#存入本地数据库 #存入本地数据库
push_dbs(data) # save_alarm_data(data,res)
else: else:
print('error: data to dict failed, data:{}'.format(data)) print('error: data to dict failed, data:{}'.format(data))
return data return json.dumps({"ecode":200,"enote":'ok'})
@tx1_box.route('/test', methods=["GET"]) @tx1_box.route('/events/list', methods=["GET"])
def test(): def getEventList():
print 'test' save_alarm_data('','')
print database.get_value() return ''
return "111" # arguments = request.args()
# for item in arguments:
# print(item)
# sql = 'select * from TB_TRAFFIC_EVENT ROWS 1 TO 19'
#
# eventResult = dbmanipulation.selectDb(sql)
# print 'test'
# # print database.get_value()
# res = flask.make_response(json.dumps(eventResult, encoding="UTF-8", ensure_ascii=False, sort_keys=False, indent=4).encode('utf-8'))
# res.headers['Access-Control-Allow-Origin'] = '*'
# res.headers['Access-Control-Allow-Methods'] = 'POST,GET,OPTIONS'
# res.headers['Access-Control-Allow-Headers'] = 'x-requested-with,content-type'
# return res
# 给所有用户发送信息 # 给所有用户发送信息
def send_all_data(sv, data): def send_all_data(sv, data):
if sv.users is not None and len ( sv.users ) > 0: if sv.users is not None and len ( sv.users ) > 0:
...@@ -63,6 +77,32 @@ def get_task_info(): ...@@ -63,6 +77,32 @@ def get_task_info():
continue continue
return json.dumps ( result_list, ensure_ascii=False ) return json.dumps ( result_list, ensure_ascii=False )
# 初始化报警数据
def save_alarm_data(adata, src):
setting = ''
with open("text", 'r') as f:
setting = json.loads(f.read())
data = setting
dataType = data['event_type']
proc.dataProcess.initData(data)
trffic_data = proc.dataProcess.trffic_data()
dbmanipulation.save_trrfic_Db(trffic_data)
if (dataType == 'vehicle' or dataType == 'xcycle' or dataType == 'pedestrian'):
if (data.has_key('driver')):
if(data['driver'].has_key('face')):
face_data = proc.dataProcess.face_data()
dbmanipulation.save_face_Db(face_data)
else:
return '人脸不存在'
elif (dataType == 'pflow' or dataType == 'tflow' or dataType == 'pdensity'):
flow_data = proc.dataProcess.flow_data()
dbmanipulation.save_flow_data_Db(flow_data)
flow_event = proc.dataProcess.flow_event()
dbmanipulation.save_flow_event_Db(flow_event)
#初始化任务详情信息:包含algo_args信息、calibration标定参数信息以及roi信息的组合 #初始化任务详情信息:包含algo_args信息、calibration标定参数信息以及roi信息的组合
def creat_mtasks(): def creat_mtasks():
......
...@@ -4,10 +4,10 @@ from flask import Blueprint, request ...@@ -4,10 +4,10 @@ from flask import Blueprint, request
import flask import flask
import json,re,time,io import json,re,time,io
import os import os
from apps.commons.util import * from commons.util import *
import apps.gbvar.ws_serv_global as sv_global import gbvar.ws_serv_global as sv_global
import apps.gbvar.dict_properties as dict_p import gbvar.dict_properties as dict_p
import apps.commons.editXml as editXml import commons.editXml as editXml
import requests import requests
import re import re
......
# coding: utf-8 #-*-coding:UTF-8-*-,
from socket import * from socket import *
import json, time, threading import json, time, threading
import apps.gbvar.ws_serv_global as sv_global import gbvar.ws_serv_global as sv_global
import sys
reload(sys)
sys.setdefaultencoding('UTF-8')
config = { config = {
'LISTEN_CLIENT': 50, 'LISTEN_CLIENT': 50,
'KEY': '391f10fadc339e9ec5fa15af60030ac1', 'KEY': '391f10fadc339e9ec5fa15af60030ac1',
...@@ -32,6 +35,7 @@ class Server (): ...@@ -32,6 +35,7 @@ class Server ():
# 所有监听的客户端 # 所有监听的客户端
self.clients = {} self.clients = {}
self.sub_task_id = ''
self.thrs = {} self.thrs = {}
self.users = {} self.users = {}
self.stops = [] self.stops = []
...@@ -126,10 +130,10 @@ class Server (): ...@@ -126,10 +130,10 @@ class Server ():
if not info: if not info:
continue continue
if info == 'quit': if info == 'quit':
self.close_client ( address ) self.close_client ( address )
break break
print(info)
code_len = ord ( info[1] ) & 127 code_len = ord ( info[1] ) & 127
if code_len == 126: if code_len == 126:
masks = info[4:8] masks = info[4:8]
...@@ -152,10 +156,30 @@ class Server (): ...@@ -152,10 +156,30 @@ class Server ():
# 开启线程记录 # 开启线程记录
if raw_str: if raw_str:
t1 = threading.Thread ( target=self.send_data, args=[raw_str, address] ) try:
t1.start () cdata = eval(raw_str)
if(cdata.has_key('subtask_id')):
self.sub_task_id = cdata['subtask_id']
else:
return
except:
print(raw_str)
#t1 = threading.Thread ( target=self.send_data, args=[raw_str, address] )
#t1.start ()
def send_data(self, data, address): def send_data(self, data, address):
try:
td = json.loads(data)
if type(td) is dict:
if (td.has_key('subtask_id')):
data = data
else:
data =''
else:
data = data
print(data)
except Exception as e:
print e
import struct import struct
from urllib import unquote from urllib import unquote
try: try:
...@@ -181,7 +205,7 @@ class Server (): ...@@ -181,7 +205,7 @@ class Server ():
# struct为Python中处理二进制数的模块,二进制流为C,或网络流的形式。 # struct为Python中处理二进制数的模块,二进制流为C,或网络流的形式。
data = '%s%s' % (token, data) data = '%s%s' % (token, data)
print data # print data
try: try:
#for key, val in self.clients.iteritems (): #for key, val in self.clients.iteritems ():
# print # print
......
...@@ -13,7 +13,7 @@ import os ...@@ -13,7 +13,7 @@ import os
import json import json
import uuid import uuid
import base64 import base64
import apps.gbvar.dict_properties as dict_p import gbvar.dict_properties as dict_p
class EventToLocalUtil(object): class EventToLocalUtil(object):
......
# coding: utf-8 # coding: utf-8
import fdb import gbvar.database_global as database
import uuid
def save_trrfic_Db(data):
con = database.get_value()
cur = con.cursor()
sql_insert = 'INSERT INTO TB_TRAFFIC_EVENT (UNID,EVENT_CATE,TASK_ID,TASK_TYPE,SUBTASK_ID,SOURCE_TYPE,EVENT_TYPE,DEV_UNID,VCHAN_REFID,VDEV_UNID,VCHAN_DUID,EVENT_DT,PLATE_COLOR_CODE,PLATE_TEXT,LOCATION_CODE,LANE_CODE,DIRECTION_CODE,BODY_TYPE_CODE,DEVICE_NAME,ILLEGAL_CODE,ILLEGAL_STATE,BODY_COLOR_CODE,BODY_LOGO_CODE,T_RANNUALINSPECTION,T_RDECORATION,T_RPENDANT,T_RSUNSHADING,XCYCLE_TYPE,LOCATION_NAME,EVENT_ID,SHOOT_DT,IS_ACTIVE,EVENT_ALLDATA) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)'
print(data)
cur.executemany(sql_insert,data)
con.commit()
def save_face_Db(sql_data):
con = database.get_value()
cur = con.cursor()
sql_insert = 'INSERT INTO TB_FACE(UNID,TRAFFIC_UNID,STATE,SEX,UPBODY_COLOR,LOBODY_COLOR) VALUES (?,?,?,?,?,?)'
cur.executemany(sql_insert, sql_data)
con.commit()
def save_flow_data_Db(sql_data):
con = database.get_value()
cur = con.cursor()
sql_insert = 'INSERT INTO TB_TFLOW_DATA(UNID,EVENT_UNID,DETECTION_TYPE,ROAD_CODE,DIRECTION_CODE,SAMPLE_DURA,SAMPLE_NUM,VELOCITY,VELOCITY_UNIT,OCCUPY,DISTANCE,QUEUE_LENGTH,REGIONID,REGIONNAME,POSTION_LIST,HEAD_LIST,AREA,DENSITY,SAMPLE_NUM_IN,SAMPLE_NUM_OUT,TASK_ID) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)'
cur.executemany(sql_insert, sql_data)
con.commit()
def save_flow_event_Db(sql_data):
con = database.get_value()
cur = con.cursor()
sql_insert = 'INSERT INTO TB_TFLOW_EVENT(UNID,TASK_ID,TASK_TYPE,SOURCE_TYPE,EVENT_TYPE,EVENT_DT,LOCATION_NAME,DEVICE_NAME,EVENT_ID) VALUES (?,?,?,?,?,?,?,?,?)'
cur.executemany(sql_insert, sql_data)
con.commit()
def selectDb(sql_sel):
con = database.get_value()
cur = con.cursor()
result = cur.execute(sql_sel)
print(result)
return result
# coding: utf-8 # coding: utf-8
def _init():#初始化 def _init():#初始化
global dbs global database
database = None database = None
def set_value(value): def set_value(value):
""" 定义一个全局变量 """ """ 定义一个全局变量 """
global dbs global database
dbs = value database = value
def get_value(): def get_value():
global dbs global database
return dbs return database
...@@ -3,18 +3,18 @@ ...@@ -3,18 +3,18 @@
from flask import Flask,Blueprint from flask import Flask,Blueprint
import flask import flask
import threading import threading
from apps.api.http_serv import tx1_box from api.http_serv import tx1_box
from apps.api.task import task from api.task import task
from apps.api.ws_serv import Server from api.ws_serv import Server
import apps.gbvar.ws_serv_global as sv_global import gbvar.ws_serv_global as sv_global
import apps.gbvar.database_global as database import gbvar.database_global as database
import apps.gbvar.dict_properties as dict_p import gbvar.dict_properties as dict_p
from apps.api.code_serv import code_sev from api.code_serv import code_sev
import fdb import fdb
import sys import sys
import os import os
from commons.util import * from commons.util import *
import apps.commons.event_to_local as etl import commons.event_to_local as etl
app = Flask(__name__, static_folder='dist') app = Flask(__name__, static_folder='dist')
# 获取本脚本所在的路径 # 获取本脚本所在的路径
pro_path = os.path.split(os.path.realpath(__file__))[0] pro_path = os.path.split(os.path.realpath(__file__))[0]
...@@ -31,10 +31,10 @@ app.register_blueprint(task, url_prefix='/api/v1/tx1_box/task') ...@@ -31,10 +31,10 @@ app.register_blueprint(task, url_prefix='/api/v1/tx1_box/task')
app.register_blueprint(code_sev, url_prefix='/api/v1/codes') app.register_blueprint(code_sev, url_prefix='/api/v1/codes')
#注册login路由 #注册login路由
app.register_blueprint(login, url_prefix='/api/v1/auth/users') # app.register_blueprint(login, url_prefix='/api/v1/auth/users')
#注册register路由 #注册register路由
app.register_blueprint(register, url_prefix='/api/v1') # app.register_blueprint(register, url_prefix='/api/v1')
@app.route('/', methods=["GET"]) @app.route('/', methods=["GET"])
def index(): def index():
...@@ -57,29 +57,29 @@ def init(): ...@@ -57,29 +57,29 @@ def init():
database._init() database._init()
dict_p._init() dict_p._init()
dict_p.set_value(dictProperties) dict_p.set_value(dictProperties)
con = fdb.connect ( host=dictProperties['tx1_host'], database=dictProperties['datasource_url'], user='sysdba',password='masterkey',charset='UTF8' ) con = fdb.connect ( host='192.168.9.239', database='/var/lib/firebird/2.5/data/little_star.fdb', user='VION_FDB',password='vion',charset='UTF8' )
cur = con.cursor () cur = con.cursor ()
print (con) print (con)
database.set_value(con) database.set_value(con)
print database.get_value() print database.get_value()
'''newLanguages = [ # newLanguages = []
(2, 'Dylan3') # cur.executemany( "insert into tb_event_(EVENT_CATE_UNID,CODE,NAME,NOTE) VALUES(?,?,?,?)",
] # newLanguages
cur.executeman hjj ( "insert into tb_traffic(id,name) VALUES(?,?)", # )
newLanguages # con.commit ()
) #
con.commit ()''' # sql_select = 'select * from tb_traffic'
sql_select = 'select * from tb_traffic' #
# # 显示全部内容
# 显示全部内容 # cur.execute ( sql_select )
cur.execute ( sql_select ) # print(cur.fetchall ())
print(cur.fetchall ()) #
# cur.close ()
cur.close () # con.close ()
con.close ()
####====================database=================== ####====================database===================
#启动服务 #启动服务
if __name__=='__main__': if __name__=='__main__':
dict_p._init () dict_p._init ()
......
#系统参数 #系统参数
tx1_host=192.168.88.159 tx1_host=192.168.9.32
tx1_http_port=20090 tx1_http_port=20090
tx1_ws_port=20080 tx1_ws_port=20080
#firebird数据库 #firebird数据库
datasource_url=F:/ssss/TT.FDB datasource_url=F:\ssss\ss\TF.FDB
#初始化任务列表(说明:路径@任务名称 #初始化任务列表(说明:路径@任务名称
task_1=F:\公司项目目录\mini_fanxin\config\TASK1\tasks.xml@F:\公司项目目录\mini_fanxin\config\TASK1\TASK1\@F:\公司项目目录\mini_fanxin\config\TASK1\TASK1\TASK1\@F:\公司项目目录\mini_fanxin\config\TrafficConfig.xml task_1=F:\公司项目目录\mini_fanxin\config\TASK1\tasks.xml@F:\公司项目目录\mini_fanxin\config\TASK1\TASK1\@F:\公司项目目录\mini_fanxin\config\TASK1\TASK1\TASK1\@F:\公司项目目录\mini_fanxin\config\TrafficConfig.xml
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!