Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
project
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
IPos-public
project
Commits
d3ffe6a1
Commit
d3ffe6a1
authored
3 years ago
by
FrankR
Browse files
Options
Downloads
Patches
Plain Diff
added sensordatafusion
parent
27318e62
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/main/java/ipos/project/Functionality/SensorDataFusion.java
+98
-0
98 additions, 0 deletions
...ain/java/ipos/project/Functionality/SensorDataFusion.java
with
98 additions
and
0 deletions
src/main/java/ipos/project/Functionality/SensorDataFusion.java
0 → 100644
+
98
−
0
View file @
d3ffe6a1
package
ipos.project.Functionality
;
import
ipos.project.DataModellntegration.iPos_Datamodel.Agent
;
import
ipos.project.DataModellntegration.iPos_Datamodel.Gaussian
;
import
ipos.project.DataModellntegration.iPos_Datamodel.PositionEvent
;
import
ipos.project.UseCaseController.PositionMonitoring
;
import
org.apache.logging.log4j.LogManager
;
import
java.time.Duration
;
import
java.time.LocalDateTime
;
import
java.time.format.DateTimeFormatter
;
import
java.util.*
;
public
class
SensorDataFusion
{
private
static
Map
<
String
,
List
<
PositionEvent
>>
recentEventStorage
=
new
HashMap
<>();
private
static
org
.
apache
.
logging
.
log4j
.
Logger
LOG
=
LogManager
.
getLogger
();
/**
* Side-effect: calls updates recent-event storage
*
* @param positionEvent
* @return
*/
public
static
boolean
isMostAccuratePositionAvailable
(
PositionEvent
positionEvent
)
{
try
{
Agent
agent
=
DataServices
.
getAgentForLocalizableObject
(
positionEvent
.
getLObjectId
());
List
<
PositionEvent
>
eventsForAgent
=
getEventStorageForAgentOrCreate
(
agent
.
getId
());
updateRecentEventStorage
(
eventsForAgent
,
positionEvent
);
return
hasHighestAccuracyAmongStoredEvents
(
positionEvent
,
eventsForAgent
);
}
catch
(
IllegalArgumentException
e
)
{
LOG
.
warn
(
"Sensor-data-fusion could not be applied to position-event as no LocalizableObject with "
+
"the provided sensor-id could be found, or no agent"
+
"is associated to the LocalizableObject that has been found."
);
return
false
;
}
}
/**
* Assumption: The larger the accuracy-value the worse is the accuracy.
* Accuracy == 0 is the best possible accuracy.
* Note: the accuracy-value corresponds conceptually to the radius of
* the circle that indicates the potential positions of the agent.
* @param positionEvent
* @param eventsForAgent
* @return
*/
private
static
boolean
hasHighestAccuracyAmongStoredEvents
(
PositionEvent
positionEvent
,
List
<
PositionEvent
>
eventsForAgent
)
{
for
(
PositionEvent
storedEvent
:
eventsForAgent
){
float
storedAccuracy
=
((
Gaussian
)
storedEvent
.
getPlacing
().
getPosition
().
getAccuracy
()).
getConfidenceInterval
();
float
eventAccuracy
=
((
Gaussian
)
positionEvent
.
getPlacing
().
getPosition
().
getAccuracy
()).
getConfidenceInterval
();;
if
(
storedAccuracy
<
eventAccuracy
){
// it is important not to use <= here, as at least the current position event itself is contained in the list
LOG
.
info
(
"SensorDataFusion rejected position-event: "
+
positionEvent
.
toString
());
return
false
;
}
}
return
true
;
}
private
static
void
updateRecentEventStorage
(
List
<
PositionEvent
>
eventsForAgent
,
PositionEvent
positionEvent
)
throws
IllegalArgumentException
{
eventsForAgent
.
add
(
0
,
positionEvent
);
removeOldEvents
(
eventsForAgent
);
}
/**
* Removes all position-events older than SDF_TIME_INTERVAL from the recentEventStorage.
* @param eventsForAgent
*/
private
static
void
removeOldEvents
(
List
<
PositionEvent
>
eventsForAgent
)
{
LocalDateTime
now
=
LocalDateTime
.
now
();
boolean
removeSubsequentElements
=
false
;
for
(
Iterator
<
PositionEvent
>
eventIt
=
eventsForAgent
.
iterator
();
eventIt
.
hasNext
();){
PositionEvent
currEvent
=
eventIt
.
next
();
if
(
removeSubsequentElements
){
eventIt
.
remove
();
// removes element of the list that was returned by the last call to next()
continue
;
}
LocalDateTime
eventTime
=
LocalDateTime
.
parse
(
currEvent
.
getTimeStamp
(),
DateTimeFormatter
.
ISO_OFFSET_DATE_TIME
);
long
eventAge
=
Duration
.
between
(
eventTime
,
now
).
toMillis
();
if
(
eventAge
>
PositionMonitoring
.
SDF_TIME_INTERVAL
){
eventIt
.
remove
();
removeSubsequentElements
=
true
;
}
}
}
private
static
List
<
PositionEvent
>
getEventStorageForAgentOrCreate
(
String
agentId
)
{
List
<
PositionEvent
>
eventsForAgent
=
recentEventStorage
.
get
(
agentId
);
if
(
eventsForAgent
==
null
){
eventsForAgent
=
new
ArrayList
<
PositionEvent
>();
recentEventStorage
.
put
(
agentId
,
eventsForAgent
);
}
return
eventsForAgent
;
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment