[storm] another question regarding inserts

Adrian Klaver aklaver at comcast.net
Tue Aug 7 22:57:06 BST 2007


On Tuesday 07 August 2007 1:33 pm, shawn bright wrote:
> ok
> here is what i have for history
> CREATE TABLE `history` (
>   `id` int(11) NOT NULL auto_increment,
>   `monitor` varchar(25) NOT NULL,
>   `function` varchar(25) NOT NULL,
>   `raw` float NOT NULL default '0',
>   `value` varchar(10) NOT NULL default '0',
>   `date_time` datetime NOT NULL default '0000-00-00 00:00:00',
>   `s_date_time` datetime NOT NULL default '0000-00-00 00:00:00',
>   `sid` varchar(20) default '0',
>   `switch` varchar(20) default '0',
>   PRIMARY KEY  (`id`),
>   KEY `monitor` (`monitor`)
> ) ENGINE=MyISAM AUTO_INCREMENT=32268398 DEFAULT CHARSET=latin1
> AUTO_INCREMENT=32268398 ;
>
>
> and status_hits
> CREATE TABLE `status_hits` (
>   `id` int(11) NOT NULL auto_increment,
>   `status_sensor_id` int(11) default NULL,
>   `raw` int(11) default NULL,
>   `value` varchar(10) default NULL,
>   `date_time` datetime NOT NULL default '0000-00-00 00:00:00',
>   `sensor_time` datetime NOT NULL default '0000-00-00 00:00:00',
>   PRIMARY KEY  (`id`),
>   KEY `sensor_id` (`status_sensor_id`,`date_time`),
>   KEY `date_time` (`date_time`)
> ) ENGINE=MyISAM AUTO_INCREMENT=17061974 DEFAULT CHARSET=latin1
> AUTO_INCREMENT=17061974 ;
>
>
> And the classes
>
> class StatusHit(Storm):
>       __storm_table__ = "status_hits"
>      id = Int(primary = True)
>      status_sensor_id = Int()
>      raw, value = Float(), Unicode()
>      date_time = DateTime()
>      sensor_time = DateTime()
>
>  class HistoryHit(object):
>       __storm_table__ = "history"
>      id = Int(primary = True)
>      monitor, function, value = Unicode(), Unicode(), Unicode()
>      raw = Float()
>      date_time, s_date_time = DateTime(), DateTime()
>      sid, switch = Unicode(), Unicode()
>
> hope this helps
> and thanks for the attention for this.
>
> shawn
>

> > > On 8/7/07, Adrian Klaver <aklaver at comcast.net> wrote:
> > > >  -------------- Original message ----------------------
> > > > From: "shawn bright" <nephish at gmail.com>
> > > >
> > > > > hello again,
> > > > >
> > > > > i have a kinda different problem with and insert function i
> > > > > created.
> > > > >
> > > > > here is the class
> > > > > class HistoryHit(object):
> > > > >     __storm_table__ = "history"
> > > > >     id = Int(primary = True)
> > > > >     monitor, function, value = Unicode(), Unicode(), Unicode()
> > > > >     raw = Float()
> > > > >     date_time, s_date_time = DateTime(), DateTime()
> > > > >     sid, switch = Unicode(), Unicode()
> > > > >
> > > > > here is the function:
> > > > > def make_history(obj, function, s_time = 'none', sid='none',
> > > >
> > > > switch='none'):
> > > > >     print '\n\n make history'
> > > > >     print 'found object %s' % obj.monitor
> > > > >     print 'found raw = %s' % obj.last_raw
> > > > >     print 'type of raw = %s' % type(obj.last_raw)
> > > > >     print 'found value = %s ' % obj.last_value
> > > > >     store = Store.of(obj)
> > > > >     hit = HistoryHit()
> > > > >     hit.monitor = obj.monitor
> > > > >     hit.raw = Float(obj.last_raw)
> > > > >     hit.value = unicode(obj.last_value)
> > > > >     hit.function =  unicode(function)
> > > > >     if s_time == 'none': hit.s_date_time = datetime.datetime.now()
> > > > >     hit.date_time = datetime.datetime.now()
> > > > >     hit.sid, hit.switch = unicode(sid), unicode(switch)
> > > > >     store.add(hit)
> > > > >
> > > > >
> > > > > the lines that call it:
> > > > > status_sensor.last_raw = raw
> > > > > status_sensor.last_value = value
> > > > > status_sensor.last_report = datetime.datetime.now()
> > > > > hit = StatusHit()
> > > > > hit.status_sensor_id = status_sensor.id
> > > > > hit.raw = raw
> > > > > hit.value = value
> > > > > hit.date_time = datetime.datetime.now()
> > > > > hit.sensor_time = sensor_time
> > > > > self.store.add(hit)
> > > > > make_history(status_sensor, 'orbcomm status', s_time = sensor_time)
> > > > >
> > > > > INSERT INTO history (date_time, function, monitor, sid, switch,
> >
> > value)
> >
> > > > > VALUES (%s, %s, %s, %s, %s, %s) (datetime.datetime(2007, 8, 7, 11,
> >
> > 31,
> >
> > > > 8,
> > > >
> > > > > 634691), u'orbcomm status', u'RNKE734X1', u'none', u'none', u'r')
> > > > > SELECT history.id, history.s_date_time FROM history WHERE
> > > > > history.id= 32246084 ()
> > > > >
> > > > >
> > > > >  why isn't raw added to the insert into ?  the rest of the info is
> > > >
> > > > there,
> > > >
> > > > > but the raw is missing, it does show up in the terminal from the
> >
> > print
> >
> > > > > statement though.
> > > > >  why is there a select on history after the insert ? Nothing else
> >
> > really
> >
> > > > > ever calls for it.
> > > > >
> > > > > thanks
> > > > >
> > > > > shawn
> > >
Just a thought but the problem may lie in this line of make_history-
hit.raw = Float(obj.last_raw)
I think you want float(obj.last_raw).
If I am following the logic the value passed to status_sensor.last_raw is an 
integer and in make_history you are changing it to a float to compensate for 
the difference in column types for raw between status_hits and history. 
Float() comes from storm and as Gustavo says does something different.
-- 
Adrian Klaver
aklaver at comcast.net



More information about the storm mailing list