예제 #1
0
파일: test.py 프로젝트: JTroshinsky/MH19
def main():
    testfarm = Farm((0, 0))
    senone = Sensor((44.790300, -92.931998))
    sentwo = Sensor((44.790300, -92.931998))
    senthree = Sensor((44.790300, -92.931998))

    testfarm.add_sensor(senone)
    testfarm.add_sensor(sentwo)
    testfarm.add_sensor(senthree)

    testfarm.pull_current()
    testfarm.pull_forecast()

    print(testfarm.future_forecast)

    #prints out some random weather data from sensors
    """
    i = 0
    while i < len(testfarm.sensors):
        print(testfarm.sensors[i].point)
        i += 1
    """

    returnlist = score.ranker(testfarm, testfarm.sensors[1])

    print(returnlist)
예제 #2
0
def main():
    testfarm = Farm((0, 0))
    senone = Sensor((44.790300, -92.931998))
    sentwo = Sensor((44.790300, -92.931998))
    senthree = Sensor((44.790300, -92.931998))

    testfarm.add_sensor(senone)
    testfarm.add_sensor(sentwo)
    testfarm.add_sensor(senthree)

    testfarm.pull_current()
    testfarm.pull_forecast()

    print("\n\n\nRandomized Example Sensor Data")
    print("------------------------------")

    i = 0
    while i < len(testfarm.sensors):
        print("sensor " + str(i + 1))
        print(testfarm.sensors[i].point)
        i += 1

    print("\n\n\nExample Aggregate Scores")
    print("------------------------")

    box = score.score(testfarm, senone.point, senone)

    list = []
    for datapoints in testfarm.future_forecast:
        box = score.aggregateScore(testfarm, datapoints, senone)
        list.append(box)

    print(list)
예제 #3
0
def main():
    macdonald = Farm("MacDonald's")
    macdonald.add_animal('cow', 5)
    macdonald.add_animal('sheep')
    macdonald.add_animal('sheep')
    macdonald.add_animal('goat', 12)

    macdonald.get_info()
예제 #4
0
def main():
    mcdonald = Farm("McDonald")
    mcdonald.add_animal('cows', 5)
    mcdonald.add_animal('sheep')
    mcdonald.add_animal('sheep')
    mcdonald.add_animal('goats', 12)

    print(mcdonald.get_info())
예제 #5
0
    def farm_cattle_init(self):
        #- Fill up with susceptible cattle:

        each_side_farm_index = range(int(self.num_farms) / int(2))

        for inum in each_side_farm_index:
            roadEastFarm = Farm(adjacent_road=self.roadeast, farm_index=inum)
            self.list_farms.append(roadEastFarm)

            for ilength in range(roadEastFarm.length):
                for iwidth in range(roadEastFarm.width):
                    if N.random.uniform() < self.INIT_CATTLE_PROBABILITY:
                        aCattle = Cattle(x_init=iwidth,
                                         y_init=ilength,
                                         dt=self.dt,
                                         env=roadEastFarm)
                        aCattle.weight += self._init_extra_weight
                        roadEastFarm.list_cattle.append(aCattle)
                        self.list_cattle.append(aCattle)

        each_side_farm_index.reverse()
        for inum in each_side_farm_index:
            roadWestFarm = Farm(adjacent_road=self.roadwest, farm_index=inum)
            self.list_farms.append(roadWestFarm)

            for ilength in range(roadWestFarm.length):
                for iwidth in range(roadWestFarm.width):
                    if N.random.uniform() < self.INIT_CATTLE_PROBABILITY:
                        aCattle = Cattle(x_init=iwidth,
                                         y_init=ilength,
                                         dt=self.dt,
                                         env=roadWestFarm)
                        aCattle.weight += self._init_extra_weight
                        roadWestFarm.list_cattle.append(aCattle)
                        self.list_cattle.append(aCattle)

        self.numSusceptible = len(self.list_cattle) - 1

        #- Make one cattle infected:

        self.list_cattle[20].state = "Infected"
        self.list_cattle[20].daysSick = 0
        self.numInfected += 1
        self.cumulativeInfected += 1
예제 #6
0
def main():
    from farm import Farm
    mcDonald = Farm("McDonald")
    mcDonald.add_animal("cow", 5)
    mcDonald.add_animal("sheep")
    mcDonald.add_animal("sheep")
    mcDonald.add_animal("goat", 12)

    mcDonald.get_info()
    print(mcDonald.get_animal_types())
    mcDonald.get_short_info()
예제 #7
0
파일: model.py 프로젝트: zmzhong/ab_cattle
    def farm_cattle_init(self):
        for inum in range(self.num_farms):
            aFarm = Farm()
            self.list_environ.append(aFarm)

            for ilength in range(aFarm.length):
                for iwidth in range(aFarm.width):
                    if N.random.uniform() < self.INIT_CATTLE_PROBABILITY:
                        aCattle = Cattle(x_init=iwidth,
                                         y_init=ilength,
                                         env=aFarm)
                        self.list_cattle.append(aCattle)
                        del aCattle
            del aFarm
예제 #8
0
    def __init__(self, farm_count=100, rng=None):
        self.activities = activity.Activities()
        if rng is None:
            rng = np.random.RandomState()
        self.rng = rng

        self.time = 0

        self.farms = []
        for i in range(farm_count):
            farm = Farm(eutopia=self, area=100)
            self.farms.append(farm)

        self.families = []
        for farm in self.farms:
            family = Family(self)
            family.add_farm(farm)
            self.families.append(family)

        self.govt_cost = 0
예제 #9
0
파일: main.py 프로젝트: JoelNielsen7/MH19
def main():
    lat = float(sys.argv[1])
    lon = float(sys.argv[2])

    testfarm = Farm((lat, lon))
    senone = Sensor((44.790300, -92.931998))
    sentwo = Sensor((44.790300, -92.931998))
    senthree = Sensor((44.790300, -92.931998))

    senone.add_water((44.790302, -92.931994))
    sentwo.add_water((44.790302, -92.931994))
    senthree.add_water((44.790302, -92.931994))

    testfarm.add_sensor(senone)
    testfarm.add_sensor(sentwo)
    testfarm.add_sensor(senthree)

    testfarm.pull_current()
    testfarm.pull_forecast()

    box = score.score(testfarm, senone.point, senone)

    print(score)
    print(score.responsetext(box))
예제 #10
0
                        if "message" in result:  #объект сообщения
                            message = result["message"]

                            if "text" in message:  #достаём данные
                                text = message["text"]

                            if "chat" in message:
                                chat = message["chat"]
                                if "id" in chat:
                                    chat_id = chat["id"]
                                if "first_name" in chat:
                                    chat_user_name = chat["first_name"]

                        m = 1
                        for i in range(m):
                            farm = Farm()
                            bird = check_name(text)
                            print(bird)
                            message_super = farm.get_eggs(bird)
                            print(
                                f"Сообщение от {chat_user_name}: \"{text}\", чат ID: {chat_id}"
                            )
                            start_message_id = start_message_id + 1
                            post_message_as_json = TelegramBot.post_message(
                                chat_id,
                                f"Ответочка {i+1} № {start_message_id}")

                            if post_message_as_json != "error":
                                if "ok" in post_message_as_json:
                                    if post_message_as_json["ok"]:
                                        print(
예제 #11
0
from animals import Animal
from farm import Farm

gekko = Animal()
python = Animal()
dog = Animal()
cat = Animal()
frog = Animal()

frog.play()
frog.play()
frog.play()
frog.play()

new_farm = Farm()

new_farm.add(gekko)
new_farm.add(python)
new_farm.add(cat)
new_farm.add(frog)
new_farm.add(dog)
new_farm.breed()

new_farm.slaughter()
예제 #12
0
    def __init__(self, farmyard):
        Animal.__init__(self, farmyard)
        self.metabolism = 1

    def ascii_rep(self):
        return 'P'


#
# Tests
#

def start_animal(animal):
    """ Returns a (running) animal thread handle """
    def start_it(a):
        a.run()
    t = Thread(target=start_it, args=(animal,))
    t.start()
    return t


if __name__ == "__main__":
    printer.start()
    f = Farm(8)
    s = Sheep(f)
    s_t = start_animal(s)
    printer.draw_farm(f.as_rows())
    s_t.join()
    printer.stop()
    printer.join()
예제 #13
0
from farm import Farm

macdonald = Farm("McDonald")
macdonald.add_animal('cow', 5)
macdonald.add_animal('sheep')
macdonald.add_animal('sheep')
macdonald.add_animal('goat', 12)

print(macdonald.get_info())
예제 #14
0
파일: app.py 프로젝트: Sceluswe/oopython
#!/usr/bin/env python3
"""
My first Flask app
"""
# Importera relevanta moduler
from flask import Flask, render_template
from flask import request
import person
import data
from farm import Farm

# Create a database connection to our farm and a session.
my_farm = Farm("db/farm.sqlite")

links = list()
links.append(("/", "main", "Me-sida"))
links.append(("/about/", "about", "Om mig"))
links.append(("/redovisning/", "redovisning", "Redovisning"))
links.append(("/farm/animals", "farmAnimals", "Farm"))

my_person = person.Person("Emil", "Mattsson", 24, "Katrineholm")

app = Flask(__name__)


@app.route("/")
def main():
    """ Main route """
    my_data = data.Data(
        links, links[0][2],
        "https://avatars1.githubusercontent.com/u/12786962?v=3&s=200")
예제 #15
0
        return 2


if __name__ == "__main__":

    # dynamics
    from dynamics import Dynamics
    sys = Dynamics(thrust=10, area=1)

    # controller
    #from controller import PID
    #con = PID(1, 1, 1)

    # origin & waypoints
    from farm import Farm
    env = Farm(5, 10, 10, 20, 5, 40, 50)
    wps = env.simple_coverage()
    org = np.array([env.dsx, env.dsy])

    # mission
    mis = Mission(org, wps, sys)

    mis.simulate(50000)
    print(mis.beta)

    # plotstate
    import matplotlib.pyplot as plt, seaborn as sb, pandas as pd

    fig, ax = plt.subplots(sys.sdim)
    for i in range(sys.sdim):
        ax[i].plot(mis.times[1:], mis.states[1:, i], "k.-")
예제 #16
0
파일: run.py 프로젝트: fuding/Poseidon
__author__ = 'rowley'

from cli import Interface
from farm import Farm
from monitor import Monitor

print_farm = Farm()
farm_monitor = Monitor()

if __name__ == '__main__':
    interface = Interface()
    interface.set_farm(print_farm)
    interface.cmdloop()
    print 'Bye!'
예제 #17
0
import time
from farm import Farm
from sorting import selection_sort_by_power_desc
from sorting import quick_sort_by_animals_count_asc
from csv import DictReader


farms = []
with open('farms_small.csv') as f:
    reader = DictReader(f)
    for row in reader:
        farms.append(Farm(row['location'], row['animals_count'], row['power']))

print('***************** Selection sort **********************')
selection_start = time.time()
number_of_comparisons, number_of_swaps = selection_sort_by_power_desc(farms)
selection_end = time.time()

print('Number of comparisons:', number_of_comparisons)
print('Number of swaps:', number_of_swaps)
print('Time:', selection_end - selection_start)
print('Farms sorted by power, descending:')
for farm in farms:
    print(farm)


print()
print('**************** Quick sort ***********************')
quick_sort_start = time.time()
number_of_comparisons, number_of_swaps = quick_sort_by_animals_count_asc(farms, 0, len(farms) - 1)
quick_sort_end = time.time()
예제 #18
0
파일: task.py 프로젝트: toTheMoon247/lug
from logger import Logger


# do not change
HOST = 'ec2-35-177-59-107.eu-west-2.compute.amazonaws.com'
PORT = 16237
USER = '******'
PASSWD = 'jNyFi9UeVNglDfxyLJQR'

time.sleep(5)
#############################################################################

# create a communicator
c = Communicator('mock')
# create 'Easy' level farm
farm = Farm(2, 2)
# create a FarmController instance
fc = FarmController(farm, c)

#############################################################################
# if you dont see a "connection successfull" message. email chelsee imediatly
# becuase this should definatly work
def on_connect(client, userdata, flags, rc):
    print("Connection Succesfull")


def message_recieved(client, userdata, message):
    value = message.payload.decode()
    fc.process(message.topic, value)

    # print(f'messsage: {message.topic} {value}')
예제 #19
0
파일: 08.py 프로젝트: nemethricsi/python2
from farm import Farm
from allat import Allat

allatFarm = Farm(5)

tigris = Allat()
malac = Allat()
allatFarm.add(tigris)
allatFarm.add(malac)
allatFarm.breed()  # uj random allat
print(allatFarm.allatok)

print(tigris.lekerEhseg())
print(malac.lekerEhseg())

malac.eszik()
print(malac.lekerEhseg())

allatFarm.slaughter()

print(allatFarm.allatok)
예제 #20
0
from farm.Farm import *

aws_bucket = "ethereum-datahub"  # Your AWS bucket

# Run
if __name__ == "__main__":

    # Load contracts
    contracts = load_contracts(aws_bucket=aws_bucket,
                               config_location="contracts")

    # Initialize Farm and get status
    farm = Farm(contracts=contracts, aws_bucket=aws_bucket,
                useBigQuery=True).status()
    farm.start_farming()
예제 #21
0
    def __init__(self, *args, **kwargs):
        super(ApartmentBlock, self).__init__(width=ApartmentBlock.WIDTH,
                                             *args,
                                             **kwargs)

        builds = []
        #######################################################################
        # build entire apt block from spans:
        # "concrete" structure (smooth stone)
        builds.append(
            BuildingBlock(ApartmentBlock.APT_BLOCK_SPAN[0],
                          block.STONE,
                          ApartmentBlock.APT_BLOCK_SPAN[1],
                          description="Apt block stone super structure"))

        # 17 apt wall sections per floor can be done using 5 wood spans & 6 interior spaces
        # build wood plank spans
        for key, span in ApartmentBlock.WOOD_PLANK_SPANS.items():
            for pos in ApartmentBlock.WOOD_PLANK_POS[key]:
                # ground floor
                builds.append(
                    BuildingBlock(span[0] + pos,
                                  block.WOOD_PLANKS,
                                  span[1] + pos,
                                  description="%s wood span ground floor" %
                                  (key)))

                # 2nd floor
                builds.append(
                    BuildingBlock(span[0] + pos + Vec3(0, 4, 0),
                                  block.WOOD_PLANKS,
                                  span[1] + pos + Vec3(0, 4, 0),
                                  description="%s wood span 2nd floor" %
                                  (key)))
        # clear apt interiors (this will leave concrete floors & ceilings)
        for pos in ApartmentBlock.APT_INTERIOR_POS:
            # ground floor
            builds.append(
                BuildingBlock(ApartmentBlock.APT_INTERIOR_SPAN[0] + pos,
                              block.AIR,
                              ApartmentBlock.APT_INTERIOR_SPAN[1] + pos,
                              description="Clear apt interior ground floor"))

            # 2nd floor
            builds.append(
                BuildingBlock(
                    ApartmentBlock.APT_INTERIOR_SPAN[0] + pos + Vec3(0, 4, 0),
                    block.AIR,
                    ApartmentBlock.APT_INTERIOR_SPAN[1] + pos + Vec3(0, 4, 0),
                    description="Clear apt interior 2nd floor"))

        # add torch to SW croner of block to indicte when this section has completed buiding in game
        #builds.append(Torch(Vec3(-11,3,-3), block.TORCH.withData(Torch.WEST),
        #					description="section complete indicator"))

        self._add_section("Apt block super structure", builds)

        # doors & torches
        # TODO: debug this: East side apartments have doors "facing" east (built on east side of block)
        #					East side apts torches should face west, but applied on east face of containing block (west face of support block)
        # TODO: add doc strings to doors and torches on what the orientation means
        for pos in ApartmentBlock.APT_DOORS_POS["East"]:
            # ground floor
            builds.append(
                Door(Door.HINGE_RIGHT,
                     pos,
                     block.DOOR_WOOD.withData(Door.EAST),
                     description="Ground floor door east side"))
            builds.append(
                Torch(pos + Vec3(-1, 2, 0),
                      block.TORCH.withData(Torch.WEST),
                      description="Ground floor interior torch"))
            builds.append(
                Torch(pos + Vec3(1, 2, 0),
                      block.TORCH.withData(Torch.EAST),
                      description="Ground floor exterior torch"))
            # 2nd floor
            builds.append(
                Door(Door.HINGE_RIGHT,
                     pos + Vec3(0, 4, 0),
                     block.DOOR_WOOD.withData(Door.EAST),
                     description="2nd floor door east side"))
            builds.append(
                Torch(pos + Vec3(-1, 6, 0),
                      block.TORCH.withData(Torch.WEST),
                      description="2nd floor interior torch"))
            builds.append(
                Torch(pos + Vec3(1, 6, 0),
                      block.TORCH.withData(Torch.EAST),
                      description="2nd floor exterior torch"))

        for pos in ApartmentBlock.APT_DOORS_POS["West"]:
            # ground floor
            builds.append(
                Door(Door.HINGE_LEFT,
                     pos,
                     block.DOOR_WOOD.withData(Door.WEST),
                     description="Ground floor door west side"))
            builds.append(
                Torch(pos + Vec3(1, 2, 0),
                      block.TORCH.withData(Torch.EAST),
                      description="Ground floor interior torch"))
            builds.append(
                Torch(pos + Vec3(-1, 2, 0),
                      block.TORCH.withData(Torch.WEST),
                      description="Ground floor exterior torch"))
            # 2nd floor
            builds.append(
                Door(Door.HINGE_LEFT,
                     pos + Vec3(0, 4, 0),
                     block.DOOR_WOOD.withData(Door.WEST),
                     description="2nd floor door west side"))
            builds.append(
                Torch(pos + Vec3(1, 6, 0),
                      block.TORCH.withData(Torch.EAST),
                      description="2nd floor interior torch"))
            builds.append(
                Torch(pos + Vec3(-1, 6, 0),
                      block.TORCH.withData(Torch.WEST),
                      description="2nd floor exterior torch"))

        # windows
        for pos in ApartmentBlock.APT_WINS_POS:
            builds.append(
                BuildingBlock(pos,
                              block.GLASS_PANE,
                              description="ground floor window"))
            builds.append(
                BuildingBlock(pos + Vec3(0, 4, 0),
                              block.GLASS_PANE,
                              description="2nd floor window"))

        # add torch to SW croner of block to indicte when this section has completed buiding in game
        #builds.append(Torch(Vec3(-11,2,-3), block.TORCH.withData(Torch.WEST),
        #					description="section complete indicator"))

        self._add_section("Apt block fittings", builds)

        #######################################################################
        # Ground floor walkway & steps
        # stone walk way
        builds.extend(self._add_walkway(block.STONE, 0))
        # stone steps at end of each walkway
        # TODO: block data for stone brick stairs
        builds.append(
            Stair(ApartmentBlock.CORNER_POS['South East'] + Vec3(0, 0, 1),
                  Block(109).withData(Stair.NORTH),
                  ApartmentBlock.CORNER_POS['South East'] + Vec3(-1, 0, 1),
                  description="Ground floor steps"))
        builds.append(
            Stair(ApartmentBlock.CORNER_POS['South West'] + Vec3(1, 0, 1),
                  Block(109).withData(Stair.NORTH),
                  ApartmentBlock.CORNER_POS['South West'] + Vec3(0, 0, 1),
                  description="Ground floor steps"))

        self._add_section("Ground floor walkway", builds)

        #######################################################################
        # Support posts for 2nd floor walkway
        for pos in ApartmentBlock.CORNER_POS.values():
            builds.append(
                BuildingBlock(pos + Vec3(0, 1, 0),
                              block.FENCE,
                              pos + Vec3(0, 3, 0),
                              description="Corner post"))

        self._add_section("2nd floor support posts", builds)

        #######################################################################
        # 2nd floor walkway
        # wooden walk way around 2nd floor
        builds.extend(self._add_walkway(block.WOOD_PLANKS, 4))
        self._add_section("2nd floor wooden walkway", builds)

        #######################################################################
        # Stairs to 2nd floor
        for i in range(0, 5):
            # wooden steps to 2nd floor.
            builds.append(
                Stair(ApartmentBlock.CORNER_POS['South East'] +
                      Vec3(-8 + i, i, 1),
                      block.STAIRS_WOOD.withData(Stair.EAST),
                      description="Steps to upper floor"))
            # TODO: figure out block data for upside down stairs and use this instead of support block
            builds.append(
                BuildingBlock(ApartmentBlock.CORNER_POS['South East'] +
                              Vec3(-7 + i, i, 1),
                              block.WOOD_PLANKS,
                              description="stair support"))

        self._add_section("Stairs to 2nd floor", builds)

        #######################################################################
        if DO_2ND_FLOOR_RAILINGS:
            # 2nd floor walkway railings (should extend these out by 1 block all around so walkway is 2 blocks wide)
            # west side railings
            builds.append(
                BuildingBlock(
                    ApartmentBlock.CORNER_POS['North West'] + Vec3(0, 5, 0),
                    block.FENCE,
                    ApartmentBlock.CORNER_POS['South West'] + Vec3(0, 5, 0),
                    description="Balcony railings"))
            # close off west side railings on north end
            builds.append(
                BuildingBlock(ApartmentBlock.CORNER_POS['North West'] +
                              Vec3(1, 5, 0),
                              block.FENCE,
                              description="Balcony railings"))
            # east side railings
            builds.append(
                BuildingBlock(
                    ApartmentBlock.CORNER_POS['North East'] + Vec3(0, 5, 0),
                    block.FENCE,
                    ApartmentBlock.CORNER_POS['South East'] + Vec3(0, 5, 0),
                    description="Balcony railings"))
            # close off east side railings on north end
            builds.append(
                BuildingBlock(ApartmentBlock.CORNER_POS['North East'] +
                              Vec3(-1, 5, 0),
                              block.FENCE,
                              description="Balcony railings"))

            # south balcony railings
            builds.append(
                BuildingBlock(
                    ApartmentBlock.CORNER_POS['South East'] + Vec3(0, 5, 0),
                    block.FENCE,
                    ApartmentBlock.CORNER_POS['South East'] + Vec3(-5, 5, 0),
                    description="Balcony railings"))
            builds.append(
                BuildingBlock(
                    ApartmentBlock.CORNER_POS['South West'] + Vec3(0, 5, 0),
                    block.FENCE,
                    ApartmentBlock.CORNER_POS['South West'] + Vec3(6, 5, 0),
                    description="Balcony railings"))

            self._add_section("2nd floor railings", builds)

        #######################################################################
        # Add the streets between as subbuildings
        street_ew = Street(9, Building.WEST)
        street_ns = Street(8, Building.NORTH)

        builds.append(
            SubBuilding(street_ew, Building.SE_CORNER_POS + Vec3(0, 0, 1)))
        builds.append(
            SubBuilding(street_ew, Building.SE_CORNER_POS + Vec3(0, 0, -24)))
        builds.append(
            SubBuilding(street_ns, Building.SE_CORNER_POS + Vec3(-13, 0, 0)))

        self._add_section("Streets", builds)

        #######################################################################
        # Add the farm subbuildings
        farms = [Farm(Building.WEST), LargeFarm(Building.NORTH)]

        for pos in ApartmentBlock.WEST_FARMS_POS:
            builds.append(SubBuilding(farms[0], pos))

        self._add_section("West Farms", builds)

        for pos in ApartmentBlock.NORTH_FARMS_POS:
            builds.append(SubBuilding(farms[1], pos))

        self._add_section("North Double Farms", builds)

        #######################################################################
        self._set_orientation()
예제 #22
0
def read_map(filename):
    file = open("config_files/" + filename)
    map_width, map_height = [int(i) for i in file.readline().split()[:2]]
    field_array = [[0 for x in range(map_width)] for y in range(map_height)]
    for y in range(map_height):
        row = file.readline().split()[:map_width]
        row = [int(i) for i in row]
        field_array[y] = row
    print(field_array)
    return field_array, map_width, map_height


if __name__ == '__main__':
    # field, width, height = read_map("map")
    # farm = Farm(width, height, field=field)
    farm = Farm(20, 20, 10)
    farm.print_field()
    monk = Monk(farm)
    generation = Generation(farm)
    print(generation.average_fitness)
    best_gen = generation
    next_gen = generation

    avg_function = []
    best_function = []
    index = 0
    f = open("animation/fitness.txt", "w")
    f.write("")
    f.close()
    f = open("animation/avg_fitness.txt", "w")
    f.write("")