[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Maintaining running values between paginator pages

Tim

6/25/2006 7:07:00 PM

I'm at a loss for how to do this and I'm wondering if there is a way
without getting too complicated.

I'm using Rails 1.8.4, MYSQL 5 and AjaxScaffold.

I have accounts and every account has many (variable) months' worth of
data. I can easily pull up the account and then pull up the many
months of data no problem.

Each month has a dollar invested column and a percentage return
column. I have created a cumulative return column which is just the
following formula

@@unit_value = 100

def unit_value
if mymonthend == inception
@@unit_value = 100.to_f
else
@@unit_value =
@@unit_value*(1+Float(read_attribute("before_fee_return")))
end
end



cum_return = cum_return * (1+ percent_return)

It's basically a quick formula for showing the account's cumullative
performance over time.

The problem is each time I go to a new page, the cumulative return is
reset to 100. I want it to pick up where the last page left off. I
thought about putting the final cum return in a session variable but
that won't work if the user skips a page or goes back a page.

Is there any way to do this? Do I need to pass every month and every
cum return to a session variable array and look up the values every
time? Is that the only way to do it?

Right now I'm cheating by forcing all the data to show up on a page
but two things are wrong with this: 1) some accounts have hundreds of
months' worth of data; 2) for accounts with a lot of data it takes too
long to load a page.

Thanks in advance
8 Answers

neleai@seznam.cz

6/26/2006 9:15:00 AM

0


Tim wrote:
> I'm at a loss for how to do this and I'm wondering if there is a way
> without getting too complicated.
>
> I'm using Rails 1.8.4, MYSQL 5 and AjaxScaffold.
>
> I have accounts and every account has many (variable) months' worth of
> data. I can easily pull up the account and then pull up the many
> months of data no problem.
>
> Each month has a dollar invested column and a percentage return
> column. I have created a cumulative return column which is just the
> following formula
>
> @@unit_value = 100
>
> def unit_value
> if mymonthend == inception
> @@unit_value = 100.to_f
> else
> @@unit_value =
> @@unit_value*(1+Float(read_attribute("before_fee_return")))
> end
> end
>
>
>
> cum_return = cum_return * (1+ percent_return)
>
> It's basically a quick formula for showing the account's cumullative
> performance over time.
>

I would recompute returns from first month by
cum_return[0]=1
months.each {|i| cum_returns[i] = cum_returns[i-1] * (1+
percent_return[i])}
and then you can compute return in interval as
def cum_ret(from,to) cum_returns[to] / cum_returns[from-1] end

Kenosis

6/26/2006 6:45:00 PM

0

Interesting approach but won't this under flow the array bounds on the
first month, ie, i=0 to start and cum_returns[i-1] would end up
mapping, as I recall, to cum_returns[cum_returns.size-1]? You'll need
to correct for this, I think, by skipping the first month or indexing
by i+1 and then stopping the each iteration a month early. (Hope I'm
not smoking crack here :)

Ken

neleai@seznam.cz wrote:
> Tim wrote:
> > I'm at a loss for how to do this and I'm wondering if there is a way
> > without getting too complicated.
> >
> > I'm using Rails 1.8.4, MYSQL 5 and AjaxScaffold.
> >
> > I have accounts and every account has many (variable) months' worth of
> > data. I can easily pull up the account and then pull up the many
> > months of data no problem.
> >
> > Each month has a dollar invested column and a percentage return
> > column. I have created a cumulative return column which is just the
> > following formula
> >
> > @@unit_value = 100
> >
> > def unit_value
> > if mymonthend == inception
> > @@unit_value = 100.to_f
> > else
> > @@unit_value =
> > @@unit_value*(1+Float(read_attribute("before_fee_return")))
> > end
> > end
> >
> >
> >
> > cum_return = cum_return * (1+ percent_return)
> >
> > It's basically a quick formula for showing the account's cumullative
> > performance over time.
> >
>
> I would recompute returns from first month by
> cum_return[0]=1
> months.each {|i| cum_returns[i] = cum_returns[i-1] * (1+
> percent_return[i])}
> and then you can compute return in interval as
> def cum_ret(from,to) cum_returns[to] / cum_returns[from-1] end

Tim

6/29/2006 2:17:00 AM

0

Thanks for the tip. It's helping me begin to think "in Ruby" which is
really a new way tothink problems out.

neleai@seznam.cz wrote:

>
>Tim wrote:
>> I'm at a loss for how to do this and I'm wondering if there is a way
>> without getting too complicated.
>>
>> I'm using Rails 1.8.4, MYSQL 5 and AjaxScaffold.
>>
>> I have accounts and every account has many (variable) months' worth of
>> data. I can easily pull up the account and then pull up the many
>> months of data no problem.
>>
>> Each month has a dollar invested column and a percentage return
>> column. I have created a cumulative return column which is just the
>> following formula
>>
>> @@unit_value = 100
>>
>> def unit_value
>> if mymonthend == inception
>> @@unit_value = 100.to_f
>> else
>> @@unit_value =
>> @@unit_value*(1+Float(read_attribute("before_fee_return")))
>> end
>> end
>>
>>
>>
>> cum_return = cum_return * (1+ percent_return)
>>
>> It's basically a quick formula for showing the account's cumullative
>> performance over time.
>>
>
>I would recompute returns from first month by
>cum_return[0]=1
>months.each {|i| cum_returns[i] = cum_returns[i-1] * (1+
>percent_return[i])}
>and then you can compute return in interval as
>def cum_ret(from,to) cum_returns[to] / cum_returns[from-1] end

Frontenac

11/17/2010 5:01:00 PM

0

"D.A.Tsenuf" <DA@Tsenuf.com> a ?crit dans le message de
news:v4mdnYlQuqH0SH_RnZ2dnUVZ_vudnZ2d@bright.net...
> Et pourtant, bien avant que les separa-tatas sevissent, et que ca soit
> illegal, j'ai ete 3 ans dans une garderie trilingue.

Pauvre Peter, tu changeras jamais...

Frontenac

11/17/2010 5:04:00 PM

0

"D.A.Tsenuf" <DA@Tsenuf.com> a ?crit dans le message de Et pourtant, bien
avant que les separa-tatas sevissent, et que ca soit
> illegal, j'ai ete 3 ans dans une garderie trilingue.

Et on voit les rt?sultats...

Frontenac

D. A. Tsenuf

11/17/2010 9:56:00 PM

0

"Frontenac" <Le_Verseau@Qu?bec.monpays.qc> wrote in message
news:cWTEo.33070$3f.23933@newsfe12.iad...
> "D.A.Tsenuf" <DA@Tsenuf.com> a ?crit dans le message de Et pourtant,
> bien avant que les separa-tatas sevissent, et que ca soit
>> illegal, j'ai ete 3 ans dans une garderie trilingue.
>
> Et on voit les rt?sultats...
>

Mes "r?sultats" aux moins n'etaient pas TES "rt?sultats".

Et merci de la demonstration de betise de ta part que tu a eu besoin de
repondre 2 fois au meme post avec des repliques differentes, mais dans le
meme bas niveau de connerie.
Au moins, t'es consistant.

D. A. Tsenuf

11/17/2010 11:31:00 PM

0

"Frontenac" <Le_Verseau@Qu?bec.monpays.qc> wrote in message
news:VTTEo.3151$663.2486@newsfe01.iad...
> "D.A.Tsenuf" <DA@Tsenuf.com> a ?crit dans le message de
> news:v4mdnYlQuqH0SH_RnZ2dnUVZ_vudnZ2d@bright.net...
>> Et pourtant, bien avant que les separa-tatas sevissent, et que ca soit
>> illegal, j'ai ete 3 ans dans une garderie trilingue.
>
> Pauvre Peter, tu changeras jamais...
Et toi, t'es toujours aussi sot, pauvre 'seau.
Pourquoi donc devrais-je changer ?
C'etait une garderie organisee par des Soeurs Hongroises pour:
1) garder les enfants de famillles Hongroises qui voulaient enseigner
l'Hongrois a leurs enfants,
2) apprendre aux enfants les bases de l'Anglais et du Francais en meme
temps.
La garderie etait sur la rue Ste-Famille entre Milton et Prince Arthur.

La prochaine fois, reflechis AVANT des poster une des conneries usuelles.





ti-coune

11/18/2010 12:09:00 AM

0


"jeannot" <gilles.jean@yahoo.ca> a ?crit dans le message de news:
280c54e2-abe8-419c-ac7b-9bdf3c931a40@s4g2000yql.googlegroups.com...
Et pourquoi pas des garderies "bilingues"? Quant ? faire, des
pouponni?res bilingues!

Oui, au bilinguisme et au trilinguisme individuel!


Je suis en faveur de l'accouchement unilingue anglais.
--
ti-coune