Re: [Zope] Re: Accumulate vars with dtml-var expr=...

2006-08-08 Thread Gabriel Genellina

At Tuesday 8/8/2006 15:53, mbr wrote:


I made this in my report:

dtml-call expr=REQUEST.set('accu',0)
dtml-in aZSQLMethod
   dtml-call expr=REQUEST.set('accu', accu + fieldvalue)
   dtml-var fieldvalue dtml-var accu
/dtml-in

return this:
VAL   ACCU
15   15
20   35
18   53

hope it can help you


- Please keep your postings on the list, don't write to me directly
- I'm not the interested person, I was one of the guys answering the question
- This does not answer the original question that was about 
accumulating the remaining values
- Using DTML as a procedural language to compute some values like 
this, is not the recommended practice.




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 )


[Zope] Re: Accumulate vars with dtml-var expr=...

2006-07-25 Thread Jesper Steen Steffensen
I have a table with a list of values. To list my values in a dtmlmethod i write dtml-var value inside the appropriate dtml-in tag.
In the next column I have the dtml-var sequence-numberI want to accumulate my values so the result will be:Is it possible to make this accumulated value as adtml-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.Gabriel GenellinaSoftlab SRLCan 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! :-)
___
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 )


Re: [Zope] Re: Accumulate vars with dtml-var expr=...

2006-07-25 Thread Gabriel Genellina

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 )