Package io.openems.edge.timedata.rrd4j
Class Rrd4jTimedataImpl
- java.lang.Object
-
- io.openems.edge.common.component.AbstractOpenemsComponent
-
- io.openems.edge.timedata.rrd4j.Rrd4jTimedataImpl
-
- All Implemented Interfaces:
CommonTimedataService
,OpenemsComponent
,Timedata
,Rrd4jTimedata
,org.osgi.service.event.EventHandler
public class Rrd4jTimedataImpl extends AbstractOpenemsComponent implements Rrd4jTimedata, Timedata, OpenemsComponent, org.osgi.service.event.EventHandler
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface io.openems.edge.common.component.OpenemsComponent
OpenemsComponent.ChannelId
-
Nested classes/interfaces inherited from interface io.openems.edge.timedata.rrd4j.Rrd4jTimedata
Rrd4jTimedata.ChannelId
-
Nested classes/interfaces inherited from interface io.openems.edge.timedata.api.Timedata
Timedata.ChannelId
-
-
Field Summary
Fields Modifier and Type Field Description protected ComponentManager
componentManager
protected static java.lang.String
DEFAULT_DATASOURCE_NAME
protected static int
DEFAULT_HEARTBEAT_SECONDS
protected static int
DEFAULT_STEP_SECONDS
protected PersistencePriority
persistencePriority
-
Constructor Summary
Constructors Constructor Description Rrd4jTimedataImpl()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
deactivate()
Handles @Deactivate of implementations.protected org.rrd4j.core.RrdDb
getExistingRrdDb(ChannelAddress channelAddress)
Gets an existing RrdDb.java.util.concurrent.CompletableFuture<java.util.Optional<java.lang.Object>>
getLatestValue(ChannelAddress channelAddress)
Gets the latest known value for the givenChannelAddress
.protected org.rrd4j.core.RrdDb
getRrdDb(ChannelAddress channelAddress, Unit channelUnit, long startTime)
Gets the RRD4j database for the given Channel-Address.void
handleEvent(org.osgi.service.event.Event event)
protected void
logInfo(org.slf4j.Logger log, java.lang.String message)
Log an info message including the Component ID.protected void
logWarn(org.slf4j.Logger log, java.lang.String message)
Log a warn message including the Component ID.protected static double[]
postProcessData(org.rrd4j.core.FetchRequest request, long resolution)
Post-Process the received data.java.util.SortedMap<java.time.ZonedDateTime,java.util.SortedMap<ChannelAddress,com.google.gson.JsonElement>>
queryHistoricData(java.lang.String edgeId, java.time.ZonedDateTime fromDate, java.time.ZonedDateTime toDate, java.util.Set<ChannelAddress> channels, Resolution resolution)
Queries historic data.java.util.SortedMap<ChannelAddress,com.google.gson.JsonElement>
queryHistoricEnergy(java.lang.String edgeId, java.time.ZonedDateTime fromDate, java.time.ZonedDateTime toDate, java.util.Set<ChannelAddress> channels)
Queries historic energy.java.util.SortedMap<java.time.ZonedDateTime,java.util.SortedMap<ChannelAddress,com.google.gson.JsonElement>>
queryHistoricEnergyPerPeriod(java.lang.String edgeId, java.time.ZonedDateTime fromDate, java.time.ZonedDateTime toDate, java.util.Set<ChannelAddress> channels, Resolution resolution)
Queries historic energy per period.-
Methods inherited from class io.openems.edge.common.component.AbstractOpenemsComponent
_channel, activate, activate, addChannel, addChannels, addChannels, alias, channels, getComponentContext, id, isEnabled, logDebug, logError, modified, removeChannel
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface io.openems.common.timedata.CommonTimedataService
handleQueryHistoricTimeseriesExportXlxsRequest, queryHistoricData
-
Methods inherited from interface io.openems.edge.common.component.OpenemsComponent
_channel, _getChannelAs, alias, channel, channel, channels, debugLog, getComponentContext, getState, getStateChannel, hasFaults, id, isEnabled, serviceFactoryPid, servicePid
-
Methods inherited from interface io.openems.edge.timedata.rrd4j.Rrd4jTimedata
_setQueueIsFull, _setUnableToInsertSample, getQueueIsFull, getQueueIsFullChannel, getUnableToInsertSample, getUnableToInsertSampleChannel
-
-
-
-
Field Detail
-
DEFAULT_DATASOURCE_NAME
protected static final java.lang.String DEFAULT_DATASOURCE_NAME
- See Also:
- Constant Field Values
-
DEFAULT_STEP_SECONDS
protected static final int DEFAULT_STEP_SECONDS
- See Also:
- Constant Field Values
-
DEFAULT_HEARTBEAT_SECONDS
protected static final int DEFAULT_HEARTBEAT_SECONDS
- See Also:
- Constant Field Values
-
componentManager
protected ComponentManager componentManager
-
persistencePriority
protected PersistencePriority persistencePriority
-
-
Method Detail
-
deactivate
protected void deactivate()
Description copied from class:AbstractOpenemsComponent
Handles @Deactivate of implementations. Prints log output.- Overrides:
deactivate
in classAbstractOpenemsComponent
-
queryHistoricData
public java.util.SortedMap<java.time.ZonedDateTime,java.util.SortedMap<ChannelAddress,com.google.gson.JsonElement>> queryHistoricData(java.lang.String edgeId, java.time.ZonedDateTime fromDate, java.time.ZonedDateTime toDate, java.util.Set<ChannelAddress> channels, Resolution resolution) throws OpenemsError.OpenemsNamedException
Description copied from interface:CommonTimedataService
Queries historic data.- Specified by:
queryHistoricData
in interfaceCommonTimedataService
- Parameters:
edgeId
- the Edge-ID; or null query allfromDate
- the From-DatetoDate
- the To-Datechannels
- the Channelsresolution
- theResolution
- Returns:
- the query result
- Throws:
OpenemsError.OpenemsNamedException
-
postProcessData
protected static double[] postProcessData(org.rrd4j.core.FetchRequest request, long resolution) throws java.io.IOException, java.lang.IllegalArgumentException
Post-Process the received data.This mainly makes sure the data has the correct resolution.
- Parameters:
request
- the RRD4jFetchRequest
resolution
- the resolution in seconds- Returns:
- the result array
- Throws:
java.io.IOException
- on errorjava.lang.IllegalArgumentException
- on error
-
queryHistoricEnergy
public java.util.SortedMap<ChannelAddress,com.google.gson.JsonElement> queryHistoricEnergy(java.lang.String edgeId, java.time.ZonedDateTime fromDate, java.time.ZonedDateTime toDate, java.util.Set<ChannelAddress> channels) throws OpenemsError.OpenemsNamedException
Description copied from interface:CommonTimedataService
Queries historic energy.- Specified by:
queryHistoricEnergy
in interfaceCommonTimedataService
- Parameters:
edgeId
- the Edge-ID; or null query allfromDate
- the From-DatetoDate
- the To-Datechannels
- the Channels- Returns:
- the query result
- Throws:
OpenemsError.OpenemsNamedException
-
queryHistoricEnergyPerPeriod
public java.util.SortedMap<java.time.ZonedDateTime,java.util.SortedMap<ChannelAddress,com.google.gson.JsonElement>> queryHistoricEnergyPerPeriod(java.lang.String edgeId, java.time.ZonedDateTime fromDate, java.time.ZonedDateTime toDate, java.util.Set<ChannelAddress> channels, Resolution resolution) throws OpenemsError.OpenemsNamedException
Description copied from interface:CommonTimedataService
Queries historic energy per period.This is for use-cases where you want to get the energy for each period (with
Resolution
) per Channel, e.g. to visualize energy in a histogram chart. For each period the energy is calculated by subtracting first value of the period from the last value of the period.- Specified by:
queryHistoricEnergyPerPeriod
in interfaceCommonTimedataService
- Parameters:
edgeId
- the Edge-ID; or null query allfromDate
- the From-DatetoDate
- the To-Datechannels
- the Channelsresolution
- theResolution
- Returns:
- the query result
- Throws:
OpenemsError.OpenemsNamedException
-
getLatestValue
public java.util.concurrent.CompletableFuture<java.util.Optional<java.lang.Object>> getLatestValue(ChannelAddress channelAddress)
Description copied from interface:Timedata
Gets the latest known value for the givenChannelAddress
.- Specified by:
getLatestValue
in interfaceTimedata
- Parameters:
channelAddress
- the ChannelAddress to be queried- Returns:
- the latest known value or Empty
-
getRrdDb
protected org.rrd4j.core.RrdDb getRrdDb(ChannelAddress channelAddress, Unit channelUnit, long startTime) throws java.io.IOException, java.net.URISyntaxException
Gets the RRD4j database for the given Channel-Address.The predefined RRD4J archives match the requirements of
CommonTimedataService.calculateResolution(ZonedDateTime, ZonedDateTime)
- Parameters:
channelAddress
- the Channel-AddresschannelUnit
- theUnit
startTime
- the starttime for newly created RrdDbs- Returns:
- the RrdDb
- Throws:
java.io.IOException
- on errorjava.net.URISyntaxException
- on error
-
getExistingRrdDb
protected org.rrd4j.core.RrdDb getExistingRrdDb(ChannelAddress channelAddress)
Gets an existing RrdDb.- Parameters:
channelAddress
- the ChannelAddress- Returns:
- the RrdDb or null
- Throws:
java.io.IOException
- on errorjava.net.URISyntaxException
- on error
-
logInfo
protected void logInfo(org.slf4j.Logger log, java.lang.String message)
Description copied from class:AbstractOpenemsComponent
Log an info message including the Component ID.- Overrides:
logInfo
in classAbstractOpenemsComponent
- Parameters:
log
- the Logger instancemessage
- the message
-
logWarn
protected void logWarn(org.slf4j.Logger log, java.lang.String message)
Description copied from class:AbstractOpenemsComponent
Log a warn message including the Component ID.- Overrides:
logWarn
in classAbstractOpenemsComponent
- Parameters:
log
- the Logger instancemessage
- the message
-
handleEvent
public void handleEvent(org.osgi.service.event.Event event)
- Specified by:
handleEvent
in interfaceorg.osgi.service.event.EventHandler
-
-