예제 #1
0
def main():
    print("Shorest Job First...")
    # Sorting the dictionary in terms of each jobs length
    # drive function reads in input from file and turns it into dictionary
    for v in sorted(drive(), key=lambda x: x[1][1]):
        print("Running task = {} {} {} for {} units.\n".format(
            v[0], v[1][0], v[1][1], v[1][1]))
예제 #2
0
def main():
    print("Scheduling priority round robin...\n")
    a = []  # slice list
    for v in sorted(drive(), key=lambda x: x[1][0]):
        slice = v[1][1]
        a.append(slice)  # add time to list
        #sort dic dictionary by priority
    dic = sorted(drive(), key=lambda x: x[1][0])

    # pass list, dictionary and indicator to robin function
    # indicator tells the function if it is its first time being passed into the
    #robin function
    # 0 indicates its first time
    robin(a, dic, 0)
    while sum(a) != 0:
        # 1 indicates its not thie first time its been passed to robin
        robin(a, dic, 1)
예제 #3
0
def step():
    x, y, theta = io.getPosition()
    robot.slimeX.append(x)
    robot.slimeY.append(y)

    # the following lines compute the robot's current position and angle
    currentPoint = util.Point(x,y).add(robot.initialLocation)
    currentAngle = util.fixAnglePlusMinusPi(theta)

    fv, rv = driver.drive(robot.path, currentPoint, currentAngle)
    io.setForward(fv)
    io.setRotational(rv)
예제 #4
0
def on_step():
    x, y, theta = io.get_position(cheat=True)
    robot.slime_x.append(x)
    robot.slime_y.append(y)
    checkoff.update(globals())

    # the following lines compute the robot's current position and angle
    current_point = util.Point(x,y).add(robot.initial_location)
    current_angle = theta

    forward_v, rotational_v = drive(robot.path, current_point, current_angle)
    io.set_forward(forward_v)
    io.set_rotational(rotational_v)
예제 #5
0
def floodResult():
    if request.method == 'POST':
        if len(request.form['DATE']) == 0:
            return redirect(url_for('floodHome'))
        else:
            user_date = request.form['DATE']
            river = request.form['SEL']
            results_dict = driver.drive(river, user_date)
            print("-----------", type(results_dict), "----------")
            Table = []
            for key, value in results_dict.items():
                Table.append(value)
            return render_template('flood_result.html', result=Table)
    else:
        return redirect(url_for('floodHome'))
예제 #6
0
def predict():
    user_date = request.form['Date']
    river = request.form['River']
    print(river, user_date)

    results_dict, classification_metrics, data, fut = driver.drive(
        river, user_date)

    if fut is 0:
        data["Date"] = data["Date"].astype(str)
        results_dict["Data"] = data.to_dict()

    results_dict["Classification Report"] = classification_metrics

    response = app.response_class(response=json.dumps(results_dict),
                                  mimetype='application/json')
    return response
예제 #7
0
def test_e2e():
    opts = {
        'PLAYERS': [(10, 0), (0, 1), (0, 2)],
        'N_CONNECTIONS': 3,
        'TIME_TO_SIM': 2,
        'MEAN_PROP_TIME': 0.1,
        'STD_PROP_TIME': 0.001,
        'SEED': 20,
        'GRAPH': False
    }

    os.system('./run_server.sh &')
    time.sleep(5)  # allow the server to boot up

    sol = driver.drive(opts)

    correctHashes = player.Player.correctHashes
    for i in sol.players:
        assert len(i.blockchain) > 0
        for j in range(len(i.blockchain)):
            assert i.blockchain[j] == correctHashes[j]
예제 #8
0
def floodResult():
    if request.method == 'POST':
        if len(request.form['DATE']) == 0:
            return redirect(url_for('floodHome'))
        else:
            user_date = request.form['DATE']
            river = request.form['SEL']
            # print("##3#######",user_date,"#####",river,"#############")
            # print(type(user_date))
            # print(type(river))
            results_dict = driver.drive(river, user_date)
            # results_dict={'Mse':0.5,
            #         'discharge':1400}
            print("-----------", type(results_dict), "----------")
            Table = []
            for key, value in results_dict.items():
                # temp = []
                # temp.extend([key,value])  #Note that this will change depending on the structure of your dictionary
                Table.append(value)
            return render_template('flood_result.html', result=Table)
    else:
        return redirect(url_for('floodHome'))
예제 #9
0
파일: main.py 프로젝트: patomems/prediction
def floodResult():
    if request.method == 'POST':
        # pdb.set_trace()
        if len(request.form['DATE']) == 0:
            flash("Please Enter Data!!")
            return redirect(url_for('floodHome'))
        else:
            user_date = request.form['DATE']
            river = request.form['SEL']
            results_dict = driver.drive(river, user_date)
            # results_dict={'Mse':0.5,
            #         'discharge':1400}
            print("-----------", type(results_dict), "----------")
            Table = []
            key: object
            for key, value in results_dict.items():
                #df = pd.DataFrame.from_dict(data)
                #temp = []
                #temp.extend([key, value])
                Table.append(value)
            return render_template('flood_result.html', result=Table)
    else:
        return redirect(url_for('floodHome'))
예제 #10
0
def main(argv):
    volume = DetectorVolume(1000.0, 1000.0)
    wirePitches = [5.0, 5.0, 5.0]
    angles = driver.generateAngles(len(wirePitches))

    numbersOfBlobs = [3]
    alphas = [0.01]

    numberOfIterations = 100

    for numberOfBlobs in numbersOfBlobs:
        for alpha in alphas:
            c1 = root.TCanvas("RecoRateCanvas", "RecoRateCanvas", 200, 10, 700,
                              500)

            correctFractions = root.TH1F("correctFractions",
                                         ("Correct Identification Fraction"),
                                         100, -0.1, 1.1)
            fakeFractions = root.TH1F("fakeFractions",
                                      ("Fake Identification Fraction"), 100,
                                      -0.1, 1.1)
            for i in range(numberOfIterations):
                blobs, cells, channelList, geometryMatrix, recoWireMatrix, recoCellMatrix, trueCellMatrix = driver.drive(
                    volume, wirePitches, angles, numberOfBlobs, alpha)

                recoCells = list(
                    map(lambda x: not math.isclose(x, 0, rel_tol=1e-5),
                        recoCellMatrix))
                trueCells = list(
                    map(lambda x: not math.isclose(x, 0, rel_tol=1e-5),
                        trueCellMatrix))

                correctID = sum(
                    bool(x[0]) and bool(x[1])
                    for x in zip(trueCells, recoCells))
                fakeID = sum(not bool(x[0]) and bool(x[1])
                             for x in zip(trueCells, recoCells))

                correctFraction = correctID / len(blobs)
                fakeFraction = fakeID / len(blobs)

                correctFractions.Fill(correctFraction)
                fakeFractions.Fill(fakeFraction)

            correctFractions.SetTitle("")
            correctFractions.GetYaxis().SetTitleSize(0.04)
            correctFractions.GetYaxis().SetTitleOffset(1.2)
            correctFractions.GetYaxis().SetLabelSize(0.04)
            correctFractions.GetXaxis().SetTitleSize(0.04)
            correctFractions.GetXaxis().SetTitleOffset(1)
            correctFractions.GetXaxis().SetLabelSize(0.04)

            correctFractions.SetLineWidth(2)
            fakeFractions.SetLineWidth(2)

            # correctFractions.SetLineStyle(2)
            fakeFractions.SetLineStyle(2)

            correctFractions.SetLineColor(root.kBlue)
            fakeFractions.SetLineColor(root.kRed)

            root.gStyle.SetOptStat(0)

            correctFractions.Draw("HIST")
            fakeFractions.Draw("HIST SAMES")

            root.gApplication.Run()
예제 #11
0
  --nconnections=<ncons>          number of connections per person in the network [default: 3]
  --timetosim=<timetosim>         virtual time in seconds to simulate the system for [default: 10]
  --meanproptime=<meanproptime>   mean propagation time of messages (latency) [default: 1]
  --stdproptime=<stdproptime>     std deviation of the propagation time of messages [default: 0.1]
  --seed=<seed>                   random seed [default: 42]
  -g                              generate graph animation
  --help                          show this
