diff --git a/timeslots/interval_test.go b/timespans/interval_test.go similarity index 100% rename from timeslots/interval_test.go rename to timespans/interval_test.go diff --git a/timeslots/intervals.go b/timespans/intervals.go similarity index 93% rename from timeslots/intervals.go rename to timespans/intervals.go index 2e11696fc..0799231e9 100644 --- a/timeslots/intervals.go +++ b/timespans/intervals.go @@ -113,7 +113,10 @@ func (i *Interval) getLeftMargin(t time.Time) (rigthtTime time.Time){ } /* - +Splits the given timespan according to how it relates to the interval. +It will modify the endtime of the received timespan and it will return +a new timespan starting from the end of the received one. +The interval will attach itself to the timespan that overlaps the interval. */ func (i *Interval) Split(ts *TimeSpan) (nts *TimeSpan) { // if the span is not in interval return nil diff --git a/timeslots/kyoto_storage.go b/timespans/kyoto_storage.go similarity index 100% rename from timeslots/kyoto_storage.go rename to timespans/kyoto_storage.go diff --git a/timeslots/redis_storage.go b/timespans/redis_storage.go similarity index 100% rename from timeslots/redis_storage.go rename to timespans/redis_storage.go diff --git a/timeslots/storage_interface.go b/timespans/storage_interface.go similarity index 100% rename from timeslots/storage_interface.go rename to timespans/storage_interface.go diff --git a/timeslots/timeslots.go b/timespans/timeslots.go similarity index 77% rename from timeslots/timeslots.go rename to timespans/timeslots.go index bd46b1fa4..58a30c97e 100644 --- a/timeslots/timeslots.go +++ b/timespans/timeslots.go @@ -7,6 +7,50 @@ import ( "encoding/json" ) +/* +A unit in which a call will be split that has a specific price related interval attached to it. +*/ +type TimeSpan struct { + TimeStart, TimeEnd time.Time + Interval *Interval +} + +/* +Returns the duration of the timespan +*/ +func (ts *TimeSpan) GetDuration() time.Duration { + return ts.TimeEnd.Sub(ts.TimeStart) +} + +/* +Returns the cost of the timespan according to the relevant cost interval. +If the first parameter is true then it adds the connection fee to the cost. +*/ +func (ts *TimeSpan) GetCost(first bool) return (cost float32) { + if ts.Interval.BillingUnit > 0 { + cost = (ts.GetDuration().seconds() / ts.Interval.BillingUnit) * ts.Interval.Price + } else { + cost = ts.GetDuration().seconds() * ts.Interval.Price + } + if first { + cost += ts.Interval.ConnectFee + } + return +} + +/* +will set ne interval as spans's interval if new ponder is greater then span's interval ponder +or if the ponders are equal and new price is lower then spans's interval price +*/ +func (ts *TimeSpan) SetInterval(i *Interval) { + if ts.Interval == nil || ts.Interval.Ponder < i.Ponder { + ts.Interval = i + } + if ts.Interval.Ponder == i.Ponder && i.Price < ts.Interval.Price { + ts.Interval = i + } +} + /* A structure containing the time intervals with the cost information and the ActivationTime when those intervals will be applied. @@ -23,14 +67,12 @@ func (c *ActivationPeriod) AddInterval(is ...*Interval) { } /* -A structure that contains the data extracted from the storage. -The CstmId and the Destination prefix represent the key and the -ActivationPeriods slice is the value. +The input stucture that contains call information. */ -type Customer struct { - CstmId string - Subject string - DestinationPrefix string +type CallDescription struct { + TOR int + CstmId, Subject, Destination string + TimeStart, TimeEnd time.Time ActivationPeriods []*ActivationPeriod } @@ -63,41 +105,12 @@ func (c *Customer) decodeValue(v []byte) { } /* -A unit in which a call will be split that has a specific price related interval attached to it. */ -type TimeSpan struct { - TimeStart, TimeEnd time.Time - Interval *Interval +func (cd *CallDescription) GetCost() (result *CallCost) { + ts := &TimeSpan{TimeStart: cd.TimeStart, TimeEnd: cd.TimeEnd} + c := &Customer{CstmId:, Subject:, DestinationPrefix: } } -/* -Returns the duration of the timespan -*/ -func (ts *TimeSpan) GetDuration() time.Duration { - return ts.TimeEnd.Sub(ts.TimeStart) -} - -/* -will set ne interval as spans's interval if new ponder is greater then span's interval ponder -or if the ponders are equal and new price is lower then spans's interval price -*/ -func (ts *TimeSpan) SetInterval(i *Interval) { - if ts.Interval == nil || ts.Interval.Ponder < i.Ponder { - ts.Interval = i - } - if ts.Interval.Ponder == i.Ponder && i.Price < ts.Interval.Price { - ts.Interval = i - } -} - -/* -The input stucture that contains call information. -*/ -type CallDescription struct { - TOR int - CstmId, Subject, Destination string - TimeStart, TimeEnd time.Time -} /* @@ -110,7 +123,4 @@ type CallCost struct { // ratesInfo *RatingProfile } -func GetCost(in *CallDescription, sg StorageGetter) (result *CallCost, err error) { - return &CallCost{TOR: 1, CstmId:"",Subject:"", Prefix:"", Cost:1, ConnectFee:1}, nil -} diff --git a/timeslots/timeslots_test.go b/timespans/timeslots_test.go similarity index 100% rename from timeslots/timeslots_test.go rename to timespans/timeslots_test.go