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
faddbb04
Commit
faddbb04
authored
Feb 18, 2020
by
Julian Zobel
Browse files
- Social Movement Monitors
- Smarter Movement classes and analyzers
parent
dce6451f
Changes
29
Hide whitespace changes
Inline
Side-by-side
src/de/tud/kom/p2psim/impl/topology/movement/smarter/dataanalyzer/DataGrabber.java
0 → 100644
View file @
faddbb04
/*
* 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.sql.Connection
;
import
java.sql.DriverManager
;
import
java.sql.ResultSet
;
import
java.sql.SQLException
;
import
java.sql.Statement
;
import
java.util.ArrayList
;
/**
* DataGrabber class is responsible for establishing a connection to a database
* and to query the data
*
* @author Marcel Verst
* @version 26.05.2018
*/
public
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
);
System
.
out
.
println
(
"Connection to "
+
filePath
+
" has been established."
);
}
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
<
DBEntry
>
select
(
String
selection
)
{
ArrayList
<
DBEntry
>
listOfEntries
=
new
ArrayList
<
DBEntry
>();
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"
);
DBEntry
entry
=
new
DBEntry
(
_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/IfFileEntry.java
0 → 100644
View file @
faddbb04
/*
* 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
;
}
}
src/de/tud/kom/p2psim/impl/topology/movement/smarter/dataanalyzer/Statistics.java
0 → 100644
View file @
faddbb04
/*
* 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
0 → 100644
View file @
faddbb04
/*
* 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
0 → 100644
View file @
faddbb04
/*
* 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
0 → 100644
View file @
faddbb04
/*
* 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
0 → 100644
View file @
faddbb04
/*
* 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
0 → 100644
View file @
faddbb04
/*
* 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
0 → 100644
View file @
faddbb04
/*
* 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
;
}
}
}
Prev
1
2
Next
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