[storm] question about relationships
shawn bright
nephish at gmail.com
Mon Aug 6 22:40:34 BST 2007
hello there, i am wondering what i may be doing wrong here.
i have a pair of classes in a module called storm_rain.py
from storm.locals import *
class VoltSensor(Storm):
__storm_table__ = "volt_sensors"
id = Int(primary=True, default = AutoReload)
monitor = Unicode()
adder, multiplier = Float(), Float()
last_value, last_raw, last_page = Float(), Float(), Float()
enable, error, alias = Unicode(), Unicode(), Unicode()
x, y, one_day_rain_total = Float(), Float(), Float()
last_report, last_page_time = DateTime(), DateTime()
volt_hits = ReferenceSet(id, "VoltHit.volt_sensor_id")
class VoltHit(Storm):
__storm_table__ = "rain_hits"
id = Int(primary=True)
volt_sensor_id = Int()
raw, value = Float(), Float()
date_time = DateTime()
now, i run this in a thread that reads information in as the sensors report
in, and we update the current value of the sensor
and create a record of the report. ( hit = report )
i have tried a few things. i mostly need in this thread for the RainSensor
to have updated the last raw, last value, and last report ( it's the time of
the report )
no problem..
the problem is when i starts to create the VoltHit. the debug info that
shows the queries output shows that it is always trying to create another
VoltSensor, but with the attributes of a VoltHit. for example:
print 'update v-sensor values'
volt_sensor.last_raw = raw
volt_sensor.last_value = value
volt_sensor.last_report = datetime.datetime.now()
print 'create the data hit'
# log into history
hit = VoltageHit()
hit.volt_sensor_id = volt_sensor.id
hit.raw, hit.value = raw, value
hit.date_time = datetime.datetime.now()
self.store.add(hit)
i have also tried
volt_sensor.volt_hits.add(hit)
both fail with an error 'no field date_time in fields list'
the debug shows the sql trying to create the VoltSensor with VoltHit
attributes.
like so:
Insert into volt_sensors ( date_time, raw, value, volt_sensor_id) Values (
datetime.datetime (yadda yadda), 23.3, 27.8, 3455)
i did manage to make it work like this, but this is kinda the reason i was
trying to move more towards storm than just SQL.
query = "insert into voltage_hits set \
`volt_sensor_id` = '"+str(volt_sensor.id)+"' ,\
`raw` = '"+str(raw)+"' ,\
`value` = '"+str(value)+"' ,\
`date_time` = '"+str(datetime.datetime.now())+"' "
self.store.execute(query)
i only have self.store.commit() in here once.
and i have other types of sensors that are processed in the same thread loop
( rain_sensors, current_sensors, status_sensors, etc... each with their own
'hits' table ( rain_hits, status_hits, etc.. ) so there are usually a lot of
objects floating around in the store before a commit is issued.
any idea what i am doing wrong? or a better practice that could prevent
these?
thanks
shawn
-------------- next part --------------
An HTML attachment was scrubbed...
URL: https://lists.ubuntu.com/archives/storm/attachments/20070806/18b815f3/attachment.htm
More information about the storm
mailing list