Exemplo n.º 1
0
 public static VTQ Make(string value, Timestamp time, Quality quality) => new VTQ(time, quality, DataValue.FromString(value));
Exemplo n.º 2
0
 public static VTQ Make(float value, Timestamp time, Quality quality) => new VTQ(time, quality, DataValue.FromFloat(value));
Exemplo n.º 3
0
 public static VTQ Make(bool value, Timestamp time, Quality quality) => new VTQ(time, quality, DataValue.FromBool(value));
Exemplo n.º 4
0
 /// <summary>
 /// Deletes all data points in the history of a variable within a certain time interval and returns
 /// the number of data points that have been deleted.
 /// </summary>
 /// <param name="variable">The variable</param>
 /// <param name="startInclusive">The start of the time interval (inclusive)</param>
 /// <param name="endInclusive">The end of the time interval (inclusive)</param>
 /// <returns>The number of data points that have been deleted</returns>
 public abstract Task <long> HistorianDeleteInterval(VariableRef variable, Timestamp startInclusive, Timestamp endInclusive);
Exemplo n.º 5
0
        public async Task <long> HistorianCount(VariableRef variable, Timestamp startInclusive, Timestamp endInclusive, QualityFilter filter)
        {
            HistoryDBWorker?worker = WorkerByVarRef(variable);

            if (worker == null)
            {
                throw new Exception("Failed to find DB worker for variable " + variable);
            }
            CheckExistingVariable(variable);
            return(await worker.Count(variable, startInclusive, endInclusive, filter));
        }
Exemplo n.º 6
0
 public static VTQ Make(Timestamp value, Timestamp time, Quality quality) => new VTQ(time, quality, DataValue.FromTimestamp(value));
Exemplo n.º 7
0
 /// <summary>
 /// Reads the history of a variable in a certain time interval.
 /// </summary>
 /// <param name="variable">The variable to read</param>
 /// <param name="startInclusive">The start of the time interval (inclusive)</param>
 /// <param name="endInclusive">The end of the time interval (inclusive)</param>
 /// <param name="maxValues">The maximum number of data points to return</param>
 /// <param name="bounding">Defines which data points to return when there are more data points in the time interval than maxValues</param>
 public abstract Task <VTTQ[]> HistorianReadRaw(VariableRef variable, Timestamp startInclusive, Timestamp endInclusive, int maxValues, BoundingMethod bounding);
Exemplo n.º 8
0
        public Task <long> DeleteInterval(VariableRef variable, Timestamp startInclusive, Timestamp endInclusive)
        {
            var promise = new TaskCompletionSource <long>();

            if (CheckPrecondition(promise))
            {
                queue.Post(new WI_DeleteInterval()
                {
                    Variable       = variable,
                    StartInclusive = startInclusive,
                    EndInclusive   = endInclusive,
                    Promise        = promise
                });
            }
            return(promise.Task);
        }
Exemplo n.º 9
0
        public Task <VTTQ?> GetLatestTimestampDb(VariableRef variable, Timestamp startInclusive, Timestamp endInclusive)
        {
            var promise = new TaskCompletionSource <VTTQ?>();

            if (CheckPrecondition(promise))
            {
                queue.Post(new WI_GetLatestTimestampDb()
                {
                    Variable       = variable,
                    StartInclusive = startInclusive,
                    EndInclusive   = endInclusive,
                    Promise        = promise
                });
            }
            return(promise.Task);
        }
Exemplo n.º 10
0
        public int OnVariableValuesChanged(string moduleID, IList <VariableValuePrev> values)
        {
            var valuesToSave = new List <StoreValue>();

            for (int i = 0; i < values.Count; ++i)
            {
                VariableValue value         = values[i].Value;
                VTQ           previousValue = values[i].PreviousValue;

                Variable?variable = fVarResolver(value.Variable);
                if (variable == null)
                {
                    logger.Warn("OnVariableValuesChanged: invalid variable reference: " + value.Variable);
                    continue;
                }

                Timestamp tNew    = value.Value.T;
                Timestamp tOld    = previousValue.T;
                History   history = variable.History;

                if (tNew < tOld)
                {
                    if (ReportTimestampWarning(history))
                    {
                        logger.Warn("Timestamp of new VTQ is older than current timestamp: " + value.Variable.ToString() + "\n\tOld: " + previousValue + "\n\tNew: " + value.Value);
                    }
                }
                else if (tNew == tOld)
                {
                    if (value.Value != previousValue)
                    {
                        if (ReportTimestampWarning(history))
                        {
                            logger.Warn("Timestamp of new VTQ is equal to current timestamp but value (or quality) differs: " + value.Variable.ToString() + "\n\tOld: " + previousValue + "\n\tNew: " + value.Value);
                        }
                    }
                }
                else
                {
                    DataType type = variable.Type;

                    switch (history.Mode)
                    {
                    case HistoryMode.None:
                        break;

                    case HistoryMode.Complete:
                        valuesToSave.Add(new StoreValue(value, type));
                        break;

                    case HistoryMode.ValueOrQualityChanged: {
                        if (value.Value.V != previousValue.V || value.Value.Q != previousValue.Q)
                        {
                            valuesToSave.Add(new StoreValue(value, type));
                        }
                        break;
                    }

                    case HistoryMode.Interval: {
                        if (IsIntervalHit(tNew, history) ||
                            (tNew - tOld >= history.Interval) ||
                            IsIntervalBetweenTimetamps(tOld, tNew, history))
                        {
                            valuesToSave.Add(new StoreValue(value, type));
                        }
                        break;
                    }

                    case HistoryMode.IntervalOrChanged: {
                        if (value.Value.V != previousValue.V ||
                            value.Value.Q != previousValue.Q ||
                            IsIntervalHit(tNew, history) ||
                            (tNew - tOld >= history.Interval) ||
                            IsIntervalBetweenTimetamps(tOld, tNew, history))
                        {
                            valuesToSave.Add(new StoreValue(value, type));
                        }
                        break;
                    }

                    case HistoryMode.IntervalExact: {
                        if (IsIntervalHit(tNew, history))
                        {
                            valuesToSave.Add(new StoreValue(value, type));
                        }
                        break;
                    }

                    case HistoryMode.IntervalExactOrChanged: {
                        if (value.Value.V != previousValue.V ||
                            value.Value.Q != previousValue.Q ||
                            IsIntervalHit(tNew, history))
                        {
                            valuesToSave.Add(new StoreValue(value, type));
                        }
                        break;
                    }

                    default:
                        logger.Error("Unknown history mode: " + history.Mode);
                        break;
                    }
                }
            }

            if (valuesToSave.Count > 0)
            {
                return(SaveToDB(moduleID, valuesToSave));
            }
            else
            {
                return(0);
            }
        }
Exemplo n.º 11
0
        public Task <IList <VTTQ> > ReadRaw(VariableRef variable, Timestamp startInclusive, Timestamp endInclusive, int maxValues, BoundingMethod bounding)
        {
            var promise = new TaskCompletionSource <IList <VTTQ> >();

            if (CheckPrecondition(promise))
            {
                queue.Post(new WI_ReadRaw()
                {
                    Variable       = variable,
                    StartInclusive = startInclusive,
                    EndInclusive   = endInclusive,
                    MaxValues      = maxValues,
                    Bounding       = bounding,
                    Promise        = promise
                });
            }
            return(promise.Task);
        }
Exemplo n.º 12
0
 private void NotifyChange(VariableRef variable, Timestamp start, Timestamp end, HistoryChangeType changeType)
 {
     fNotifyChanges(new HistoryChange[] { new HistoryChange(variable, start, end, changeType) });
 }
Exemplo n.º 13
0
        public async Task <VTTQ?> HistorianGetLatestTimestampDb(VariableRef variable, Timestamp startInclusive, Timestamp endInclusive)
        {
            HistoryDBWorker?worker = WorkerByVarRef(variable);

            if (worker == null)
            {
                throw new Exception("Failed to find DB worker for variable " + variable);
            }

            CheckExistingVariable(variable);
            return(await worker.GetLatestTimestampDb(variable, startInclusive, endInclusive));
        }
Exemplo n.º 14
0
        public async Task <long> HistorianDeleteInterval(VariableRef variable, Timestamp startInclusive, Timestamp endInclusive)
        {
            HistoryDBWorker?worker = WorkerByVarRef(variable);

            if (worker == null)
            {
                throw new Exception("Failed to find DB worker for variable " + variable);
            }

            CheckExistingVariable(variable);
            long res = await worker.DeleteInterval(variable, startInclusive, endInclusive);

            NotifyChange(variable, startInclusive, endInclusive, HistoryChangeType.Delete);
            return(res);
        }
Exemplo n.º 15
0
 public static VTQ Make(Duration value, Timestamp time, Quality quality) => new VTQ(time, quality, DataValue.FromDuration(value));
