Example #1
0
    def __init__(self,
                 door_config: DoorConfig,
                 room_type: RoomType = RoomType.STANDARD):
        self.north_door: Optional[Door] = Door(
            Direction.NORTH) if door_config.north else None
        self.south_door: Optional[Door] = Door(
            Direction.SOUTH) if door_config.south else None
        self.east_door: Optional[Door] = Door(
            Direction.EAST) if door_config.east else None
        self.west_door: Optional[Door] = Door(
            Direction.WEST) if door_config.west else None

        self.door_map = {
            Direction.NORTH: self.north_door,
            Direction.SOUTH: self.south_door,
            Direction.EAST: self.east_door,
            Direction.WEST: self.west_door
        }

        self.number_of_connections = sum(door_config.raw)

        self.treasure: Optional[Treasure] = None

        self.enemies: List[Enemy] = []

        self.type = room_type
        self.entity_type = EntityType.ROOM
        self.id = generate_random_id(self.entity_type)

        self.visited = False
Example #2
0
    def __init__(self, enemy_type: EnemyType):
        self.enemy_type = enemy_type

        self.entity_type = EntityType.ENEMY
        self.id = generate_random_id(self.entity_type)

        self.health = int(self.enemy_type)
Example #3
0
def add_sports_record(name: str, age: int, fav_sport: str) -> None:
    """Adds one sports record, based on certain parameters given"""
    conn = utils.get_sqlite_db_connection(db_name=config.DB_SPORTS)
    conn.execute(
        f"""
        INSERT INTO {config.TBL_SPORTS}(ID, Name, Age, FavouriteSport)
        VALUES (?, ?, ?, ?);
    """, (utils.generate_random_id(), name, age, fav_sport))
    conn.commit()
    conn.close()
    return None
def add_record(name, age, fav_sport):
    """Adds one record to the database (CSV file)"""
    df = utils.read_dataframe()
    df_record_to_add = pd.DataFrame(data={
        "ID": utils.generate_random_id(),
        "Name": name,
        "Age": age,
        "FavouriteSport": fav_sport
    }, index=[0])
    df_concatenated = pd.concat(objs=[df, df_record_to_add], ignore_index=True, sort=False)
    utils.save_dataframe(data=df_concatenated)
    return None
Example #5
0
def add_quote(quote):
    """Adds one quote to a collection in the MongoDB database"""
    collection = utils.get_collection_object(
        collection_name=config.MONGODB_COLLECTION_QUOTES)
    obj_to_add = {
        "_id": utils.generate_random_id(),
        "id": "",
        "quote": quote,
        "author": "",
        "source": "",
        "rating": np.nan,
        "addedBy": "",
    }
    collection.insert_one(obj_to_add)
    return None
def add_sensor_record(reading: float, sensor_type: str) -> None:
    """Adds one record to the sensor collection in the MongoDB database"""
    collection = db_utils.get_collection_object(
        collection_name=config.MONGODB_COLLECTION_SENSOR_DATA)
    ts = utils.get_current_timestamp()
    dt = utils.timestamp_to_datetime(timestamp_obj=ts)
    obj_to_add = {
        '_id': utils.generate_random_id(),
        'reading': reading,
        'timestamp': ts,
        'datetime': str(dt),
        'sensorType': sensor_type,
    }
    collection.insert_one(obj_to_add)
    return None
Example #7
0
def generate_fake_records(how_many):
    """Generates list of fake records"""
    records = []
    for _ in range(how_many):
        ts = generate_random_timestamp()
        dt = utils.timestamp_to_datetime(timestamp_obj=ts)
        record = {
            '_id': utils.generate_random_id(),
            'reading': generate_random_float(start=10, end=40),
            'timestamp': ts,
            'datetime': str(dt),
            'sensorType': 'temperature'
        }
        records.append(record)
    return records
Example #8
0
def promo3(request):
    """
    asignar codigo de descuento a una lista de usuarios
    """
    if request.POST:
        post_data = request.POST.copy()
        users = post_data.getlist('user', [])
        discount = post_data.get('discount', '10')
        for user in users:
            user_ = User.objects.get(username=user)
            code = generate_random_id()
            promo = Promo3.objects.create(user=user_,
                                          code=code,
                                          discount=discount)
            promo.save()
    return render_to_response('manager/promo3.html',
                              locals(),
                              context_instance=RequestContext(request))
def get_list_of_excel_posts():
    """
    Extracts posts from the given Excel spreadsheet.
    Returns list of dictionaries containing the posts to be added to a collection in the MongoDB database.
    NOTE: Adds an additional "_id" (will be unique field) key in each dictionary.
    """
    posts = []
    df = read_excel_data(filepath=config.EXCEL_DATASET_FILEPATH)
    for tuple_obj in df.itertuples():
        post = {
            "_id": utils.generate_random_id(),
            "id": tuple_obj.id,
            "quote": tuple_obj.quotes,
            "author": tuple_obj.author,
            "source": tuple_obj.source,
            "rating": tuple_obj.rating,
            "addedBy": tuple_obj.addedBy,
        }
        posts.append(post)
    return posts
Example #10
0
    def __init__(self, value: TreasureValue):
        self.value = value

        self.entity_type = EntityType.TREASURE
        self.id = generate_random_id(self.entity_type)
Example #11
0
    def discover(self, localhost_only=False):
        broadcast_msg = { 'operation': 'DISCOVER', 'join': True, 'sender': list(self.node), 'key': utils.generate_random_id() }
        broadcast_msg = utils.dumps_json(broadcast_msg)
        broadcast_msg = broadcast_msg.encode()
        sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)

        if localhost_only:
            for p in range(8000, 8011):
                if p != self.node.port:
                    sock.sendto(broadcast_msg, ('127.0.0.1', p))
        else:
            sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
            sock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
            sock.sendto(broadcast_msg, ('255.255.255.255', 8081))