Jump to content

altering list slices in python 2.7


physica
 Share

Recommended Posts

I am practicing my programming before I start my masters. I am writing a simple rota program for work. We already having rostering system. The main focus of this program is to look at the amount of patients coming in per hour, make the assumption that one doctor takes one hour per patient to process and calculate how many people will be waiting over 4 hours and how many people have to wait x y and z hours before seeing a doctor depending on the amount of patients coming in per hour and the amount of doctors on for that hour. I am having problems assigning doctors to each hour. Here is the following code:

 

patients_each_hour = [4, 3, 2, 2, 2, 2, 1, 1, 3, 3, 5, 7, 7, 6, 7, 6, 6, 6, 5, 5, 5, 4, 5, 5]
hours_in_day = list(range(1, 25))
doctors_per_hour = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
print
print("Above are the amount of patients coming into the department per hour with the first diget being 1am to 2am and the final diget being 11pm to midnight based on an average presentation in the data of 6000 attendances and the distribution.")
print
print(patients_each_hour)
print
print("Above are the following hours in the 24 hour period which you have to choose from when inputing following hours for the SHO shifts.")
print
clocking_in = int(raw_input("please enter an hour he/she starts: "))
clocking_out = int(raw_input("please enter an hour he/she finishes: "))
for i, n in doctors_per_hour[clocking_in : clocking_out]:
if n == 0:
n = 1
elif n == 1:
n = 2
print
print(doctors_per_hour)
I did a 24 bit list. However, when I try and do the final part 'int' object is not iterable. Could someone please help? If I can alter a slice in the list I will then do it for the other 7 doctors and I can move forward with my program.
Many thanks
Edited by physica
Link to comment
Share on other sites

Use a while loop. As in while when the doc starts is less than when the doc finishes add an hour.

 

Also doctors should be scheduled for more than enough time because you don't know how many patients A&E will get.

Edited by fiveworlds
Link to comment
Share on other sites

For the patients coming in I have accessed a data base and did a probability distribution of 6000 attendances with respect to the time they came in. I then wrote a matlab program mimicking the distribution but scaled to the amount of patients coming in for that day. It made a prediction reconstructing the distribution based on the amount of patients coming in between 10am to 11am. I then calculated the error of prediction per hour. It's fairly accurate. I then looked at the average number of patients coming in in that time over 3 months. This is why my consultant asked me to write a computer program to get him to optimise the rota.

 

Thank you for the help. I am new to python. Could you show me an example of how you'd implement a while loop? There is also another technicality. Some doctors will start in the evening and work through till the morning. This means that the time finished will be lower than the time started. I'm guessing you can make an if condition (finish < start) you can go down a different path.

 

many thanks

Link to comment
Share on other sites

Could you show me an example of how you'd implement a while loop?

 

Using the 24 hour day. Since array indexes start at 0 it should be 24-1. I'd like to see you finish this.

done=""
while done!="done":
    
    clocking_in = int(raw_input("please enter an hour he/she starts: "))    
    clocking_out = int(raw_input("please enter an hour he/she finishes: "))
    
    while clocking_in-1 != clocking_out-1:
        doctors_per_hour[clocking_in]=doctors_per_hour[clocking_in]+1
        clocking_in=clocking_in+1
        if clocking_in == 24:
            clocking_in=0
    
    done = raw_input("are you done?")

print(doctors_per_hour)
clocking_out = int(raw_input("pause"))
Link to comment
Share on other sites

I modified it a bit so now it counts the number of staff per hour but it also counts the number of staff per their respective specialty and takes their name which could be tested in a username=>password type deal.

patients_each_hour = [4, 3, 2, 2, 2, 2, 1, 1, 3, 3, 5, 7, 7, 6, 7, 6, 6, 6, 5, 5, 5, 4, 5, 5]
 
staff_per_hour = [[0], [0], [0], [0], [0], [0], [0], [0], [0], [0], [0], [0], [0], [0], [0], [0], [0], [0], [0], [0], [0], [0], [0], [0]]

staff = ["doc", "rgn", "cnm1", "cnm2", "cnm3", "surgeons", "gyn", "ortho", "hca", "porters"]


for staffname in staff:
    i=0
    while i<23:
        staff_per_hour[i].append(staffname)
        staff_per_hour[i].append(0)
        staff_per_hour[i].append("")
        i=i+1


done=""
while done!="done":
    
    clocking_in = int(raw_input("please enter an hour he/she starts: "))    
    clocking_out = int(raw_input("please enter an hour he/she finishes: "))
    staffname= raw_input("please enter your name: ")
    profession= raw_input("please enter your profession: ")
    
    while clocking_in-1 != clocking_out-1:
        staff_per_hour[clocking_in][0]=staff_per_hour[clocking_in][0]+1
        staff_per_hour[clocking_in][staff_per_hour[clocking_in].index(profession)+1]=staff_per_hour[clocking_in][staff_per_hour[clocking_in].index(profession)+1]+1
        staff_per_hour[clocking_in][staff_per_hour[clocking_in].index(profession)+2]=staff_per_hour[clocking_in][staff_per_hour[clocking_in].index(profession)+2]+staffname
        clocking_in=clocking_in+1
        if clocking_in == 24:
            clocking_in=0
    
    done = raw_input("are you done?")

print(staff_per_hour)

clocking_out = int(raw_input("pause"))

Link to comment
Share on other sites

wow you have really taken it to the next level. This will definitely help when I start collecting data on the amount of patients in the department and how it will affect the nursing levels. The next step is calculating how many patients have to wait and for how long. At handover which is 8am there are usually no patients left to be processed which makes it a goo handover time. The task at hand is to start at 8am, add the patients that come in at 8am and then minus the amount of doctors on for that hour giving the amount of patients left to be seen. The next hour taking away the amount of doctors on from the patients left over in the previous hour, the main aim is to calculate how many patients have to wait X amount of hours to be seen by a doctor if we have a y configuration on the rota. There has to be some function. I started writing a ton of if conditions for each hour but it spun out of control very quickly.

 

 

Did he say masters? Damn kid just print the piece of paper, its gona save you alot of money.

 

Whats your major?

my major is physics. I got into University College London for msc(physics and engineering in medicine). The fields I'm interested in working in require masters minimum. As you can see I am new to programming so I need to practice my programming on simple tasks before I start over wise I'm going to find tasks like signal processing to be very hard.

Link to comment
Share on other sites

wow you have really taken it to the next level. This will definitely help when I start collecting data on the amount of patients in the department and how it will affect the nursing levels. The next step is calculating how many patients have to wait and for how long. At handover which is 8am there are usually no patients left to be processed which makes it a goo handover time. The task at hand is to start at 8am, add the patients that come in at 8am and then minus the amount of doctors on for that hour giving the amount of patients left to be seen. The next hour taking away the amount of doctors on from the patients left over in the previous hour, the main aim is to calculate how many patients have to wait X amount of hours to be seen by a doctor if we have a y configuration on the rota. There has to be some function. I started writing a ton of if conditions for each hour but it spun out of control very quickly.

 

 

my major is physics. I got into University College London for msc(physics and engineering in medicine). The fields I'm interested in working in require masters minimum. As you can see I am new to programming so I need to practice my programming on simple tasks before I start over wise I'm going to find tasks like signal processing to be very hard.

 

Ah my apologies, i presumed that because you were brushing up on your programming that you meant your masters was in programming.

 

I have the cooley-tukey fast fourier transform in c and c++ if that helps, tried implementing it on the forex data but didnt really fit.

 

i breifed over the algorithm to get a better understanding and to try get my data to fit but i think the format is wrong, however it shows quite clearly how it calculates frequency based on N period not sure about phase or amplitude, although the amplitude may have been a secondary function of frequency. Just hola if you want it. I think signal processing is easier on a platform like matlab than any single programming language as it facilitates huge libraries for specific functions such as signal processing, you then literally have to input your variables or modify the code if required.

Edited by DevilSolution
Link to comment
Share on other sites

 

Ah my apologies, i presumed that because you were brushing up on your programming that you meant your masters was in programming.

 

I have the cooley-tukey fast fourier transform in c and c++ if that helps, tried implementing it on the forex data but didnt really fit.

 

i breifed over the algorithm to get a better understanding and to try get my data to fit but i think the format is wrong, however it shows quite clearly how it calculates frequency based on N period not sure about phase or amplitude, although the amplitude may have been a secondary function of frequency. Just hola if you want it. I think signal processing is easier on a platform like matlab than any single programming language as it facilitates huge libraries for specific functions such as signal processing, you then literally have to input your variables or modify the code if required.

Yes I would love it thanks. I am finding the coding community to be very helpful and creative. I wish I got involved in it sooner. I start my masters in sept so I have just under a year to get my head round some programming and apply my physics I learnt in my major to engineering subjects. I will purchase matlab soon as it it is used a fair amount in the masters. I am working on python, I would also like to get off the ground in C++ . Do you know how to get started in terms of where to download a compiler and editor? I am using mac.

Link to comment
Share on other sites

