mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-17 14:19:54 +05:00
workoing on getcost
This commit is contained in:
@@ -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
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user