コード例 #1
0
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

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

        wild_an = WildAnimal(san_id, animal_type, vacc, entry_reason, arr_date,
                             dep_date, dest, dest_address)
        wild_animals_tree.insert(wild_an)
コード例 #2
0
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))