On Thursday 07 February 2008 13:34:16 Oleg Broytmann wrote: > On Thu, Feb 07, 2008 at 01:18:33PM -0600, Christopher Singley wrote: > > > I mean "dynamical system" where the state of the system is a function > > > of time. I need a function which accepts a time variable as an input, > > > and returns a state. > > > > > > Consider exchange-traded securities (e.g. stocks). An important > > > attribute of a stock is its price. Stock trading prices are a time > > > series of discrete points. Yahoo Finance, among others, persists > > > series of prices and allows users to look them up by time. That's the > > > kind of thing I'm talking about: > > > > So then: > > class SecurityState(SQLObject): > > parent = ForeignKey('Security') > > date = DateCol() > > price = DecimalCol(size=10, precision=4) > > > > class Security(SQLObject): > > states = MultipleJoin('SecurityState', joinColumn='parent_id') > > > > Why define a separate class for security? So that Security.id can be > > used as a foreign key in other tables. For example: > > > > class SecurityTransaction(SQLObject): > > time = DateTimeCol() > > price = DecimalCol(size=10, precision=4) > > security = ForeignKey('Security') > > > > Is there a better way of representing data like this in SQL/SQLObject? > > I don't think so, and I think you scheme is very good for the task. > > Oleg.
Well, as I wrote in my original email on this thread, I am trying to solve this problem in a generic way, then subclass it. It is verbose & error-prone to keep writing the ForeignKey/MultipleJoin, when there's an easy rule to predict what is needed ahead of time. Any ideas for a more elegant solution? If anybody's interested, and it will help to specify the problem, I've attached the actual code I'm writing (warning - probably still contains errors). I'm talking about the DynamicState and DynamicSQLObject classes, which are themselves subclasses of simpler classes I wrote to implement user-friendly lookup & merge functionality. These are very general classes helping me in the way I use SQLObject to make things. If they are of any use to anybody else, you are welcome to use them, as long as you don't try to hold me responsible for any consequences. Feedback is of course appreciated. Sorry if the comments in the code are extremely verbose, but that's the way I do things since I'm not an experienced programmer. TIA, cs
sqlobjectextensions.py
Description: application/python
------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________ sqlobject-discuss mailing list sqlobject-discuss@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss