At Tuesday 25/7/2006 20:21, Jesper Steen Steffensen wrote:

>I have a table with a list of values. To list my values in a dtml
>method i write <dtml-var value> inside the appropriate dtml-in tag.
>In the next column I have the <dtml-var sequence-number>
>
>I want to accumulate my values so the result will be:
>
>Is it possible to make this accumulated value as a
><dtml-var expr="[something like sum of values where seq-num <=seq-num]">

Write a simple python script. Input=original list of values.
Output=list of (value, accum). Iterate the result with dtml-in as before.


Can you pls explain it a bit more in detail - afraid I'm still a bit new to Zope and dtml/python. What would the Script (Python) look like?
Thanks for your help! :-)

This is a pure programming exercise. You said:

VALUE SEQNUMBER
13 1
10 2
11 3
10 4
12 5
...

I want to accumulate my values so the result will be:

VALUE SEQNUMBER ACCU
13 1 56
10 2 43
11 3 33
10 4 22
12 5 12

So apparently you need to accumulate the *remaining* values. The script would receive a list of values: [13,10,11,10,12] and return a list of tuples [(13,56),(10,43),(11,33)...]
A pure python function would look like this:

def accumulate_remaining(values):
    values = map(float, values) # make sure they are true numbers
    result = []
    for i in range(len(values)):
        result.append((values[i], sum(values[i:])))
    return result

To convert it to a "Script (Python)": create the script, name it as the function, leave out the "def" line and put the body inside the script, declare a single parameter "values". Then use <dtml-in "accumulate_remaining(your_list_of_values)"> and inside it, <dtml-var "sequence-item[0]"> <dtml-var "sequence-item[1]"> or something like that. This has not been tested but should work. The dtml syntax may be wrong, tough, I dont use dtml anymore.



Gabriel Genellina
Softlab SRL

        
        
                
__________________________________________________
Preguntá. Respondé. Descubrí.
Todo lo que querías saber, y lo que ni imaginabas,
está en Yahoo! Respuestas (Beta).
¡Probalo ya! http://www.yahoo.com.ar/respuestas

_______________________________________________
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - http://mail.zope.org/mailman/listinfo/zope-announce
http://mail.zope.org/mailman/listinfo/zope-dev )

Reply via email to