mirror of https://github.com/zlatinb/muwire
change state on observation even if there is not enough history yet. Initialize MC with last state from DB
parent
e1b2582ca6
commit
f5f84899ec
|
@ -73,6 +73,7 @@ class H2HostCache extends HostCache {
|
|||
def count = sql.firstRow("select count(*) as COUNT from HOST_ATTEMPTS where DESTINATION=${d.toBase64()}")
|
||||
if (count.COUNT < settings.minHostProfileHistory) {
|
||||
log.fine("not enough history for Markov")
|
||||
profiles.put(d, new HostMCProfile(state))
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -316,8 +317,11 @@ class H2HostCache extends HostCache {
|
|||
if (uniqueHosts.add(dest)) {
|
||||
def fromDB = sql.firstRow("select * from HOST_PROFILES where DESTINATION=${dest.toBase64()}")
|
||||
def profile = new HostMCProfile()
|
||||
if (fromDB != null)
|
||||
profile = new HostMCProfile(fromDB, ConnectionAttemptStatus.SUCCESSFUL)
|
||||
if (fromDB != null) {
|
||||
def lastObservation = sql.firstRow("select STATUS from HOST_ATTEMPTS where DESTINATION=${dest.toBase64()} order by TSTAMP desc limit 1")
|
||||
if (lastObservation != null)
|
||||
profile = new HostMCProfile(fromDB, ConnectionAttemptStatus.valueOf(lastObservation.STATUS))
|
||||
}
|
||||
profiles.put(dest, profile)
|
||||
allHosts.add(dest)
|
||||
log.fine("Loaded profile for ${dest.toBase32()} $profile")
|
||||
|
|
|
@ -40,11 +40,18 @@ class HostMCProfile {
|
|||
boolean successfulAttempt
|
||||
|
||||
/**
|
||||
* constructs an "optimistic" predictor for newly discovered hosts.
|
||||
* Constructs an optimistic predictor for newly discovered hosts
|
||||
*/
|
||||
HostMCProfile() {
|
||||
this(ConnectionAttemptStatus.SUCCESSFUL)
|
||||
}
|
||||
|
||||
/**
|
||||
* constructs a predictor with default values and the specified state
|
||||
*/
|
||||
HostMCProfile(ConnectionAttemptStatus state) {
|
||||
this.hasHistory = false
|
||||
this.state = ConnectionAttemptStatus.SUCCESSFUL
|
||||
this.state = state
|
||||
S = new Probability[3]
|
||||
R = new Probability[3]
|
||||
F = new Probability[3]
|
||||
|
@ -67,7 +74,7 @@ class HostMCProfile {
|
|||
"RF:${R[2].probability},"+
|
||||
"FS:${F[0].probability},"+
|
||||
"FR:${F[1].probability},"+
|
||||
"FF:${F[2].probability}"
|
||||
"FF:${F[2].probability} " + state
|
||||
|
||||
Arrays.sort(S)
|
||||
S[1].probability += S[0].probability
|
||||
|
@ -134,7 +141,7 @@ class HostMCProfile {
|
|||
"RF:${R[2].probability},"+
|
||||
"FS:${F[0].probability},"+
|
||||
"FR:${F[1].probability},"+
|
||||
"FF:${F[2].probability}"
|
||||
"FF:${F[2].probability} " + state
|
||||
|
||||
Arrays.sort(S)
|
||||
S[1].probability += S[0].probability
|
||||
|
@ -193,7 +200,7 @@ class HostMCProfile {
|
|||
|
||||
@Override
|
||||
public String toString() {
|
||||
toString + " state " + state
|
||||
toString
|
||||
}
|
||||
|
||||
private static class Probability implements Comparable<Probability> {
|
||||
|
|
Loading…
Reference in New Issue