Richard Shea avatar Richard Shea committed cf3e0e4

Now able to load wind data

Comments (0)

Files changed (2)


 from dcdemo.apps.dmodrv.models import City   
 from dcdemo.apps.dmodrv.models import Station
-from dcdemo.apps.dmodrv.models import Observation
 from dcdemo.apps.dmodrv.models import WindObservation
 from dcdemo.apps.dmodrv.models import TemperatureObservation
 from django.conf import settings
 from decimal import Decimal
+from datetime import datetime
 STATIONDATAPATH = """/home/rshea/dev/djchdemo/data/weatherstationdata.csv"""
-WINDDATAPATH = """/home/rshea/dev/djchdemo/data/worldcitiespop.txt"""
-TEMPDATAPATH = """/home/rshea/dev/djchdemo/data/worldcitiespop.txt"""
+WINDDATAPATH = """/home/rshea/dev/djchdemo/data/wind.csv"""
+TEMPDATAPATH = """/home/rshea/dev/djchdemo/data/screen.csv"""
 def removeLineFeed(line):
     Removes line feeds from the argument supplied
     Name,Agent Number,Network Number,Latitude (dec.deg),Longitude (dec.deg),Height (m),Posn_Precision,Observing Authority
     lstData = line_from_file.split(",")
-    import pprint
-    pprint.pprint(lstData)
     nam = lstData[0]
     lat = Decimal(lstData[3])
     lng = Decimal(lstData[4])
     s = Station(name=nam, longitude=lng, latitude=lat, height_in_m=ht)
+def processWindData(line_from_file, notUsed):
+    '''
+    Station,Date(NZST),Dir(DegT),Speed(km/hr),Dir StdDev,Spd StdDev,Period(Hrs),Freq
+    '''
+    lstData = line_from_file.split(",")
+    s = Station.objects.get(name=lstData[0])
+    dt= datetime.strptime(lstData[1] , '%Y%m%d:%H%M') 
+    dirctn = Decimal(lstData[2])
+    spd_kmh = Decimal(lstData[3])
+    wo = WindObservation(station=s, when=dt, speed=spd_kmh, direction=dirctn)
 def populateAbstract(pathToData, lineProcessingFunction, lpfArg0=None):
     Opens file on specified path, ignores first line and then
                 lstOut.append(lineProcessingFunction(line, lpfArg0))
     return lstOut
+def populateWindObservations(pathToWindData):
+    '''
+    Invokes populateAbstract to process the input data
+    defined in the file at 'pathToStationData'
+    '''
+    populateAbstract(pathToWindData, processWindData)
 def populateStations(pathToStationData):
     Invokes populateAbstract to process the input data
 def main():
     lstStations = populateStations(STATIONDATAPATH)
+    lstWindObs = populateWindObservations(WINDDATAPATH)
 if __name__ == '__main__':


     latitude = models.DecimalField("latitude", default=0, max_digits=9, decimal_places=5)
     height_in_m = models.DecimalField("height in metres", default=0, max_digits=6, decimal_places=2) 
-class Observation(models.Model):
-    name = models.CharField("station name", max_length=200)
-    when = models.DateTimeField()
 class WindObservation(models.Model):
     station = models.ForeignKey(Station)
-    observation = models.ForeignKey(Observation)
+    when = models.DateTimeField()
     speed = models.DecimalField("speed (km/h)", default=0, max_digits=6, decimal_places=3)
     direction = models.IntegerField("direction", default=0)
 class TemperatureObservation(models.Model):
     station = models.ForeignKey(Station)
-    observation = models.ForeignKey(Observation)
+    when = models.DateTimeField()
     air = models.DecimalField("air", default=0, max_digits=6, decimal_places=3)
     wet = models.DecimalField("wet", default=0, max_digits=6, decimal_places=3)
     relative_humidity = models.DecimalField("air", default=0, max_digits=6, decimal_places=3)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.