# Help with equation in ruby

**URL:** <https://discuss.elastic.co/t/help-with-equation-in-ruby/267172>\
**Category:** Logstash\
**Created:** [March 14, 2021, 2:24am UTC](https://discuss.elastic.co/t/help-with-equation-in-ruby/267172 "2021-03-14T02:24:58Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sketchy](https://avatars.discourse-cdn.com/v4/letter/s/258eb7/32.png) [@Sketchy](https://discuss.elastic.co/u/Sketchy)\
**Post date:** [March 14, 2021, 2:24am UTC](https://discuss.elastic.co/t/help-with-equation-in-ruby/267172/1 "2021-03-14T02:24:58Z")

</div>

I'm doing some calculations in ruby and works well when doing basic stuff like subtracting a from b but I have something a little more complex that I just cant get the syntax right or work out the most efficient way to do this.

In our previous reporting system we basically do the below formula to calculate "Service Level" I'm really stuck trying to do this correctly in ruby.

> ServiceLevel = (CallsAnswered + CallsAbandoned) – (CallsAnsweredAftThreshold + CallsAbandonedAftThreshold) / (CallsAnswered + CallsAbandoned) x 100

---

<div class="post-metadata">

**Author:** ![Badger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/badger/32/25190_2.png) [@Badger](https://discuss.elastic.co/u/Badger)\
**Post date:** [March 14, 2021, 2:43pm UTC](https://discuss.elastic.co/t/help-with-equation-in-ruby/267172/2 "2021-03-14T14:43:14Z")

</div>

What have you tried? You will need to event.get each of the values and probably .to\_f some of the values if you do not want integer arithmetic.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [April 11, 2021, 2:43pm UTC](https://discuss.elastic.co/t/help-with-equation-in-ruby/267172/3 "2021-04-11T14:43:42Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
