Exemple #1
0
def update_item(item_id):
    """ Updates a furniture item using the given item_id, from the furniture store """
    item_id = int(item_id)
    data = request.json
    response_dict = {'status': 200}

    item = my_store.get(item_id)

    if item:
        #  Create a new item with all the updated properties
        #  and assign the same ID to it as the item being
        #  replaced.

        item_type = data.pop('type', None)
        updated_item = None

        if item_type == Bed.FURNITURE_TYPE:
            updated_item = Bed(**data)
        elif item_type == Sofa.FURNITURE_TYPE:
            data["number_of_seats"] = int(data["number_of_seats"])
            data["number_of_cushions"] = int(data["number_of_cushions"])
            updated_item = Sofa(**data)

        updated_item.id = item_id
        my_store.update(updated_item)

        response_dict["response"] = ("Item of ID " + str(item_id) +
                                     " successfully updated.")

    else:
        response_dict['status'] = 404
        response_dict[
            "response"] = "No item was found corresponding to the given item_id"

    return app.response_class(**response_dict)
Exemple #2
0
    def __init__(self,
                 bam,
                 bed,
                 info,
                 out,
                 analytical_threshold=ANALYTICAL_THRESHOLD):

        self.bam = bam
        self.bed = bed
        self.info = info
        self.out = out
        self.analytical_threshold = analytical_threshold

        # Init
        self.bed_obj = Bed(self.bed)
        self.info_obj = Info(self.info)
        self.mh_dict = {}
        self.filters_obj = Filters(
            analytical_threshold=self.analytical_threshold,
            abs_analytical_threshold=self.ABSOLUTE_ANALYTICAL_THRESHOLD,
            min_mapq=self.MIN_MAPPING_QUALITY,
            max_mapq=self.MAX_MAPPING_QUALITY,
            remove_deletions=self.REMOVE_DELETIONS)
        self.short_reads_count = 0
        self.total_reads_count = 0
        self.number_of_contributors_overall = 0
 def test_get_item_description(self):
     """ 050A - Valid Item Description """
     test_bed = Bed("001", "2019", "BrandX", 99.99, 139.99, "180cm x 120cm", "50cm")
     self.assertEqual(
         test_bed.get_item_description(),
         "bed with serial number 001 manufactured by BrandX with 180cm x 120cm dimensions and 50cm height is available for $139.99",
         "Output must match 'bed with serial number 001 manufactured by BrandX with 180cm x 120cm dimensions and 50cm height is available for $139.99'",
     )
    def setUp(self):
        """
        setUp method for testing methods of the FurnitureManager class
        """
        engine = create_engine("sqlite:///test_furniture.sqlite")

        # Creates all the tables
        Base.metadata.create_all(engine)
        Base.metadata.bind = engine

        self.manager = FurnitureManager("test_furniture.sqlite")
        self.beds = {
            "Bed1": ["001", "2019", "Ikea", 24.99, 44.99, "190x100cm", "25cm"],
            "Bed2": [
                "002",
                "2015",
                "HelloFurniture",
                124.99,
                144.99,
                "190x100cm",
                "25cm",
            ],
        }

        self.sofas = {
            "Sofa1": ["003", "2012", "HelloFurniture", 99.99, 119.99, 4, 6]
        }
        self.Bed1 = Bed(
            self.beds["Bed1"][0],
            self.beds["Bed1"][1],
            self.beds["Bed1"][2],
            self.beds["Bed1"][3],
            self.beds["Bed1"][4],
            self.beds["Bed1"][5],
            self.beds["Bed1"][6],
        )
        self.Bed2 = Bed(
            self.beds["Bed2"][0],
            self.beds["Bed2"][1],
            self.beds["Bed2"][2],
            self.beds["Bed2"][3],
            self.beds["Bed2"][4],
            self.beds["Bed2"][5],
            self.beds["Bed2"][6],
        )
        self.Sofa1 = Sofa(
            self.sofas["Sofa1"][0],
            self.sofas["Sofa1"][1],
            self.sofas["Sofa1"][2],
            self.sofas["Sofa1"][3],
            self.sofas["Sofa1"][4],
            self.sofas["Sofa1"][5],
            self.sofas["Sofa1"][6],
        )
def process_message(msg, val):
    if 'bed' in msg:
        # test if bed already exists
        # print(f'{msg} {val}')
        bed_location = get_bed_location(msg)
        # if flipped (as sometimes happens in medium)
        if (bed_location[0].isdigit()):
            bed_location = f"{bed_location[1]}{bed_location[0]}"

        if (bed_location not in bed_dict.keys()):
            bed_dict[bed_location] = Bed(bed_location[0], bed_location[1])

        if 'water_level' in msg:
            # print('wl')
            bed_dict[bed_location].water_level = int(val)

        elif 'target_min' in msg:
            # print('tm')
            bed_dict[bed_location].target_min = int(val)

        elif 'target_max' in msg:
            # print('tm')
            bed_dict[bed_location].target_max = int(val)

        elif 'target' in msg:
            # print('tg')
            bed_dict[bed_location].target = val

        elif 'capacity' in msg:
            # print('cy')
            bed_dict[bed_location].capacity = int(val)

        elif 'valve' in msg:
            # print('vl')
            bed_dict[bed_location].valve_status = val
        else:
            pass

    elif 'harry/meta' in msg:
        if 'score-%' in msg:
            global score_perc
            score_perc = int(val)

        elif 'score-max' in msg:
            # pass here otherwise the below test for score will also
            # return this msg.
            global score_max
            score_max = int(val)

        elif 'score' in msg:
            global score
            score = int(val)

    elif 'harry/tank/water_level' in msg:
        global tank_level
        tank_level = int(val)
 def test_to_dict_valid(self):
     """ 060 A - Valid to_dict test"""
     test_bed = Bed("001", "2019", "BrandX", 99.99, 139.99, "180cm x 120cm", "50cm")
     self.assertEqual(
         test_bed.to_dict(),
         {
             "id": None,
             "type": "bed",
             "item_serial_num": "001",
             "item_brand": "BrandX",
             "year_manufactured": "2019",
             "cost": 99.99,
             "price": 139.99,
             "is_sold": False,
             "size": "180cm x 120cm",
             "height": "50cm",
         },
     )
    def createBeds(self):
        if self.unicity:
            nbeds = 2
        else:
            nbeds = random.randint(2, 10)

        for i in range(1, nbeds):
            self.beds.append(Bed(greenhouseId=self.id, unicity=self.unicity))
            print('created bed ' + str(i) + ' for greenhouse ' + self.id)
    def add_bed(self):

        length = input('len of bed: ')
        bre = input('breadth of bed: ')
        year = input('enter the year made: ')
        posts = input('has posts?: ')
        headboard = input('has head board?: ')
        material  = input('material: ')

        self.bed = Bed(length, bre, year, posts, headboard, material)
Exemple #9
0
 def get_all_beds(self):
     beds_list = list()
     for l in self.f:
         values = l.rstrip().split(",")
         bed_id = int(values[0])
         if values[1] == 'true':
             equipped_crit = True
         else:
             equipped_crit = False
         bed = Bed(bed_id, equipped_crit)
         beds_list.append(bed)
     return beds_list
Exemple #10
0
    def __init__(self, bed_num):
        # self.bed_num = bed_num
        self.yy = bed_num // 20
        self.xx = bed_num // self.yy
        if bed_num % self.yy:
            self.xx += 1

        self.beds = np.array([])
        for i in range(self.xx):
            for j in range(self.yy):
                bed = Bed(i, j, True)
                self.beds = np.append(self.beds, bed)
Exemple #11
0
	def __init__(self, bed_counts):
		self.bed_counts = bed_counts

		self.width = int(bed_counts / 20)
		self.column = int(bed_counts / self.width)
		if not bed_counts % self.width == 0:
			self.column += 1
		
		self.beds = np.array([])
		for i in range(self.column):
			for j in range(self.width):
				bed = Bed(True, i, j)
				self.beds = np.append(self.beds, bed)
Exemple #12
0
def add_item():
    """ Creates and adds a new item to the furniture shop using the JSON info provided """
    data = request.json
    response_dict = {"status": 200, "response": None}

    try:
        item_type = data.pop("type", None)
        item_id = None

        if item_type == Bed.FURNITURE_TYPE:
            item_id = my_store.add(Bed(**data))
        elif item_type == Sofa.FURNITURE_TYPE:
            item_id = my_store.add(Sofa(**data))

        response_dict["response"] = "Id of new item added: " + str(item_id)

    except (ValueError, KeyError) as e:
        response_dict["status"] = 400
        response_dict["response"] = str(e)

    return app.response_class(**response_dict)
 def test_get_item_type_valid(self):
     """ 040A - Valid furniture type """
     test_bed = Bed("001", "2019", "BrandX", 99.99, 139.99, "180cm x 120cm", "50cm")
     self.assertEqual(test_bed.get_item_type(), "bed", "Item type must be 'bed'")
Exemple #14
0
#coding:gbk

from sofa import Sofa
from bed import Bed

sofa = Sofa()
bed = Bed()

sofa.print_define()
sofa.print_classify("µÍ±³É³·¢")
sofa.print_colour("ºìÉ«")

bed.print_define()
bed.print_classify("ƽ°å")
bed.print_colour("°×·ã")
Exemple #15
0
def bad_bed_obj(inputs_path):
    from bed import Bed
    return Bed(bed_file_path=inputs_path + '/test_bad_bed_less_cols.bed')
Exemple #16
0
def bed_obj(inputs_path):
    from bed import Bed
    return Bed(bed_file_path=inputs_path + '/test_default.bed')
Exemple #17
0
 def use(self, w, h, board, menu):
     if start_field[w][h] == 4 and menu[board.id][1] > 0:
         Bed('mak', (w, h), all_beds)
    def test_bed_valid_parameters(self):
        """ 010A - Valid constructor """

        test_bed = Bed("001", "2019", "BrandX", 99.99, 139.99, "180cm x 120cm", "100cm")
        self.assertIsNotNone(test_bed, "Bed must be defined")
Exemple #19
0
class Microhaplotyper(object):
    ANALYTICAL_THRESHOLD = 0.02
    ABSOLUTE_ANALYTICAL_THRESHOLD = 10
    MIN_MAPPING_QUALITY = 60
    MAX_MAPPING_QUALITY = 254
    REMOVE_DELETIONS = True

    def __init__(self,
                 bam,
                 bed,
                 info,
                 out,
                 analytical_threshold=ANALYTICAL_THRESHOLD):

        self.bam = bam
        self.bed = bed
        self.info = info
        self.out = out
        self.analytical_threshold = analytical_threshold

        # Init
        self.bed_obj = Bed(self.bed)
        self.info_obj = Info(self.info)
        self.mh_dict = {}
        self.filters_obj = Filters(
            analytical_threshold=self.analytical_threshold,
            abs_analytical_threshold=self.ABSOLUTE_ANALYTICAL_THRESHOLD,
            min_mapq=self.MIN_MAPPING_QUALITY,
            max_mapq=self.MAX_MAPPING_QUALITY,
            remove_deletions=self.REMOVE_DELETIONS)
        self.short_reads_count = 0
        self.total_reads_count = 0
        self.number_of_contributors_overall = 0

    def get_microhaplotypes(self):
        self._process_bed_file()
        if self.info:
            self._process_info_file()
        self._process_microhaplotypes()

    def _process_bed_file(self):
        self.bed_obj.get_bed_dict()

    def _process_info_file(self):
        self.info_obj.get_info_dict()

    def _process_microhaplotypes(self):
        self._get_mh_count()
        self._get_number_of_contributors_overall()

    def _get_mh_count(self):
        bam_file_obj = pysam.AlignmentFile(self.bam, 'rb')
        for mh_name in self.bed_obj.bed_dict.keys():

            self.mh_dict.setdefault(mh_name, Microhaplotype(name=mh_name))
            mh_number_of_bases_targeted = len(self.bed_obj.bed_dict[mh_name])

            for chromosome, start_position in self.bed_obj.bed_dict[mh_name]:
                self.mh_dict[mh_name].process_overlapping_reads(
                    chromosome, start_position, bam_file_obj)

            reads_processed, short_reads = self.mh_dict[mh_name].get_alleles(
                mh_number_of_bases_targeted)
            self.total_reads_count += reads_processed
            self.short_reads_count += short_reads
            self.mh_dict[mh_name].calculate_avg_mapping_quality()
            self.mh_dict[mh_name].calculate_total_coverage()
            self.mh_dict[mh_name].filter_alleles_and_set_analytical_threshold(
                self.filters_obj)
            self.mh_dict[mh_name].calculate_number_of_alleles()
            self.mh_dict[mh_name].calculate_number_of_contributors()
            if self.info:
                self.info_obj.add_info(self.mh_dict[mh_name])

    def _get_number_of_contributors_overall(self):
        self.number_of_contributors_overall = max([
            self.mh_dict[mh_name].number_of_contributors
            for mh_name in self.mh_dict.keys()
        ])
 def test_get_size_valid(self):
     """ 020A - Valid size of bed """
     test_bed = Bed("001", "2019", "BrandX", 99.99, 139.99, "180cm x 120cm", "50cm")
     self.assertEqual(
         test_bed.size, "180cm x 120cm", "Size of bed must be '180cm x 120cm'"
     )
 def test_get_height_valid(self):
     """ 030A - Valid height of bed """
     test_bed = Bed("001", "2019", "BrandX", 99.99, 139.99, "180cm x 120cm", "50cm")
     self.assertEqual(test_bed.height, "50cm", "Height of bed must be 50cm")
Exemple #22
0
from furniture_manager import FurnitureManager
from sofa import Sofa

qwerty = FurnitureManager("furniture.sqlite")
beds = {
    "Bed1": ["001", "2019", "Ikea", 24.99, 44.99, "190x100cm", "25cm"],
    "Bed2":
    ["002", "2015", "HelloFurniture", 124.99, 144.99, "190x100cm", "25cm"],
}

sofas = {"Sofa1": ["003", "2012", "HelloFurniture", 99.99, 119.99, 4, 6]}
Bed1 = Bed(
    beds["Bed1"][0],
    beds["Bed1"][1],
    beds["Bed1"][2],
    beds["Bed1"][3],
    beds["Bed1"][4],
    beds["Bed1"][5],
    beds["Bed1"][6],
)
Bed2 = Bed(
    beds["Bed2"][0],
    beds["Bed2"][1],
    beds["Bed2"][2],
    beds["Bed2"][3],
    beds["Bed2"][4],
    beds["Bed2"][5],
    beds["Bed2"][6],
)
Sofa1 = Sofa(
    sofas["Sofa1"][0],