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
cd980908
Commit
cd980908
authored
Apr 08, 2020
by
Julian Zobel
Browse files
Deleted old MV code
parent
8d14d16e
Changes
9
Hide whitespace changes
Inline
Side-by-side
src/de/tud/kom/p2psim/impl/topology/movement/SmarterMovementModelNew.java
deleted
100644 → 0
View file @
8d14d16e
/*
* 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.util.LinkedHashSet
;
import
java.util.Set
;
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.mapvisualization.IMapVisualization
;
import
de.tud.kom.p2psim.impl.topology.movement.smarter.dataanalyzer.Statistics
;
import
de.tud.kom.p2psim.impl.topology.movement.smarter.host.SmarterHost
;
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.component.sensor.location.Location
;
/**
* Represents the movement model of the acquired SMARTER traces. By calling the class an analyzing procedure is started which analyzes the
* .sqlite database files and creates If files in case they do not exist already.
* Adds and places components to the simulation based on the created If files.
*
* @author MarcelV
* @version 1.0, 12.06.2018
*/
public
class
SmarterMovementModelNew
implements
MovementModel
,
EventHandler
{
protected
IMapVisualization
mapVisualization
;
private
static
final
Location
DEFAULT_LOCATION
=
new
PositionVector
(
Double
.
NaN
,
Double
.
NaN
);
public
static
SmarterMovementModelNew
movement
;
protected
long
timeBetweenMoveOperations
;
boolean
dataAnalyzed
;
private
Set
<
SimLocationActuator
>
actuatorList
=
new
LinkedHashSet
<
SimLocationActuator
>();
/**
* Creates the movement model and checks if the databases should be analyzed
*/
public
SmarterMovementModelNew
()
{
movement
=
this
;
dataAnalyzed
=
false
;
// scheduling initalization!
Event
.
scheduleImmediately
(
this
,
null
,
42
);
}
private
void
initialize
()
{
if
(
mapVisualization
!=
null
)
{
VisualizationInjector
.
injectComponent
(
mapVisualization
);
}
}
/**
* Returns the instance of this class
* @return instance of this class
*/
public
static
SmarterMovementModelNew
getInstance
()
{
return
movement
;
}
/**
* Checks if all 94 If files have already been created.
* @return true if files have been created, else false
*/
private
boolean
filesAlreadyExist
()
{
String
folderName
=
"smarter/traces-mv/"
;
File
folder
=
new
File
(
folderName
);
if
(!
folder
.
exists
())
folder
.
mkdir
();
int
counter
=
0
;
for
(
File
file
:
folder
.
listFiles
())
{
String
currentFile
=
file
.
getName
();
for
(
int
index
=
1
;
index
<=
125
;
index
++)
{
String
tempFile
=
"mobilityTraceFile-File-Modified-"
+
index
+
".if"
;
if
(
currentFile
.
equals
(
tempFile
))
counter
++;
}
}
// Total correct files collected from the fieldtest is 93 (removed file 116 due to Staumuehle appearance)!
if
(
counter
==
93
)
return
true
;
else
return
false
;
}
/**
* Is fired each time an event occured. Updates the location of the host and calculates the next location for the next call of this method
*/
@Override
public
void
eventOccurred
(
Object
content
,
int
type
)
{
if
(
type
==
42
)
{
initialize
();
}
else
{
SmarterHost
host
=
(
SmarterHost
)
content
;
Location
location
=
host
.
getNextLocation
();
if
(
location
!=
null
)
{
host
.
getActuator
().
updateCurrentLocation
(
location
);
}
if
(
host
.
tryNextStep
())
{
long
sleepTime
=
host
.
getSleepTime
();
// Reschedule next step
Event
.
scheduleWithDelay
(
sleepTime
,
this
,
host
,
0
);
}
}
}
/**
* Called once during simulation setup for each host. Creates a SmarterHost object at a default location.
*/
@Override
public
void
addComponent
(
SimLocationActuator
actuator
)
{
actuator
.
updateCurrentLocation
(
DEFAULT_LOCATION
);
if
(!
actuatorList
.
contains
(
actuator
))
{
actuatorList
.
add
(
actuator
);
Event
.
scheduleImmediately
(
this
,
new
SmarterHost
(
actuator
,
(
int
)
actuator
.
getHost
().
getId
().
value
()),
0
);
}
}
/**
* Called once during simulation setup for each host. Creates a SmarterHost object.
*/
@Override
public
void
placeComponent
(
SimLocationActuator
actuator
)
{
if
(!
actuatorList
.
contains
(
actuator
))
{
actuatorList
.
add
(
actuator
);
Event
.
scheduleImmediately
(
this
,
new
SmarterHost
(
actuator
,
(
int
)
actuator
.
getHost
().
getId
().
value
()),
0
);
}
}
/**
* Set the time between movement operations
* @param time the time between movement operations
*/
@Override
public
void
setTimeBetweenMoveOperations
(
long
time
)
{
this
.
timeBetweenMoveOperations
=
time
;
}
/**
* Returns the time between movement operations
* @return time between movement operations
*/
public
long
getTimeBetweenMoveOperations
()
{
return
timeBetweenMoveOperations
;
}
public
void
setIMapVisualization
(
IMapVisualization
mapVisualization
)
{
this
.
mapVisualization
=
mapVisualization
;
}
}
src/de/tud/kom/p2psim/impl/topology/movement/smarter/DataConverter.java
deleted
100644 → 0
View file @
8d14d16e
/*
* 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
;
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
;
import
java.sql.SQLException
;
import
java.sql.Statement
;
import
java.util.ArrayList
;
import
java.util.List
;
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
{
@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
<
String
>
filePaths
=
DataConverter
.
getFilePaths
(
sqliteFolderPath
);
try
{
System
.
out
.
println
(
Class
.
forName
(
"org.sqlite.JDBC"
));
}
catch
(
ClassNotFoundException
e
)
{
// TODO Auto-generated catch block
e
.
printStackTrace
();
}
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"
);
}
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
;
// 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
.
isWithinGPSBoundaries
(
lat
,
lon
))
{
PositionVector
p
=
GPSCalculation
.
transformGPSWindowToOwnWorld
(
lat
,
lon
);
if
(!
active
)
{
for
(
IAttractionPoint
ap
:
IAttractionGenerator
.
attractionPoints
)
{
if
(
p
.
distanceTo
(
ap
)
<=
ap
.
getRadius
())
{
active
=
true
;
}
}
}
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
*
* @param directory
* The
* @return
*/
public
static
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
())
{
if
(
listOfFiles
[
i
].
getName
().
contains
(
".db"
))
{
filePaths
.
add
(
directory
+
listOfFiles
[
i
].
getName
());
}
}
}
return
filePaths
;
}
/*
* @author Marcel Verst
*/
private
static
class
SmarterDBEntry
{
// All columns of the row
public
int
_id
;
double
longitude
;
double
latitude
;
double
altitude
;
double
accuracy
;
String
timestamp
;
/**
* Creates SmarterDBEntry object
*
* @param _id
* the id entry
* @param longitude
* the longitude entry
* @param latitude
* the latitude entry
* @param altitude
* the altitude entry
* @param accuracy
* the accuracy entry
* @param timestamp
* the timestamp entry
*/
public
SmarterDBEntry
(
int
_id
,
double
longitude
,
double
latitude
,
double
altitude
,
double
accuracy
,
String
timestamp
)
{
super
();
this
.
_id
=
_id
;
this
.
longitude
=
longitude
;
this
.
latitude
=
latitude
;
this
.
altitude
=
altitude
;
this
.
accuracy
=
accuracy
;
this
.
timestamp
=
timestamp
;
}
/**
* Print entry
*
* @return String containing all entries of the row
*/
@Override
public
String
toString
()
{
return
"DBEntry [_id="
+
_id
+
", longitude="
+
longitude
+
", latitude="
+
latitude
+
", altitude="
+
altitude
+
", accuracy="
+
accuracy
+
", timestamp="
+
timestamp
+
"]"
;
}
/**
* Gets the ID
*
* @return _id
*/
public
int
get_id
()
{
return
_id
;
}
/**
* Gets the longitude
*
* @return longitude
*/
public
double
getLongitude
()
{
return
longitude
;
}
/**
* Gets the latitude
*
* @return latitude
*/
public
double
getLatitude
()
{
return
latitude
;
}
/**
* Gets the altitude
*
* @return altitude
*/
public
double
getAltitude
()
{
return
altitude
;
}
/**
* Gets the accuracy
*
* @return accuracy of GPS signal
*/
public
double
getAccuracy
()
{
return
accuracy
;
}
/**
* Gets the timestamp
*
* @return timestamp
*/
public
String
getTimestamp
()
{
return
timestamp
;
}
}
/**
* DataGrabber class is responsible for establishing a connection to a database
* and to query the data
*
* @author Marcel Verst
* @version 26.05.2018
*/
private
static
class
DataGrabber
{
// The connection to the database.
private
Connection
conn
;
/**
* DataGrabber constructor, initializes the connection
*/
public
DataGrabber
()
{
conn
=
null
;
}
/**
* Connect to a database specified in params.properties Code from
* "http://www.sqlitetutorial.net/sqlite-java/sqlite-jdbc-driver/"
*
* @throws SQLException
* if the connection cannot be established
*/
public
void
connect
(
String
filePath
)
{
try
{
// db parameters
String
url
=
"jdbc:sqlite:"
+
filePath
;
// create a connection to the database
conn
=
DriverManager
.
getConnection
(
url
);
}
catch
(
SQLException
e
)
{
System
.
out
.
println
(
e
.
getMessage
());
}
}
/**
* Disconnects database
*
* @throws SQLException
* if disconnection failed
*/
public
void
disconnect
()
{
try
{
conn
.
close
();
}
catch
(
SQLException
e
)
{
e
.
printStackTrace
();
}
}
/**
* Queries the database with a given query string, stores the values within an
* ArrayList and returns it for further analyzes
*
* @param selection
* The SQL query
* @return listOfEntries ArrayList object containing DBEntry types
* @throws SQLException
* if there are problems with connecting to the database
*/
public
ArrayList
<
SmarterDBEntry
>
select
(
String
selection
)
{
ArrayList
<
SmarterDBEntry
>
listOfEntries
=
new
ArrayList
<
SmarterDBEntry
>();
try
(
Statement
stmt
=
conn
.
createStatement
();
ResultSet
rs
=
stmt
.
executeQuery
(
selection
))
{
// loop through the result set
while
(
rs
.
next
())
{
int
_id
=
rs
.
getInt
(
"_id"
);
double
longitude
=
rs
.
getDouble
(
"longitude"
);
double
latitude
=
rs
.
getDouble
(
"latitude"
);
double
altitude
=
rs
.
getDouble
(
"altitude"
);
double
accuracy
=
rs
.
getDouble
(
"accuracy"
);
String
timestamp
=
rs
.
getString
(
"timestamp"
);
SmarterDBEntry
entry
=
new
SmarterDBEntry
(
_id
,
longitude
,
latitude
,
altitude
,
accuracy
,
timestamp
);
listOfEntries
.
add
(
entry
);
}
}
catch
(
SQLException
e
)
{
System
.
out
.
println
(
e
.
getMessage
());
}
return
listOfEntries
;
}
}
}
src/de/tud/kom/p2psim/impl/topology/movement/smarter/dataanalyzer/Statistics.java
deleted
100644 → 0
View file @
8d14d16e
/*
* 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.FileOutputStream
;
import
java.io.FileReader
;
import
java.io.IOException
;
import
java.io.PrintWriter
;
import
java.util.ArrayList
;
/**
* Calculates statistics like travel distance, speed, idle time, moving time, phone out time etc. and stores the results within a file.
* Statistic calculation is based on .if files, which are located in the "smarter/traces-mv/" folders
*
* @author Marcel Verst
* @version 26.05.2018
*/
public
class
Statistics
{
// Statistical values for one fieldtest participant
private
double
distance
;
private
double
avSpeed
;
private
int
idleTime
;
private
int
movingTime
;
private
int
phoneOutTime
;
private
String
filePath
;
ArrayList
<
IfFileEntry
>
fileEntries
;
/**
* Initialize statistical values
*/
public
Statistics
(
String
filePath
)
{
distance
=
0.0
;
avSpeed
=
0.0
;
idleTime
=
0
;
movingTime
=
0
;
phoneOutTime
=
0
;
this
.
filePath
=
filePath
;
fileEntries
=
readFile
();
}
public
ArrayList
<
IfFileEntry
>
readFile
()
{
ArrayList
<
IfFileEntry
>
entryList
=
new
ArrayList
<
IfFileEntry
>();
try
{
//File file = new File("smarter/traces-mv/mobilityTraceFile-File-Modified-10.if");
File
file
=
new
File
(
filePath
);
if
(
file
.
exists
())
{
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
]);
double
x
=
Double
.
parseDouble
(
split
[
1
]);
double
y
=
Double
.
parseDouble
(
split
[
2
]);
IfFileEntry
entry
=
new
IfFileEntry
(
lineID
,
x
,
y
);
entryList
.
add
(
entry
);
}
fileReader
.
close
();
}
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
return
entryList
;
}
/**
* Calculates the total distance traveled during the field test
* @return the total distance
*/
public
void
calcDistance
()
{
double
lastX
=
fileEntries
.
get
(
0
).
getX
();
double
lastY
=
fileEntries
.
get
(
0
).
getY
();
for
(
int
index
=
1
;
index
<
fileEntries
.
size
();
index
++)
{
double
newX
=
fileEntries
.
get
(
index
).
getX
();
double
newY
=
fileEntries
.
get
(
index
).
getY
();
// Pythagoras for distance estimation between two points.
distance
+=
Math
.
sqrt
(
Math
.
pow
(
Math
.
abs
(
newX
-
lastX
),
2
)
+
Math
.
pow
(
Math
.
abs
(
newY
-
lastY
),
2
));
lastX
=
newX
;
lastY
=
newY
;
}
}
/**
* Calculates the average speed during the field test
* @return the average speed
*/
public
void
calcAvSpeed
()
{
// Time difference between end and start of the fieldtest
int
totalTravelTime
=
fileEntries
.
get
(
fileEntries
.
size
()-
1
).
getId
()
-
fileEntries
.
get
(
0
).
getId
();
if
(
totalTravelTime
==
0
)
avSpeed
=
0.0
;
else
avSpeed
=
distance
/
totalTravelTime
;
}
/**
* Calculates the time a participant did not move (was idle)
* @return the idle time
*/
public
void
calcIdleTime
()
{
int
lastID
=
fileEntries
.
get
(
0
).
getId
();
double
lastX
=
fileEntries
.
get
(
0
).
getX
();
double
lastY
=
fileEntries
.
get
(
0
).
getY
();
for
(
int
index
=
1
;
index
<
fileEntries
.
size
();
index
++)
{
int
newID
=
fileEntries
.
get
(
index
).
getId
();
double
newX
=
fileEntries
.
get
(
index
).
getX
();
double
newY
=
fileEntries
.
get
(
index
).
getY
();
// No movement
if
(
newX
==
lastX
&&
newY
==
lastY
)
idleTime
+=
newID
-
lastID
;
lastID
=
newID
;
lastX
=
newX
;
lastY
=
newY
;
}
}
/**
* Calculates the time a participant was moving
* @return the moving time
*/
public
void
calcMovingTime
()
{
int
lastID
=
fileEntries
.
get
(
0
).
getId
();
double
lastX
=
fileEntries
.
get
(
0
).
getX
();
double
lastY
=
fileEntries
.
get
(
0
).
getY
();
for
(
int
index
=
1
;
index
<
fileEntries
.
size
();
index
++)
{
int
newID
=
fileEntries
.
get
(
index
).
getId
();
double
newX
=
fileEntries
.
get
(
index
).
getX
();
double
newY
=
fileEntries
.
get
(
index
).
getY
();
// Movement
if
(!(
newX
==
lastX
&&
newY
==
lastY
))
movingTime
+=
newID
-
lastID
;
lastID
=
newID
;
lastX
=
newX
;
lastY
=
newY
;
}
}
/**
* Calculates the duration how long a phone was outside the pocket. Based on lumen values of the mobile phone sensor
* @return the time a phone was out
*/
public
void
calcPhoneOutTime
()
{
phoneOutTime
=
100
;
}
public
static
void
clearFile
()
{
File
file
=
new
File
(
"smarter/statistics/stats.csv"
);
PrintWriter
writer
;
try
{
writer
=
new
PrintWriter
(
file
);
writer
.
close
();
}
catch
(
FileNotFoundException
e
)
{
e
.
printStackTrace
();
}
}
/**
* Calculates all statistics and stores them in a file
*/
public
void
calcStatistics
()
{
try
{
// Create folder if it does not already exist
File
folder
=
new
File
(
"smarter/statistics/"
);
if
(!
folder
.
exists
())
folder
.
mkdir
();
//File file = new File("smarter/statistics/stats.txt");
//PrintWriter printWriter = new PrintWriter(file);
PrintWriter
printWriter
=
new
PrintWriter
(
new
FileOutputStream
(
new
File
(
"smarter/statistics/stats.csv"
),
true
));
if
(
fileEntries
.
size
()
>
0
)
{
calcDistance
();
calcAvSpeed
();
calcIdleTime
();
calcMovingTime
();
calcPhoneOutTime
();
// path format: smarter/traces-mv/mobilityTraceFile-File-Modified-10.if
String
[]
split
=
filePath
.
split
(
"-"
);
String
appendix
=
split
[
4
];
String
[]
split2
=
appendix
.
split
(
"\\."
);
int
id
=
Integer
.
parseInt
(
split2
[
0
]);
// Format of stats.csv: fileID;distance;avSpeed;idleTime;movingTime;phoneOutTime
printWriter
.
append
(
id
+
";"
+
getDistance
()
+
";"
+
getAvSpeed
()
+
";"
+
getIdleTime
()
+
";"
+
getMovingTime
()
+
";"
+
getPhoneOutTime
()
+
"\n"
);
}
printWriter
.
close
();
}
catch
(
FileNotFoundException
e
)
{
e
.
printStackTrace
();
}
}
// ########## GETTER AND SETTER METHODS ##########
public
double
getDistance
()
{
return
distance
;
}
public
void
setDistance
(
double
distance
)
{
this
.
distance
=
distance
;
}
public
double
getAvSpeed
()
{
return
avSpeed
;
}
public
void
setAvSpeed
(
double
avSpeed
)
{
this
.
avSpeed
=
avSpeed
;
}
public
int
getIdleTime
()
{
return
idleTime
;
}
public
void
setIdleTime
(
int
idleTime
)
{
this
.
idleTime
=
idleTime
;
}
public
int
getMovingTime
()
{
return
movingTime
;
}
public
void
setMovingTime
(
int
movingTime
)
{
this
.
movingTime
=
movingTime
;
}
public
int
getPhoneOutTime
()
{
return
phoneOutTime
;
}
public
void
setPhoneOutTime
(
int
phoneOutTime
)
{
this
.
phoneOutTime
=
phoneOutTime
;
}
// ###############################################
}
src/de/tud/kom/p2psim/impl/topology/movement/smarter/host/IfPlacement.java
deleted
100644 → 0
View file @
8d14d16e
/*
* 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.host
;
import
java.io.BufferedReader
;
import
java.io.FileReader
;
import
java.io.IOException
;
import
java.util.List
;
import
java.util.Vector
;
import
de.tud.kom.p2psim.api.topology.TopologyComponent
;
import
de.tud.kom.p2psim.api.topology.placement.PlacementModel
;
import
de.tud.kom.p2psim.impl.topology.util.PositionVector
;
/**
* Sets the initial positions for the nodes by reading an If file with the format "ID x y". From the SMARTER traces we acquired the If files
* by transforming the GPS coordinates into 2D coordinates with x and y values with a certain reference point placed in Staumuehle.
* Before calling this class you should apply the analyzing function in (@link SmarterMovementModelNew) to create a new If file which contains
* the first relevant position of all nodes where each line corresponds to the initial position of a node.
*
* @author MarcelV
* @version 1.0, 12.06.2018
*/
public
class
IfPlacement
implements
PlacementModel
{
private
List
<
PositionVector
>
positions
;
private
String
file
;
private
int
numberOfComponents
;
// The file parts separator. If file has the format "nodeID x y"
private
final
String
SEP
=
" "
;
private
int
positionIndex
;
IfPlacement
(
String
file
){
positions
=
new
Vector
<
PositionVector
>();
// TODO Set String to file either in XML document or hard code it here. Discuss solution
this
.
file
=
file
;
numberOfComponents
=
0
;
}
/**
* Calculating the total number of added components
*/
@Override
public
void
addComponent
(
TopologyComponent
comp
)
{
numberOfComponents
++;
}
/**
* Placing the components on their initial position acquired from the If file. Is called for each component to be created
*/
@Override
public
PositionVector
place
(
TopologyComponent
comp
)
{
if
(
positions
.
isEmpty
()
||
positionIndex
>=
positions
.
size
())
{
readData
();
positionIndex
=
0
;
}
PositionVector
vec
=
positions
.
get
(
positionIndex
);
// TODO implementieren
//comp.updateCurrentLocation(positions.get(positionIndex));
positionIndex
++;
return
vec
;
}
/**
* Reads the If file and stores all positions locally in the class variable where they can then be accessed later within the place()
* function in order to place the components.
*/
public
void
readData
()
{
positions
.
clear
();
boolean
entrySuccessfullyRead
=
false
;
BufferedReader
ifReader
=
null
;
try
{
ifReader
=
new
BufferedReader
(
new
FileReader
(
file
));
// Extracting initial position values and storing them in a list of PositionVector objects
while
(
ifReader
.
ready
())
{
String
line
=
ifReader
.
readLine
();
if
(
line
.
indexOf
(
SEP
)
>
-
1
)
{
// nodeID x y
String
[]
parts
=
line
.
split
(
SEP
);
if
(
parts
.
length
==
3
)
{
try
{
double
x
=
Double
.
parseDouble
(
parts
[
1
]);
double
y
=
Double
.
parseDouble
(
parts
[
2
]);
positions
.
add
(
new
PositionVector
(
x
,
y
));
entrySuccessfullyRead
=
true
;
}
catch
(
NumberFormatException
e
)
{
if
(!
entrySuccessfullyRead
)
e
.
printStackTrace
();
}
}
}
else
{
throw
new
AssertionError
(
"To many columns in CSV."
);
}
}
}
catch
(
Exception
e
)
{
System
.
err
.
println
(
e
.
toString
());
}
// Closing the reader
finally
{
if
(
ifReader
!=
null
)
{
try
{
ifReader
.
close
();
}
catch
(
IOException
e
)
{
//
}
}
}
}
public
int
getNumberOfComponents
()
{
return
numberOfComponents
;
}
}
\ No newline at end of file
src/de/tud/kom/p2psim/impl/topology/movement/smarter/host/SmarterHost.java
deleted
100644 → 0
View file @
8d14d16e
/*
* 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.host
;
import
java.io.File
;
import
java.io.FileNotFoundException
;
import
java.util.Scanner
;
import
de.tud.kom.p2psim.api.topology.movement.SimLocationActuator
;
import
de.tud.kom.p2psim.impl.topology.movement.SmarterMovementModelNew
;
import
de.tud.kom.p2psim.impl.topology.util.PositionVector
;
import
de.tudarmstadt.maki.simonstrator.api.Time
;
import
de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Location
;
public
class
SmarterHost
{
private
SimLocationActuator
actuator
;
private
Location
nextLocation
;
private
long
_sleepTime
;
private
int
currentIndex
;
private
Scanner
scanner
;
private
boolean
init
=
false
;
public
SmarterHost
(
SimLocationActuator
actuator
,
int
currentIndex
)
{
this
.
actuator
=
actuator
;
this
.
currentIndex
=
currentIndex
;
}
public
SimLocationActuator
getActuator
()
{
return
actuator
;
}
public
Location
getNextLocation
()
{
return
nextLocation
;
}
public
long
getSleepTime
()
{
return
_sleepTime
;
}
public
boolean
tryNextStep
()
{
if
(
scanner
==
null
&&
!
init
)
{
init
=
true
;
try
{
//File file = new File("smarter/trace/mobilityTraceFile-File-" + currentIndex + ".if");
File
file
=
new
File
(
"smarter/traces-mv/mobilityTraceFile-File-Modified-"
+
currentIndex
+
".if"
);
if
(!
file
.
exists
())
{
_sleepTime
=
-
1
;
return
false
;
}
scanner
=
new
Scanner
(
file
);
}
catch
(
FileNotFoundException
e
)
{
_sleepTime
=
-
1
;
return
false
;
}
}
if
(!
scanner
.
hasNextLine
())
{
_sleepTime
=
-
1
;
return
false
;
}
String
line
=
scanner
.
nextLine
();
String
[]
split
=
line
.
split
(
" "
);
long
nextTimestamp
=
Long
.
valueOf
(
split
[
0
]);
double
positionX
=
Double
.
valueOf
(
split
[
1
]);
double
positionY
=
Double
.
valueOf
(
split
[
2
]);
// The offset to place the nodes correctly at their real starting point on the map (Staum�hle as reference)
double
offsetX
=
-
700
;
double
offsetY
=
-
230
;
// Calculation of next position
double
posX
=
positionX
+
offsetX
;
double
posY
=
positionY
+
offsetY
;
nextLocation
=
new
PositionVector
(
positionX
,
positionY
);
_sleepTime
=
nextTimestamp
*
SmarterMovementModelNew
.
getInstance
().
getTimeBetweenMoveOperations
()
-
Time
.
getCurrentTime
();
return
true
;
}
}
src/de/tud/kom/p2psim/impl/topology/movement/smarter/host/SmarterHostComponent.java
deleted
100644 → 0
View file @
8d14d16e
/*
* 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.host
;
import
de.tudarmstadt.maki.simonstrator.api.Host
;
import
de.tudarmstadt.maki.simonstrator.api.component.HostComponent
;
public
class
SmarterHostComponent
implements
HostComponent
{
private
final
Host
host
;
public
SmarterHostComponent
(
Host
host
)
{
this
.
host
=
host
;
}
/**
* Called once during system startup. Initializes host.
*/
@Override
public
void
initialize
()
{
System
.
out
.
println
(
"Initializing SmarterHostComponent"
);
}
/**
* Is called whenever a host is shutdown by the system
*/
@Override
public
void
shutdown
()
{
System
.
out
.
println
(
"Shutting down SmarterHostComponent"
);
}
/**
* Returns a host object
* @return Host
*/
@Override
public
Host
getHost
()
{
return
host
;
}
}
src/de/tud/kom/p2psim/impl/topology/movement/smarter/host/SmarterServiceFactory.java
deleted
100644 → 0
View file @
8d14d16e
/*
* 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.host
;
import
de.tudarmstadt.maki.simonstrator.api.Host
;
import
de.tudarmstadt.maki.simonstrator.api.component.HostComponent
;
import
de.tudarmstadt.maki.simonstrator.api.component.HostComponentFactory
;
public
class
SmarterServiceFactory
implements
HostComponentFactory
{
@Override
public
HostComponent
createComponent
(
Host
host
)
{
SmarterHostComponent
comp
=
new
SmarterHostComponent
(
host
);
return
comp
;
}
}
src/de/tud/kom/p2psim/impl/topology/movement/smarter/metrics/NumberOfNodes.java
deleted
100644 → 0
View file @
8d14d16e
/*
* 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.metrics
;
import
java.util.ArrayList
;
import
java.util.List
;
import
de.tud.kom.p2psim.impl.topology.movement.smarter.host.SmarterHost
;
import
de.tudarmstadt.maki.simonstrator.api.Host
;
import
de.tudarmstadt.maki.simonstrator.api.Time
;
import
de.tudarmstadt.maki.simonstrator.api.common.metric.AbstractMetric
;
import
de.tudarmstadt.maki.simonstrator.api.component.ComponentNotAvailableException
;
public
class
NumberOfNodes
extends
AbstractMetric
<
de
.
tud
.
kom
.
p2psim
.
impl
.
topology
.
movement
.
smarter
.
metrics
.
NumberOfNodes
.
Nodes
>
{
public
NumberOfNodes
()
{
super
(
"Counts the nodes within the scenario"
,
MetricUnit
.
NONE
);
}
public
void
initialize
(
List
<
Host
>
hosts
)
{
System
.
out
.
println
(
"NumberOfNodes"
);
ArrayList
<
SmarterHost
>
comps
=
new
ArrayList
<
SmarterHost
>();
// TODO continue here
/**
for (Host host: hosts) {
try {
comps.add(host.getComponent(SmarterHost.class));
}
catch (ComponentNotAvailableException e) {
e.printStackTrace();
}
}
*/
}
public
class
Nodes
implements
de
.
tudarmstadt
.
maki
.
simonstrator
.
api
.
common
.
metric
.
Metric
.
MetricValue
<
Integer
>
{
private
ArrayList
<
SmarterHost
>
hosts
;
int
count
=
0
;
public
Nodes
(
ArrayList
<
SmarterHost
>
hosts
)
{
this
.
hosts
=
hosts
;
}
@Override
public
Integer
getValue
()
{
calc
();
return
count
;
}
public
void
calc
()
{
//calculate count value
}
@Override
public
boolean
isValid
()
{
return
true
;
}
}
}
\ No newline at end of file
src/de/tud/kom/p2psim/impl/topology/movement/smarter/metrics/TotalDistanceWalked.java
deleted
100644 → 0
View file @
8d14d16e
/*
* 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.metrics
;
import
java.util.List
;
import
de.tudarmstadt.maki.simonstrator.api.Host
;
import
de.tudarmstadt.maki.simonstrator.api.Time
;
import
de.tudarmstadt.maki.simonstrator.api.common.metric.AbstractMetric
;
public
class
TotalDistanceWalked
extends
AbstractMetric
<
de
.
tud
.
kom
.
p2psim
.
impl
.
topology
.
movement
.
smarter
.
metrics
.
TotalDistanceWalked
.
SmarterHosts
>{
public
TotalDistanceWalked
()
{
super
(
"Calculates the total distance walked by the nodes."
,
MetricUnit
.
NONE
);
}
public
void
initialize
(
List
<
Host
>
hosts
)
{
System
.
out
.
println
(
"TotalDistanceWalked"
);
}
public
class
SmarterHosts
implements
de
.
tudarmstadt
.
maki
.
simonstrator
.
api
.
common
.
metric
.
Metric
.
MetricValue
<
Integer
>
{
int
count
;
private
long
lastCalcTimestamp
;
public
SmarterHosts
()
{
}
@Override
public
Integer
getValue
()
{
calc
();
return
count
;
}
public
void
calc
()
{
if
(
Time
.
getCurrentTime
()
==
lastCalcTimestamp
)
return
;
lastCalcTimestamp
=
Time
.
getCurrentTime
();
count
=
0
;
}
@Override
public
boolean
isValid
()
{
return
true
;
}
}
}
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