def pets_adoption(pet_type):
    adopt_ready = AVLTree()

    # function to recursively look for cats or dogs and add them to the tree
    def in_order_recur(node):
        if node is None:
            return
        in_order_recur(node.left)
        if node.animal.animal_type == pet_type \
                and node.animal.vacc \
                and node.animal.neut\
                and node.animal.microchip:
            adopt_ready.insert(node.animal)
        in_order_recur(node.right)

    in_order_recur(pet_tree.root)
    return adopt_ready
Example #2
0
def rank_patient():
    ranked_tree = AVLTree()

    def in_order_recur(node):
        if node is None:
            return
        in_order_recur(node.left)
        node.patient.setRankValue()
        ranked_tree.insert(NodePatientRankValue(node.patient))
        in_order_recur(node.right)

    def in_order_recur_rank(node):
        if node is None:
            return
        in_order_recur_rank(node.right)
        pat = node.patient
        pat.displayRankInfo()
        in_order_recur_rank(node.left)

    in_order_recur(patient_tree.root)
    in_order_recur_rank(ranked_tree.root)
def abused_abandoned_list(crime):
    people_crime = AVLTree()

    # function to recursively look for abusers or abandoners and add them to the list
    def in_order_recur(node):
        if node is None:
            return

        in_order_recur(node.left)
        if crime == 'abuse':
            person = node.animal.abuse
        else:
            person = node.animal.abandon

        if person != "" and ("not exist" in people_crime.search(
                person, "person")):
            people_crime.insert(person, "person")

        in_order_recur(node.right)

    in_order_recur(treatment_tree.root)
    return people_crime
def return_to_owner():
    return_ready = AVLTree()

    def check_ready(curr_root):
        if curr_root is None:
            return 0
        check_ready(curr_root.left)
        an = curr_root.animal

        if an.vacc and str(an.dest) == "":
            treat = treatment_tree.search(an.san_id)
            # if animal is NOT in treatment, or in treatment but med_fin is specified, it can go
            if type(treat) == str or (type(treat) != str
                                      and str(treat.med_fin) != ""):
                if (type(an) == Pet and an.reason not in ["Abused", "Abandoned", "Stray"])\
                        or (type(an) == WildAnimal and an.reason == 'Lost'):
                    return_ready.insert(an)

        check_ready(curr_root.right)

    check_ready(pet_tree.root)
    check_ready(wild_animals_tree.root)

    return return_ready
Example #5
0
import csv
from AVL_tree import AVLTree
from Date import date_format
from Animal import Pet, WildAnimal, Treatment

pet_tree = AVLTree()
wild_animals_tree = AVLTree()
treatment_tree = AVLTree()

with open("csv_files\\PETS.csv") as file:
    reader = csv.reader(file)
    next(reader
         )  # index is the list of headers in the first line of the csv file

    for row in reader:
        san_id, animal_type, breed, vacc, neut, microchip, entry_reason, arr_date, dep_date, dest, dest_address = row

        arr_date = date_format(arr_date)
        dep_date = date_format(dep_date)

        pet = Pet(san_id, animal_type, vacc, entry_reason, arr_date, dep_date,
                  dest, dest_address, breed, neut, microchip)
        pet_tree.insert(pet)

with open("csv_files\\WILD ANIMALS.csv") as file:
    reader = csv.reader(file)
    next(reader)

    for row in reader:
        san_id, animal_type, vacc, entry_reason, arr_date, dep_date, dest, dest_address = row
Example #6
0
from AVL_tree import AVLTree
from RBTREE import RedBlackTree
from random import *

at = AVLTree()
rbt = RedBlackTree()


def count(var):
    for i in range(var):
        at.insert(i)
        rbt.add(i)
    at_count = 0
    rbt_count = 0
    counter = 0
    rbt.prin()
    for i in range(var):
        at_count += at.search(randrange(0, var))
        rbt_count += rbt.find_node(randrange(0, var))[1]
    print(int(at_count / var), int(rbt_count / var))


count(10000)
import csv
from AVL_tree import AVLTree, NodePatient
from pprint import pprint
from Patient import Patient

patient_tree = AVLTree()

patient_ids = ["A1", "A2", "A3", "B1", "B2", "B3", "B4", "B5", "B6", "B7"]
patient_csv = list(
    map(lambda pat: "PATIENT DATA - PATIENT " + pat + ".csv", patient_ids))

for i in range(len(patient_ids)):
    with open("patients\\" + patient_csv[i]) as file:
        reader = csv.reader(file)
        data = list(reader)
        # pprint(data)
        risk = data[0][1]  # get risk (LR/HR)
        age = data[0][2].split(" ")[1]  # get age
        weight = data[0][4].split(" ")[1]  # get weight (kg)
        feeding_chart = []

        for j in range(5):
            feeding_chart.append(
                [data[k + 3] for k in range(24 * j, 24 * (j + 1))])

        patient = Patient(patient_ids[i], risk, int(age), float(weight),
                          feeding_chart)
        patient_tree.insert(NodePatient(patient))