Forum Home › Forums › Understanding the Software › Using Formulas › Formula lowestValue
- This topic has 4 replies, 2 voices, and was last updated 1 year, 3 months ago by
Mikhail.
-
AuthorPosts
-
February 29, 2024 at 12:48 pm #14092
gabeirinhas
ParticipantI am trying to store the lowest value recorded for a channel on one day, the next day it should be set to 0
I apply the following formula in the formula dictionary (LowValue):
double lowestValue;
DateTime lastResetDate = DateTime.Now.Date;public double LowValue(double val)
{if (DateTime.Now.Date > lastResetDate)
{
lowestValue = 0;
lastResetDate = DateTime.Now.Date;
}if (val < lowestValue)
{
lowestValue = val;
}
return lowestValue;
}I collect the value associated with “channel 1061” in “channel 1062” with the following formula:
LowValue(Val(1061))/10
Channel 1061, has the following formula to maintain its value on connection loss:
CnlStat > 0 ? Cnl : Val(1061); CnlStat > 0 ? CnlStat : Stat(1061).
The problem I need help with is that when I restart the server because I make changes, the value of 1062 is updated and loses its last valid value.
Both channels associated with the same signal
Thanks in advance
-
This topic was modified 1 year, 3 months ago by
gabeirinhas.
March 1, 2024 at 10:57 am #14099gabeirinhas
ParticipantAttached is an updated formula.
The approach I use to update the value daily is to give a server reset scheduled for 00:00,
The previous formula was stored globally so it did not allow linking more than one channel.
The approach is as follows:
1. Implement the following formula in the formula dictionary ( it is put that the value cannot be less than -170, for reasons of errors in a transmitter):
Dictionary<int, double> lowestValues = new Dictionary<int, double>();
public double LowValue(double val, int channelNumber)
{if (!lowestValues.ContainsKey(channelNumber))
{lowestValues[channelNumber] = val;
}
else
{if (val >= -1700)
{
lowestValues[channelNumber] = Math.Min(lowestValues[channelNumber], val);
}
}return lowestValues[channelNumber];
}2. Use the following formula for a “Real” channel:
LowValue(Cnl, 1090) / 10
# Where 1090, is the channel number,
I hope it helps and someone is able to improve it so that the last recorded value is not lost when the server disconnects.
Regards
-
This reply was modified 1 year, 3 months ago by
gabeirinhas.
March 1, 2024 at 12:24 pm #14107Mikhail
ModeratorHi,
There is a ready to use DayStarted() function. It equals to true in the beginning of the day. Probably, using this function inside your formulas can fix the issue.
If you provide screenshots of your channels, I can check them.March 1, 2024 at 6:12 pm #14109gabeirinhas
ParticipantThe real problem is that when I upload changes to the server, the last valid value is reset.
If this didn’t happen, I could implement this formula in a natural way, so I could add “DayStarted() function”.
Resetting the server on a scheduled basis at 00:00 I do this so that if I make changes to the server, they are not updated until 0:00 and it does not affect the performance of the formula.
March 4, 2024 at 11:56 am #14125Mikhail
ModeratorWhen Server starts, it loads channel values that saved before it Server stop. Value is reset because of your function. Using DayStarted() may help not to reset lowest value on start.
-
This topic was modified 1 year, 3 months ago by
-
AuthorPosts
- You must be logged in to reply to this topic.