Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError #5

Closed
lmorroni opened this issue Feb 4, 2014 · 7 comments
Closed

TypeError #5

lmorroni opened this issue Feb 4, 2014 · 7 comments
Labels

Comments

@lmorroni
Copy link

lmorroni commented Feb 4, 2014

Hi,
I have been trying to get anycluster working for a project I am doing. The error I keep receiving is:
TypeError: set(['1,2', '0,2', '3,2', '2,2']) is not JSON serializable

I'm running Django 1.6.1 Python 2.7.5
I have a psql database with all the relevant extensions installed. The model/field I am using to cluster is defined as follows:

class PlaceMark(models.Model):
name = models.CharField(max_length=255)
description = models.TextField()
geom = models.PointField(srid=4326)
objects = models.GeoManager()
layer = models.ForeignKey(Layer)
def unicode(self):
return self.name

In settings, I have added:
#anycluster settings
ANYCLUSTER_GEODJANGO_MODEL = "locator.PlaceMark"
ANYCLUSTER_COORDINATES_COLUMN = "geom"

The error originates from my main map page. My console shows that the specific page being requested is:
http://localhost:8080/anycluster/kmeans/2/256/?left=-180&top=30.000000000000018&right=180&bottom=30.000000000000018&cache=load&time=%3E%3D_2012-02-26&is_doubt=%3D_FALSE&_=1391549514849

Any ideas?
Thanks,
Larry

@lmorroni
Copy link
Author

lmorroni commented Feb 4, 2014

I may have fixed it although I'm not entirely sure it's the best approach. It seems like clusterer.py is trying to pass back a set for json serialization. I had to change two lines in compareWithCache.

Line 448:
new_clustercells = list(clustercells)-old_cells
Line 453:
clustered_cells = list(clustercells)

It appears that the proper json is now being returned. I'm interested in hearing your opinion on this solution.
Larry

@biodiv
Copy link
Owner

biodiv commented Feb 5, 2014

Hi Larry,
thank you for your report!
python cannot subtract lists, so we need to use sets. You might get errors when panning the map.
Have you tried to change the following line in views.py :

Line 26:
list(markers)

I think Django changed a few things in geodjango since 1.4. Although at first sight I do not see why 1.6 should be a problem, I will install 1.6 and do tests with your exact setup.
As this might take a few days until I find the time to do it, please try the above first if you get errors when panning.

A further test would be to disable cache when querying: remove the &cache= parameter from the query

If the error goes away, we know it is within compareWithCache.

By the way: I found out out that, although unsurprisingly, an SSD significantly improves the cluster speed.

@biodiv biodiv added the bug label Feb 5, 2014
@lmorroni
Copy link
Author

lmorroni commented Feb 5, 2014

biodiv,
Thanks for getting back to me. I am a novice in Python and I am still
learning it so bear with me. I have a programming background so I
understand the principals but I still don't have a firm grasp on syntax
and behavior. That being said, I did try to set things back in
clusterer.py to the way they were and then tried to json.dump
list(markers) instead of just markers but I received the same error.

I am using PyCharm to develop/debug and my tracing abilities are not
great. What I did notice though is that it never makes it to Line 26 in
views.py. It appears that things are crashing out in clusterer.py. I
tested this by simply placing a 1 on line 26 instead of markers. I
still get the same error. If I comment out the two previous calls to:
clustercells, filters =
clusterer.getClusterParameters(request,int(zoom),int(gridSize))

 markers = clusterer.kmeansCluster(clustercells,filters,int(zoom), 

int(gridSize))

...then it runs and returns a 1.

Larry

On 2/5/14, 5:06 AM, biodiv wrote:

Hi Larry,
thank you for your report!
python cannot subtract lists, so we need to use sets. You might get
errors when panning the map.
Have you tried to change the following line in views.py :

Line 26:
list(markers)

I think Django changed a few things in geodjango since 1.4. Although
at first sight I do not see why 1.6 should be a problem, I will
install 1.6 and do tests with your exact setup.
As this might take a few days until I find the time to do it, please
try the above first if you get errors when panning.

A further test would be to disable cache when querying: remove the
&cache= parameter from the query

If the error goes away, we know it is within compareWithCache.

By the way: I found out out that, although unsurprisingly, an SSD
significantly improves the cluster speed.


Reply to this email directly or view it on GitHub
#5 (comment).

@biodiv
Copy link
Owner

biodiv commented Feb 5, 2014

no problem. I can reproduce your error using django 1.6.1. It has something to do with the way django stores sessions since 1.6. We cant use sets in the session. Furthermore I found another error when detecting the SRID of the database. Hopefully I will be able to provide an update to support django 1.6 very soon.

@biodiv
Copy link
Owner

biodiv commented Feb 5, 2014

Please try the new version and let me know if it works for you.
The cache is now stored as list:

clustercache['cellIDs'] = list(clustered_cells)

and converted back to a set after retrieving

old_cells = set(clustercache['cellIDs'])

Your first approach was actually very close...

@lmorroni
Copy link
Author

lmorroni commented Feb 5, 2014

Hi,
I updated clusterer.py and was getting an error because srid_sb was not
being set. I am using 4326. I tried it with and without adding the new
setting you mentioned in your readme. I made a change and it worked.
Here's what I did on line 876:

     if len(list(srid_db_objs)) > 0:
       srid_db = srid_db_objs[0].st_srid
     else:
         try:
             srid_db = settings.ANYCLUSTER_COORDINATES_COLUMN_SRID
         except:
             srid_db = 4326

Larry

On 2/5/14, 12:15 PM, biodiv wrote:

Please try the new version and let me know if it worked for you


Reply to this email directly or view it on GitHub
#5 (comment).

@biodiv
Copy link
Owner

biodiv commented Feb 5, 2014

Thanks a lot for the fix :)

btw you can remove the

&time=%3E%3D_2012-02-26&is_doubt=%3D_FALSE

from your javascript query. I should update the javascript soon, too - it has some smaller parts in it that are specific to the original project it was made for.

@biodiv biodiv closed this as completed Feb 5, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants