![]() |
missing positional argument error - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Homework (https://python-forum.io/forum-9.html) +--- Thread: missing positional argument error (/thread-21863.html) |
missing positional argument error - programmert - Oct-18-2019 Hi, I do not understand how to solve the following error which pops up when running this code: TypeError: __init__() missing 1 required positional argument: 'request' The code: import random import simpy import statistics class DiagnosticsSimulator: def __init__(self): self.nr_patients = 0 # the number of patients that arrived self.nr_patients_processed = 0 # the number of patients that was processed until completion self.nr_ultrasounds = 0 # the number of patients that received an ultrasound self.sojourn_time_per_patient = 0 # the average sojourn time per patient self.sojourn_lst = [] # list storing all sojourn times def patient(self, env, bed, receptionist, nurse, lab_assistant): arrival_time = env.now rr = receptionist.request() yield rr # wait for receptionist to become available wait_for_form = random.uniform(0.5, 1.5) yield env.timeout(wait_for_form) # time it takes waiting for the form receptionist.release() fill_out_form = random.uniform(15, 25) yield env.timeout(fill_out_form) # time it takes for filling out the form rr = receptionist.request() yield rr # wait for receptionist to become available return_and_brief = random.uniform(2, 4) yield env.timeout(return_and_brief) # time is takes to return form and receive briefing receptionist.release() br = bed.request() yield br # wait for bed to become available nr = nurse.request() yield nr # wait for nurse to become available preparation = random.uniform(2, 8) yield env.timeout(preparation) # time it takes to get prepared nurse.release() lr = lab_assistant.request() yield lr # wait for lab assistant to become available take_blood = random.uniform(4, 6) yield env.timeout(take_blood) # time it takes to take blood lab_assistant.release() if random.randint(0,100) < 30: nr = nurse.request() yield nr # wait for nurse to become available ultrasound = random.uniform(7, 13) yield env.timeout(ultrasound) self.nr_ultrasounds += 1 nurse.release() bed.release() completion_time = env.now self.nr_patients_processed += 1 sojourn_time_per_per_patient = completion_time - arrival_time # calculate the sojourntime self.sojourn_lst.append(sojourn_time_per_per_patient) self.sojourn_time_per_patient = statistics.mean(self.sojourn_lst) def patient_generator(self, env, bed, receptionist, nurse, lab_assistant): while True: p = self.patient(env, bed, receptionist, nurse, lab_assistant) # create a new patient env.process(p) # start the simulation of the patient interarrivalTime = random.expovariate(1/6) # exponential interarrival yield env.timeout(interarrivalTime) # wait for the sampled interarrival time # seed: the random seed with which the simulator is initiated # duration: the amount of simulation time for which the simulator has to run def simulate(self, seed, duration): random.seed(seed) env = simpy.Environment() bed = simpy.Resource(env, capacity = 12) receptionist = simpy.Resource(env, capacity = 1) nurse = simpy.Resource(env, capacity = 2) lab_assistant = simpy.Resource(env, capacity = 1) env.process(self.patient_generator(env, bed, receptionist, nurse, lab_assistant)) # start patient generation process env.run(duration) return env diags = DiagnosticsSimulator() env = diags.simulate(2019, 10000) print(diags.nr_patients_processed, diags.sojourn_time_per_patient) RE: missing positional argument error - Larz60+ - Oct-18-2019 show the complete unmodified error traceback. |