Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
The container registry cleanup task is now completed and the registry can be used normally.
Open sidebar
vadere
vadere
Commits
740fea64
Commit
740fea64
authored
May 21, 2019
by
Daniel Lehmberg
Browse files
WIP: headerProcSep and error in PostViz when multiple required column names detected
parent
ec80f092
Changes
2
Hide whitespace changes
Inline
Side-by-side
VadereSimulator/src/org/vadere/simulator/projects/dataprocessing/outputfile/OutputFile.java
View file @
740fea64
...
...
@@ -2,6 +2,7 @@
package
org.vadere.simulator.projects.dataprocessing.outputfile
;
import
org.vadere.simulator.projects.dataprocessing.DataProcessingJsonManager
;
import
org.vadere.simulator.projects.dataprocessing.datakey.DataKey
;
import
org.vadere.simulator.projects.dataprocessing.processor.DataProcessor
;
import
org.vadere.simulator.projects.dataprocessing.writer.VadereWriter
;
...
...
@@ -54,7 +55,11 @@ public abstract class OutputFile<K extends DataKey<K>> {
private
boolean
isWriteMetaData
;
private
String
separator
;
public
final
static
String
nameConflictAdd
=
"-PID?"
;
// the # is replaced with the processor id
// Check also the PostVis where there is a dependency
public
final
static
String
headerProcSep
=
"-"
;
public
final
static
String
headerNameAdd
=
headerProcSep
+
"PID?"
;
// the # is replaced with the processor id
private
VadereWriterFactory
writerFactory
;
private
VadereWriter
writer
;
...
...
@@ -129,7 +134,7 @@ public abstract class OutputFile<K extends DataKey<K>> {
// characters
String
md
=
"#IDXCOL="
+
dataIndices
.
length
+
",DATACOL="
+(
getEntireHeader
().
size
()-
dataIndices
.
length
)+
","
+
"SEP=\'"
+
this
.
separator
+
"\'"
;
"SEP=\'"
+
DataProcessingJsonManager
.
DEFAULT_SEPARATOR
+
"\'"
;
//Make a list with one element to reuse 'writeLine' function
List
<
String
>
line
=
new
LinkedList
<>();
...
...
@@ -166,16 +171,37 @@ public abstract class OutputFile<K extends DataKey<K>> {
}
public
String
getHeaderLine
()
{
return
String
.
join
(
this
.
separator
,
this
.
getEntireHeader
());
return
String
.
join
(
DataProcessingJsonManager
.
DEFAULT_SEPARATOR
,
this
.
getEntireHeader
());
}
public
String
getIndicesLine
()
{
return
String
.
join
(
this
.
separator
,
this
.
getIndices
());
return
String
.
join
(
DataProcessingJsonManager
.
DEFAULT_SEPARATOR
,
this
.
getIndices
());
}
private
List
<
String
>
uniqueHeaderNames
(){
// This function adds to every header "headerNameAdd", for ALL headers EVERY time
// (cmp. headersWithNameMangling)
LinkedList
<
String
>
headers
=
new
LinkedList
<>();
for
(
DataProcessor
l:
dataProcessors
)
{
List
<
String
>
allProcHeaders
=
Arrays
.
asList
(
l
.
getHeaders
());
for
(
String
singleHeader:
allProcHeaders
)
{
// add the processor id to make header unique
headers
.
addLast
(
singleHeader
+
headerNameAdd
.
replace
(
"?"
,
""
+
l
.
getId
()));
}
}
return
headers
;
}
private
List
<
String
>
headersWithNameMangling
(){
// This function adds to every header "headerNameAdd", ONLY if there is a name conflict detected
// (cmp. uniqueHeaderNames)
LinkedList
<
String
>
headers
=
new
LinkedList
<>();
boolean
isNameMangle
=
false
;
// assume there is no nameing conflict
boolean
isNameMangle
Detected
=
false
;
// assume there is no nameing conflict
mainloop:
for
(
DataProcessor
l:
dataProcessors
)
{
...
...
@@ -183,7 +209,7 @@ public abstract class OutputFile<K extends DataKey<K>> {
for
(
String
el:
list
)
{
if
(
headers
.
contains
(
el
)){
isNameMangle
=
true
;
// conflict found: stop collecting
headers
isNameMangle
Detected
=
true
;
// conflict found: stop collecting
and name make every header unique
break
mainloop
;
}
else
{
headers
.
addLast
(
el
);
...
...
@@ -191,24 +217,16 @@ public abstract class OutputFile<K extends DataKey<K>> {
}
}
if
(
isNameMangle
){
headers
.
clear
();
//start from new...
for
(
DataProcessor
l:
dataProcessors
)
{
List
<
String
>
list
=
Arrays
.
asList
(
l
.
getHeaders
());
for
(
String
h:
list
)
{
// ... but now add the processor id
headers
.
addLast
(
h
+
nameConflictAdd
.
replace
(
"?"
,
""
+
l
.
getId
()+
'0'
));
}
}
if
(
isNameMangleDetected
){
headers
=
(
LinkedList
<
String
>)
uniqueHeaderNames
();
}
return
headers
;
}
private
List
<
String
>
composeHeaderLine
(){
final
List
<
String
>
allHeaders
=
new
LinkedList
<>(
Arrays
.
asList
(
dataIndices
));
List
<
String
>
procHeaders
=
this
.
headersWithNameMangling
();
List
<
String
>
procHeaders
=
this
.
uniqueHeaderNames
();
allHeaders
.
addAll
(
procHeaders
);
...
...
VadereSimulator/src/org/vadere/simulator/projects/io/TrajectoryReader.java
View file @
740fea64
...
...
@@ -3,6 +3,7 @@ package org.vadere.simulator.projects.io;
import
org.apache.commons.math3.util.Pair
;
import
org.jetbrains.annotations.NotNull
;
import
org.vadere.simulator.projects.Scenario
;
import
org.vadere.simulator.projects.dataprocessing.outputfile.OutputFile
;
import
org.vadere.simulator.projects.dataprocessing.processor.PedestrianPositionProcessor
;
import
org.vadere.state.attributes.scenario.AttributesAgent
;
import
org.vadere.state.scenario.Agent
;
...
...
@@ -65,6 +66,8 @@ public class TrajectoryReader {
private
int
groupSizeIndex
;
private
int
stridesIndex
;
private
static
final
int
notSetColumnIndexIdentifier
=
-
1
;
public
TrajectoryReader
(
final
Path
trajectoryFilePath
,
final
Scenario
scenario
)
{
this
(
trajectoryFilePath
,
scenario
.
getAttributesPedestrian
());
}
...
...
@@ -98,26 +101,29 @@ public class TrajectoryReader {
stridesKeys
.
add
(
"strides"
);
stridesKeys
.
add
(
"footSteps"
);
pedIdIndex
=
-
1
;
stepIndex
=
-
1
;
xIndex
=
-
1
;
yIndex
=
-
1
;
targetIdIndex
=
-
1
;
groupIdIndex
=
-
1
;
groupSizeIndex
=
-
1
;
stridesIndex
=
-
1
;
pedIdIndex
=
notSetColumnIndexIdentifier
;
stepIndex
=
notSetColumnIndexIdentifier
;
xIndex
=
notSetColumnIndexIdentifier
;
yIndex
=
notSetColumnIndexIdentifier
;
targetIdIndex
=
notSetColumnIndexIdentifier
;
groupIdIndex
=
notSetColumnIndexIdentifier
;
groupSizeIndex
=
notSetColumnIndexIdentifier
;
stridesIndex
=
notSetColumnIndexIdentifier
;
}
public
Map
<
Step
,
List
<
Agent
>>
readFile
()
throws
IOException
{
if
(
checkFile
()){
return
readStandardTrajectoryFile
();
}
else
{
throw
new
IOException
(
"could not read trajectory file, some colums are missing."
);
checkFile
();
return
readStandardTrajectoryFile
();
}
private
void
errorWhenNotUniqueColumn
(
int
currentValue
,
String
columnName
)
throws
IOException
{
if
(
currentValue
!=
notSetColumnIndexIdentifier
){
throw
new
IOException
(
"The header "
+
columnName
+
" is not unique in the file. This is likely to have "
+
"unwanted side effects"
);
}
}
public
boolean
checkFile
()
throws
IOException
{
public
void
checkFile
()
throws
IOException
{
// 1. Get the correct column
String
header
;
//read only first line.
...
...
@@ -127,50 +133,58 @@ public class TrajectoryReader {
String
[]
columns
=
header
.
split
(
SPLITTER
);
for
(
int
index
=
0
;
index
<
columns
.
length
;
index
++)
{
if
(
pedestrianIdKeys
.
contains
(
columns
[
index
]))
{
// header name without processor ID
String
headerName
=
columns
[
index
].
split
(
OutputFile
.
headerProcSep
)[
0
];
if
(
pedestrianIdKeys
.
contains
(
headerName
))
{
errorWhenNotUniqueColumn
(
pedIdIndex
,
headerName
);
pedIdIndex
=
index
;
}
else
if
(
stepKeys
.
contains
(
columns
[
index
]))
{
}
else
if
(
stepKeys
.
contains
(
headerName
))
{
errorWhenNotUniqueColumn
(
stepIndex
,
headerName
);
stepIndex
=
index
;
}
else
if
(
xKeys
.
contains
(
columns
[
index
]))
{
}
else
if
(
xKeys
.
contains
(
headerName
))
{
errorWhenNotUniqueColumn
(
xIndex
,
headerName
);
xIndex
=
index
;
}
else
if
(
yKeys
.
contains
(
columns
[
index
]))
{
}
else
if
(
yKeys
.
contains
(
headerName
))
{
errorWhenNotUniqueColumn
(
yIndex
,
headerName
);
yIndex
=
index
;
}
else
if
(
targetIdKeys
.
contains
(
columns
[
index
]))
{
}
else
if
(
targetIdKeys
.
contains
(
headerName
))
{
errorWhenNotUniqueColumn
(
targetIdIndex
,
headerName
);
targetIdIndex
=
index
;
}
else
if
(
groupIdKeys
.
contains
(
columns
[
index
])){
}
else
if
(
groupIdKeys
.
contains
(
headerName
)){
errorWhenNotUniqueColumn
(
groupIdIndex
,
headerName
);
groupIdIndex
=
index
;
}
else
if
(
groupSizeKeys
.
contains
(
columns
[
index
])){
else
if
(
groupSizeKeys
.
contains
(
headerName
)){
errorWhenNotUniqueColumn
(
groupSizeIndex
,
headerName
);
groupSizeIndex
=
index
;
}
else
if
(
stridesKeys
.
contains
(
columns
[
index
]))
{
else
if
(
stridesKeys
.
contains
(
headerName
))
{
errorWhenNotUniqueColumn
(
stridesIndex
,
headerName
);
stridesIndex
=
index
;
}
}
try
{
if
(
pedIdIndex
!=
-
1
&&
xIndex
!=
-
1
&&
yIndex
!=
-
1
&&
stepIndex
!=
-
1
)
{
// load default values with no groups
return
true
;
}
else
{
return
false
;
}
}
catch
(
Exception
e
)
{
logger
.
warn
(
"could not read trajectory file. The file format might not be compatible or it is missing."
);
throw
e
;
}
if
(!
(
pedIdIndex
!=
notSetColumnIndexIdentifier
&&
xIndex
!=
notSetColumnIndexIdentifier
&&
yIndex
!=
notSetColumnIndexIdentifier
&&
stepIndex
!=
notSetColumnIndexIdentifier
))
{
// load default values with no groups
throw
new
IOException
(
String
.
format
(
"All columns with "
+
notSetColumnIndexIdentifier
+
" value could "
+
"not be found in the trajectory file pedIdIndex=%d, x-values=%d, y-values=%d, step "
+
"values=%d"
,
pedIdIndex
,
xIndex
,
yIndex
,
stepIndex
));
}
}
private
Map
<
Step
,
List
<
Agent
>>
readStandardTrajectoryFile
()
throws
IOException
{
try
(
BufferedReader
in
=
IOUtils
.
defaultBufferedReader
(
this
.
trajectoryFilePath
))
{
return
in
.
lines
()
// a stream of lines
.
skip
(
1
)
// skip the first line i.e. the header
.
map
(
line
->
split
(
line
))
// split the line into string tokens
.
map
(
line
->
split
(
line
))
// split the line into string tokens
.
map
(
rowTokens
->
parseRowTokens
(
rowTokens
))
// transform those tokens into a pair of java objects (step, agent)
.
collect
(
Collectors
.
groupingBy
(
Pair:
:
getKey
,
// group all agent objects by the step.
Collectors
.
mapping
(
Pair:
:
getValue
,
Collectors
.
toList
())));
}
catch
(
Exception
e
){
logger
.
warn
(
"
c
ould not read trajectory file. The file format might not be compatible or it is missing."
);
logger
.
warn
(
"
C
ould not read trajectory file. The file format might not be compatible or it is missing."
);
throw
e
;
}
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment