Forum: Ruby on Rails Find condition calculation

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
30f3084a34f811f9262394ed31ca2e24?d=identicon&s=25 Paul Nichols (pcdj)
on 2007-07-12 11:12
I'm trying to do a find with a particular condition.

I have a runs table with a n_passed_steps column and an n_failed_steps
column.

I'm trying to do a find, to find all records, limited to the last 10,
ordered by descending id, but with a pass percentage rate greater than
50%.

So i've got the :all, :limit => 10, :order => 'id DESC' bit, it's just
the :conditions bit I'm struggling with.

The calculation is ((n_passed_steps/(n_passed_steps + n_failed_steps)) *
100) > 50 but if I simply insert that after :conditions, whether it be
in 'quotes' or [square brackets] I get an error.

What is the correct way to go about this?
3203ed0e608d3bfae1e31282e629ffa2?d=identicon&s=25 Peter Fitzgibbons (Guest)
on 2007-07-12 15:50
(Received via mailing list)
HI Paul,

What's your error?  Also, post to us the dbms you're using and maybe the
schema of your table (migration?) and the snippet being used for the
find.

We need more info in order to effectively help you!

Regards,

--
Peter Fitzgibbons
------------------------------
iPhone -- "IT"-ness.
href=
http://www.macdailynews.com/index.php/weblog/comme...
------------------------------
Ef3aa7f7e577ea8cd620462724ddf73b?d=identicon&s=25 Rob Biedenharn (Guest)
on 2007-07-12 17:31
(Received via mailing list)
On Jul 12, 2007, at 5:12 AM, Paul Nichols wrote:
> the :conditions bit I'm struggling with.
>
> The calculation is ((n_passed_steps/(n_passed_steps +
> n_failed_steps)) *
> 100) > 50 but if I simply insert that after :conditions, whether it be
> in 'quotes' or [square brackets] I get an error.
>
> What is the correct way to go about this?

Don't try so hard:

   :conditions => 'n_passed_steps > n_failed_steps'

-Rob

Rob Biedenharn    http://agileconsultingllc.com
Rob@AgileConsultingLLC.com
30f3084a34f811f9262394ed31ca2e24?d=identicon&s=25 Paul Nichols (pcdj)
on 2007-07-13 10:51
Rob Biedenharn wrote:
> On Jul 12, 2007, at 5:12 AM, Paul Nichols wrote:
>> the :conditions bit I'm struggling with.
>>
>> The calculation is ((n_passed_steps/(n_passed_steps +
>> n_failed_steps)) *
>> 100) > 50 but if I simply insert that after :conditions, whether it be
>> in 'quotes' or [square brackets] I get an error.
>>
>> What is the correct way to go about this?
>
> Don't try so hard:
>
>    :conditions => 'n_passed_steps > n_failed_steps'
>
> -Rob
>
> Rob Biedenharn    http://agileconsultingllc.com
> Rob@AgileConsultingLLC.com

That's so obvious now you mention it!

However... the 50% figure was just as an example. Say I wanted to set
the pass rate to something else?
Ef3aa7f7e577ea8cd620462724ddf73b?d=identicon&s=25 Rob Biedenharn (Guest)
on 2007-07-13 13:34
(Received via mailing list)
On Jul 13, 2007, at 4:51 AM, Paul Nichols wrote:
>>> What is the correct way to go about this?
> That's so obvious now you mention it!
>
> However... the 50% figure was just as an example. Say I wanted to set
> the pass rate to something else?

Assuming:  0..100 === pass_rate,

   :conditions => [ '(100.0 * n_passed_steps)/(n_passed_steps +
n_failed_steps) > ?',
                    pass_rate ]

-Rob

Rob Biedenharn    http://agileconsultingllc.com
Rob@AgileConsultingLLC.com
This topic is locked and can not be replied to.