clairenied15 / heart_rate_sentinel_server

0 stars 0 forks source link

Problems with interval average #8

Open clairenied15 opened 5 years ago

clairenied15 commented 5 years ago

I am trying to find the indices for where the time stamp list is greater than a certain date and time but keep getting an error. I'm not sure if the error is coming from the formatting of the date and time (I tried different variations, like using strptime on both the recorded time stamps and the time "inputted" by the user) or if its coming from my list comprehension to find the indices. I've been trying different things for a while and can't get it to work. Any help would be greatly appreciated.

dward2 commented 5 years ago

Please post what code you are running that generates the error, the specific function that generates the error, and post the specific error message.

clairenied15 commented 5 years ago

https://github.com/clairenied15/heart_rate_sentinel_server/blob/aa4f560ac4853e3578adea6b779c300c9a07ec3c/hr_server.py#L112-L125

clairenied15 commented 5 years ago

For the above part of the hr_server.py file, I am getting the error "TypeError: The view function did not return a valid response. The function either returned None or ended without a return statement."

clairenied15 commented 5 years ago

I tried using time_av["heart_rate_average_since"] instead of strp_since_tm. I also tried "stripping" both time variables because I thought maybe they were strings that couldn't be mathematically compared.

dward2 commented 5 years ago

Do you have a test function that you can share that generates this error? Or, is it when you are trying to access the server from a client program?

dward2 commented 5 years ago

I ask because I cannot generate that error when I try running your code. So, I will need to see the specific sequence of events that causes the error. A test function is the best way for that to happen.

dward2 commented 5 years ago

Since I cannot generate your specific error, I cannot be sure about this, but one possibility could be the following: Your function int_av has the return statement inside an if block. If that if statement is never true, your function never returns anything. That could explain why you are getting the error about not returning a valid response. Consider adding return "found nothing" or something similar at the end of the function outside of the for block and see if that fixes your error.

clairenied15 commented 5 years ago

I do not have a test function. I first run hr_server.py, followed by callserver.py, callserverhr.py, and then call_hr_int_av.py. It is the call_hr_int_av.py that is getting the error

clairenied15 commented 5 years ago

So if the if statement is causing the problem, why isn't it true? I am inputting patient info for patient_id "1" and then using that same id in the time_av dictionary

dward2 commented 5 years ago

Just to verify, look at the code on the master branch?

clairenied15 commented 5 years ago

Oh I'm actually not getting the error anymore, but call_hr_int_av.py is returning "None"

clairenied15 commented 5 years ago

So something is still not working properly

clairenied15 commented 5 years ago

Yes the master branch

clairenied15 commented 5 years ago

Maybe it has to do with "indices"?

dward2 commented 5 years ago

When I run your code, I don't get your error. First, I run hr_server.py and the server starts normally. I then run callserver.py and get the following response, which seems correct:

{'attending_email': 'cen17@duke.edu', 'patient_id': '1', 'user_age': 1}

Process finished with exit code 0

I then run callserverhr.py and get the following response:

{'heart_rate': 160, 'patient_id': '1', 'time_stamp': 'Fri, 16 Nov 2018 10:34:07 GMT'}

Process finished with exit code 0

Again, that looks fine. I then fun call_hr_int_av.py and get the following response:

None

Process finished with exit code 0

Back in the server terminal window, here is what I see:

 * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
127.0.0.1 - - [16/Nov/2018 10:34:04] "POST /api/new_patient HTTP/1.1" 200 -
[{'patient_id': '1', 'age': 1, 'heart_rates': [], 'heart_rate_times': [], 'attending_email': 'cen17@duke.edu'}]
[{'patient_id': '1', 'age': 1, 'heart_rates': [160], 'heart_rate_times': [datetime.datetime(2018, 11, 16, 10, 34, 7, 993345)], 'attending_email': 'cen17@duke.edu'}]
127.0.0.1 - - [16/Nov/2018 10:34:07] "POST /api/heart_rate HTTP/1.1" 200 -
127.0.0.1 - - [16/Nov/2018 10:34:44] "GET /api/heart_rate/interval_average HTTP/1.1" 200 -

So, I don't seem to be getting an error.

dward2 commented 5 years ago

Oops, I just now saw your comment that you are now getting the same thing. You now need to look at your code and check your algorithm.

dward2 commented 5 years ago

I would recommend writing a test function that calls the int_av function, sending it known data, and then using debug mode to step through your code line by line and see where the algorithm is failing to do what you want.

dward2 commented 5 years ago

So if the if statement is causing the problem, why isn't it true? I am inputting patient info for patient_id "1" and then using that same id in the time_av dictionary

I'm trying to answer your question above. When I write a test function to run int_av(), I do find that the if statement is true. And, then I get a different error related to time.

So, my idea that it is related to whether you enter the if statement or not may not be correct. But, I still don't generate the "TypeError: The view function did not return a valid response. The function either returned None or ended without a return statement." error you previously mentioned.

So, as above, I would suggest writing a function that will call int_av() and then step through it line by line to check your intended algorithm.