protected
def splitTimeslotByPoliciesAndAgreements(referenceTimeslot: Timeslot,
policyTimeslots: List[Timeslot],
- agreementTimeslots: List[Timeslot]): List[Timeslot] = {
+ agreementTimeslots: List[Timeslot],
+ clogM: Maybe[ContextualLogger] = NoVal): List[Timeslot] = {
+
+ val clog = ContextualLogger.fromOther(clogM, logger, "splitTimeslotByPoliciesAndAgreements()")
+ clog.begin()
+
// Align policy and agreement validity timeslots to the referenceTimeslot
val alignedPolicyTimeslots = referenceTimeslot.align(policyTimeslots)
val alignedAgreementTimeslots = referenceTimeslot.align(agreementTimeslots)
- alignTimeslots(alignedPolicyTimeslots, alignedAgreementTimeslots)
+ ContextualLogger.debugList(clog, "alignedPolicyTimeslots", alignedPolicyTimeslots)
+ ContextualLogger.debugList(clog, "alignedAgreementTimeslots", alignedAgreementTimeslots)
+
+ val result = alignTimeslots(alignedPolicyTimeslots, alignedAgreementTimeslots, Just(clog))
+ clog.end()
+ result
}
/**
contextualLogger: Maybe[ContextualLogger] = NoVal): Maybe[List[Chargeslot]] = Maybe {
val clog = ContextualLogger.fromOther(contextualLogger, logger, "computeInitialChargeslots()")
+ clog.begin()
val policyTimeslots = policiesByTimeslot.keySet
val agreementTimeslots = agreementNamesByTimeslot.keySet
- clog.begin()
-
clog.debug("policiesByTimeslot:")
clog.withIndent {
- policyTimeslots.foreach(pt ⇒ clog.debug("%s: %s", pt, policyTimeslots(pt)))
+ policyTimeslots.foreach(pt ⇒ clog.debug("%s: %s", pt, policiesByTimeslot(pt)))
}
clog.debug("agreementNamesByTimeslot:")
clog.withIndent {
}
// 1. Round ONE: split time according to overlapping policies and agreements.
- val alignedTimeslots = splitTimeslotByPoliciesAndAgreements(referenceTimeslot, policyTimeslots.toList, agreementTimeslots.toList)
+ val alignedTimeslots = splitTimeslotByPoliciesAndAgreements(referenceTimeslot, policyTimeslots.toList, agreementTimeslots.toList, Just(clog))
clog.debug("ROUND 1: alignedTimeslots:")
clog.withIndent {
alignedTimeslots.foreach(ts ⇒ clog.debug("%s", ts))
// fine-grained timeslots according to applicable algorithms.
// Then pack the info into charge slots.
clog.debug("ROUND 2")
- clog.begin()
+ clog.indent()
val allChargeslots = for {
alignedTimeslot <- alignedTimeslots
} yield {
chargeslots.toList
}
}
+ clog.unindent() // ROUND 2
clog.end()
- clog.end()
allChargeslots.flatten
}
}
}
- clog.end()
-
- fullChargeslotsM match {
+ val result = fullChargeslotsM match {
case Just(fullChargeslots) ⇒
fullChargeslots
case NoVal ⇒
case failed @ Failed(e, m) ⇒
throw new Exception(m, e)
}
+
+ clog.end()
+
+ result
}
/**
* result: List(Timeslot(a.from, b.to), Timeslot(b.to, a.to))
*/
private[logic] def alignTimeslots(a: List[Timeslot],
- b: List[Timeslot]): List[Timeslot] = {
+ b: List[Timeslot],
+ clogM: Maybe[ContextualLogger] = NoVal): List[Timeslot] = {
+ val clog = ContextualLogger.fromOther(clogM, logger, "alignTimeslots()")
+ clog.begin()
+
+ ContextualLogger.debugList(clog, "a", a)
+ ContextualLogger.debugList(clog, "b", b)
+
if (a.isEmpty) return b.tail
if (b.isEmpty) return a.tail
assert (a.head.from == b.head.from)
- if (a.head.endsAfter(b.head)) {
- a.head.slice(b.head.to) ::: alignTimeslots(a.tail, b.tail)
+ val clogJ = Just(clog)
+ val result = if (a.head.endsAfter(b.head)) {
+ clog.debug("Branch: a.head.endsAfter(b.head)")
+ a.head.slice(b.head.to) ::: alignTimeslots(a.tail, b.tail, clogJ)
} else if (b.head.endsAfter(a.head)) {
- b.head.slice(a.head.to) ::: alignTimeslots(a.tail, b.tail)
+ clog.debug("Branch: b.head.endsAfter(a.head)")
+ b.head.slice(a.head.to) ::: alignTimeslots(a.tail, b.tail, clogJ)
} else {
- a.head :: alignTimeslots(a.tail, b.tail)
+ clog.debug("Branch: !a.head.endsAfter(b.head) && !b.head.endsAfter(a.head)")
+ a.head :: alignTimeslots(a.tail, b.tail, clogJ)
}
+
+ clog.end()
+ result
}
}