[prog] Converting definitions into 'on the fly' code...

Rasjid Wilcox rasjidw at openminddev.net
Sat May 8 19:26:24 EST 2004


On Friday 07 May 2004 08:37, Conor Daly wrote:
> "Does the sum of minute by minute rainfall amounts equal the hourly
> rainfall value"
>
> as:
>
> rrr[h] = sum(r[0]:r[59])

I have done a simple application that implements this test in a generic and 
extendable way.

The test is written as:
abs(rrr - self.sumOverDate('r', 'minute', hour, -1, 0)) < 0.01

The python code is only 130 lines - which is not long but I was not sure if I 
should post it directly to the list or not, so instead the code and mysql 
test data is at
http://www.openminddev.net/files/python/on_the_fly_formulas/

Feautures:
* New tests can be defined in a single line.

* New 'custom functions' (like the sumOverDate function) are very easy to 
write, and any inbuilt python function (like abs) is automatically available.

Note: No security precautions have been implemented in the code.  New test 
functions should be written by trusted users only.

  -----------

Now, having spent all day playing with someone else's problem[1], I should 
solve some of my own.  :-)

Cheers,

Rasjid.

[1] But it was a fun problem!  The ones I have to deal with at the moment are 
boring.  It is also a good example of why I like Python as a language.

-- 
Rasjid Wilcox
Canberra, Australia (UTC +10 hrs)
http://www.openminddev.net



More information about the Programming mailing list