WIP chargeslot computations
authorChristos KK Loverdos <loverdos@gmail.com>
Mon, 9 Jul 2012 09:43:05 +0000 (12:43 +0300)
committerChristos KK Loverdos <loverdos@gmail.com>
Mon, 9 Jul 2012 09:43:05 +0000 (12:43 +0300)
src/main/scala/gr/grnet/aquarium/computation/TimeslotComputations.scala
src/main/scala/gr/grnet/aquarium/computation/UserStateComputations.scala
src/main/scala/gr/grnet/aquarium/logic/accounting/dsl/DSLTimeFrame.scala
src/main/scala/gr/grnet/aquarium/logic/accounting/dsl/DSLUtils.scala
src/main/scala/gr/grnet/aquarium/policy/EffectivePriceTable.scala
src/main/scala/gr/grnet/aquarium/policy/EffectiveUnitPrice.scala

index 9c3c673..33a1055 100644 (file)
@@ -209,6 +209,7 @@ trait TimeslotComputations extends Loggable {
         // referring to (almost) an instant in time
         val previousValue = chargingBehavior.getResourceInstanceUndefinedAmount
 
+        // TODO: Check semantics of this
         val referenceTimeslot = Timeslot(new MutableDateCalc(occurredDate).goPreviousMilli.toDate, occurredDate)
 
         // TODO: store policies in mem?
index 2d5f92d..b2e8677 100644 (file)
@@ -261,7 +261,7 @@ final class UserStateComputations extends AquariumAwareSkeleton with Loggable {
 
             // B. Compute new wallet entries
             clog.debug("agreementsSnapshot = %s", _workingUserState.agreementHistory)
-            val alltimeAgreements = _workingUserState.agreementHistory.agreementsByTimeslot
+            val agreementByTimeslot = _workingUserState.agreementHistory.agreementsByTimeslot
 
             //              clog.debug("Computing full chargeslots")
             val (referenceTimeslot, fullChargeslots) = timeslotComputations.computeFullChargeslots(
@@ -271,7 +271,7 @@ final class UserStateComputations extends AquariumAwareSkeleton with Loggable {
               oldAmount,
               newAccumulatingAmount,
               resourceType,
-              alltimeAgreements,
+              agreementByTimeslot,
               policyStore,
               Some(clog)
             )
index 7d2454b..31d7b89 100644 (file)
@@ -74,7 +74,7 @@ case class DSLTimeFrame (
    *  */
   def intervalsOf(t:Timeslot) : List[Timeslot]=
     if(repeat.isEmpty)
-      t.overlappingTimeslots(List(Timeslot(start,end)))
+      List(t) // .overlappingTimeslots(List(Timeslot(start,end)))
     else {
       val result = new mutable.ListBuffer[Timeslot]()
       var offset = t.from
index 2500a27..3a72eec 100644 (file)
@@ -52,7 +52,7 @@ trait DSLUtils {
    * provided timeslot and returns it as a Map
    */
   def resolveEffectiveUnitPricesForTimeslot(
-      timeslot: Timeslot,
+      alignedTimeslot: Timeslot,
       policy: PolicyModel,
       agreement: UserAgreementModel,
       resourceType: ResourceType
@@ -81,16 +81,39 @@ trait DSLUtils {
         effectivePriceTable
     }
 
-    resolveEffective3(timeslot, effectivePriceTable)
+    resolveEffective(alignedTimeslot, effectivePriceTable)
   }
 
+  /*private def printPolicy[T <: DSLTimeBoundedItem[T]](t : T) : Unit = {
+      Console.err.println("Policy " + t.name + " " + t.toTimeslot + " DETAIL : " + t.effective)
+      t.overrides match {
+        case None => Console.println
+        case Some(t) => printPolicy(t)
+      }
+    }
+
+    private def printMap[T <: DSLTimeBoundedItem[T]](m: immutable.SortedMap[Timeslot, T]) = {
+      Console.err.println("BEGIN MAP: ")
+      for { (t,p) <- m.toList } Console.err.println("Timeslot " + t + "\t\t" + p.name)
+      Console.err.println("END MAP")
+    } */
+
+  def resolveEffective[T <: DSLTimeBoundedItem[T]](timeslot0: Timeslot,policy: T):
+    immutable.SortedMap[Timeslot, T] = {
+      //Console.err.println("\n\nInput timeslot: " + timeslot0 + "\n\n")
+      ///printPolicy(policy)
+      val ret =  resolveEffective3(timeslot0,policy) //HERE
+      //printMap(ret)
+      ret
+    }
+
 
   def resolveEffective3(
-      timeslot0: Timeslot,
+      alignedTimeslot: Timeslot,
       effectivePriceTable: EffectivePriceTable
   ): immutable.SortedMap[Timeslot, Double/*unit price*/] = {
 //    assert(policy.toTimeslot contains timeslot0,"Policy does not contain timeslot")
-    val timeslot = timeslot0 //TODO: timeslot0.align(5000)
+    val timeslot = alignedTimeslot //TODO: timeslot0.align(5000)
     val subtimeslots_of_this_policy = Timeslot.mergeOverlaps(policy.effective intervalsOf timeslot)
     val subtimeslots_NOT_IN_this_policy = Timeslot.mergeOverlaps(timeslot.nonOverlappingTimeslots
                                                                                           (subtimeslots_of_this_policy))
index a5a2cff..24247e5 100644 (file)
@@ -39,6 +39,8 @@ package gr.grnet.aquarium.policy
  * A specific price table for a particular resource type that has information of what unit price is
  * effective when.
  *
+ * NOTE: head of `priceOverrides` is most specific.
+ *
  * @author Christos KK Loverdos <loverdos@gmail.com>
  */
 
index 72fa2fd..85a1279 100644 (file)
 
 package gr.grnet.aquarium.policy
 
+import gr.grnet.aquarium.logic.accounting.dsl.DSLTimeFrame
+
 /**
  *
  * @author Christos KK Loverdos <loverdos@gmail.com>
  */
 
-case class EffectiveUnitPrice(unitPrice: Double, when: List[(String, String)])
+case class EffectiveUnitPrice(unitPrice: Double, when: DSLTimeFrame) // TODO: use DSLTimeframe