Permalink
Browse files

made working noaa import again, but it is so slow

  • Loading branch information...
1 parent cac189e commit d376762d57d68c386f11dba15be9fe49432ac588 @jrasky jrasky committed May 24, 2012
Showing with 14 additions and 5 deletions.
  1. +5 −0 geocamLayer/models.py
  2. +3 −1 geocamLayer/noaaExampleParser.py
  3. +6 −4 geocamLayer/quadTree.py
View
5 geocamLayer/models.py
@@ -48,6 +48,8 @@ class Feature(BaseFeature):
name = models.CharField(max_length=80)
description = models.TextField()
cell = models.ForeignKey('QuadTreeCell', null=True, blank=True)
+ # primary key because
+ pkey = models.FloatField(primary_key=True)
def __unicode__(self):
return u'Feature "%s" (%.6f, %.6f)' % (self.name, self.lng, self.lat)
@@ -61,6 +63,7 @@ def randomFeature():
feature.timespan = random.randint(0,3)
feature.name = "Random Feature"
feature.description = "Random Feature"
+ feature.pkey = random.random()
return feature
def getPosition(self): return (self.lng,self.lat)
@@ -147,6 +150,8 @@ def updateStats(self, feature):
self.north = feature.lat
self.count += 1
+ self.save()
+ feature.save()
self.features.add(feature)
def getDiameter(self):
View
4 geocamLayer/noaaExampleParser.py
@@ -5,6 +5,7 @@
# __END_LICENSE__
from geocamLayer.models import Feature
+import random
def parseDegrees(data, positiveDirection):
@@ -41,4 +42,5 @@ def readNoaaWeatherStations(fname):
yield Feature(lat=parseLatitude(stationLatitude),
lng=parseLongitude(stationLongitude),
name=placeName,
- description=countryName)
+ description=countryName,
+ pkey=random.random())
View
10 geocamLayer/quadTree.py
@@ -42,13 +42,15 @@ def addFeature(self, feature):
def addFeatureToCell(self, feature, cell):
cell.updateStats(feature)
+ cell.save()
+ feature.save()
if cell.isLeaf:
feature.cell = cell
self.features.append(feature)
- if not hasattr(cell, 'features'):
- cell.features = []
- cell.features.append(feature)
+ #if not hasattr(cell, 'features'):
+ # cell.features = []
+ cell.features.add(feature)
if cell.count >= MAX_FEATURES_PER_CELL and cell.zoom < MAX_ZOOM - 1:
self.splitCell(cell)
@@ -62,7 +64,7 @@ def addFeatureToZoom(self, feature, zoom):
def splitCell(self, cell):
cell.isLeaf = False
- for feature in cell.features:
+ for feature in cell.features.all():
self.addFeatureToZoom(feature, cell.zoom + 1)
@transaction.commit_manually

0 comments on commit d376762

Please sign in to comment.