예제 #1
0
def main(data):
    pool_outputs = []
    (rest_name, user_id) = util.parse_url_data(data)

    # return spaces
    rest_name.replace("%20", " ")
    rest_name = rest_name.lower()
    globals = Globals.Globals(user_id)
    Dishes = globals.getDb().GetAllDishesFromRestaurant(rest_name)
    if Dishes == []:
        return []

    ingredientsGroups = globals.getIngredientsGroups()
    userPreferences = (PreProcessUserPreferences(globals.getUserPreferences(),
                                                 ingredientsGroups))
    previouslyLiked = globals.getDb().GetUserPreviouslyLiked(user_id)
    previouslyDisliked = globals.getDb().GetUserPreviouslyDisliked(user_id)

    # init worker
    worker = CalcBestMatchDishes(ingredientsGroups, userPreferences,
                                 previouslyLiked, previouslyDisliked)
    for dish in Dishes:
        pool_outputs.append(worker.calculate(dish))
    top5 = sorted(pool_outputs,
                  key=lambda x: list(x.values())[0],
                  reverse=True)[:5]
    return top5
예제 #2
0
    time.sleep(2)
    print("Just kidding, I'm built to serve!\n\n")
elif (intro == 2):
    print("Welcome dino! How can I help?\n\n")
elif (intro == 3):
    print(
        "I'm programmed to obey the three laws of robotics. I always forget what they are though.\n\n"
    )
elif (intro == 4):
    print(
        "Guess you're not as clever as you thought if you need me to do all this maths.\n\n"
    )
else:
    print("Well... that didn't work as well as I thought.\n\n")

Globals.Globals()

with open("comments_replied_to.txt", "r") as f:
    comments_replied_to = f.read()
    comments_replied_to = comments_replied_to.split("\n")
    comments_replied_to = list(filter(None, comments_replied_to))
subreddit = reddit.subreddit('CenturyofBlood')
for comment in subreddit.stream.comments(skip_existing=False):
    comment.refresh()
    if (re.search('/u/maesterbot', comment.body, re.IGNORECASE)
            and comment.id not in comments_replied_to
        ):  #Make sure we're tagged in order to run. Non caps-sensitive.
        comments_replied_to.append(comment.id)

        if (re.search("Naval Battle", comment.body, re.IGNORECASE)):
            Globals.battleType = "Naval"
예제 #3
0
import os
import Globals as g
import Main as m
import GenBXDMain as gm
import DosMain  as dm


path = os.getcwd()
gl = g.Globals(path)
if gl.RunType == "MechGen":
    m.run(gl)
elif gl.RunType == "GenBXD":
    gm.run(gl)
elif gl.RunType == "DOS":
    dm.run(gl)
def main():
    myWorld = World()
    status = Globals()

    verbose = False
    runTime = 0
    worldName = "X"
    totalTime = 0.0
    compressConcave = 0
    perimeter = 0
    physicsMoveTowardsDestination = 0
    physicsFlyTowardsCentre = 0
    physicsMoveAway = 0
    physicsAvoidObstacle = 0
    physicsMoveTowardsDestination = 0
    physicsCompressConcave = 0
    frameRate = 0
    neighbourDistance = 0
    minDistance = 0
    maxSpeed = 0

    status.total_iterations = 0
    status.compressConcave = False
    status.startTime = 0
    status.energyRecording = True
    status.processing = True
    status.finiteMachine = True

    try:
        opts, args = getopt.getopt(sys.argv[1:],
                                   "vhw:c:p:t:s:m:n:C:R:o:O:D:V:S:", ["help"])
    except getopt.GetoptError as err:
        # print help information and exit:
        print(err)  # will print something like "option -a not recognized"
        usage()
        sys.exit(2)

    for o, a in opts:
        if o == "-v":
            verbose = True
        elif o in ("-h", "--help"):
            usage()
            sys.exit(0)
        elif o in ("-w"):
            worldName = a

    print("VERSION: %s" % status.version)

    if not myWorld.loadWorld(worldName):
        print("+-----------------------+")
        print("| Error World Not Found!|")
        print("+-----------------------+\n")
        usage()
        exit(0)
    print("+-----------------------+")
    print("|     Loaded World      |")
    print("+-----------------------+")
    print("%s Loaded!" % (worldName))
    print("%s Bots" % myWorld.getSwarmSize())
    print("%s Destinations" % myWorld.getDestinationSize())
    print("%s Obstacles" % myWorld.getObstacleSize())

    compressConcave = status.compressConcave
    perimeter = status.perimeter
    physicsMoveTowardsDestination = status.physicsMoveTowardsDestination
    physicsFlyTowardsCentre = status.physicsFlyTowardsCentre
    physicsMoveAway = status.physicsMoveAway
    physicsAvoidObstacle = status.physicsAvoidObstacle
    physicsMoveTowardsDestination = status.physicsMoveTowardsDestination
    physicsCompressConcave = status.physicsCompressConcave
    frameRate = status.frameRate
    maxSpeed = status.maxSpeed
    neighbourDistance = status.neighbourDistance
    minDistance = status.minDistance

    for o, a in opts:
        if o in ("-c"):
            compressConcave = int(a)
        elif o in ("-p"):
            perimeter = int(a)
        elif o in ("-s"):
            frameRate = int(a)  # sample rate
        elif o in ("-t"):
            runTime = int(a)
        elif o in ("-n"):
            neighbourDistance = int(a)
        elif o in ("-o"):
            obstacleRepulsion = int(a)
        elif o in ("-m"):
            minDistance = int(a)
        elif o in ("-D"):
            physicsMoveTowardsDestination = int(a)
        elif o in ("-C"):
            physicsFlyTowardsCentre = int(a)
        elif o in ("-R"):
            physicsMoveAway = int(a)
        elif o in ("-O"):
            physicsAvoidObstacle = int(a)
        elif o in ("-V"):
            physicsCompressConcave = int(a)
        elif o in ("-S"):
            maxSpeed = int(a)

    status.compressConcave = compressConcave

    status.perimeter = perimeter
    status.physicsMoveTowardsDestination = physicsMoveTowardsDestination
    status.physicsFlyTowardsCentre = physicsFlyTowardsCentre
    status.physicsMoveAway = physicsMoveAway
    status.physicsCompressConcave = physicsCompressConcave
    status.physicsAvoidObstacle = physicsAvoidObstacle
    status.obstacleRepulsion = obstacleRepulsion
    status.frameRate = frameRate
    status.maxSpeed = maxSpeed
    status.neighbourDistance = neighbourDistance
    status.minDistance = minDistance
    status.minDistance = minDistance

    status.time_passed_seconds = status.frameRate / 100

    myWorld.swarmObstacleRepel(status.obstacleRepulsion)
    myWorld.swarmSpeed(status.maxSpeed)
    myWorld.swarmNeighbourDistance(status.neighbourDistance)
    myWorld.swarmMinDistance(status.minDistance)

    print("+-----------------------+")
    print("| Simulation Parameters |")
    print("+-----------------------+")
    print("Compress - %s" % (status.compressConcave))
    print("GPS - %s" % (status.perimeterName[status.perimeter]))
    print("Sample Rate - %ss" % (status.time_passed_seconds))
    print("Min Distance - %s Units" % (status.minDistance))
    print("Neighbour Range - %s Units" % (status.neighbourDistance))
    print("Obstacle Range - %s Units" % (status.obstacleRepulsion))
    print("================================")
    print("Destination Physics - %s" % (status.physicsMoveTowardsDestination))
    print("Cohesion Physics - %s" % (status.physicsFlyTowardsCentre))
    print("Repulsion Physics - %s" % (status.physicsMoveAway))
    print("Obstacle Physics - %s" % (status.physicsAvoidObstacle))
    print("Compression Physics - %s" % (status.physicsCompressConcave))
    print("================================")

    if runTime:
        print("Duration - %ss" % (runTime))
        print("================================")

    logDate = datetime.datetime.today().strftime("%Y%m%d-%H%M%S")
    status.logCount = 0
    status.log.start(logDate, "Swarm.sql")

    while status.processing == True:
        totalTime += status.time_passed_seconds
        #        status.frame = status.getFrame()
        print(".", end="")
        sys.stdout.flush()
        myWorld.process()
        if runTime > 0:
            if (totalTime > runTime):
                status.processing = False

    logDate = datetime.datetime.today().strftime("%Y%m%d-%H%M%S")
    status.log.finish(logDate)
    print()
    print("======= COMPLETE =======")
예제 #5
0
파일: Writer.py 프로젝트: chernals/bdsim
import numpy as _np
from scipy import constants as _con
import os as _os
import glob as _glob
from pybdsim import Beam as _Beam
from pybdsim import Writer as _Writer
from pybdsim import Builder as _Builder
import pybdsimTest
import Globals

multiEntryTypes = [tuple, list, _np.ndarray]

GlobalData = Globals.Globals()


class Writer:
    def __init__(self):
        self._beamFilename = ''
        self._optionsFilename = ''
        self._numFilesWritten = 0
        self._fileNamesWritten = {}

    def calcBField(self, length, angle, energy, particle):
        # Calculate the magnetic field for a dipole
        if angle == 0:
            return 0
        else:
            energies = self.calcEnergy(energy, particle)
            rho = length / angle
            b = energies['brho'] / rho
            return b
#!/usr/bin/env python3
from World import *
from Swarm import *
from Obstacle import *
from Destination import *
from BoidSwarm import *
from WsnSwarm import *
from Globals import *
import sys

status = Globals()
myWorld = World(status.X, status.Y, "crash.jpg")
myWorld.start()

destination = Destination(myWorld.screen.get_size()[0] / 2,
                          myWorld.screen.get_size()[1] / 2, True)

myWorld.pushDestination(destination)

status.running = False
status.total_iterations = 0

myWorld.intro()

while True:

    status.time_passed = myWorld.clock.tick(status.frameRate)
    status.time_passed_seconds = status.time_passed / status.systemSpeed
    status.frame = status.getFrame()

    for event in pygame.event.get():
        if not os.path.exists(settings_folder):
            try:
                os.makedirs(settings_folder)
            except OSError:
                raise
        settings_dict = Common.CommonResources.get_setting_dictionary(
            global_params)
        Common.CommonResources.write_to_file(settings_file, settings_dict)
    else:
        with open(settings_file) as data_file:
            data = json.load(data_file)
        try:
            Common.CommonResources.set_global_settings(data, global_params)
        except KeyError:
            print("Corrupt setting file")
        except:
            raise


if __name__ == '__main__':
    w = WorkTimeCounter()
    global_params = Globals.Globals()
    check_settings()
    LogonTime = Common.CommonResources.get_login_time(global_params)
    timer_thread = MainThread(1)
    timer_thread.start()
    timer_thread3 = MainThread(3)
    timer_thread3.start()
    win32gui.PumpMessages()
os._exit(1)