now on the second part of the program. I will be processing each hour then printing lists of how many patients had to wait X hours before seeing a doctor. The problem is that it says syntax error on the first line but gives me nothing else. Can anyone see the syntax error?

 

# first hour process (8am to 9am)
patients_waiting_since eight = patients_each_hour[9] - doctors_per_hour[9]
if patients_waiting_since eight < 0:
patients_waiting_since_eight = 0
patients_waiting_two_hours_eight = 0
patients_waiting_three_hours_eight = 0
patients_waiting_four_hours_eight = 0
patients_waiting_five_hours_eight = 0
patients_waiting_six_hours_eight = 0
patients_waiting_seven_hours_eight = 0
patients_waiting_nine_hours_eight = 0
patients_waiting_ten_hours_eight = 0
# second hour process (9am to 10am)
if patients_waiting_since_eight > 0:
patients_waiting_two_hours_nine = patients_waiting_since_eight - doctors_per_hour[10]
if patients_waiting_two_hours_nine <= 0:
patients_waiting_since_nine = patients_each_hour[10] + patients_waiting_two_hours_nine
patients_waiting_two_hours_nine = 0
if patients_waiting_two_hours_nine > 0:
patients_waiting_since_nine = patients_each_hour[10]
if patients_waiting_since_eight == 0:
patients_waiting_since_nine = patients_each_hour[10] - doctors_per_hour[10]
else:
print("there is an error in the program from 9am to 10am")
patients_waiting_three_hours_nine = 0
patients_waiting_four_hours_nine = 0
patients_waiting_five_hours_nine = 0
patients_waiting_six_hours_nine = 0
patients_waiting_seven_hours_nine = 0
patients_waiting_nine_hours_nine = 0
patients_waiting_ten_hours_nine = 0
# third hour process (10am to 11am)
if patients_waiting_two_hours_nine > 0:
patients_waiting_three_hours_ten = patients_waiting_two_hours_nine - doctors_per_hour[11]
if patients_waiting_three_hours_ten <= 0:
patients_waiting_two_hours_ten = patients_waiting_since_nine + patients_waiting_three_hours_ten
patients_waiting)three_hours_ten = 0
if patients_waiting_two_hours_ten <= 0:
patients_waiting_since_10 = patients_each_hour[11] + patients_waiting_two_hours_ten
patients_waiting_two_hours_ten = 0
if patients_waiting_two_hours > 0:
patients_waiting_since_ten = patients_each_hour[11]
if patients_waiting_three_hours_ten > 0:
patients_waiting_since_ten = patients_each_hour[11]
patients_waiting_two_hours_ten = patients_waiting_since_nine
patients_waiting_four_hours_ten = 0
patients_waiting_five_hours_ten = 0
patients_waiting_six_hours_ten = 0
patients_waiting_seven_hours_ten = 0
patients_waiting_nine_hours_ten = 0
patients_waiting_ten_hours_ten = 0
Link to comment
Share on other sites

havent used python for years, but whats the hash for? its usually used a declaration for pre-compilation.

 

Yeh get matlab student edition is £50 or something? very cheap

 

i dont know if the # is for a func declaration but it usually has like func return name(data)

Edited by DevilSolution
Link to comment
Share on other sites

hash is for a note, it doesn't affect the script process. It's to stop me getting confused. Just brought matlab student licence. it was £50 but when you add additional add ons and tax it came up to £200. I bit of a kick in the teeth but loads of engineering jobs require matlab skills and part of my assessment in the masters is in matlab. I'd be very short sighted to deny an extra year of practice on this for £200. Do you know of any good compilers and editors to download for C++ for mac?

Edited by physica
Link to comment
Share on other sites

Usually with them add ons you can email the creator directly and ask for a special licence for learning purposes. I think we got like statistics for like £10. Don't quote me though. c++ is a good place to start because you get a bit of both worlds, some higher level features and some lower level features. Mostly everything that can be done in c can be done in c++ and then you get the bonus namespaces, classes, unions etc (though i dont know how much unions differ from a typedef struct) but yeh its OOP capable though i dont know think its built with OOP in mind.

 

And you can dip into all the c libraries you want aswell as c++ and DLL's so c++ is the way to go.

 

Pythons nicer on eyes and usually alot quicker at getting a job done though. You'll carry alot of c++ with you into mostly any language (other than some of the older more specific languages).

Link to comment
Share on other sites

havent used python for years, but whats the hash for? its usually used a declaration for pre-compilation.

 

Yeh get matlab student edition is £50 or something? very cheap

 

i dont know if the # is for a func declaration but it usually has like func return name(data)

 

The hash in python is pythons comment, it has nothing to do with the preprocessor.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.