From 8b7bdc1db973bfb424acd5bb63a28b5f4c0c8db0 Mon Sep 17 00:00:00 2001 From: Radu Ioan Fericean Date: Tue, 10 Jul 2012 17:59:36 +0300 Subject: [PATCH] moved weight from rates to ratetimings --- cmd/cgr-loader/cgr-loader.go | 4 +- cmd/cgr-loader/helpers.go | 23 ++++--- cmd/cgr-loader/rates.go | 9 ++- data/RateTimings.csv | 9 +++ data/Rates.csv | 18 ++--- data/RatesTimings.csv | 9 --- docs/importing.rst | 127 ++++++++++++++++++----------------- docs/intro.rst | 2 +- 8 files changed, 101 insertions(+), 100 deletions(-) create mode 100644 data/RateTimings.csv delete mode 100644 data/RatesTimings.csv diff --git a/cmd/cgr-loader/cgr-loader.go b/cmd/cgr-loader/cgr-loader.go index 791c64110..c9ce8a010 100644 --- a/cmd/cgr-loader/cgr-loader.go +++ b/cmd/cgr-loader/cgr-loader.go @@ -36,7 +36,7 @@ var ( destinationsFn = flag.String("destinations", "Destinations.csv", "Destinations file") ratesFn = flag.String("rates", "Rates.csv", "Rates file") timingsFn = flag.String("timings", "Timings.csv", "Timings file") - ratestimingsFn = flag.String("ratestimings", "RatesTimings.csv", "Rates timings file") + ratetimingsFn = flag.String("ratetimings", "RateTimings.csv", "Rates timings file") ratingprofilesFn = flag.String("ratingprofiles", "RatingProfiles.csv", "Rating profiles file") actionsFn = flag.String("actions", "Actions.csv", "Actions file") actiontimingsFn = flag.String("actiontimings", "ActionTimings.csv", "Actions timings file") @@ -88,7 +88,7 @@ func main() { loadDestinations() loadRates() loadTimings() - loadRatesTimings() + loadRateTimings() loadRatingProfiles() loadActions() loadActionTimings() diff --git a/cmd/cgr-loader/helpers.go b/cmd/cgr-loader/helpers.go index 9c34cb1c9..aa278b469 100644 --- a/cmd/cgr-loader/helpers.go +++ b/cmd/cgr-loader/helpers.go @@ -27,11 +27,11 @@ import ( ) type Rate struct { - DestinationsTag string - ConnectFee, Price, BillingUnit, Weight float64 + DestinationsTag string + ConnectFee, Price, BillingUnit float64 } -func NewRate(destinationsTag, connectFee, price, billingUnit, weight string) (r *Rate, err error) { +func NewRate(destinationsTag, connectFee, price, billingUnit string) (r *Rate, err error) { cf, err := strconv.ParseFloat(connectFee, 64) if err != nil { log.Printf("Error parsing connect fee from: %v", connectFee) @@ -47,17 +47,11 @@ func NewRate(destinationsTag, connectFee, price, billingUnit, weight string) (r log.Printf("Error parsing billing unit from: %v", billingUnit) return } - w, err := strconv.ParseFloat(weight, 64) - if err != nil { - log.Printf("Error parsing weight from: %v", weight) - return - } r = &Rate{ DestinationsTag: destinationsTag, ConnectFee: cf, Price: p, BillingUnit: bu, - Weight: w, } return } @@ -85,12 +79,19 @@ func NewTiming(timeingInfo ...string) (rt *Timing) { type RateTiming struct { RatesTag string + Weight float64 timing *Timing } -func NewRateTiming(ratesTag string, timing *Timing) (rt *RateTiming) { +func NewRateTiming(ratesTag string, timing *Timing, weight string) (rt *RateTiming) { + w, err := strconv.ParseFloat(weight, 64) + if err != nil { + log.Printf("Error parsing weight unit from: %v", weight) + return + } rt = &RateTiming{ RatesTag: ratesTag, + Weight: w, timing: timing, } return @@ -102,10 +103,10 @@ func (rt *RateTiming) GetInterval(r *Rate) (i *timespans.Interval) { MonthDays: rt.timing.MonthDays, WeekDays: rt.timing.WeekDays, StartTime: rt.timing.StartTime, + Weight: rt.Weight, ConnectFee: r.ConnectFee, Price: r.Price, BillingUnit: r.BillingUnit, - Weight: r.Weight, } return } diff --git a/cmd/cgr-loader/rates.go b/cmd/cgr-loader/rates.go index bc477199b..a24fe4aae 100644 --- a/cmd/cgr-loader/rates.go +++ b/cmd/cgr-loader/rates.go @@ -83,7 +83,7 @@ func loadRates() { // skip header line continue } - r, err := NewRate(record[1], record[2], record[3], record[4], record[5]) + r, err := NewRate(record[1], record[2], record[3], record[4]) if err != nil { continue } @@ -113,8 +113,8 @@ func loadTimings() { } } -func loadRatesTimings() { - fp, err := os.Open(*ratestimingsFn) +func loadRateTimings() { + fp, err := os.Open(*ratetimingsFn) if err != nil { log.Printf("Could not open rates timings file: %v", err) return @@ -136,8 +136,7 @@ func loadRatesTimings() { continue } for _, t := range ts { - rt := NewRateTiming(record[1], t) - //ratesTimings[tag] = append(ratesTimings[tag], rt) + rt := NewRateTiming(record[1], t, record[3]) rs, exists := rates[record[1]] if !exists { log.Printf("Could not rate for tag %v", record[2]) diff --git a/data/RateTimings.csv b/data/RateTimings.csv new file mode 100644 index 000000000..cbbe7e678 --- /dev/null +++ b/data/RateTimings.csv @@ -0,0 +1,9 @@ +Tag,RatesTag,TimingProfile,Weight +STANDARD,RT_STANDARD,WORKDAYS_00,10 +STANDARD,RT_STD_WEEKEND,WORKDAYS_18,10 +STANDARD,RT_STD_WEEKEND,WEEKENDS,10 +PREMIUM,RT_STD_WEEKEND,WEEKENDS,10 +DEFAULT,RT_DEFAULT,WORKDAYS_00,10 +EVENING,P1,WORKDAYS_00,10 +EVENING,P2,WORKDAYS_18,10 +EVENING,P2,WEEKENDS,10 \ No newline at end of file diff --git a/data/Rates.csv b/data/Rates.csv index 137782ca5..e6946c608 100644 --- a/data/Rates.csv +++ b/data/Rates.csv @@ -1,9 +1,9 @@ -Tag,DestinationsTag,ConnectFee,Price,BillingUnit,Weight -RT_STANDARD,GERMANY,0,0.2,1,10 -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 -P1,NAT,0,1,1,10 -P2,NAT,0,0.5,1,10 \ No newline at end of file +Tag,DestinationsTag,ConnectFee,Price,BillingUnit +RT_STANDARD,GERMANY,0,0.2,1 +RT_STANDARD,GERMANY_O2,0,0.1,1 +RT_STANDARD,GERMANY_PREMIUM,0,0.1,1 +RT_DEFAULT,ALL,0,0.1,1 +RT_STD_WEEKEND,GERMANY,0,0.1,1 +RT_STD_WEEKEND,GERMANY_O2,0,0.05,1 +P1,NAT,0,1,1 +P2,NAT,0,0.5,1 \ No newline at end of file diff --git a/data/RatesTimings.csv b/data/RatesTimings.csv deleted file mode 100644 index 2d49a5112..000000000 --- a/data/RatesTimings.csv +++ /dev/null @@ -1,9 +0,0 @@ -Tag,RatesTag,TimingProfile -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 -EVENING,P1,WORKDAYS_00 -EVENING,P2,WORKDAYS_18 -EVENING,P2,WEEKENDS \ No newline at end of file diff --git a/docs/importing.rst b/docs/importing.rst index 711fd8462..e8cd9421a 100644 --- a/docs/importing.rst +++ b/docs/importing.rst @@ -18,40 +18,43 @@ The rates profile describes the prices to be applied for various calls to variou | CUSTOMER_1 | 0 | OUT | rif:from:tm | danb | STANDARD | 2012-02-28T00:00:00Z | +------------+-----+-----------+-------------+----------------------+----------------+----------------------+ -+ Tenant +Tenant Used to distinguish between carriers if more than one share the same database in the CGRates system. -+ TOR +TOR Type of record specifies the kind of transmission this rate profile applies to. -+ Direction +Direction Can be IN or OUT for the INBOUND and OUTBOUND calls. -+ Subject +Subject The client/user for who this profile is detailing the rates. -+ RatesFallbackSubject +RatesFallbackSubject This specifies another profile to be used in case the call destination will not be found in the current profile. The same tenant, tor and direction will be used. -+ RatesTimingTag +RatesTimingTag Forwards to a tag described in the rates timing file to be used for this profile. -+ ActivationTime +ActivationTime Multiple rates timings/prices can be created for one profile with different activation times. When a call is made the appropriate profile(s) will be used to rate the call. -Rates timings +Rates timing ------------- This file makes links between a ratings and timings so each of them can be described once and various combinations are made possible. -+----------+----------------+--------------+ -| Tag | RatesTag | TimingTag | -+==========+================+==============+ -| STANDARD | RT_STANDARD | WORKDAYS_00 | -+----------+----------------+--------------+ -| STANDARD | RT_STD_WEEKEND | WORKDAYS_18 | -+----------+----------------+--------------+ ++----------+----------------+--------------+--------+ +| Tag | RatesTag | TimingTag | Weight | ++==========+================+==============+========+ +| STANDARD | RT_STANDARD | WORKDAYS_00 | 10 | ++----------+----------------+--------------+--------+ +| STANDARD | RT_STD_WEEKEND | WORKDAYS_18 | 10 | ++----------+----------------+--------------+--------+ -+ Tag +Tag A string by witch this rates timing will be referenced in other places by. -+ RatesTag +RatesTag The rating tag described in the rates file. -+ TimingTag +TimingTag The timing tag described in the timing file +Weight + If multiple timings cab be applied to a call the one with the lower weight wins. + Rates ----- @@ -65,36 +68,34 @@ Rates +---------------------+-----------------+------------+-------+-------------+ -+ Tag +Tag A string by witch this rate will be referenced in other places by. -+ DestinationsTag +DestinationsTag The destination tag witch these rates apply to. -+ ConnectFee +ConnectFee The price to be charged once at the beginning of the call to the specified destination. -+ Price +Price The price for the billing unit expressed in cents. -+ BillingUnit +BillingUnit The billing unit expressed in seconds Timings ------- -+-------------+--------+-----------+-----------+----------+--------+ -| Tag | Months | MonthDays | WeekDays | StartTime| Weight | -+=============+========+===========+===========+==========+========+ -| WORKDAYS_00 | *all | *all | 1;2;3;4;5 | 00:00:00 | 10 | -+-------------+--------+-----------+-----------+----------+--------+ -| WORKDAYS_18 | *all | *all | 1;2;3;4;5 | 18:00:00 | 10 | -+-------------+--------+-----------+-----------+----------+--------+ ++-------------+--------+-----------+-----------+----------+ +| Tag | Months | MonthDays | WeekDays | StartTime| ++=============+========+===========+===========+==========+ +| WORKDAYS_00 | *all | *all | 1;2;3;4;5 | 00:00:00 | ++-------------+--------+-----------+-----------+----------+ +| WORKDAYS_18 | *all | *all | 1;2;3;4;5 | 18:00:00 | ++-------------+--------+-----------+-----------+----------+ -+ Tag +Tag A string by witch this timing will be referenced in other places by. -+ Months -+ MonthDays -+ WeekDays -+ StartTime -+ Weight - If multiple timings cab be applied to a call the one with the lower weight wins. +Months +MonthDays +WeekDays +StartTime Destinations ------------ @@ -109,9 +110,9 @@ The destinations are binding together various prefixes / caller ids to define a | GERMANY_O2 | 49176 | +------------+-------+ -+ Tag +Tag A string by witch this destination will be referenced in other places by. -+ Prefix +Prefix The prefix or caller id to be added to the specified destination. Account actions @@ -125,11 +126,11 @@ Account actions | CUSTOMER_1 | dan | OUT | STANDARD_ABO | STANDARD_TRIGGER | +------------+---------+-----------+------------------+------------------+ -+ Tenant -+ Account -+ Direction -+ ActionTimingsTag -+ ActionTriggersTag +Tenant +Account +Direction +ActionTimingsTag +ActionTriggersTag Action triggers --------------- @@ -142,13 +143,13 @@ Action triggers | STANDARD_TRIGGER | SMS | 30 | *all |SOME_2 | 10 | +------------------+------------+----------------+----------------+------------+--------+ -+ Tag +Tag A string by witch this action trigger will be referenced in other places by. -+ BalanceTag -+ ThresholdValue -+ DestinationTag -+ ActionsTag -+ Weight +BalanceTag +ThresholdValue +DestinationTag +ActionsTag +Weight Action timings -------------- @@ -161,11 +162,11 @@ Action timings | STANDARD_ABO | SOME | WEEKLY_SAME_TIME | 10 | +--------------+------------+------------------+--------+ -+ Tag +Tag A string by witch this action timing will be referenced in other places by. -+ ActionsTag -+ TimingTag -+ Weight +ActionsTag +TimingTag +Weight Actions ------- @@ -178,13 +179,13 @@ Actions | SOME_1 | DEBIT | MINUTES | 10 | GERMANY_O2 | PERCENT | 25 | 10 | 10 | +--------+-------------+------------+-------+----------------+-----------+------------+---------------+--------+ -+ Tag +Tag A string by witch this action will be referenced in other places by. -+ Action -+ BalanceTag -+ Units -+ DestinationTag -+ PriceType -+ PriceValue -+ MinutesWeight -+ Weight +Action +BalanceTag +Units +DestinationTag +PriceType +PriceValue +MinutesWeight +Weight diff --git a/docs/intro.rst b/docs/intro.rst index e90eec49f..330396770 100644 --- a/docs/intro.rst +++ b/docs/intro.rst @@ -2,7 +2,7 @@ Introduction ============ CGRateS is a very fast and easy scalable rating engine targeted especially for telecom providers. -It is written in go (http://golang.net) and accessible from any language via JSON RPC. The code is well documented (go doc compliant API docs) and heavily tested. +It is written in go (http://golang.org) and accessible from any language via JSON RPC. The code is well documented (go doc compliant API docs) and heavily tested. After testing various databases like Kyoto_ cabinet, Redis_ or Mongodb_, the project focused on Redis as it delivers the best trade-off between speed, configuration and scalability. However connection to any database can be easily integrated by writing a simple adapter.