"""
import random

import grpc
from docopt import docopt

import driver
import player
import solver

if __name__ == "__main__":
    args = docopt(__doc__)
    opts = {
        "PLAYERS": eval(args["--players"]),
        "N_CONNECTIONS": int(args["--nconnections"]),
        "TIME_TO_SIM": int(args["--timetosim"]),
        "MEAN_PROP_TIME": float(args["--meanproptime"]),
        "STD_PROP_TIME": float(args["--stdproptime"]),
        "SEED": int(args["--seed"]),
        "GRAPH": bool(args["-g"]),
    }

    driver.drive(opts)
예제 #12
0
def main():
    print("Scheduling priority...\n")
    for v in sorted(drive(), key=lambda x: x[1][0]):
        print("Running task = {} {} {} for {} units.\n".format(
            v[0], v[1][0], v[1][1], v[1][1]))
예제 #13
0
s.listen(10)
# total number of stops

while True:
    # continue to prompt until correct stop number has been entered
    while True:
        conn, addr = s.accept()
        buffer = conn.recv(64)
        stopNumber = int(buffer)
        conn.close()

        if stopNumber > 0 and stopNumber < STOP_COUNT:
            break
        else:
            print "Invalid stop number, please try again..."

    # wait until cups have been placed
    detector.setup()

    # drive to stop
    driver.drive(stopNumber)

    # wait until cups have been picked up
    detector.dropoff()

    # return home
    driver.drive(STOP_COUNT - stopNumber)

    # message
    print "Arrived back home!!"
예제 #14
0
#a = os.path.join("India")
count = 0
for i in range(len(username)):
    count += 1
    #print(count)
    a = open(os.path.join(sys.argv[1],str(username[i]).replace(':','-').replace('?','-').replace('|','-').replace('/','-').replace("\\","-")+'.txt'),'w',encoding = 'utf-8')
    #if len(text[i]) > 1:
        #print(username[i])
    for j in range(0,len(text[i])):
        #text[i][j].replace('[',' ').replace(']',' ').replace('<')
        new_str = re.sub('[^a-zA-Z0-9\n\.]', ' ', text[i][j])
        text[i][j] = new_str
        lda_model=gensim.models.LdaModel.load('lda.model')
        id2word={}
        f = open("file.pkl","rb")
        id2word=pickle.load(f)
        pp=getTopicForQuery(new_str,lda_model,id2word)
        a.write(new_str)
        a.write('\n-------------------||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||---------------------------\n')
    #print(pp)
    mat[i]=pp
    a.close()
#print(users[2])


#for i in range(len(username)):
#    print(mat[i])


drive(mat)
def efficiencyPurityGraph(volume, wirePitches, angles, numberOfBlobs, alphas,
                          numberOfIterations):
    efficiency = array('f', len(alphas) * [0.])
    purity = array('f', len(alphas) * [0.])

    eventNo = 0
    for pointNo, alpha in enumerate(alphas):
        correctSum = 0
        fakeSum = 0

        for i in range(numberOfIterations):
            blobs, cells, channelList, geometryMatrix, recoWireMatrix, recoCellMatrix, trueCellMatrix = driver.drive(
                volume, wirePitches, angles, numberOfBlobs, alpha)

            if (eventNo % 1000 == 0) or (eventNo == 0):
                print("Processed ", eventNo, "/",
                      len(alphas) * numberOfIterations, " events")

            eventNo += 1

            recoCells = list(
                map(lambda x: not math.isclose(x, 0, rel_tol=1e-5),
                    recoCellMatrix))
            trueCells = list(
                map(lambda x: not math.isclose(x, 0, rel_tol=1e-5),
                    trueCellMatrix))

            correctID = sum(
                bool(x[0]) and bool(x[1]) for x in zip(trueCells, recoCells))
            fakeID = sum(not bool(x[0]) and bool(x[1])
                         for x in zip(trueCells, recoCells))

            correctSum += correctID / len(blobs)
            fakeSum += fakeID / len(blobs)

        efficiency[pointNo] = correctSum / numberOfIterations
        purity[pointNo] = 1 - fakeSum / numberOfIterations

    g = root.TGraph(len(alphas), efficiency, purity)

    return g
예제 #16
0
파일: main.py 프로젝트: wyh136/iotex-core
  --players=<players>             list of tuples e.g. "[(# of players, player type), ...]"; player type 0 = honest node, 1 = failure stop, 2 = fuzz test, 3 = byzantine fault [default: [(10, 0)]]
  --nconnections=<ncons>          number of connections per person in the network [default: 3]
  --timetosim=<timetosim>         virtual time in seconds to simulate the system for [default: 10]
  --meanproptime=<meanproptime>   mean propagation time of messages (latency) [default: 1]
  --stdproptime=<stdproptime>     std deviation of the propagation time of messages [default: 0.1]
  --seed=<seed>                   random seed [default: 42]
  -g                              generate graph animation
  --help                          show this
"""
import random

import grpc
from docopt     import docopt

import driver
import player
import solver

if __name__=="__main__":
    args = docopt(__doc__)
    opts = {"PLAYERS":              eval(args["--players"]),      
            "N_CONNECTIONS":         int(args["--nconnections"]),   
            "TIME_TO_SIM":           int(args["--timetosim"]),
            "MEAN_PROP_TIME":      float(args["--meanproptime"]),
            "STD_PROP_TIME":       float(args["--stdproptime"]),
            "SEED":                  int(args["--seed"]),
            "GRAPH":                 bool(args["-g"]),
           }

    driver.drive(opts)
예제 #17
0
def main():
    print("First Come First Served...")
    # calling drive function to read the input and turn it into a dictionary
    for v in drive():
        print("Running task = {} {} {} for {} units\n".format(
            v[0], v[1][0], v[1][1], v[1][1]))