workoing on getcost

This commit is contained in:
Radu Ioan Fericean
2012-02-02 18:51:57 +02:00
parent edf631e58c
commit 1d7c2c0689
7 changed files with 56 additions and 43 deletions

View File

@@ -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

View File

@@ -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
}