-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2151 from ControlSystemStudio/db_formula_init_1972
Data browser: Extend formula samples to 'now'
- Loading branch information
Showing
3 changed files
with
99 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
app/databrowser/src/main/java/org/csstudio/trends/databrowser3/model/FormulaSamples.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2022 Oak Ridge National Laboratory. | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
******************************************************************************/ | ||
package org.csstudio.trends.databrowser3.model; | ||
|
||
import java.time.Instant; | ||
|
||
import org.epics.vtype.AlarmSeverity; | ||
import org.phoebus.archive.vtype.VTypeHelper; | ||
|
||
/** Samples of a {@link FormulaItem}. | ||
* <p>If the last sample is valid, it's | ||
* extended to 'now' assuming no new data means | ||
* that the last value is still valid. | ||
* | ||
* @author Kay Kasemir | ||
*/ | ||
public class FormulaSamples extends PlotSampleArray | ||
{ | ||
/** @return Sample count, includes the last sample extended to 'now' */ | ||
@Override | ||
public int size() | ||
{ | ||
final int raw = super.size(); | ||
if (raw <= 0) | ||
return raw; | ||
final PlotSample last = get(raw-1); | ||
if (org.phoebus.core.vtypes.VTypeHelper.getSeverity(last.getVType()) == AlarmSeverity.UNDEFINED) | ||
return raw; | ||
// Last sample is valid, so it should still apply 'now' | ||
return raw+1; | ||
} | ||
|
||
/** @param index 0... size()-1 | ||
* @return Sample from historic or live sample subsection | ||
*/ | ||
@Override | ||
public PlotSample get(final int index) | ||
{ | ||
final int raw_count = super.size(); | ||
if (index < raw_count) | ||
return super.get(index); | ||
// Last sample is valid, so it should still apply 'now' | ||
final PlotSample sample = super.get(raw_count-1); | ||
if (Instant.now().compareTo(sample.getPosition()) < 0) | ||
return sample; | ||
else | ||
return new PlotSample(sample.getSource(), VTypeHelper.transformTimestampToNow(sample.getVType())); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters