Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Jon Shahen
vagabond
Commits
664f3fca
Commit
664f3fca
authored
May 22, 2016
by
Jonathan Shahen
Browse files
Junit tests are passing
parent
54a75e5e
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/vagabond/results/StatisticsManager.java
View file @
664f3fca
...
...
@@ -6,7 +6,6 @@ import vagabond.pieces.*;
import
vagabond.singleton.VagabondSettings
;
public
class
StatisticsManager
{
public
VagabondSettings
settings
;
public
String
startDTStr
;
public
String
testName
=
""
;
...
...
@@ -27,8 +26,7 @@ public class StatisticsManager {
public
String
comments
=
""
;
public
StatisticsManager
()
{
settings
=
VagabondSettings
.
getInstance
();
startDTStr
=
settings
.
getCurrentDateTimeStr
();
startDTStr
=
VagabondSettings
.
getCurrentDateTimeStr
();
}
public
String
getCSVHeader
()
{
...
...
@@ -80,6 +78,8 @@ public class StatisticsManager {
public
String
getCSVStatsLine
()
{
StringBuilder
sb
=
new
StringBuilder
(
3000
);
VagabondSettings
settings
=
VagabondSettings
.
getInstance
();
// sb.append("Date Time,");
sb
.
append
(
startDTStr
).
append
(
","
);
// sb.append("Test Name,");
...
...
@@ -169,23 +169,42 @@ public class StatisticsManager {
return
sb
.
toString
();
}
public
int
traceBackList
(
ArrayList
<
Integer
>
list
,
Integer
value
)
{
public
void
addEpochTime
(
Long
epochTime
)
{
epochTimes
.
add
(
epochTime
);
}
public
Long
getAvgEpochTime
()
{
return
getAvgEpochTime
(
false
);
}
public
Long
getAvgEpochTime
(
boolean
recalculate
)
{
if
(
avgEpochTime
==
null
||
recalculate
)
{
Long
sum
=
(
long
)
0
;
for
(
Long
epochTime
:
epochTimes
)
{
sum
+=
epochTime
;
}
avgEpochTime
=
(
long
)
((
double
)
sum
)
/
epochTimes
.
size
();
}
return
avgEpochTime
;
}
public
static
int
traceBackList
(
ArrayList
<
Integer
>
list
,
Integer
value
)
{
for
(
int
i
=
list
.
size
()
-
1
;
i
>=
0
;
i
--)
{
if
(
value
!=
null
)
{
if
(!
list
.
get
(
i
).
equals
(
value
))
{
return
i
;
}
if
(!
list
.
get
(
i
).
equals
(
value
))
{
return
i
+
1
;
}
}
else
{
if
(
i
==
list
.
size
()
-
1
)
{
continue
;
}
// Check with previous value
if
(!
list
.
get
(
i
).
equals
(
list
.
get
(
i
+
1
)))
{
return
i
;
}
if
(!
list
.
get
(
i
).
equals
(
list
.
get
(
i
+
1
)))
{
return
i
+
1
;
}
}
}
return
0
;
}
p
rivate
String
getArrayStr
(
int
[]
arr
,
String
delim
)
{
p
ublic
static
String
getArrayStr
(
int
[]
arr
,
String
delim
)
{
StringBuilder
sb
=
new
StringBuilder
(
arr
.
length
*
10
);
for
(
int
i
=
0
;
i
<
arr
.
length
;
i
++)
{
...
...
@@ -198,11 +217,16 @@ public class StatisticsManager {
return
sb
.
toString
();
}
p
rivate
int
[]
getDistribution
(
ClientToClientInformationLeakage
ccil
,
int
maxVal
)
{
p
ublic
static
int
[]
getDistribution
(
ClientToClientInformationLeakage
ccil
,
int
maxVal
)
{
int
[]
rtn
=
new
int
[
maxVal
+
1
];
// initialized to 0
for
(
Integer
c0
:
ccil
.
_clientIDs
)
{
for
(
Integer
c1
:
ccil
.
_clientIDs
)
{
// DO NOT count the information leakage from a client to itself
if
(
c0
.
equals
(
c1
))
{
continue
;
}
rtn
[
ccil
.
get
(
c0
,
c1
)]++;
}
}
...
...
@@ -210,7 +234,7 @@ public class StatisticsManager {
return
rtn
;
}
public
String
getListStr
(
ArrayList
<?>
list
,
String
delim
)
{
public
static
String
getListStr
(
ArrayList
<?>
list
,
String
delim
)
{
StringBuilder
sb
=
new
StringBuilder
(
list
.
size
()
*
10
);
for
(
int
i
=
0
;
i
<
list
.
size
();
i
++)
{
...
...
@@ -222,23 +246,4 @@ public class StatisticsManager {
return
sb
.
toString
();
}
public
void
addEpochTime
(
Long
epochTime
)
{
epochTimes
.
add
(
epochTime
);
}
public
Long
getAvgEpochTime
()
{
return
getAvgEpochTime
(
false
);
}
public
Long
getAvgEpochTime
(
boolean
recalculate
)
{
if
(
avgEpochTime
==
null
||
recalculate
)
{
Long
sum
=
(
long
)
0
;
for
(
Long
epochTime
:
epochTimes
)
{
sum
+=
epochTime
;
}
avgEpochTime
=
(
long
)
((
double
)
sum
)
/
epochTimes
.
size
();
}
return
avgEpochTime
;
}
}
src/vagabond/singleton/VagabondSettings.java
View file @
664f3fca
...
...
@@ -161,7 +161,7 @@ public class VagabondSettings {
public
Level
logLevel
=
Level
.
FINE
;
public
FileHandler
fileHandler
;
public
Boolean
WriteCSVFileHeader
=
true
;
public
DateFormat
df
=
new
SimpleDateFormat
(
"yyyy/MM/dd hh:mm:ss.SSSZ"
);
public
static
final
DateFormat
df
=
new
SimpleDateFormat
(
"yyyy/MM/dd hh:mm:ss.SSSZ"
);
/**
* A flag that when TRUE will print out to the logger on INFO the PlacementMap at the END of every epoch as well
...
...
@@ -182,15 +182,15 @@ public class VagabondSettings {
/**
* The timing manager that holds all of the raw timing information for the instance.
*/
public
TimingManager
timing
=
new
TimingManager
()
;
public
TimingManager
timing
;
/**
* The results manager that holds all of the raw results information for the instance.
*/
public
ResultsManager
results
=
new
ResultsManager
()
;
public
ResultsManager
results
;
/**
* The statistics manager that calculates all of the stats that can be graphed later
*/
public
StatisticsManager
stats
=
new
StatisticsManager
()
;
public
StatisticsManager
stats
;
// ################################################################
// CONTROL SETTINGS
...
...
@@ -283,6 +283,9 @@ public class VagabondSettings {
* @see #getInstance()
*/
protected
VagabondSettings
()
{
timing
=
new
TimingManager
();
results
=
new
ResultsManager
();
stats
=
new
StatisticsManager
();
}
/**
...
...
@@ -547,7 +550,7 @@ public class VagabondSettings {
return
new
File
(
dataFolder
+
File
.
separator
+
cnfInstanceFile
);
}
public
String
getCurrentDateTimeStr
()
{
public
static
String
getCurrentDateTimeStr
()
{
return
df
.
format
(
new
Date
(
System
.
currentTimeMillis
()));
}
...
...
src/vagabond/testing/StatisticsManagerTests.java
View file @
664f3fca
package
vagabond.testing
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
org.junit.Test
;
import
vagabond.pieces.ClientToClientInformationLeakage
;
import
vagabond.pieces.PlacementMap
;
import
vagabond.results.StatisticsManager
;
public
class
StatisticsManagerTests
{
@Test
public
void
traceBackListTest
()
{
ArrayList
<
Integer
>
test1
=
new
ArrayList
<
Integer
>(
Arrays
.
asList
(
0
,
1
,
2
,
3
,
4
,
4
,
4
,
4
,
4
,
4
,
4
));
assertEquals
(
4
,
StatisticsManager
.
traceBackList
(
test1
,
4
));
assertEquals
(
4
,
StatisticsManager
.
traceBackList
(
test1
,
null
));
assertEquals
(
test1
.
size
(),
StatisticsManager
.
traceBackList
(
test1
,
-
1
));
}
@Test
public
void
getArrayStrTest
()
{
int
[]
test1
=
{
1
,
2
,
3
,
4
};
String
test1Str
=
StatisticsManager
.
getArrayStr
(
test1
,
";"
);
assertEquals
(
"0=1;1=2;2=3;3=4"
,
test1Str
);
}
@Test
public
void
getListStrTest
()
{
ArrayList
<
Integer
>
test
=
new
ArrayList
<>(
Arrays
.
asList
(
1
,
2
,
3
,
4
));
String
test1Str
=
StatisticsManager
.
getListStr
(
test
,
";"
);
assertEquals
(
"1;2;3;4"
,
test1Str
);
}
@Test
public
void
getDistributionTest
()
{
PlacementMap
place
=
PlacementMapExamples
.
equalSpreadClients
(
3
);
ClientToClientInformationLeakage
testCCIL
=
new
ClientToClientInformationLeakage
(
place
);
int
[]
testDist
=
StatisticsManager
.
getDistribution
(
testCCIL
,
testCCIL
.
getMaxInformationLeak
());
int
[]
expectedDist
=
{
0
,
0
,
0
,
6
};
assertEquals
(
expectedDist
.
length
,
testDist
.
length
);
for
(
int
t
=
0
;
t
<
expectedDist
.
length
;
t
++)
{
// System.out.println(t);
assertEquals
(
expectedDist
[
t
],
testDist
[
t
]);
}
}
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment