Server to Celery

Now that Ridminder lives, during my mini mini testing (me going to work and going home), its sometimes getting the vehicle that has already past me. This is happening because heroku times out and I had to comment out the code that verifies if my closest vehicle hasn’t already past my stop.

So I worked on drawing out how the change of data flow will have to become:

IMG_20160110_192430
Before I start writing any code, I need to branch. So I watched Branch * GitHub & Git that was really helpful. This was a lot easier than I thought it would be – for some reason I had this huge fear of breaking all the things. But nope, it was a few simple commands and tada!

psql-newSince I’m moving selecting the closest vehicle processing to my celery I’ll need to save (aka put into my psql) the data that my server is getting so my celery can access it. So instead of my server working on selecting the closest vehicle, its just getting the list of tuples of the vehicles with their distance, sorting it and returning the two closest vehicle and their current distance- my server now just needs to save two vehicles and their distances. Now my celery can pull it out from my database and have it to reference. Since I was redoing my psql, I also added finished_timestamp_difference and finished_vehicle_difference so I can see which process (firebase or google direction) triggered the text and what was the disparity. Since I am also keeping the arrival_time time stamp, I could use this data to help fine tune my project (ie. if my google directions is not as accurate during rush hour I can tweak it to take that into account).

if_id_none

Since I am adding these options, I had to add new functions that can process them. First, I had to figure out how to set the condition to process the two vehicles only once. So I did an if statement for the request.vehicle_id is None. At first I had it as:

if request.vehicle_id != None:

Which didn’t work because None in python is an object which is not zero, has no length and has its own type. When I tired running this script, it gave me an error I laughed, HA! Silly Jessica, your drunk on lack of sleep.

selects_closest.jpg

So if my celery task hasn’t already processed this request, it sends the vehicles number and their distance from the request into selects_closest_vehicle function- which is similar to what my old function did on the server side. Now it checks the closest vehicle and if its distance is smaller (ie. getting closer to my user), sets the vehicle id to that one. It the distance is larger (ie. going away from my user) it sets it to the next closest (I thought about checking it again and keeping track of three vehicles, but I want to test it out first and if its an issue, I’ll add the third vehicle and verify the second).

recordsAt the end of my celery task, I have it recording in the database the distance difference and the time difference.

I did all this work locally and its working. Now I’ll have to push it to heroku and test it out, but I’m going to wait until this weekend so I can have enough time to work out the bugs.

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s