Skip to content

Instantly share code, notes, and snippets.

@progressiverocker
Created September 16, 2013 10:32
Show Gist options
  • Save progressiverocker/6579013 to your computer and use it in GitHub Desktop.
Save progressiverocker/6579013 to your computer and use it in GitHub Desktop.
Premeds for Dog, Cat, and Rabbit
"""The Premedicant Dose for animal type is the weight of animal multipled by drug dose rate, divided by drug concertration."""
# Dictionaries start here. 1. drug concerntrations. 2. drug rates 3. animal weight ranges
from __future__ import division # to fix rounding error on rate ranges eg dog ketamine
import re # need regular expressions (re) for weightQ while loop to check for a float from raw_input
drug_concerntrations = {"meloxicam" : 5.0, "amoxicillin clavulanic acid" : 32.5, "ketamine" : 100, "enrofloxacin 2.5 percent solution" : 25, "enrofloxacin 5.0 percent solution" : 50 }
rates = {
'dog' : {"meloxicam" : [0.2], "amoxicillin clavulanic acid" : [8.75,12.5], "ketamine" : [5.0,7.0]},
'cat' : {"meloxicam" : [0.2], "amoxicillin clavulanic acid" : [8.75,12.5], "ketamine" : [5.0,7.5]},
'rabbit' : {"meloxicam" : [0.6], "ketamine" : [20], "enrofloxacin 2.5 percent solution" : [10.0, 15.0, 20.0, 25.0], "enrofloxacin 5.0 percent solution" : [10.0, 15.0, 20.0, 25.0]}
}
weight_range = {"dog" : 100.0, "cat" : 15.0, "rabbit" : 15.0} # weight_range for maximum weight inputs (defensive programming for input from user)
restart = "y" # Restarts Loop 1 using input "y".
while restart == "y": # LOOP 1. Loops the following two inputs and returns premeds. Option to restart at the end using input.
# LOOP 1.1. Matches input (stripped and lower case) with dictionary key.
finished = "" # Ends loop 1.1. (Not sure if there is a better way using break? I couldn't get it to work)
while finished == "":
species = raw_input("\nEnter the species as dog, cat, or rabbit: ")
species_stripped = species.lower().strip() # more defensive programming
for animal in rates: #LOOP 1.1.1. Looking to match the input from species with a dictionary key and then ending the loop 2.
if species_stripped == animal or species_stripped == animal[0:1]: # The slice animal[0:1] makes it so the user can lazily enter one letter
species_stripped = animal # user enters first letter of species (eg. d == dog). More defensive programming.
finished = "fin" # probably some better solutions to this loop!
# LOOP 1.2. I've no idea how this works as I googled the solution, but it checks for a float in loop 2.
# It is more defensive programming to make sure the input from the user is okay. I need to read up on regular expressions.
p = re.compile('\d+(\.\d+)?')
while True:
weight = raw_input("\nEnter the weight in kilograms (eg. 500 grams is '0.5'): ")
if (p.match(weight) != None) and (float(weight) > 0.0) and (float(weight) < weight_range[species_stripped]):
# not sure how p.match works here, but looks for a float from the input. More reading to be done.
break
weight_float = float(weight) # everything that follows needs weight input to be a float
print "\nRESULT FOR %.2f kg %s:" % (weight_float, species_stripped) # Trying to make the print out look easier on the eye.
# LOOP 1.3. There are two for loops which print the premed dose for animal type.
# The weight of animal multipled by drug dose rate, divided by drug concertration.
# Loop 1.3.1 Starts looping the drug stored in the dictionary matched for the input from Loop 1.1 (ie. species)
# Loop 1.3.2 Hurts my brain, but it works damn it! There is probably a more eloquent solution here.
for drugloop in sorted(rates[species_stripped]): # LOOP 1.3.1
for drug, number in enumerate(rates[species_stripped][drugloop]): # LOOP 1.3.2
number = float(number)
user_input = (weight_float * number) / float(drug_concerntrations[drugloop])
# Result! Not sure the best way to display the information. User then uses their discretion to make a choice from the results.
print "When using %s at dose rate %.2fml: %.2fml" % (drugloop, number, user_input) # %.2f, only need two decimal places.
restart = raw_input("\nTO RESTART ENTER 'Y'.") # back to Loop 1.1 if 'y' is entered
# NEXT: work out how this can be put on any computer, in a work environment, for quick and easy access.
# Portable hard drive/USB stick type solution, or launch/download from an internet site.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment