Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Simonstrator
PeerfactSim.KOM
Commits
a18638c5
Commit
a18638c5
authored
Feb 25, 2020
by
Julian Zobel
Browse files
Converter for smarter trace databases to .if movement file for simonstrator
parent
bbdc285e
Changes
7
Hide whitespace changes
Inline
Side-by-side
src/de/tud/kom/p2psim/impl/topology/movement/TracefileMovementModel.java
0 → 100644
View file @
a18638c5
/*
* Copyright (c) 2005-2010 KOM – Multimedia Communications Lab
*
* This file is part of PeerfactSim.KOM.
*
* PeerfactSim.KOM is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* PeerfactSim.KOM is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with PeerfactSim.KOM. If not, see <http://www.gnu.org/licenses/>.
*
*/
package
de.tud.kom.p2psim.impl.topology.movement
;
import
java.io.File
;
import
java.io.FileNotFoundException
;
import
java.util.LinkedHashMap
;
import
java.util.LinkedList
;
import
java.util.Scanner
;
import
de.tud.kom.p2psim.api.scenario.ConfigurationException
;
import
de.tud.kom.p2psim.api.topology.movement.MovementModel
;
import
de.tud.kom.p2psim.api.topology.movement.SimLocationActuator
;
import
de.tud.kom.p2psim.impl.topology.movement.modularosm.IAttractionBasedMovementAnalyzer
;
import
de.tud.kom.p2psim.impl.topology.movement.modularosm.attraction.IAttractionGenerator
;
import
de.tud.kom.p2psim.impl.topology.movement.modularosm.mapvisualization.IMapVisualization
;
import
de.tud.kom.p2psim.impl.topology.util.PositionVector
;
import
de.tud.kom.p2psim.impl.topology.views.VisualizationTopologyView.VisualizationInjector
;
import
de.tudarmstadt.maki.simonstrator.api.Event
;
import
de.tudarmstadt.maki.simonstrator.api.EventHandler
;
import
de.tudarmstadt.maki.simonstrator.api.Monitor
;
import
de.tudarmstadt.maki.simonstrator.api.Time
;
public
class
TracefileMovementModel
implements
MovementModel
,
EventHandler
{
public
static
String
tracefileFolder
=
"smarter/tracefiles/"
;
public
static
String
tracefilePrefix
=
"smarterTraceFile-"
;
protected
final
int
EVENT_MOVE
=
1
;
protected
long
timeBetweenMoveOperations
;
protected
IMapVisualization
mapVisualization
;
protected
IAttractionGenerator
attractionGenerator
;
protected
boolean
initialized
=
false
;
private
final
LinkedHashMap
<
SimLocationActuator
,
LinkedList
<
Step
>>
components
;
private
LinkedList
<
File
>
tracefiles
;
private
boolean
first
=
true
;
public
TracefileMovementModel
()
{
components
=
new
LinkedHashMap
<
SimLocationActuator
,
LinkedList
<
Step
>>();
tracefiles
=
new
LinkedList
<
File
>();
}
public
void
initialize
()
{
if
(
initialized
)
{
return
;
}
File
folder
=
new
File
(
tracefileFolder
);
if
(!
folder
.
exists
())
{
throw
new
UnsupportedOperationException
(
"Tracefile folder not found"
);
}
for
(
File
tracefile
:
folder
.
listFiles
())
{
if
(
tracefile
.
getName
().
contains
(
tracefilePrefix
))
{
tracefiles
.
add
(
tracefile
);
}
}
if
(
mapVisualization
!=
null
)
{
VisualizationInjector
.
injectComponent
(
mapVisualization
);
}
initialized
=
true
;
Event
.
scheduleWithDelay
(
timeBetweenMoveOperations
,
this
,
null
,
EVENT_MOVE
);
}
@Override
public
void
eventOccurred
(
Object
content
,
int
type
)
{
if
(
type
==
EVENT_MOVE
)
{
move
();
}
}
private
void
move
()
{
if
(
first
)
{
components
.
forEach
((
component
,
steps
)
->
{
component
.
updateCurrentLocation
(
new
PositionVector
(-
1
,
-
1
));
});
}
// as the files contain the timestamp in seconds, the current time needs to be converted in seconds
long
currentTime
=
Time
.
getCurrentTime
()
/
Time
.
SECOND
;
LinkedList
<
SimLocationActuator
>
toRemove
=
new
LinkedList
<>();
components
.
forEach
((
component
,
steps
)
->
{
Step
step
=
steps
.
peek
();
if
(
step
!=
null
)
{
if
(
currentTime
<
step
.
timestamp
)
{
//component.updateCurrentLocation(new PositionVector(-1, -1));
}
else
{
step
=
steps
.
pop
();
component
.
updateCurrentLocation
(
new
PositionVector
(
step
.
x
,
step
.
y
));
}
}
else
{
System
.
out
.
println
(
"Component "
+
component
.
getHost
().
getId
()+
" left the area at "
+
Time
.
getFormattedTime
());
component
.
updateCurrentLocation
(
new
PositionVector
(-
1
,
-
1
));
toRemove
.
add
(
component
);
}
});
for
(
SimLocationActuator
simLocationActuator
:
toRemove
)
{
components
.
remove
(
simLocationActuator
);
}
Event
.
scheduleWithDelay
(
timeBetweenMoveOperations
,
this
,
null
,
EVENT_MOVE
);
if
(
first
)
{
System
.
out
.
println
(
"first with "
+
components
.
keySet
().
size
()
+
" hosts"
);
// Inform analyzer of resolved movement
if
(
Monitor
.
hasAnalyzer
(
IAttractionBasedMovementAnalyzer
.
class
))
{
Monitor
.
getOrNull
(
IAttractionBasedMovementAnalyzer
.
class
).
onAllNodeInitializationCompleted
(
components
.
keySet
());
}
first
=
false
;
}
}
@Override
public
void
addComponent
(
SimLocationActuator
actuator
)
{
if
(!
initialized
)
{
initialize
();
}
associateTracefile
(
actuator
);
}
private
void
associateTracefile
(
SimLocationActuator
actuator
)
{
if
(
tracefiles
.
isEmpty
())
{
throw
new
UnsupportedOperationException
(
"List of tracefiles is empty, thus cannot initiate the component!"
);
}
if
(
components
.
containsKey
(
actuator
))
{
throw
new
UnsupportedOperationException
(
"Component was already assigned!"
);
}
LinkedList
<
Step
>
stepQueue
=
new
LinkedList
<
Step
>();
File
tracefile
=
tracefiles
.
pop
();
Scanner
filescanner
;
try
{
filescanner
=
new
Scanner
(
tracefile
);
while
(
filescanner
.
hasNextLine
())
{
String
line
=
filescanner
.
nextLine
();
String
[]
split
=
line
.
split
(
" "
);
long
timestamp
=
Long
.
valueOf
(
split
[
0
]);
//double lat = Double.valueOf(split[1]);
//double lon = Double.valueOf(split[2]);
double
x
=
Double
.
valueOf
(
split
[
3
]);
double
y
=
Double
.
valueOf
(
split
[
4
]);
Step
s
=
new
Step
(
timestamp
,
x
,
y
);
stepQueue
.
add
(
s
);
}
filescanner
.
close
();
}
catch
(
FileNotFoundException
e
)
{
e
.
printStackTrace
();
}
catch
(
Exception
e
)
{
System
.
err
.
println
(
tracefile
.
getName
());
e
.
printStackTrace
();
}
System
.
out
.
println
(
actuator
.
getHost
().
getId
()
+
" <> "
+
tracefile
.
getName
());
components
.
put
(
actuator
,
stepQueue
);
}
@Override
public
void
placeComponent
(
SimLocationActuator
actuator
)
{
// Initial placement
actuator
.
updateCurrentLocation
(
new
PositionVector
(-
1
,
-
1
));
}
@Override
public
void
setTimeBetweenMoveOperations
(
long
time
)
{
this
.
timeBetweenMoveOperations
=
time
;
}
public
void
setIMapVisualization
(
IMapVisualization
mapVisualization
)
{
this
.
mapVisualization
=
mapVisualization
;
}
public
void
setIAttractionGenerator
(
IAttractionGenerator
attractionGenerator
)
{
if
(
attractionGenerator
==
null
)
{
throw
new
ConfigurationException
(
"AttractionGenerator is missing in ModularMovementModel!"
);
}
this
.
attractionGenerator
=
attractionGenerator
;
}
private
class
Step
{
public
final
double
x
;
public
final
double
y
;
public
final
long
timestamp
;
public
Step
(
long
timestamp
,
double
x
,
double
y
)
{
this
.
x
=
x
;
this
.
y
=
y
;
this
.
timestamp
=
timestamp
;
}
}
}
src/de/tud/kom/p2psim/impl/topology/movement/modularosm/IAttractionBasedMovementAnalyzer.java
View file @
a18638c5
...
...
@@ -28,7 +28,7 @@ import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.IAttractio
public
interface
IAttractionBasedMovementAnalyzer
extends
Analyzer
{
public
void
onAllNode
Movement
Completed
(
Set
<
SimLocationActuator
>
nodes
);
public
void
onAllNode
Initialization
Completed
(
Set
<
SimLocationActuator
>
nodes
);
public
void
onAttractionPointAdded
(
IAttractionPoint
attractionpoint
);
...
...
src/de/tud/kom/p2psim/impl/topology/movement/modularosm/ModularMovementModel.java
View file @
a18638c5
...
...
@@ -177,7 +177,7 @@ public class ModularMovementModel implements MovementModel, EventHandler, Attrac
// Inform analyzer of resolved movement
if
(
Monitor
.
hasAnalyzer
(
IAttractionBasedMovementAnalyzer
.
class
))
{
Monitor
.
getOrNull
(
IAttractionBasedMovementAnalyzer
.
class
).
onAllNode
Movement
Completed
(
moveableHosts
);
Monitor
.
getOrNull
(
IAttractionBasedMovementAnalyzer
.
class
).
onAllNode
Initialization
Completed
(
moveableHosts
);
}
}
...
...
src/de/tud/kom/p2psim/impl/topology/movement/modularosm/SocialGroupMovementModel.java
View file @
a18638c5
...
...
@@ -130,7 +130,7 @@ public class SocialGroupMovementModel extends ModularMovementModel {
// Inform analyzer of resolved movement
if
(
Monitor
.
hasAnalyzer
(
IAttractionBasedMovementAnalyzer
.
class
))
{
Monitor
.
getOrNull
(
IAttractionBasedMovementAnalyzer
.
class
).
onAllNode
Movement
Completed
(
moveableHosts
);
Monitor
.
getOrNull
(
IAttractionBasedMovementAnalyzer
.
class
).
onAllNode
Initialization
Completed
(
moveableHosts
);
}
}
...
...
src/de/tud/kom/p2psim/impl/topology/movement/smarter/DataConverter.java
View file @
a18638c5
...
...
@@ -21,6 +21,9 @@
package
de.tud.kom.p2psim.impl.topology.movement.smarter
;
import
java.io.File
;
import
java.io.FileNotFoundException
;
import
java.io.PrintWriter
;
import
java.io.UnsupportedEncodingException
;
import
java.sql.Connection
;
import
java.sql.DriverManager
;
import
java.sql.ResultSet
;
...
...
@@ -29,29 +32,32 @@ import java.sql.Statement;
import
java.util.ArrayList
;
import
java.util.List
;
import
org.apache.commons.io.FilenameUtils
;
import
de.tud.kom.p2psim.impl.topology.movement.modularosm.GPSCalculation
;
import
de.tud.kom.p2psim.impl.topology.movement.modularosm.attraction.IAttractionGenerator
;
import
de.tud.kom.p2psim.impl.topology.util.PositionVector
;
import
de.tudarmstadt.maki.simonstrator.api.component.sensor.location.IAttractionPoint
;
import
de.tudarmstadt.maki.simonstrator.api.util.XMLConfigurableConstructor
;
public
class
DataConverter
{
public
DataConverter
()
{
@XMLConfigurableConstructor
({
"sqlitefolderPath"
,
"tracefileFolder"
,
"tracefilePrefix"
})
public
DataConverter
(
String
sqlitefolderPath
,
String
tracefileFolder
,
String
tracefilePrefix
)
{
this
.
sqliteFolderPath
=
sqlitefolderPath
;
this
.
tracefileFolder
=
tracefileFolder
;
this
.
tracefilePrefix
=
tracefilePrefix
;
readTraceDatabases
();
}
public
static
String
tracefileFolder
=
"smarter/tracefiles/"
;
public
static
String
tracefilePrefix
=
"smarterTraceFile-"
;
public
static
String
sqliteFolderPath
=
"smarter/databases/"
;
public
static
long
start
=
10
*
3600
+
30
*
60
;
// 10:30
public
static
long
end
=
15
*
3600
+
30
*
60
;
// 15:30
public
static
void
readTraceDatabases
()
{
List
<
IAttractionPoint
>
aps
=
IAttractionGenerator
.
attractionPoints
;
DataGrabber
grabber
=
new
DataGrabber
();
// Set the path to folder containing the .sqlite files here
String
sqliteFolderPath
=
"D:/Simonstrator/simrunner/smarter/databases/"
;
List
<
String
>
filePaths
=
DataConverter
.
getFilePaths
(
sqliteFolderPath
);
try
{
...
...
@@ -61,47 +67,95 @@ public class DataConverter {
e
.
printStackTrace
();
}
for
(
String
filePath
:
filePaths
)
{
grabber
.
connect
(
filePath
);
List
<
SmarterDBEntry
>
listOfEntries
=
grabber
.
select
(
"SELECT * FROM gps_data"
);
grabber
.
disconnect
();
for
(
String
filePath
:
filePaths
)
{
createTraceFile
(
filePath
);
}
}
private
static
void
createTraceFile
(
String
filePath
)
{
DataGrabber
grabber
=
new
DataGrabber
();
grabber
.
connect
(
filePath
);
List
<
SmarterDBEntry
>
listOfEntries
=
grabber
.
select
(
"SELECT * FROM gps_data"
);
grabber
.
disconnect
();
boolean
active
=
false
;
int
fileID
=
Integer
.
parseInt
(
filePath
.
split
(
"\\."
)[
3
]);
if
(
listOfEntries
.
isEmpty
())
{
System
.
out
.
println
(
"DataConverter: "
+
fileID
+
" has no entries."
);
return
;
}
try
{
String
tracefilePath
=
tracefileFolder
+
tracefilePrefix
+
fileID
+
".if"
;
File
yourFile
=
new
File
(
tracefilePath
);
if
(
yourFile
.
exists
())
{
System
.
out
.
println
(
"DataConverter: "
+
tracefilePath
+
" exists - overwrite"
);
}
// Analyze data
for
(
SmarterDBEntry
entry
:
listOfEntries
)
{
int
id
=
entry
.
get_id
();
String
timestamp
=
entry
.
getTimestamp
();
double
lat
=
entry
.
getLatitude
();
double
lon
=
entry
.
getLongitude
();
double
alt
=
entry
.
getAltitude
();
double
acc
=
entry
.
getAccuracy
();
PrintWriter
writer
=
new
PrintWriter
(
tracefilePath
,
"UTF-8"
);
long
lastSimulationtimestamp
=
-
1
;
for
(
SmarterDBEntry
entry
:
listOfEntries
)
{
String
timestamp
=
entry
.
getTimestamp
().
split
(
" "
)[
1
];
String
[]
values
=
timestamp
.
split
(
":"
);
int
hours
=
Integer
.
parseInt
(
values
[
0
]);
int
minutes
=
Integer
.
parseInt
(
values
[
1
]);
int
seconds
=
Integer
.
parseInt
(
values
[
2
]);
// Example: 13:42:10 = 3*3600s + 42*60s + 10*1s
long
simulationtimestamp
=
hours
*
3600
+
minutes
*
60
+
seconds
*
1
;
if
(
GPSCalculation
.
isWithinSimulationBoundaries
(
lat
,
lon
))
{
PositionVector
p
=
GPSCalculation
.
transformGPSWindowToOwnWorld
(
lat
,
lon
);
for
(
IAttractionPoint
ap
:
aps
)
{
// filter double entries
if
(
simulationtimestamp
==
lastSimulationtimestamp
)
{
continue
;
}
else
{
lastSimulationtimestamp
=
simulationtimestamp
;
}
if
(
simulationtimestamp
>=
start
&&
simulationtimestamp
<=
end
)
{
double
lat
=
entry
.
getLatitude
();
double
lon
=
entry
.
getLongitude
();
// if the position in the database is within the simulated area, parse the position to a simulation position and save it
if
(
GPSCalculation
.
isWithinSimulationBoundaries
(
lat
,
lon
))
{
PositionVector
p
=
GPSCalculation
.
transformGPSWindowToOwnWorld
(
lat
,
lon
);
if
(
ap
.
distanceTo
(
p
)
<=
ap
.
getRadius
())
{
System
.
out
.
println
(
ap
.
getName
());
System
.
out
.
println
(
id
+
": "
+
lat
+
" / "
+
lon
+
" / "
+
alt
+
" +/- "
+
acc
+
" --- "
+
timestamp
);
System
.
out
.
println
(
p
);
if
(!
active
)
{
for
(
IAttractionPoint
ap
:
IAttractionGenerator
.
attractionPoints
)
{
if
(
p
.
distanceTo
(
ap
)
<=
ap
.
getRadius
())
{
active
=
true
;
}
}
}
}
}
}
return
;
}
if
(
active
)
{
// truncate the date from the timestamp, separate entries and parse to a timestamp containing only the seconds.
// as the test started around 10:00, reduce the timestamp by 10 hours
if
(
simulationtimestamp
>=
start
&&
simulationtimestamp
<=
end
)
{
simulationtimestamp
-=
start
;
writer
.
println
(
simulationtimestamp
+
" "
+
lat
+
" "
+
lon
+
" "
+
p
.
getX
()
+
" "
+
p
.
getY
());
}
}
}
}
}
writer
.
close
();
}
catch
(
FileNotFoundException
e
)
{
// TODO Auto-generated catch block
e
.
printStackTrace
();
}
catch
(
UnsupportedEncodingException
e
)
{
// TODO Auto-generated catch block
e
.
printStackTrace
();
}
}
}
/**
* Returns a list of full file paths of a given directory
...
...
@@ -268,14 +322,8 @@ public class DataConverter {
try
{
// db parameters
String
url
=
"jdbc:sqlite:"
+
filePath
;
// create a connection to the database
System
.
out
.
println
(
url
);
// create a connection to the database
conn
=
DriverManager
.
getConnection
(
url
);
System
.
out
.
println
(
"Connection to "
+
filePath
+
" has been established."
);
}
catch
(
SQLException
e
)
{
System
.
out
.
println
(
e
.
getMessage
());
}
...
...
src/de/tud/kom/p2psim/impl/topology/movement/smarter/dataanalyzer/Analyzer.java
deleted
100644 → 0
View file @
bbdc285e
/*
* Copyright (c) 2005-2010 KOM � Multimedia Communications Lab
*
* This file is part of PeerfactSim.KOM.
*
* PeerfactSim.KOM is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* PeerfactSim.KOM is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with PeerfactSim.KOM. If not, see <http://www.gnu.org/licenses/>.
*
*/
package
de.tud.kom.p2psim.impl.topology.movement.smarter.dataanalyzer
;
import
java.io.BufferedReader
;
import
java.io.File
;
import
java.io.FileNotFoundException
;
import
java.io.FileReader
;
import
java.io.IOException
;
import
java.io.PrintWriter
;
import
java.io.UnsupportedEncodingException
;
import
java.util.ArrayList
;
/**
* Starting point for analyzing SQLite Files.
*
* @author Marcel Verst
* @version 26.05.2018
*/
public
class
Analyzer
{
// Area of Runway = rectangle between the points High and Low
public
static
double
latRunwayHigh
=
51.791816
;
public
static
double
lonRunwayHigh
=
8.781827
;
public
static
double
latRunwayLow
=
51.790350
;
public
static
double
lonRunwayLow
=
8.786664
;
// Area of Town = rectangle between the points High and Low
public
static
double
latTownHigh
=
51.791955
;
public
static
double
lonTownHigh
=
8.772932
;
public
static
double
latTownLow
=
51.791039
;
public
static
double
lonTownLow
=
8.774717
;
// Area of TinCity = rectangle between the points High and Low
public
static
double
latTinHigh
=
51.818949
;
public
static
double
lonTinHigh
=
8.807715
;
public
static
double
latTinLow
=
51.817314
;
public
static
double
lonTinLow
=
8.813276
;
/**
* Checks, if a certain GPS point is within Runway area
*
* @param lat
* Latitude to check
* @param lon
* Longitude to check
* @return true if in Runway area and false if not
*/
public
static
boolean
inRunway
(
double
lat
,
double
lon
)
{
return
(
lat
>=
latRunwayLow
&&
lat
<=
latRunwayHigh
&&
lon
>=
lonRunwayHigh
&&
lon
<=
lonRunwayLow
);
}
/**
* Checks, if a certain GPS point is within Town area
*
* @param lat
* Latitude to check
* @param lon
* Longitude to check
* @return true if in Town area and false if not
*/
public
static
boolean
inTown
(
double
lat
,
double
lon
)
{
return
(
lat
>=
latTownLow
&&
lat
<=
latTownHigh
&&
lon
>=
lonTownHigh
&&
lon
<=
lonTownLow
);
}
/**
* Checks, if a certain GPS point is within TinCity area
*
* @param lat
* Latitude to check
* @param lon
* Longitude to check
* @return true if in TinCity area and false if not
*/
public
static
boolean
inTinCity
(
double
lat
,
double
lon
)
{
return
(
lat
>=
latTinLow
&&
lat
<=
latTinHigh
&&
lon
>=
lonTinHigh
&&
lon
<=
lonTinLow
);
}
/**
* Checks, if a certain GPS point is within one of the start areas
*
* @param lat
* Latitude to check
* @param lon
* Longitude to check
* @return true if in one of the three areas, false if not
*/
public
static
boolean
inStartArea
(
double
lat
,
double
lon
)
{
return
(
inRunway
(
lat
,
lon
)
||
inTown
(
lat
,
lon
)
||
inTinCity
(
lat
,
lon
));
}
/**
* Returns a list of full file paths of a given directory
*
* @param directory
* The
* @return
*/
public
ArrayList
<
String
>
getFilePaths
(
String
directory
)
{
File
folder
=
new
File
(
directory
);
File
[]
listOfFiles
=
folder
.
listFiles
();
ArrayList
<
String
>
filePaths
=
new
ArrayList
<
String
>();
if
(
listOfFiles
.
length
==
0
)
{
System
.
out
.
println
(
"No files in directory"
);
return
null
;
}
for
(
int
i
=
0
;
i
<
listOfFiles
.
length
;
i
++)
{
if
(
listOfFiles
[
i
].
isFile
())
{
filePaths
.
add
(
directory
+
listOfFiles
[
i
].
getName
());
}
}
return
filePaths
;
}
/**
* Creates an .if File which has the following format for a line: timestamp
* x-coordinate y-coordinate
*
* @param fileName
* The file name of the database
* @param listOfEntries
* all entries of the current database
* @param startID
* The startID on which we start with the first entry for the .if
* file
*/
private
static
void
createIFFile
(
String
fileName
,
ArrayList
<
DBEntry
>
listOfEntries
,
int
startID
)
{
// filename = gps_data-192.168.0.10.db
// 0 1 2 3 4
int
fileID
=
Integer
.
parseInt
(
fileName
.
split
(
"\\."
)[
3
]);
try
{
System
.
out
.
println
(
"Creating file: mobilityTraceFile-File-Modified-"
+
fileID
+
".if"
);
PrintWriter
writer
=
new
PrintWriter
(
"smarter/traces-mv/mobilityTraceFile-File-Modified-"
+
fileID
+
".if"
,
"UTF-8"
);
for
(
DBEntry
entry
:
listOfEntries
)
{
if
(
entry
.
get_id
()
>=
startID
)
{
double
lat
=
entry
.
getLatitude
();
double
lon
=
entry
.
getLongitude
();
String
timestamp
=
entry
.
getTimestamp
();
// timestamp format: 2017-09-02 10:21:02
// 0 1
String
time
=
timestamp
.
split
(
" "
)[
1
];
// time format: 10:21:02
// 0 1 2
String
[]
values
=
time
.
split
(
":"
);
int
hours
=
Integer
.
parseInt
(
values
[
0
]);
int
minutes
=
Integer
.
parseInt
(
values
[
1
]);
int
seconds
=
Integer
.
parseInt
(
values
[
2
]);
// Example: 13:42:10 = 3*3600s + 42*60s + 10*1s
int
time_for_file
=
(
hours
-
10
)
*
3600
+
minutes
*
60
+
seconds
*
1
;
writer
.
println
(
time_for_file
+
" "
+
lat
+
" "
+
lon
);
}
}
writer
.
close
();
}
catch
(
FileNotFoundException
|
UnsupportedEncodingException
e
)
{
e
.
printStackTrace
();
}
}
/**
* Creates a modified version of the .if file. Calculates based on the timestamp
* the first relevant ID and from then on copies the lines from the original .if
* file. This procedure ensures that the modified .if files only contains the
* relevant entries, meaning the starting point, when a person reached one of
* the start areas (Runway, Town or TinCity). The timestamp parameter is the
* timestamp on which a person first entered one of the three start areas. Time
* conversion from timestamp to seconds is also applied.
*
* @param fileName
* The file name of the database
*/
private
static
void
createModifiedIFFile
(
String
fileName
,
String
timestamp
)
{
// filename = gps_data-192.168.0.10.db
// 0 1 2 3 4
int
fileID
=
Integer
.
parseInt
(
fileName
.
split
(
"\\."
)[
3
]);
// timestamp format: 2017-09-02 10:21:02
// 0 1
String
time
=
timestamp
.
split
(
" "
)[
1
];
// time format: 10:21:02
// 0 1 2
String
[]
values
=
time
.
split
(
":"
);
int
hours
=
Integer
.
parseInt
(
values
[
0
]);
int
minutes
=
Integer
.
parseInt
(
values
[
1
]);
int
seconds
=
Integer
.
parseInt
(
values
[
2
]);
// Example: 13:42:10 = 3*3600s + 42*60s + 10*1s
int
startID
=
(
hours
-
10
)
*
3600
+
minutes
*
60
+
seconds
*
1
;
try
{
System
.
out
.
println
(
"Creating file: mobilityTraceFile-File-Modified-"
+
fileID
+
".if"
);
PrintWriter
writer
=
new
PrintWriter
(
"smarter/traces-mv/mobilityTraceFile-File-Modified-"
+
fileID
+
".if"
,
"UTF-8"
);
File
file
=
new
File
(
"smarter/trace/mobilityTraceFile-File-"
+
fileID
+
".if"
);
FileReader
fileReader
=
new
FileReader
(
file
);
BufferedReader
bufferedReader
=
new
BufferedReader
(
fileReader
);
String
line
;
while
((
line
=
bufferedReader
.
readLine
())
!=
null
)
{
// line format: 1234 450 123
// 0 1 2
String
[]
split
=
line
.
split
(
" "
);
int
lineID
=
Integer
.
parseInt
(
split
[
0
]);
if
(
lineID
>=
startID
)
writer
.
println
(
line
);
}
fileReader
.
close
();
writer
.
close
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
/**
* Connects to all .sqlite databases in a given directory and analyzes the
* entries.
*/
public
static
void
analyzeTraces
()
{
// Objects
Analyzer
analyzer
=
new
Analyzer
();
DataGrabber
grabber
=
new
DataGrabber
();
// Set the path to folder containing the .sqlite files here
String
sqliteFolderPath
=
"C:/Users/MarcelV/Desktop/Uni Programme/Feldtest/DB Gefiltert/"
;
// Initialize counters
int
counterRunway
=
0
;
int
counterTown
=
0
;
int
counterTinCity
=
0
;
boolean
foundStartID
;
boolean
createModifiedIFFile
=
true
;
ArrayList
<
String
>
filePaths
=
analyzer
.
getFilePaths
(
sqliteFolderPath
);
try
{
PrintWriter
writer
=
new
PrintWriter
(
"smarter/start_ids.txt"
,
"UTF-8"
);
for
(
String
filePath
:
filePaths
)
{
foundStartID
=
false
;
// Get data
grabber
.
connect
(
filePath
);
ArrayList
<
DBEntry
>
listOfEntries
=
grabber
.
select
(
"SELECT * FROM gps_data"
);
grabber
.
disconnect
();
// C:/Users/Marcel/Desktop/Uni Programme/Feldtest/DB
// Gefiltert/gps_data-192.168.0.10.db
String
[]
split
=
filePath
.
split
(
"/"
);
String
fileName
=
split
[
7
];
// Analyze data
for
(
DBEntry
entry
:
listOfEntries
)
{
if
(!
foundStartID
)
{
double
lat
=
entry
.
getLatitude
();
double
lon
=
entry
.
getLongitude
();
if
(
inRunway
(
lat
,
lon
))
{
System
.
out
.
println
(
"Entered Runway at ID: "
+
entry
.
get_id
()
+
" at time: "
+
entry
.
getTimestamp
());
writer
.
println
(
fileName
+
": Entered Runway at ID: "
+
entry
.
get_id
()
+
" at time: "
+
entry
.
getTimestamp
());
// Create of the files
if
(
createModifiedIFFile
)
createModifiedIFFile
(
fileName
,
entry
.
getTimestamp
());
else
createIFFile
(
fileName
,
listOfEntries
,
entry
.
get_id
());
counterRunway
++;
foundStartID
=
true
;
}
else
if
(
inTown
(
lat
,
lon
))
{
System
.
out
.
println
(
"Entered Town at ID: "
+
entry
.
get_id
()
+
" at time: "
+
entry
.
getTimestamp
());
writer
.
println
(
fileName
+
": Entered Town at ID: "
+
entry
.
get_id
()
+
" at time: "
+
entry
.
getTimestamp
());
// Create of the files
if
(
createModifiedIFFile
)
createModifiedIFFile
(
fileName
,
entry
.
getTimestamp
());
else
createIFFile
(
fileName
,
listOfEntries
,
entry
.
get_id
());
counterTown
++;
foundStartID
=
true
;
}
else
if
(
inTinCity
(
lat
,
lon
))
{
System
.
out
.
println
(
"Entered TinCity at ID: "
+
entry
.
get_id
()
+
" at time: "
+
entry
.
getTimestamp
());
writer
.
println
(
fileName
+
": Entered TinCity at ID: "
+
entry
.
get_id
()
+
" at time: "
+
entry
.
getTimestamp
());
// Create of the files
if
(
createModifiedIFFile
)
createModifiedIFFile
(
fileName
,
entry
.
getTimestamp
());
else
createIFFile
(
fileName
,
listOfEntries
,
entry
.
get_id
());
counterTinCity
++;
foundStartID
=
true
;
}
}
}
}
writer
.
println
(
"Counter Runway : "
+
counterRunway
);
writer
.
println
(
"Counter Town : "
+
counterTown
);
writer
.
println
(
"Counter TinCity : "
+
counterTinCity
);
writer
.
close
();
}
catch
(
FileNotFoundException
e
)
{
e
.
printStackTrace
();
}
catch
(
UnsupportedEncodingException
e
)
{
e
.
printStackTrace
();
}
System
.
out
.
println
(
"\nCounter Runway: "
+
counterRunway
+
"\nCounter Town : "
+
counterTown
+
"\nCounter TinCity : "
+
counterTinCity
);
}
}
\ No newline at end of file
src/de/tud/kom/p2psim/impl/topology/movement/smarter/dataanalyzer/IfFileEntry.java
deleted
100644 → 0
View file @
bbdc285e
/*
* Copyright (c) 2005-2010 KOM � Multimedia Communications Lab
*
* This file is part of PeerfactSim.KOM.
*
* PeerfactSim.KOM is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* PeerfactSim.KOM is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with PeerfactSim.KOM. If not, see <http://www.gnu.org/licenses/>.
*
*/
package
de.tud.kom.p2psim.impl.topology.movement.smarter.dataanalyzer
;
public
class
IfFileEntry
{
int
id
;
double
x
;
double
y
;
public
IfFileEntry
(
int
id
,
double
x
,
double
y
)
{
this
.
id
=
id
;
this
.
x
=
x
;
this
.
y
=
y
;
}
public
int
getId
()
{
return
id
;
}
public
void
setId
(
int
id
)
{
this
.
id
=
id
;
}
public
double
getX
()
{
return
x
;
}
public
void
setX
(
double
x
)
{
this
.
x
=
x
;
}
public
double
getY
()
{
return
y
;
}
public
void
setY
(
double
y
)
{
this
.
y
=
y
;
}
}
Write
Preview
Markdown
is supported
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