# Find condition calculation

**URL:** <https://www.ruby-forum.com/t/find-condition-calculation/109198>\
**Category:** Rails\
**Created:** [July 12, 2007, 11:12am UTC](https://www.ruby-forum.com/t/find-condition-calculation/109198 "2007-07-12T11:12:07Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![nanouk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/da6949/32.png) [@nanouk](https://www.ruby-forum.com/u/nanouk)\
**Post date:** [July 12, 2007, 11:12am UTC](https://www.ruby-forum.com/t/find-condition-calculation/109198/1 "2007-07-12T11:12:07Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![nanouk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/da6949/32.png) [@nanouk](https://www.ruby-forum.com/u/nanouk)\
**Post date:** [July 12, 2007, 3:50pm UTC](https://www.ruby-forum.com/t/find-condition-calculation/109198/2 "2007-07-12T15:50:16Z")

</div>

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 F.

## iPhone – “IT”-ness. href= [Apple’s iPhone could become iconic ‘It Object’ - MacDailyNews](http://www.macdailynews.com/index.php/weblog/comments/apples_iphone_could_become_iconic_it_object)

---

<div class="post-metadata">

**Author:** ![nanouk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/da6949/32.png) [@nanouk](https://www.ruby-forum.com/u/nanouk)\
**Post date:** [July 12, 2007, 5:31pm UTC](https://www.ruby-forum.com/t/find-condition-calculation/109198/3 "2007-07-12T17:31:36Z")

</div>

On Jul 12, 2007, at 5:12 AM, Paul N. 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 B. [http://agileconsultingllc.com](http://agileconsultingllc.com)  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![nanouk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/da6949/32.png) [@nanouk](https://www.ruby-forum.com/u/nanouk)\
**Post date:** [July 13, 2007, 10:51am UTC](https://www.ruby-forum.com/t/find-condition-calculation/109198/4 "2007-07-13T10:51:02Z")

</div>

Rob B. wrote:

> On Jul 12, 2007, at 5:12 AM, Paul N. 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 B. [http://agileconsultingllc.com](http://agileconsultingllc.com)  
> removed\_email\_address@domain.invalid

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?

---

<div class="post-metadata">

**Author:** ![nanouk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/da6949/32.png) [@nanouk](https://www.ruby-forum.com/u/nanouk)\
**Post date:** [July 13, 2007, 1:34pm UTC](https://www.ruby-forum.com/t/find-condition-calculation/109198/5 "2007-07-13T13:34:13Z")

</div>

On Jul 13, 2007, at 4:51 AM, Paul N. 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 B. [http://agileconsultingllc.com](http://agileconsultingllc.com)  
removed\_email\_address@domain.invalid
