示例#1
0
 def __init__(self):
     self.userView = self
     self.ctrl = Controller(self.userView)
     # self.nlInput = raw_input("Enter Natural Language Input:\n")
     self.nlInput = "Return number of authors who published theory papers before 1980 ."
     #self.nlInput = "Return the conference in each area whose papers have the most total citations ."
     self.choiceList = []
示例#2
0
def setup(app: Controller):
    """
    Perform first-time setup
    Create database
    :param Controller app:
    """
    app.show_setup()
    # Set up DB
    return
示例#3
0
def main():
    """
    Turn on the lights.
    Initialize Controller and Root, then begin loop
    """
    global DB_NAME

    root = tkinter.Tk()

    # TODO: Set tkinter window dimensions, title, etc.

    app = Controller(root)
    app.mainloop()
def run(randomGeneration=True, individual=None, optimization=False):
    global step, c, activities
    activities = ""
    if not optimization:
        simId = create_simulation(0, c.stop_time, 2020, "Running")
    else:
        c.load_data(individual)
        simId = -1
    step = 0
    i = 0
    c.setID(simId)
    sumoBinary = checkBinary('sumo')
    
    try: 
        traci.start([sumoBinary, "-c", "app/data/blou.sumocfg", "--tripinfo-output", 
            "app/data/tripinfo.xml"])
        while (not stop()):
            traci.simulationStep()
            if c.emergencies_to_process > 0:
                check_for_arrivals()
            if (not optimization):
                get_positions()

            if randomGeneration :
                if random() < c.prob:
                    generate_emergency()
            else:
                i = process_emergency(i, step)
            step += 1
            
        traci.simulationStep()
        traci.close()
        sys.stdout.flush()
        step = 0
        sort_output(simId)
        
        if optimization:
            c.prob = c.prob_static
            return float(get_avg_response_time(simId))
        else:
            c = Controller() #reset controller
            print(activities)
            return simId, True
    except Exception as e:
        print(str(e))
        if optimization:
            traci.close()
            c.prob = c.prob_static
            return run(optimization=True, individual=individual)
        return simId, False
            pos = traci.vehicle.getPosition(name)
            if not (pos[0] == -1073741824.0 or pos[1] == -1073741824.0):
                lng, lat = net.convertXY2LonLat(pos[0], pos[1])
                create_heatpoint(lng, lat, c.simId)
                # self.outData.append({'position': [lng, lat], 'weight': 1 })
        except Exception as e:
            # print(str(e))
            depot = c.depots[ambu.depotID]
            c.emergencies_to_process -= 1
            activities += "Arrived at Depot: Ambulance:" + str(ambu.ambuID) + " at TimeStep: " + str(traci.simulation.getTime()) + "\n"
            depot.receive_ambulance()
            c.ambulances.pop(ambu.ambuID)
            return

if __name__ == '__main__':
    c = Controller()
    c.parse_data([])
    options = get_options()
    # check binary
    if options.nogui:
        sumoBinary = checkBinary('sumo')
    else:
        sumoBinary = checkBinary('sumo-gui')

    # # # traci starts sumo as a subprocess and then this script connects and runs
    # traci.start([sumoBinary, "-c", "app/data/blou.sumocfg",
    #              "--tripinfo-output", "app/data/tripinfo.xml"])
    run()

if 'SUMO_HOME' in os.environ:
    tools = os.path.join(os.environ['SUMO_HOME'], 'tools')
示例#6
0
from app import app
import pdfkit
from base64 import b64encode
import base64
from flask_mail import Mail,Message
import ldap
from io import BytesIO
import json
import easygui
from itsdangerous import URLSafeTimedSerializer,SignatureExpired
s = URLSafeTimedSerializer('this is seceret')
mail = Mail(app)
re=1
from werkzeug.security import generate_password_hash, \
     check_password_hash
control=Controller()
#index page function
@app.route('/')
@app.route('/index')
def index():

    return render_template('index.html')
#login
@app.route('/login',methods = ['POST', 'GET'])
def loginuser():
    if request.method == 'POST':
        category=request.form['cat']
        username=request.form['username']
        password=request.form['password']
        row=None
        us=None
示例#7
0
from app.Controller import Controller

if __name__ == "__main__":
    app = Controller()
示例#8
0
 def test_simulation():
     c = Controller()
示例#9
0
class Ui_MainWindow(object):
    stage = None
    app = None
    ctrl = None
    nlInput = ""
    userView = None
    choiceList = []

    def setupUi(self, MainWindow):
        MainWindow.setObjectName(_fromUtf8("MainWindow"))
        MainWindow.resize(800, 600)
        font = QtGui.QFont()
        font.setBold(False)
        font.setWeight(50)
        font.setKerning(True)
        MainWindow.setFont(font)
        self.centralwidget = QtGui.QWidget(MainWindow)
        self.centralwidget.setObjectName(_fromUtf8("centralwidget"))
        self.btnTranslate = QtGui.QPushButton(self.centralwidget)
        self.btnTranslate.setGeometry(QtCore.QRect(140, 190, 117, 32))
        font = QtGui.QFont()
        font.setFamily(_fromUtf8("Times New Roman"))
        font.setPointSize(10)
        font.setBold(True)
        font.setWeight(75)
        self.btnTranslate.setFont(font)
        self.btnTranslate.setObjectName(_fromUtf8("btnTranslate"))
        self.btnTranslate.clicked.connect(lambda: self.startTranslation())

        self.queryInputText = QtGui.QPlainTextEdit(self.centralwidget)
        self.queryInputText.setGeometry(QtCore.QRect(40, 40, 341, 141))
        self.queryInputText.viewport().setProperty(
            "cursor", QtGui.QCursor(QtCore.Qt.ArrowCursor))
        self.queryInputText.setObjectName(_fromUtf8("plainTextEdit"))
        font = QtGui.QFont()
        font.setFamily(_fromUtf8("Times New Roman"))
        font.setPointSize(10)
        font.setItalic(False)
        self.queryInputText.setFont(font)
        self.queryInputText.viewport().setProperty(
            "cursor", QtGui.QCursor(QtCore.Qt.ArrowCursor))
        self.queryInputText.setObjectName(_fromUtf8("plainTextEdit"))

        self.choiceBox = QtGui.QComboBox(self.centralwidget)
        self.choiceBox.setGeometry(QtCore.QRect(470, 230, 241, 32))
        self.choiceBox.setVisible(False)
        sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Expanding,
                                       QtGui.QSizePolicy.Fixed)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(
            self.choiceBox.sizePolicy().hasHeightForWidth())
        self.choiceBox.setSizePolicy(sizePolicy)
        font = QtGui.QFont()
        font.setFamily(_fromUtf8("Georgia"))
        font.setPointSize(10)
        font.setBold(False)
        font.setWeight(50)
        self.choiceBox.setFont(font)
        self.choiceBox.setObjectName(_fromUtf8("choiceBox"))

        self.btnConfirmChoice = QtGui.QPushButton(self.centralwidget)
        self.btnConfirmChoice.setGeometry(QtCore.QRect(520, 270, 141, 32))
        self.btnConfirmChoice.clicked.connect(
            lambda: self.btnConfirmChoiceClick(self.btnConfirmChoice, self.
                                               choiceBox))
        self.btnConfirmChoice.setVisible(False)
        font = QtGui.QFont()
        font.setFamily(_fromUtf8("Times New Roman"))
        font.setPointSize(10)
        font.setBold(True)
        font.setItalic(False)
        font.setWeight(75)
        self.btnConfirmChoice.setFont(font)
        self.btnConfirmChoice.setObjectName(_fromUtf8("btnConfirmChoice"))

        self.treeChoice = QtGui.QComboBox(self.centralwidget)
        self.treeChoice.setGeometry(QtCore.QRect(540, 360, 81, 32))
        font = QtGui.QFont()
        font.setFamily(_fromUtf8("Times New Roman"))
        font.setPointSize(10)
        self.treeChoice.setFont(font)
        self.treeChoice.setObjectName(_fromUtf8("treeChoice"))
        self.treeChoice.setVisible(False)

        self.btnTreeConfirm = QtGui.QPushButton(self.centralwidget)
        self.btnTreeConfirm.setGeometry(QtCore.QRect(520, 400, 131, 32))
        self.btnTreeConfirm.setVisible(False)
        self.btnTreeConfirm.clicked.connect(
            lambda: self.btnTreeConfirmClick(self.treeChoice))
        font = QtGui.QFont()
        font.setFamily(_fromUtf8("Times New Roman"))
        font.setPointSize(10)
        font.setBold(True)
        font.setWeight(75)
        self.btnTreeConfirm.setFont(font)
        self.btnTreeConfirm.setObjectName(_fromUtf8("btnTreeConfirm"))

        self.label = QtGui.QLabel(self.centralwidget)
        self.label.setGeometry(QtCore.QRect(330, 0, 261, 22))
        self.label.setObjectName(_fromUtf8("label"))
        self.display = QtGui.QTextEdit(self.centralwidget)
        self.display.setGeometry(QtCore.QRect(410, 40, 381, 171))
        font = QtGui.QFont()
        font.setFamily(_fromUtf8("Times New Roman"))
        font.setPointSize(10)
        self.display.setFont(font)
        self.display.setObjectName(_fromUtf8("display"))

        MainWindow.setCentralWidget(self.centralwidget)
        self.menubar = QtGui.QMenuBar(MainWindow)
        self.menubar.setGeometry(QtCore.QRect(0, 0, 800, 30))
        self.menubar.setObjectName(_fromUtf8("menubar"))

        MainWindow.setMenuBar(self.menubar)
        self.statusbar = QtGui.QStatusBar(MainWindow)
        self.statusbar.setObjectName(_fromUtf8("statusbar"))
        MainWindow.setStatusBar(self.statusbar)

        self.retranslateUi(MainWindow)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)

    def retranslateUi(self, MainWindow):
        MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow", None))
        self.btnTranslate.setText(_translate("MainWindow", "Translate", None))
        self.queryInputText.setPlainText(
            _translate("MainWindow", self.nlInput, None))
        self.btnConfirmChoice.setText(
            _translate("MainWindow", "Confirm Choice ", None))
        self.btnTreeConfirm.setText(
            _translate("MainWindow", "Confirm Tree", None))
        self.label.setText(_translate("MainWindow", "Welcome to NLIDB ", None))

    def __init__(self):
        self.userView = self
        self.ctrl = Controller(self.userView)
        # self.nlInput = raw_input("Enter Natural Language Input:\n")
        self.nlInput = "Return number of authors who published theory papers before 1980 ."
        #self.nlInput = "Return the conference in each area whose papers have the most total citations ."
        self.choiceList = []

    def setDisplay(self, text):
        self.display.setText(text)

    def appendDisplay(self, text):
        self.display.setText(self.display.toPlainText() + text)

    def showNodesChoice(self):
        self.choiceBox.show()
        self.btnConfirmChoice.show()

    def removeChoiceBoxButton(self):
        self.choiceBox.hide()
        self.btnConfirmChoice.hide()

    def btnConfirmChoiceClick(self, btn, chBox):
        self.ctrl.chooseNode(self.getNodeInfoObject(self.getChoice()))

    def getNodeInfoObject(self, string):
        nodeInfo = string.split(' ')
        type = nodeInfo[0]
        value = nodeInfo[2]
        return self.findNodeInfo(type, value)

    def findNodeInfo(self, type, value):
        for nodeInfo in self.choiceList:
            if nodeInfo.getType() == type and nodeInfo.getValue() == value:
                return nodeInfo

    def setChoices(self, choices):
        self.choiceList = choices
        self.choiceBox.clear()
        for choice in choices:
            self.choiceBox.addItem(
                self.userView.createOptionMsg(choice.getType(),
                                              choice.getValue(),
                                              choice.getScore()))
        self.choiceBox.setCurrentIndex(0)
        self.choiceBox.show()
        self.btnConfirmChoice.show()

    def createOptionMsg(self, type, value, score):
        sb = []
        sb.append(type)
        sb.append(" : ")
        sb.append(value)
        str = ''.join(sb)
        return str

    def getChoice(self):
        return self.choiceBox.currentText()

    def showTreesChoice(self):
        self.treeChoice.addItem("select")
        self.treeChoice.addItem("0")
        self.treeChoice.addItem("1")
        self.treeChoice.addItem("2")
        self.btnTreeConfirm.show()
        self.treeChoice.show()

    def removeTreesChoices(self):
        self.treeChoice.clear()
        self.btnConfirmChoice.hide()
        self.btnTreeConfirm.hide()
        self.treeChoice.hide()

    def startTranslation(self):
        self.ctrl.processNaturalLanguage(str(
            self.queryInputText.toPlainText()))

    def btnTreeConfirmClick(self, treeChoice):
        if (treeChoice.currentText() == "select"):
            return
        self.ctrl.chooseTree(int(treeChoice.currentText()))