Example #1
0
def update_dt_vehicle_gps(**item):
    """
    更新车辆当前位置信息
    item:
    {u'direction': 270.001, u'posInvalidate': 0, 'pt': 'POINT(104.0328 30.645)', 
    u'taxiNo': u'\u4eacA33333', u'empty': u'yes', u'time': u'/Date(1487317354000)/', 
    u'lat': 30.645, u'lng': 104.0328, 'vehicle_type': 3, u'speed': 15.433333333333334, u'alarmType': 0}

    """
    #print item

    action_type = "update"
    time_str = parse_time2str(item['time'])

    update_sql = "UPDATE here_is_db_table SET pt=ST_GeomFromText('{0}', 4326), is_empty='{1}', key={2}, key={3}, time='{4}', key={5} WHERE vehicle_card = '{6}'".format(
        item['pt'], item['key'], int(item['key']), int(item['key']), time_str,
        item['key'], item['taxiNo'])

    try:
        cursor.execute(update_sql)
        connection.commit()
        if log_details_true:
            mylogger.info("[update gps data] {0}".format(update_sql))

    except Exception, e:
        connection.rollback()
        mylogger.error("db Error -{0}- when update, sql---: {1}".format(
            e, update_sql))
Example #2
0
	def post(self):
		# db Error: 'ascii' codec can't encode character u'\u5ddd' in position 101: ordinal not in range(128)
		reload(sys)
		sys.setdefaultencoding('utf-8')

		url_type = self.get_argument('type')
		if url_type == gpsDataName:
			
			data = self.get_body_argument(gpsDataName)
			datas = json.loads(data)
			logger.info("===== load  %s items :  %s" % (gpsDataName, len(datas)) )	

			for item in datas:
				item["pt"] = 'POINT({0} {1})'.format(item['lng'], item['lat'])
				model.car_real_location_to_db(**item)

				exist = model.query_vehicle_is_exist(item['taxiNo'])
				if exist:
					model.update_dt_vehicle_gps(**item)
				else:
					model.insert_dt_vehicle_gps(**item)


		elif url_type == "serviceData":
			print " Module for serviceData === todo"
			pass
Example #3
0
def push_gps_json_to_redis(action_type, **item):
    """推送到redis 车辆GPS实时信息队列"""
    location_json = json_encode({
        "type": "",
        "action": action_type,
        "data": {
            "vehicle_card": item["taxiNo"],
            "lng": float(item["lng"]),
            "lat": float(item["lat"]),
            "direction": float(item["direction"]),
            "speed": float(item["speed"])
        }
    })
    rsdb.lpush(GPS_QUEUE_KEY, location_json)
    if log_details_true:
        mylogger.info("[redis push:] {0}".format(location_json))
Example #4
0
def insert_dt_vehicle_gps(**item):
    """ 向here_is_db_table 插入新数据"""
    action_type = "insert"
    time_str = parse_time2str(item['time'])

    insert_sql = """INSERT INTO "here_is_db_table" (key, sync_type, key, key, time, alarm_type, is_empty, pt) VALUES ('{0}',{1},{2},{3},'{4}','{5}','{6}',ST_GeomFromText('{7}', 4326))""".format(
        item['taxiNo'], SYNC_TYPE['weijie'], int(item['key']),
        int(item['key']), time_str, item['alarmType'], item['empty'],
        item['pt'])

    try:
        cursor.execute(insert_sql)
        connection.commit()
        if log_details_true:
            mylogger.info("[insert gps data] {0}".format(insert_sql))

    except Exception, e:
        connection.rollback()
        mylogger.error("db Error -{0}- when insert, sql---: {1}".format(
            e, insert_sql))
Example #5
0
def car_real_location_to_db(**item):
    """ 将所有接收的gps信息写入总表 here_is_db_table """

    _sql = """INSERT INTO "here_is_db_table" (key, key, key, key, time, key, is_empty, is_validate, pt)
               VALUES ('{0}',{1},{2},{3},'{4}','{5}','{6}','{7}',ST_GeomFromText('{8}', 4326))""".format(
        item['key'], SYNC_TYPE['key'], int(item['key']), int(item['key']),
        parse_time2str(item['time']), item['key'], item['empty'],
        is_validate(item['key']), item['pt'])

    if log_details_true:
        mylogger.info("[insert GPS datas] {0}".format(_sql))

    try:
        cursor.execute(_sql)
        connection.commit()

    except Exception, e:
        connection.rollback()
        mylogger.error("db Error -{0}- when insert sql---: {1}".format(
            e, _sql))
Example #6
0
from log.mylogger import logger

define("port", default=9031, help="run on the given port", type=int)


class IndexHandler(tornado.web.RequestHandler):
    def get(self):
        self.write("hello, welcome to [GpsCollecter]!")


class MyApplication(tornado.web.Application):
    def __init__(self):
        handlers = [
            (r"/", IndexHandler),
            (r"/collect", TaxGpsCollector),
            (r"/analysis/publish", PublishTaxiWeijieHandler),
        ]
        setting = dict(
            template_path=os.path.join(os.path.dirname(__file__), "templates"),
            static_path=os.path.join(os.path.dirname(__file__), "static"),
            debug=True,
        )
        tornado.web.Application.__init__(self, handlers, **setting)


if __name__ == "__main__":
    tornado.options.parse_command_line()
    http_server = tornado.httpserver.HTTPServer(MyApplication())
    http_server.listen(options.port)
    logger.info("the app is running at: %s" % options.port)
    tornado.ioloop.IOLoop.instance().start()