# How to do prediction using dates in ignition

**URL:** <https://forum.inductiveautomation.com/t/how-to-do-prediction-using-dates-in-ignition/50727>\
**Category:** Ignition\
**Created:** [September 8, 2021, 5:34pm UTC](https://forum.inductiveautomation.com/t/how-to-do-prediction-using-dates-in-ignition/50727 "2021-09-08T17:34:14Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![prasath.t](https://avatars.discourse-cdn.com/v4/letter/p/898d66/32.png) [@prasath.t](https://forum.inductiveautomation.com/u/prasath.t)\
**Post date:** [September 8, 2021, 5:34pm UTC](https://forum.inductiveautomation.com/t/how-to-do-prediction-using-dates-in-ignition/50727/1 "2021-09-08T17:34:14Z")

</div>

Hi,

I have a value b = 500 created in table with date 07/01/2020  
i have value 600

if my b value reaches greater than 600  
i want to find the exact date when my value changed  
how to do my predicition

can any one give me script or idea please

---

<div class="post-metadata">

**Author:** ![andrews](https://avatars.discourse-cdn.com/v4/letter/a/898d66/32.png) [@andrews](https://forum.inductiveautomation.com/u/andrews)\
**Post date:** [September 8, 2021, 5:37pm UTC](https://forum.inductiveautomation.com/t/how-to-do-prediction-using-dates-in-ignition/50727/2 "2021-09-08T17:37:45Z")

</div>

You need to be more descriptive. How does value b change?

For instance you could track it in your audit log possibly.

Or the ideal way would to be create an alarm for b. And set a notification pipeline to inform you when it triggers.

What is value b?  
how does value b change?  
How do you need to track or be notified of value b changing?

---

<div class="post-metadata">

**Author:** ![prasath.t](https://avatars.discourse-cdn.com/v4/letter/p/898d66/32.png) [@prasath.t](https://forum.inductiveautomation.com/u/prasath.t)\
**Post date:** [September 8, 2021, 5:41pm UTC](https://forum.inductiveautomation.com/t/how-to-do-prediction-using-dates-in-ignition/50727/3 "2021-09-08T17:41:06Z")

</div>

value b will change according to my calculation

i am doing a calculation like example  
pervious record date = 07/01/2020  
insterting record date = 08/0/2020  
difference between the record is 30 days and i adding and dividing some value so b value change  
like wise i am while inserting b value change for each row

but i want to find the when b value will became greater then 500 (note: 500 is constant)  
is there any way to run loop until my exact date is found?

---

<div class="post-metadata">

**Author:** ![prasath.t](https://avatars.discourse-cdn.com/v4/letter/p/898d66/32.png) [@prasath.t](https://forum.inductiveautomation.com/u/prasath.t)\
**Post date:** [September 8, 2021, 5:44pm UTC](https://forum.inductiveautomation.com/t/how-to-do-prediction-using-dates-in-ignition/50727/4 "2021-09-08T17:44:11Z")

</div>

my idea is currrent date is 07/01/2020  
if i add one year 07/01/2021  
difference in date is 365 days and some calculation to get b value

i will check b \> 500 or not  
if it is greater than i have to check which month and week and date exactly b value change

how to run loop for this one?

i want to insert record which date when b value change… until that i have to run loop and check

---

<div class="post-metadata">

**Author:** ![andrews](https://avatars.discourse-cdn.com/v4/letter/a/898d66/32.png) [@andrews](https://forum.inductiveautomation.com/u/andrews)\
**Post date:** [September 8, 2021, 5:47pm UTC](https://forum.inductiveautomation.com/t/how-to-do-prediction-using-dates-in-ignition/50727/5 "2021-09-08T17:47:13Z")

</div>

Would you be able to post your code. It’s very hard since I don’t know what your math is like.

Again, if you want to know when b reaches this value. make b a tag and setup and alarm for it.

what do you want to happen when said date is found?

---

<div class="post-metadata">

**Author:** ![prasath.t](https://avatars.discourse-cdn.com/v4/letter/p/898d66/32.png) [@prasath.t](https://forum.inductiveautomation.com/u/prasath.t)\
**Post date:** [September 8, 2021, 5:50pm UTC](https://forum.inductiveautomation.com/t/how-to-do-prediction-using-dates-in-ignition/50727/6 "2021-09-08T17:50:49Z")

</div>

`Max A * Temperature ^ Max B * (Time Actual - Time n-1)/365`

this is the formula… i will get max a and max b and temperature value from tag … difference between the time 30 days for example and divide by 365  
i will get b value

i want to run the loop and until b\> 500

note : 500 is constant

then only i want to insert record to table

---

<div class="post-metadata">

**Author:** ![prasath.t](https://avatars.discourse-cdn.com/v4/letter/p/898d66/32.png) [@prasath.t](https://forum.inductiveautomation.com/u/prasath.t)\
**Post date:** [September 8, 2021, 5:52pm UTC](https://forum.inductiveautomation.com/t/how-to-do-prediction-using-dates-in-ignition/50727/7 "2021-09-08T17:52:22Z")

</div>

when date is found i want to insert record to tabel

---

<div class="post-metadata">

**Author:** ![prasath.t](https://avatars.discourse-cdn.com/v4/letter/p/898d66/32.png) [@prasath.t](https://forum.inductiveautomation.com/u/prasath.t)\
**Post date:** [September 8, 2021, 5:53pm UTC](https://forum.inductiveautomation.com/t/how-to-do-prediction-using-dates-in-ignition/50727/8 "2021-09-08T17:53:43Z")

</div>

i don’t know how to run loop to check the condition… which exact date is b value changing

i want to predict it this date the value b value becomes greater than 500

please help me out in this… to check this condtion

---

<div class="post-metadata">

**Author:** ![andrews](https://avatars.discourse-cdn.com/v4/letter/a/898d66/32.png) [@andrews](https://forum.inductiveautomation.com/u/andrews)\
**Post date:** [September 8, 2021, 5:55pm UTC](https://forum.inductiveautomation.com/t/how-to-do-prediction-using-dates-in-ignition/50727/9 "2021-09-08T17:55:23Z")

</div>

see this article [https://docs.inductiveautomation.com/display/DOC79/Conditions+and+Loops](https://docs.inductiveautomation.com/display/DOC79/Conditions+and+Loops)

it explains scripting if conditions in ignition.

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [September 9, 2021, 9:42am UTC](https://forum.inductiveautomation.com/t/how-to-do-prediction-using-dates-in-ignition/50727/10 "2021-09-09T09:42:51Z")

</div>

> [@andrews](#):
>
> make b a tag and setup and alarm for it

Imo an alarm should be an alarm, not used for other things. I would make it a tag and use a tag change event handler to check its value.

I'm still quite confused what the end goal is though. I'll have a better read in a bit and come back to this

---

<div class="post-metadata">

**Author:** ![prasath.t](https://avatars.discourse-cdn.com/v4/letter/p/898d66/32.png) [@prasath.t](https://forum.inductiveautomation.com/u/prasath.t)\
**Post date:** [September 9, 2021, 9:56am UTC](https://forum.inductiveautomation.com/t/how-to-do-prediction-using-dates-in-ignition/50727/11 "2021-09-09T09:56:09Z")

</div>

yaa please read my all post. you will uunderstand

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [September 9, 2021, 9:58am UTC](https://forum.inductiveautomation.com/t/how-to-do-prediction-using-dates-in-ignition/50727/12 "2021-09-09T09:58:49Z")

</div>

What is the purpose of what you’re trying to do ?

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [September 9, 2021, 9:59am UTC](https://forum.inductiveautomation.com/t/how-to-do-prediction-using-dates-in-ignition/50727/13 "2021-09-09T09:59:32Z")

</div>

I’ve read everything and I’m still not sure I understand…

Let me try, though:  
You have a variable that depends on a date/time, and you want to process that variable with an expression/formula to predict when that variable will reach a certain value, and insert that date/time into your database.  
Is that correct ?

---

<div class="post-metadata">

**Author:** ![prasath.t](https://avatars.discourse-cdn.com/v4/letter/p/898d66/32.png) [@prasath.t](https://forum.inductiveautomation.com/u/prasath.t)\
**Post date:** [September 9, 2021, 10:10am UTC](https://forum.inductiveautomation.com/t/how-to-do-prediction-using-dates-in-ignition/50727/14 "2021-09-09T10:10:48Z")

</div>

exactly thats is what i want

---

<div class="post-metadata">

**Author:** ![prasath.t](https://avatars.discourse-cdn.com/v4/letter/p/898d66/32.png) [@prasath.t](https://forum.inductiveautomation.com/u/prasath.t)\
**Post date:** [September 9, 2021, 10:16am UTC](https://forum.inductiveautomation.com/t/how-to-do-prediction-using-dates-in-ignition/50727/15 "2021-09-09T10:16:33Z")

</div>

predict the value change… its furnace module… so i want to predict the coating change in future. in which date coating is changing one coating to another

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [September 9, 2021, 12:20pm UTC](https://forum.inductiveautomation.com/t/how-to-do-prediction-using-dates-in-ignition/50727/16 "2021-09-09T12:20:53Z")

</div>

Do you already have a linear approximation model or similar for predicting future temps based on current temperatures? Or do you have enough data to where you can formulate one? For this predictive model you are trying to build to have any value it should be accurate to some degree and only you can come up with that based on your historical data you have on your hands.

At the very least, the easiest model seems to be to get the current temperature differential per minute/hour or whatever is most appropriate for your furnace (I have no idea how long it takes your furnace to heat up), and use that in a `y=mx+b` to solve for when you would expect to hit 600.

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [September 9, 2021, 12:21pm UTC](https://forum.inductiveautomation.com/t/how-to-do-prediction-using-dates-in-ignition/50727/17 "2021-09-09T12:21:11Z")

</div>

Coming in late to the party. Not much to add yet,

- Are A, B and Temperature coming from tag histories?
- Would a linear regression be helpful?

EDIT: Looks like Brian and I are on the same page. 🙂

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [September 9, 2021, 12:26pm UTC](https://forum.inductiveautomation.com/t/how-to-do-prediction-using-dates-in-ignition/50727/18 "2021-09-09T12:26:54Z")

</div>

Haha yea. Fact of the universe is that most things, especially when you “zoom” in, are at least pretty well approximated by a linear function or group of linear functions. Definitely the best place to start.

If I recall calc 4 correctly there are some differential equations related to heating/cooling that might be useful, but the extra degree of accuracy you get from that might not be worth all the extra coding/math you’d have to do. I would most definitely start with linear approximations/regression.

---

<div class="post-metadata">

**Author:** ![andrews](https://avatars.discourse-cdn.com/v4/letter/a/898d66/32.png) [@andrews](https://forum.inductiveautomation.com/u/andrews)\
**Post date:** [September 9, 2021, 12:27pm UTC](https://forum.inductiveautomation.com/t/how-to-do-prediction-using-dates-in-ignition/50727/19 "2021-09-09T12:27:56Z")

</div>

When tag hits value insert record into table to track date value was hit. Unless I mis understood that sounds like an alarm to me. He could have an alarm journal showing each time b hits 500. Unless he wants to do something other than display data.

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [September 9, 2021, 12:30pm UTC](https://forum.inductiveautomation.com/t/how-to-do-prediction-using-dates-in-ignition/50727/20 "2021-09-09T12:30:07Z")

</div>

If it's to predict when to recoat the inside of the furnace, then dead naught accuracy probably isn't needed.

This is a nice example of wanting to do predictive maintenance, though.

> [@bkarabinchak.psi](#):
>
> If I recall calc 4 correctly

I barely remember college in general.

[Next page](https://forum.inductiveautomation.com/t/how-to-do-prediction-using-dates-in-ignition/50727.md?page=2)
