public static VTQ Make(string value, Timestamp time, Quality quality) => new VTQ(time, quality, DataValue.FromString(value));
public static VTQ Make(float value, Timestamp time, Quality quality) => new VTQ(time, quality, DataValue.FromFloat(value));
public static VTQ Make(bool value, Timestamp time, Quality quality) => new VTQ(time, quality, DataValue.FromBool(value));
/// <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);
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)); }
public static VTQ Make(Timestamp value, Timestamp time, Quality quality) => new VTQ(time, quality, DataValue.FromTimestamp(value));
/// <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);
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); }
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); }
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); } }
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); }
private void NotifyChange(VariableRef variable, Timestamp start, Timestamp end, HistoryChangeType changeType) { fNotifyChanges(new HistoryChange[] { new HistoryChange(variable, start, end, changeType) }); }
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)); }
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); }
public static VTQ Make(Duration value, Timestamp time, Quality quality) => new VTQ(time, quality, DataValue.FromDuration(value));
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); }
public static VTQ Make(LocalTime value, Timestamp time, Quality quality) => new VTQ(time, quality, DataValue.FromLocalTime(value));
public VTQ(Timestamp time, Quality quality, DataValue value) { T = time; Q = quality; V = value; }
public VTQ WithTime(Timestamp time) => new VTQ(time, Q, V);
public static VTQ Make(DataValue value, Timestamp time, Quality quality) => new VTQ(time, quality, value);
/// <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);
public static VTQ Make(double value, Timestamp time, Quality quality) => new VTQ(time, quality, DataValue.FromDouble(value));
/// <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);
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)); }