Exemplo n.º 1
0
    def __init__(self, traffic_manager=None):
        super(VirtualOuluServer, self).__init__()
        if traffic_manager is not None:
            self.traffic_manager = traffic_manager
        else:
            self.traffic_manager = TrafficManager()

        self.traffic_manager.start()
Exemplo n.º 2
0
class VirtualOuluServer(object):
    def __init__(self, traffic_manager=None):
        super(VirtualOuluServer, self).__init__()
        if traffic_manager is not None:
            self.traffic_manager = traffic_manager
        else:
            self.traffic_manager = TrafficManager()

        self.traffic_manager.start()

    def get_vehicles_positions(self):
        return {'time': self.traffic_manager.simulating_time,
                           'vehicles_positions': self.traffic_manager.vehicles_positions,
                           'congested_places': self.traffic_manager.congested_places}

    def delete_congestion(self, congestion_id):
        self.traffic_manager.remove_congestion(congestion_id)
        return True

    def add_congestion(self, lat, lgn):
        congestion = self.traffic_manager.add_congestion(lat, lgn)
        return congestion['id']

    def update_congestion(self, congestion_id, lat, lng):
        self.traffic_manager.update_congestion(congestion_id, lat, lng)
        return congestion_id
Exemplo n.º 3
0
from traffic_manager import TrafficManager
from flask import Flask, render_template, Response, request
import json
import logging

try:
    from flask_cors import CORS  # The typical way to import flask-cors
except ImportError:
    # Path hack allows examples to be run without installation.
    import os
    parentdir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
    os.sys.path.insert(0, parentdir)

    from flask.ext.cors import CORS

traffic_manager = TrafficManager()
if (config.ALWAYS_RELOAD_PEOPLE):
    traffic_manager.generate_new_data(config.PEOPLE_COUNT)
#traffic_manager.create_route_file()


app = Flask(__name__)
cors = CORS(app)

@app.route('/vehicles_positions.php')
def vehicles_positions():
    return Response(json.dumps({'time': traffic_manager.simulating_time, 'vehicles_positions': traffic_manager.vehicles_positions, 'congested_places': traffic_manager.congested_places}), 200, mimetype='application/json')

@app.route('/delete_congestion/<congestion_id>')
def delete_congestion(congestion_id):
    traffic_manager.remove_congestion(congestion_id)