Exemplo n.º 16
0
        private void Append(WI_BatchAppend append)
        {
            var nonExisting = new List <StoreValue>();
            var set         = new Dictionary <VariableRef, VarHistoyChange>();

            foreach (StoreValue sv in append.Values)
            {
                VariableRef vr   = sv.Value.Variable;
                Timestamp   newT = sv.Value.Value.T;
                if (!set.ContainsKey(vr))
                {
                    set[vr] = new VarHistoyChange()
                    {
                        Var   = vr,
                        Start = newT,
                        End   = newT
                    };
                    if (!ExistsChannel(vr))
                    {
                        nonExisting.Add(sv);
                    }
                }
                else
                {
                    VarHistoyChange change = set[vr];
                    if (newT < change.Start)
                    {
                        change.Start = newT;
                    }
                    if (newT > change.End)
                    {
                        change.End = newT;
                    }
                }
            }

            if (nonExisting.Count > 0)
            {
                int count = nonExisting.Count;
                logger.Debug("Creating {0} not yet existing channels.", count);
                ChannelInfo[] newChannels = nonExisting.Select(v => new ChannelInfo(v.Value.Variable.Object.LocalObjectID, v.Value.Variable.Name, v.Type)).ToArray();
                var           swCreate    = Stopwatch.StartNew();
                Channel[]     channels    = db.CreateChannels(newChannels);
                logger.Debug("Created {0} channels completed in {1} ms", count, swCreate.ElapsedMilliseconds);
                for (int i = 0; i < nonExisting.Count; ++i)
                {
                    mapChannels[nonExisting[i].Value.Variable] = channels[i];
                }
            }

            var swBatch = Stopwatch.StartNew();

            Func <PrepareContext, string>[] appendActions = append.Values.Select(v => {
                Channel ch = GetChannelOrThrow(v.Value.Variable);
                Func <PrepareContext, string> f = ch.PrepareAppend(v.Value.Value);
                return(f);
            }).ToArray();

            string[] errors = db.BatchExecute(appendActions);

            logger.Debug("db.BatchExecute completed for {0} appends in {1} ms", appendActions.Length, swBatch.ElapsedMilliseconds);

            if (errors.Length > 0)
            {
                logger.Error("Batch append actions failed ({0} of {1}): \n\t{2}", errors.Length, appendActions.Length, string.Join("\n\t", errors));
            }

            notifyAppend(set.Values);
        }
Exemplo n.º 17
0
 public static VTQ Make(LocalTime value, Timestamp time, Quality quality) => new VTQ(time, quality, DataValue.FromLocalTime(value));
Exemplo n.º 18
0
 public VTQ(Timestamp time, Quality quality, DataValue value)
 {
     T = time;
     Q = quality;
     V = value;
 }
Exemplo n.º 19
0
 public VTQ WithTime(Timestamp time) => new VTQ(time, Q, V);
Exemplo n.º 20
0
 public static VTQ Make(DataValue value, Timestamp time, Quality quality) => new VTQ(time, quality, value);
Exemplo n.º 21
0
 /// <summary>
 /// Counts the number of data points in the history of a variable within a certain time interval.
 /// </summary>
 /// <param name="variable">The variable</param>
 /// <param name="startInclusive">The start of the time interval (inclusive)</param>
 /// <param name="endInclusive">The end of the time interval (inclusive)</param>
 /// <returns>The number of data points</returns>
 public abstract Task <long> HistorianCount(VariableRef variable, Timestamp startInclusive, Timestamp endInclusive);
Exemplo n.º 22
0
 public static VTQ Make(double value, Timestamp time, Quality quality) => new VTQ(time, quality, DataValue.FromDouble(value));
Exemplo n.º 23
0
 /// <summary>
 /// Returns the data point in the history of a variable in a certain time interval that
 /// has the most recent value for the T_DB value, i.e. that has most recently been
 /// inserted or updated.
 /// </summary>
 /// <param name="variable">The variable</param>
 /// <param name="startInclusive">The start of the time interval (inclusive)</param>
 /// <param name="endInclusive">The end of the time interval (inclusive)</param>
 /// <returns>The most recently updated data point or null if the time interval is empty</returns>
 public abstract Task <VTTQ?> HistorianGetLatestTimestampDB(VariableRef variable, Timestamp startInclusive, Timestamp endInclusive);
Exemplo n.º 24
0
        public async Task <List <VTTQ> > HistorianReadRaw(VariableRef variable, Timestamp startInclusive, Timestamp endInclusive, int maxValues, BoundingMethod bounding, QualityFilter filter)
        {
            HistoryDBWorker?worker = WorkerByVarRef(variable);

            if (worker == null)
            {
                throw new Exception("Failed to find DB worker for variable " + variable);
            }
            CheckExistingVariable(variable);
            return(await worker.ReadRaw(variable, startInclusive, endInclusive, maxValues, bounding, filter));
        }