mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
correcting rates loading
This commit is contained in:
@@ -119,3 +119,15 @@ func (cds CallDescriptors) getKey(key string) *timespans.CallDescriptor {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
/*func (cds CallDescriptors) setIntervalEndTime() {
|
||||
for _, cd := range cds {
|
||||
for _, ap := range cd.ActivationPeriods {
|
||||
for x, i := range ap.Intervals {
|
||||
if x < len(ap.Intervals)-1 {
|
||||
i.EndTime = ap.Intervals[x+1].StartTime
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
@@ -134,7 +134,6 @@ func loadRatesTimings() {
|
||||
log.Printf("Could not get timing for tag %v", record[2])
|
||||
continue
|
||||
}
|
||||
|
||||
for _, t := range ts {
|
||||
rt := NewRateTiming(record[1], t)
|
||||
ratesTimings[tag] = append(ratesTimings[tag], rt)
|
||||
@@ -163,18 +162,17 @@ func loadRatingProfiles() {
|
||||
continue
|
||||
}
|
||||
tenant, tor, direction, subject, fallbacksubject := record[0], record[1], record[2], record[3], record[4]
|
||||
fmt.Sprintf("%s:%s:%s:%s:%s", direction, tenant, tor, subject)
|
||||
at, err := time.Parse(time.RFC3339, record[6])
|
||||
if err != nil {
|
||||
log.Printf("Cannot parse activation time from %v", record[5])
|
||||
log.Printf("Cannot parse activation time from %v", record[6])
|
||||
continue
|
||||
}
|
||||
rts, exists := ratesTimings[record[5]]
|
||||
if !exists {
|
||||
log.Printf("Could not get rate timing for tag %v", record[4])
|
||||
log.Printf("Could not get rate timing for tag %v", record)
|
||||
continue
|
||||
}
|
||||
for _, rt := range rts { // rates timing
|
||||
for _, rt := range rts { // rates timing
|
||||
rs, exists := rates[rt.RatesTag]
|
||||
if !exists {
|
||||
log.Printf("Could not get rates for tag %v", rt.RatesTag)
|
||||
@@ -186,10 +184,9 @@ func loadRatingProfiles() {
|
||||
for _, r := range rs { //rates
|
||||
for _, d := range destinations {
|
||||
if d.Id == r.DestinationsTag {
|
||||
log.Print("dId: ", d.Id)
|
||||
ap.AddInterval(rt.GetInterval(r))
|
||||
log.Print(d)
|
||||
for _, p := range d.Prefixes { //destinations
|
||||
log.Print("P: ", p)
|
||||
for _, p := range d.Prefixes { //destinations
|
||||
// Search for a CallDescriptor with the same key
|
||||
var cd *timespans.CallDescriptor
|
||||
key := fmt.Sprintf("%s:%s:%s:%s:%s", direction, tenant, tor, subject, p)
|
||||
@@ -242,6 +239,7 @@ func loadRatingProfiles() {
|
||||
log.Print("Call descriptors:")
|
||||
for dest, cds := range ratingProfiles {
|
||||
log.Print(dest)
|
||||
//cds.setIntervalEndTime()
|
||||
for _, cd := range cds {
|
||||
log.Print(cd)
|
||||
}
|
||||
|
||||
@@ -4,4 +4,7 @@ GERMANY_O2,41
|
||||
GERMANY_PREMIUM,43
|
||||
ALL,49
|
||||
ALL,41
|
||||
ALL,43
|
||||
ALL,43
|
||||
NAT,0256
|
||||
NAT,0257
|
||||
NAT,0723
|
||||
|
@@ -4,4 +4,6 @@ RT_STANDARD,GERMANY_O2,0,0.1,1,10
|
||||
RT_STANDARD,GERMANY_PREMIUM,0,0.1,1,10
|
||||
RT_DEFAULT,ALL,0,0.1,1,10
|
||||
RT_STD_WEEKEND,GERMANY,0,0.1,1,10
|
||||
RT_STD_WEEKEND,GERMANY_O2,0,0.05,1,10
|
||||
RT_STD_WEEKEND,GERMANY_O2,0,0.05,1,10
|
||||
P1,NAT,0,1,1,10
|
||||
P2,NAT,0,0.5,1,10
|
||||
|
@@ -3,4 +3,7 @@ STANDARD,RT_STANDARD,WORKDAYS_00
|
||||
STANDARD,RT_STD_WEEKEND,WORKDAYS_18
|
||||
STANDARD,RT_STD_WEEKEND,WEEKENDS
|
||||
PREMIUM,RT_STD_WEEKEND,WEEKENDS
|
||||
DEFAULT,RT_DEFAULT,WORKDAYS_00
|
||||
DEFAULT,RT_DEFAULT,WORKDAYS_00
|
||||
EVENING,P1,WORKDAYS_00
|
||||
EVENING,P2,WORKDAYS_18
|
||||
EVENING,P2,WEEKENDS
|
||||
|
@@ -2,4 +2,6 @@ Tenant,TOR,Direction,Subject,RatesFallbackSubject,RatesTimingTag,ActivationTime
|
||||
CUSTOMER_1,0,OUT,rif:from:tm,danb,PREMIUM,2012-01-01T00:00:00Z
|
||||
CUSTOMER_1,0,OUT,rif:from:tm,danb,STANDARD,2012-02-28T00:00:00Z
|
||||
CUSTOMER_2,0,OUT,danb:87.139.12.167,danb,STANDARD,2012-01-01T00:00:00Z
|
||||
CUSTOMER_1,0,OUT,danb,,PREMIUM,2012-01-01T00:00:00Z
|
||||
CUSTOMER_1,0,OUT,danb,,PREMIUM,2012-01-01T00:00:00Z
|
||||
vdf,0,OUT,rif,,EVENING,2012-01-01T00:00:00Z
|
||||
vdf,0,OUT,rif,,EVENING,2012-02-28T00:00:00Z
|
||||
|
@@ -1,6 +1,6 @@
|
||||
TimingTag,Months,MonthDays,WeekDays,StartTime
|
||||
WORKDAYS_00,*all,*all,*all,00:00:00
|
||||
WORKDAYS_18,*all,*all,*all,18:00:00
|
||||
WORKDAYS_00,*all,*all,1;2;3;4;5,00:00:00
|
||||
WORKDAYS_18,*all,*all,6;7,18:00:00
|
||||
WEEKENDS,*all,*all,6;7,00:00:00
|
||||
WEEKLY_SAME_TIME,*all,*all,1,*now
|
||||
FIRST_DAY_OF_MONTH,*all,1,*all,00:00:00
|
||||
|
||||
|
@@ -146,17 +146,17 @@ func TestActionTimingHourMonthdaysMonths(t *testing.T) {
|
||||
if now.After(testTime) {
|
||||
day = tomorrow.Day()
|
||||
}
|
||||
/*month := now.Month()
|
||||
month := now.Month()
|
||||
if now.After(testTime) {
|
||||
month = nextMonth.Month()
|
||||
}*/
|
||||
}
|
||||
at := &ActionTiming{Timing: &Interval{
|
||||
Months: Months{now.Month(), nextMonth.Month()},
|
||||
MonthDays: MonthDays{now.Day(), tomorrow.Day()},
|
||||
StartTime: "10:01:00",
|
||||
}}
|
||||
st := at.GetNextStartTime()
|
||||
expected := time.Date(y, m, day, 10, 1, 0, 0, time.Local)
|
||||
expected := time.Date(y, month, day, 10, 1, 0, 0, time.Local)
|
||||
if !st.Equal(expected) {
|
||||
t.Errorf("Expected %v was %v", expected, st)
|
||||
}
|
||||
|
||||
@@ -39,10 +39,7 @@ func TestApRestoreRedis(t *testing.T) {
|
||||
Subject: "rif:from:tm",
|
||||
Destination: "49"}
|
||||
cd.SearchStorageForPrefix()
|
||||
if len(cd.ActivationPeriods) != 4 {
|
||||
for _, ap := range cd.ActivationPeriods {
|
||||
t.Log(ap)
|
||||
}
|
||||
if len(cd.ActivationPeriods) != 2 {
|
||||
t.Error("Error restoring activation periods: ", len(cd.ActivationPeriods))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,69 +32,78 @@ func init() {
|
||||
func TestSingleResultMerge(t *testing.T) {
|
||||
t1 := time.Date(2012, time.February, 2, 17, 00, 0, 0, time.UTC)
|
||||
t2 := time.Date(2012, time.February, 2, 17, 01, 0, 0, time.UTC)
|
||||
cd := &CallDescriptor{Tenant: "vdf", Subject: "rif", Destination: "0256", TimeStart: t1, TimeEnd: t2}
|
||||
cd := &CallDescriptor{Direction: "OUT", TOR: "0", Tenant: "vdf", Subject: "rif", Destination: "0256", TimeStart: t1, TimeEnd: t2}
|
||||
cc1, _ := cd.GetCost()
|
||||
if cc1.Cost != 12 {
|
||||
t.Errorf("expected 12 was %v", cc1.Cost)
|
||||
if cc1.Cost != 60 {
|
||||
t.Errorf("expected 60 was %v", cc1.Cost)
|
||||
}
|
||||
t1 = time.Date(2012, time.February, 2, 17, 01, 0, 0, time.UTC)
|
||||
t2 = time.Date(2012, time.February, 2, 17, 02, 0, 0, time.UTC)
|
||||
cd = &CallDescriptor{Tenant: "vdf", Subject: "rif", Destination: "0256", TimeStart: t1, TimeEnd: t2}
|
||||
cd = &CallDescriptor{Direction: "OUT", TOR: "0", Tenant: "vdf", Subject: "rif", Destination: "0256", TimeStart: t1, TimeEnd: t2}
|
||||
cc2, _ := cd.GetCost()
|
||||
if cc2.Cost != 12 {
|
||||
t.Errorf("expected 12 was %v", cc2.Cost)
|
||||
if cc2.Cost != 60 {
|
||||
t.Errorf("expected 60 was %v", cc2.Cost)
|
||||
}
|
||||
cc1.Merge(cc2)
|
||||
if len(cc1.Timespans) != 1 || cc1.Timespans[0].GetDuration().Seconds() != 120 {
|
||||
t.Error("wrong resulted timespan")
|
||||
t.Error("wrong resulted timespan: ", len(cc1.Timespans), cc1.Timespans[0].GetDuration().Seconds())
|
||||
}
|
||||
if cc1.Cost != 24 {
|
||||
t.Errorf("Exdpected 24 was %v", cc1.Cost)
|
||||
if cc1.Cost != 120 {
|
||||
t.Errorf("Exdpected 120 was %v", cc1.Cost)
|
||||
}
|
||||
}
|
||||
|
||||
func TestMultipleResultMerge(t *testing.T) {
|
||||
t1 := time.Date(2012, time.February, 2, 17, 59, 0, 0, time.UTC)
|
||||
t2 := time.Date(2012, time.February, 2, 18, 00, 0, 0, time.UTC)
|
||||
cd := &CallDescriptor{Tenant: "vdf", Subject: "rif", Destination: "0256", TimeStart: t1, TimeEnd: t2}
|
||||
cd := &CallDescriptor{Direction: "OUT", TOR: "0", Tenant: "vdf", Subject: "rif", Destination: "0256", TimeStart: t1, TimeEnd: t2}
|
||||
cc1, _ := cd.GetCost()
|
||||
if cc1.Cost != 12 {
|
||||
t.Errorf("expected 12 was %v", cc1.Cost)
|
||||
if cc1.Cost != 60 {
|
||||
t.Errorf("expected 60 was %v", cc1.Cost)
|
||||
for _, ts := range cc1.Timespans {
|
||||
t.Log(ts.Interval)
|
||||
}
|
||||
}
|
||||
t1 = time.Date(2012, time.February, 2, 18, 00, 0, 0, time.UTC)
|
||||
t2 = time.Date(2012, time.February, 2, 18, 01, 0, 0, time.UTC)
|
||||
cd = &CallDescriptor{Tenant: "vdf", Subject: "rif", Destination: "0256", TimeStart: t1, TimeEnd: t2}
|
||||
cd = &CallDescriptor{Direction: "OUT", TOR: "0", Tenant: "vdf", Subject: "rif", Destination: "0256", TimeStart: t1, TimeEnd: t2}
|
||||
cc2, _ := cd.GetCost()
|
||||
if cc2.Cost != 6 {
|
||||
t.Errorf("expected 6 was %v", cc2.Cost)
|
||||
if cc2.Cost != 30 {
|
||||
t.Errorf("expected 30 was %v", cc2.Cost)
|
||||
for _, i := range cd.ActivationPeriods[1].Intervals {
|
||||
t.Log(i)
|
||||
}
|
||||
for _, ts := range cc1.Timespans {
|
||||
t.Log(ts.Interval)
|
||||
}
|
||||
}
|
||||
cc1.Merge(cc2)
|
||||
if len(cc1.Timespans) != 2 || cc1.Timespans[0].GetDuration().Seconds() != 60 {
|
||||
t.Error("wrong resulted timespan")
|
||||
t.Error("wrong resulted timespan: ", len(cc1.Timespans), cc1.Timespans[0].GetDuration().Seconds())
|
||||
}
|
||||
if cc1.Cost != 18 {
|
||||
t.Errorf("Exdpected 18 was %v", cc1.Cost)
|
||||
if cc1.Cost != 90 {
|
||||
t.Errorf("Exdpected 90 was %v", cc1.Cost)
|
||||
}
|
||||
}
|
||||
|
||||
func TestMultipleInputLeftMerge(t *testing.T) {
|
||||
t1 := time.Date(2012, time.February, 2, 17, 59, 0, 0, time.UTC)
|
||||
t2 := time.Date(2012, time.February, 2, 18, 01, 0, 0, time.UTC)
|
||||
cd := &CallDescriptor{Tenant: "vdf", Subject: "rif", Destination: "0256", TimeStart: t1, TimeEnd: t2}
|
||||
cd := &CallDescriptor{Direction: "OUT", TOR: "0", Tenant: "vdf", Subject: "rif", Destination: "0256", TimeStart: t1, TimeEnd: t2}
|
||||
cc1, _ := cd.GetCost()
|
||||
if cc1.Cost != 18 {
|
||||
t.Errorf("expected 12 was %v", cc1.Cost)
|
||||
}
|
||||
t1 = time.Date(2012, time.February, 2, 18, 01, 0, 0, time.UTC)
|
||||
t2 = time.Date(2012, time.February, 2, 18, 02, 0, 0, time.UTC)
|
||||
cd = &CallDescriptor{Tenant: "vdf", Subject: "rif", Destination: "0256", TimeStart: t1, TimeEnd: t2}
|
||||
cd = &CallDescriptor{Direction: "OUT", TOR: "0", Tenant: "vdf", Subject: "rif", Destination: "0256", TimeStart: t1, TimeEnd: t2}
|
||||
cc2, _ := cd.GetCost()
|
||||
if cc2.Cost != 6 {
|
||||
t.Errorf("expected 6 was %v", cc2.Cost)
|
||||
}
|
||||
cc1.Merge(cc2)
|
||||
if len(cc1.Timespans) != 2 || cc1.Timespans[1].GetDuration().Seconds() != 120 {
|
||||
t.Error("wrong resulted timespan")
|
||||
t.Error("wrong resulted timespan: ", len(cc1.Timespans), cc1.Timespans[0].GetDuration().Seconds())
|
||||
}
|
||||
if cc1.Cost != 24 {
|
||||
t.Errorf("Exdpected 24 was %v", cc1.Cost)
|
||||
@@ -104,21 +113,21 @@ func TestMultipleInputLeftMerge(t *testing.T) {
|
||||
func TestMultipleInputRightMerge(t *testing.T) {
|
||||
t1 := time.Date(2012, time.February, 2, 17, 58, 0, 0, time.UTC)
|
||||
t2 := time.Date(2012, time.February, 2, 17, 59, 0, 0, time.UTC)
|
||||
cd := &CallDescriptor{Tenant: "vdf", Subject: "rif", Destination: "0256", TimeStart: t1, TimeEnd: t2}
|
||||
cd := &CallDescriptor{Direction: "OUT", TOR: "0", Tenant: "vdf", Subject: "rif", Destination: "0256", TimeStart: t1, TimeEnd: t2}
|
||||
cc1, _ := cd.GetCost()
|
||||
if cc1.Cost != 12 {
|
||||
t.Errorf("expected 12 was %v", cc1.Cost)
|
||||
}
|
||||
t1 = time.Date(2012, time.February, 2, 17, 59, 0, 0, time.UTC)
|
||||
t2 = time.Date(2012, time.February, 2, 18, 01, 0, 0, time.UTC)
|
||||
cd = &CallDescriptor{Tenant: "vdf", Subject: "rif", Destination: "0256", TimeStart: t1, TimeEnd: t2}
|
||||
cd = &CallDescriptor{Direction: "OUT", TOR: "0", Tenant: "vdf", Subject: "rif", Destination: "0256", TimeStart: t1, TimeEnd: t2}
|
||||
cc2, _ := cd.GetCost()
|
||||
if cc2.Cost != 18 {
|
||||
t.Errorf("expected 18 was %v", cc2.Cost)
|
||||
}
|
||||
cc1.Merge(cc2)
|
||||
if len(cc1.Timespans) != 2 || cc1.Timespans[0].GetDuration().Seconds() != 120 {
|
||||
t.Error("wrong resulted timespan")
|
||||
t.Error("wrong resulted timespan: ", len(cc1.Timespans), cc1.Timespans[0].GetDuration().Seconds())
|
||||
t.Log(cc1.Timespans[0].GetDuration())
|
||||
}
|
||||
if cc1.Cost != 30 {
|
||||
|
||||
@@ -36,7 +36,7 @@ func init() {
|
||||
func TestSplitSpans(t *testing.T) {
|
||||
t1 := time.Date(2012, time.February, 2, 17, 30, 0, 0, time.UTC)
|
||||
t2 := time.Date(2012, time.February, 2, 18, 30, 0, 0, time.UTC)
|
||||
cd := &CallDescriptor{Tenant: "vdf", Subject: "rif", Destination: "0256", TimeStart: t1, TimeEnd: t2}
|
||||
cd := &CallDescriptor{Direction: "OUT", TOR: "0", Tenant: "vdf", Subject: "rif", Destination: "0256", TimeStart: t1, TimeEnd: t2}
|
||||
|
||||
cd.SearchStorageForPrefix()
|
||||
timespans := cd.splitInTimeSpans()
|
||||
|
||||
@@ -102,17 +102,21 @@ a new timespan starting from the end of the received one.
|
||||
The interval will attach itself to the timespan that overlaps the interval.
|
||||
*/
|
||||
func (ts *TimeSpan) SplitByInterval(i *Interval) (nts *TimeSpan) {
|
||||
//log.Print("here: ", i)
|
||||
// if the span is not in interval return nil
|
||||
if !(i.Contains(ts.TimeStart) || i.Contains(ts.TimeEnd)) {
|
||||
//log.Print("Not in interval")
|
||||
return
|
||||
}
|
||||
// if the span is enclosed in the interval try to set as new interval and return nil
|
||||
if i.Contains(ts.TimeStart) && i.Contains(ts.TimeEnd) {
|
||||
//log.Print("All in interval")
|
||||
ts.SetInterval(i)
|
||||
return
|
||||
}
|
||||
// if only the start time is in the interval split the interval
|
||||
if i.Contains(ts.TimeStart) {
|
||||
//log.Print("Start in interval")
|
||||
splitTime := i.getRightMargin(ts.TimeStart)
|
||||
ts.SetInterval(i)
|
||||
if splitTime == ts.TimeStart {
|
||||
@@ -125,6 +129,7 @@ func (ts *TimeSpan) SplitByInterval(i *Interval) (nts *TimeSpan) {
|
||||
}
|
||||
// if only the end time is in the interval split the interval
|
||||
if i.Contains(ts.TimeEnd) {
|
||||
//log.Print("End in interval")
|
||||
splitTime := i.getLeftMargin(ts.TimeEnd)
|
||||
if splitTime == ts.TimeEnd {
|
||||
return
|
||||
@@ -151,7 +156,7 @@ func (ts *TimeSpan) SplitByActivationPeriod(ap *ActivationPeriod) (newTs *TimeSp
|
||||
}
|
||||
|
||||
/*
|
||||
Splits the given timespan on activation period's activation time.
|
||||
Splits the given timespan on minute bucket's duration.
|
||||
*/
|
||||
func (ts *TimeSpan) SplitByMinuteBucket(mb *MinuteBucket) (newTs *TimeSpan) {
|
||||
s := ts.GetDuration().Seconds()
|
||||
|
||||
Reference in New Issue
Block a user