removed get present second

This commit is contained in:
Radu Ioan Fericean
2012-07-07 11:20:35 +03:00
parent 1ff3548d9e
commit 43f88836b1
2 changed files with 2 additions and 32 deletions

View File

@@ -266,23 +266,6 @@ func (cd *CallDescriptor) GetCost() (*CallCost, error) {
return cc, err
}
/*
Returns the cost of a second in the present time conditions.
*/
func (cd *CallDescriptor) getPresentSecondCost() (cost float64, err error) {
// TODO: remove this method if if not still used
_, err = cd.SearchStorageForPrefix()
now := time.Now()
oneSecond, _ := time.ParseDuration("1s")
ts := &TimeSpan{TimeStart: now, TimeEnd: now.Add(oneSecond)}
timespans := cd.splitTimeSpan(ts)
if len(timespans) > 0 {
cost = round(timespans[0].getCost(cd), 3)
}
return
}
/*
Returns the approximate max allowed session for user balance. It will try the max amount received in the call descriptor
and will decrease it by 10% for nine times. So if the user has little credit it will still allow 10% of the initial amount.
@@ -307,6 +290,7 @@ func (cd *CallDescriptor) GetMaxSessionTime() (seconds float64, err error) {
if availableCredit == 0 {
return availableSeconds, nil
}
maxSessionSeconds := cd.Amount
for i := 0; i < 10; i++ {
maxDuration, _ := time.ParseDuration(fmt.Sprintf("%vs", maxSessionSeconds-availableSeconds))

View File

@@ -35,7 +35,7 @@ func populateDB() {
Id: "OUT:vdf:minu",
Type: UB_TYPE_PREPAID,
BalanceMap: map[string]float64{
CREDIT: 21,
CREDIT: 0,
},
MinuteBuckets: []*MinuteBucket{
&MinuteBucket{Seconds: 200, DestinationId: "NAT", Weight: 10},
@@ -148,20 +148,6 @@ func TestUniquePrice(t *testing.T) {
}
}
func TestPresentSecodCost(t *testing.T) {
cd := &CallDescriptor{Direction: "OUT", TOR: "0", Tenant: "vdf", Subject: "rif", Destination: "0723"}
result, _ := cd.getPresentSecondCost()
expected := 1.0
now := time.Now()
after18 := time.Date(now.Year(), now.Month(), now.Day(), 18, 0, 0, 1, now.Location())
if now.After(after18) {
expected = 0.5
}
if result != expected {
t.Errorf("Expected %v was %v", expected, result)
}
}
func TestMinutesCost(t *testing.T) {
t1 := time.Date(2012, time.February, 8, 22, 50, 0, 0, time.UTC)
t2 := time.Date(2012, time.February, 8, 22, 51, 50, 0, time.UTC)