only decode if we get something from storage

This commit is contained in:
Radu Ioan Fericean
2012-02-07 22:51:04 +02:00
parent ae6e5dc497
commit b9ced45f52
4 changed files with 18 additions and 19 deletions

View File

@@ -52,7 +52,7 @@ func (cd *CallDescriptor) getActivePeriods() (is []*ActivationPeriod) {
bestTime := cd.ActivationPeriods[0].ActivationTime
is = append(is, cd.ActivationPeriods[0])
for _, ap := range cd.ActivationPeriods {
for _, ap := range cd.ActivationPeriods {
if ap.ActivationTime.After(bestTime) && ap.ActivationTime.Before(cd.TimeStart) {
bestTime = ap.ActivationTime
is[0] = ap
@@ -70,9 +70,9 @@ Splits the call timespan into sub time spans accordin to the activation periods
func (cd *CallDescriptor) splitInTimeSpans(aps []*ActivationPeriod) (timespans []*TimeSpan) {
ts1 := &TimeSpan{TimeStart: cd.TimeStart, TimeEnd: cd.TimeEnd}
ts1.ActivationPeriod = aps[0] // first activation period starts before the timespan
timespans = append(timespans, ts1)
timespans = append(timespans, ts1)
for _, ap := range aps {
for i := 0; i < len(timespans); i++ {
ts := timespans[i]
@@ -82,7 +82,7 @@ func (cd *CallDescriptor) splitInTimeSpans(aps []*ActivationPeriod) (timespans [
}
}
}
for i := 0; i < len(timespans); i++ {
ts := timespans[i]
for _, interval := range ts.ActivationPeriod.Intervals {
@@ -106,12 +106,13 @@ func (cd *CallDescriptor) RestoreFromStorage(sg StorageGetter) (destPrefix strin
destPrefix = cd.DestinationPrefix[:i]
key = base + destPrefix
}
for _, aps := range strings.Split(values, "\n") {
if len(aps) > 0 {
ap := &ActivationPeriod{}
ap.restore(aps)
cd.ActivationPeriods = append(cd.ActivationPeriods, ap)
if err == nil {
for _, aps := range strings.Split(values, "\n") {
if len(aps) > 0 {
ap := &ActivationPeriod{}
ap.restore(aps)
cd.ActivationPeriods = append(cd.ActivationPeriods, ap)
}
}
}
return
@@ -125,10 +126,10 @@ func (cd *CallDescriptor) GetCost(sg StorageGetter) (result *CallCost, err error
timespans := cd.splitInTimeSpans(cd.getActivePeriods())
cost := 0.0
for _, ts := range timespans {
for _, ts := range timespans {
cost += ts.GetCost()
}
cc := &CallCost{TOR: cd.TOR,
CstmId: cd.CstmId,
Subject: cd.Subject,

View File

@@ -158,5 +158,3 @@ func BenchmarkKyotoGetCost(b *testing.B) {
cd.GetCost(getter)
}
}

View File

@@ -92,7 +92,7 @@ func (ts *TimeSpan) SplitByInterval(i *Interval) (nts *TimeSpan) {
}
nts = &TimeSpan{TimeStart: splitTime, TimeEnd: ts.TimeEnd}
ts.TimeEnd = splitTime
nts.SetInterval(i)
return
}
@@ -105,8 +105,8 @@ Splits the given timespan on activation period's activation time.
func (ts *TimeSpan) SplitByActivationPeriod(ap *ActivationPeriod) (newTs *TimeSpan) {
if !ts.Contains(ap.ActivationTime) {
return nil
}
}
newTs = &TimeSpan{TimeStart: ap.ActivationTime, TimeEnd: ts.TimeEnd, ActivationPeriod: ap}
ts.TimeEnd = ap.ActivationTime
return
return
}

View File

@@ -153,7 +153,7 @@ func TestSplitByActivationTime(t *testing.T) {
ap1 := &ActivationPeriod{ActivationTime: t1}
ap2 := &ActivationPeriod{ActivationTime: t2}
ap3 := &ActivationPeriod{ActivationTime: t3}
if ts.SplitByActivationPeriod(ap1) != nil {
t.Error("Error spliting on left margin")
}