mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
changed rif to cgrates and introduced balance map
This commit is contained in:
@@ -21,9 +21,9 @@ package main
|
||||
import (
|
||||
"errors"
|
||||
"flag"
|
||||
"github.com/rif/cgrates/sessionmanager"
|
||||
"github.com/rif/cgrates/timespans"
|
||||
"github.com/rif/cgrates/balancer"
|
||||
"github.com/cgrates/cgrates/sessionmanager"
|
||||
"github.com/cgrates/cgrates/timespans"
|
||||
"github.com/cgrates/cgrates/balancer"
|
||||
"log"
|
||||
"runtime"
|
||||
"time"
|
||||
|
||||
@@ -19,7 +19,7 @@ package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"github.com/rif/cgrates/timespans"
|
||||
"github.com/cgrates/cgrates/timespans"
|
||||
"log"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
@@ -19,7 +19,7 @@ package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/rif/cgrates/timespans"
|
||||
"github.com/cgrates/cgrates/timespans"
|
||||
"log"
|
||||
"net"
|
||||
"net/rpc"
|
||||
|
||||
@@ -20,7 +20,7 @@ package main
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"github.com/rif/cgrates/timespans"
|
||||
"github.com/cgrates/cgrates/timespans"
|
||||
"log"
|
||||
"net/rpc/jsonrpc"
|
||||
"os"
|
||||
|
||||
@@ -18,9 +18,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/csv"
|
||||
"log"
|
||||
"os"
|
||||
"encoding/csv"
|
||||
)
|
||||
|
||||
var (
|
||||
|
||||
@@ -31,7 +31,8 @@ var (
|
||||
weekdaysFn = flag.String("weekdays", "WeekDays.csv", "Week days file")
|
||||
destinationsFn = flag.String("destinations", "Destinations.csv", "Destinations file")
|
||||
ratesFn = flag.String("rates", "Rates.csv", "Rates file")
|
||||
ratestimingFn = flag.String("ratestiming", "RatesTiming.csv", "Rates timing file")
|
||||
timingsFn = flag.String("timings", "Timings.csv", "Timings file")
|
||||
ratestimingsFn = flag.String("ratestimings", "RatesTimings.csv", "Rates timings file")
|
||||
ratingprofilesFn = flag.String("ratingprofiles", "RatingProfiles.csv", "Rating profiles file")
|
||||
volumediscountsFn = flag.String("volumediscounts", "VolumeDiscounts.csv", "Volume discounts file")
|
||||
volumeratesFn = flag.String("volumerates", "VolumeRates.csv", "Volume rates file")
|
||||
@@ -49,7 +50,8 @@ func main() {
|
||||
loadDataSeries()
|
||||
loadDestinations()
|
||||
loadRates()
|
||||
loadRatesTiming()
|
||||
loadTimings()
|
||||
loadRatesTimings()
|
||||
loadRatingProfiles()
|
||||
loadVolumeDicounts()
|
||||
loadVolumeRates()
|
||||
|
||||
@@ -19,9 +19,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/cgrates/cgrates/timespans"
|
||||
"log"
|
||||
"strconv"
|
||||
"github.com/rif/cgrates/timespans"
|
||||
)
|
||||
|
||||
type Rate struct {
|
||||
@@ -60,27 +60,39 @@ func NewRate(destinationsTag, connectFee, price, billingUnit, weight string) (r
|
||||
return
|
||||
}
|
||||
|
||||
type RateTiming struct {
|
||||
RatesTag, MonthsTag, MonthDaysTag, WeekDaysTag, StartTime string
|
||||
type Timing struct {
|
||||
MonthsTag, MonthDaysTag, WeekDaysTag, StartTime string
|
||||
}
|
||||
|
||||
func NewRateTiming(ratesTag, monthsTag, monthDaysTag, weekDaysTag, startTime string) (rt *RateTiming) {
|
||||
func NewTiming(timeingInfo ...string) (rt *Timing) {
|
||||
rt = &RateTiming{
|
||||
RatesTag: ratesTag,
|
||||
MonthsTag: monthsTag,
|
||||
MonthDaysTag: monthDaysTag,
|
||||
WeekDaysTag: weekDaysTag,
|
||||
StartTime: startTime,
|
||||
MonthsTag: timeingInfo[0],
|
||||
MonthDaysTag: timeingInfo[1],
|
||||
WeekDaysTag: timeingInfo[2],
|
||||
StartTime: timeingInfo[3],
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
type RateTiming struct {
|
||||
RatesTag string
|
||||
timing *Timing
|
||||
}
|
||||
|
||||
func NewRateTiming(ratesTag string, timing *Timing) (rt *RateTiming) {
|
||||
rt = &RateTiming{
|
||||
RatesTag: ratesTag,
|
||||
timing: timing,
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (rt *RateTiming) GetInterval(r *Rate) (i *timespans.Interval) {
|
||||
i = ×pans.Interval{
|
||||
Months: timespans.Months(months[rt.MonthsTag]),
|
||||
MonthDays: timespans.MonthDays(monthdays[rt.MonthDaysTag]),
|
||||
WeekDays: timespans.WeekDays(weekdays[rt.WeekDaysTag]),
|
||||
StartTime: rt.StartTime,
|
||||
Months: timespans.Months(months[rt.timing.MonthsTag]),
|
||||
MonthDays: timespans.MonthDays(monthdays[rt.timing.MonthDaysTag]),
|
||||
WeekDays: timespans.WeekDays(weekdays[rt.timing.WeekDaysTag]),
|
||||
StartTime: rt.timing.StartTime,
|
||||
ConnectFee: r.ConnectFee,
|
||||
Price: r.Price,
|
||||
BillingUnit: r.BillingUnit,
|
||||
|
||||
@@ -18,10 +18,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/rif/cgrates/timespans"
|
||||
"encoding/csv"
|
||||
"github.com/cgrates/cgrates/timespans"
|
||||
"log"
|
||||
"os"
|
||||
"encoding/csv"
|
||||
"time"
|
||||
)
|
||||
|
||||
@@ -31,7 +31,8 @@ var (
|
||||
weekdays = make(map[string][]time.Weekday)
|
||||
destinations = make(map[string][]string)
|
||||
rates = make(map[string][]*Rate)
|
||||
ratesTiming = make(map[string][]*RateTiming)
|
||||
timings = make(map[string][]*Timing)
|
||||
ratesTimings = make(map[string][]*RateTiming)
|
||||
ratingProfiles = make(map[string][]*timespans.CallDescriptor)
|
||||
)
|
||||
|
||||
@@ -148,10 +149,10 @@ func loadRates() {
|
||||
}
|
||||
}
|
||||
|
||||
func loadRatesTiming() {
|
||||
fp, err := os.Open(*ratestimingFn)
|
||||
func loadTiming() {
|
||||
fp, err := os.Open(*timingsFn)
|
||||
if err != nil {
|
||||
log.Printf("Could not open rates file: %v", err)
|
||||
log.Printf("Could not open timings file: %v", err)
|
||||
return
|
||||
}
|
||||
defer fp.Close()
|
||||
@@ -164,8 +165,8 @@ func loadRatesTiming() {
|
||||
continue
|
||||
}
|
||||
|
||||
rt := NewRateTiming(record[1], record[2], record[3], record[4], record[5])
|
||||
ratesTiming[tag] = append(ratesTiming[tag], rt)
|
||||
t := NewTiming(rates[1:]...)
|
||||
timings[tag] = append(timings[tag], t)
|
||||
|
||||
log.Print(tag)
|
||||
for _, i := range ratesTiming[tag] {
|
||||
@@ -174,6 +175,39 @@ func loadRatesTiming() {
|
||||
}
|
||||
}
|
||||
|
||||
func loadRatesTiming() {
|
||||
fp, err := os.Open(*ratestimingsFn)
|
||||
if err != nil {
|
||||
log.Printf("Could not open rates timings file: %v", err)
|
||||
return
|
||||
}
|
||||
defer fp.Close()
|
||||
csvReader := csv.NewReader(fp)
|
||||
csvReader.Comma = sep
|
||||
for record, err := csvReader.Read(); err == nil; record, err = csvReader.Read() {
|
||||
tag := record[0]
|
||||
if tag == "Tag" {
|
||||
// skip header line
|
||||
continue
|
||||
}
|
||||
|
||||
ts, exists := timings[record[2]]
|
||||
if !exists {
|
||||
log.Printf("Could not get timing for tag %v", record[2])
|
||||
continue
|
||||
}
|
||||
|
||||
for _, t := range ts {
|
||||
rt := NewRateTiming(record[1], t)
|
||||
ratesTiming[tag] = append(ratesTiming[tag], rt)
|
||||
}
|
||||
log.Print(tag)
|
||||
for _, i := range ratesTiming[tag] {
|
||||
log.Print(i)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func loadRatingProfiles() {
|
||||
fp, err := os.Open(*ratingprofilesFn)
|
||||
if err != nil {
|
||||
|
||||
@@ -25,7 +25,7 @@ import (
|
||||
"flag"
|
||||
"fmt"
|
||||
_ "github.com/bmizerany/pq"
|
||||
"github.com/rif/cgrates/timespans"
|
||||
"github.com/cgrates/cgrates/timespans"
|
||||
"log"
|
||||
"net/rpc/jsonrpc"
|
||||
"os"
|
||||
|
||||
@@ -21,8 +21,8 @@ package main
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"github.com/rif/cgrates/sessionmanager"
|
||||
"github.com/rif/cgrates/timespans"
|
||||
"github.com/cgrates/cgrates/sessionmanager"
|
||||
"github.com/cgrates/cgrates/timespans"
|
||||
"log"
|
||||
"net"
|
||||
"net/rpc"
|
||||
|
||||
@@ -19,7 +19,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/rif/cgrates/timespans"
|
||||
"github.com/cgrates/cgrates/timespans"
|
||||
"log"
|
||||
"net/rpc"
|
||||
"os"
|
||||
|
||||
@@ -20,8 +20,8 @@ package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"github.com/rif/cgrates/sessionmanager"
|
||||
"github.com/rif/cgrates/timespans"
|
||||
"github.com/cgrates/cgrates/sessionmanager"
|
||||
"github.com/cgrates/cgrates/timespans"
|
||||
"log"
|
||||
"net/rpc/jsonrpc"
|
||||
)
|
||||
|
||||
@@ -19,7 +19,7 @@ package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"github.com/rif/cgrates/timespans"
|
||||
"github.com/cgrates/cgrates/timespans"
|
||||
"log"
|
||||
"net/rpc"
|
||||
"net/rpc/jsonrpc"
|
||||
|
||||
@@ -18,7 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/rif/cgrates/timespans"
|
||||
"github.com/cgrates/cgrates/timespans"
|
||||
"log"
|
||||
"net/rpc/jsonrpc"
|
||||
"time"
|
||||
|
||||
@@ -19,7 +19,7 @@ package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"github.com/rif/cgrates/timespans"
|
||||
"github.com/cgrates/cgrates/timespans"
|
||||
"log"
|
||||
"os"
|
||||
"runtime/pprof"
|
||||
|
||||
@@ -23,7 +23,7 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
_ "github.com/bmizerany/pq"
|
||||
"github.com/rif/cgrates/timespans"
|
||||
"github.com/cgrates/cgrates/timespans"
|
||||
"log"
|
||||
)
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ package sessionmanager
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/rif/cgrates/timespans"
|
||||
"github.com/cgrates/cgrates/timespans"
|
||||
"log"
|
||||
"time"
|
||||
)
|
||||
|
||||
@@ -19,9 +19,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
package sessionmanager
|
||||
|
||||
import (
|
||||
"github.com/rif/cgrates/timespans"
|
||||
"github.com/cgrates/cgrates/timespans"
|
||||
"log"
|
||||
"github.com/rif/cgrates/balancer"
|
||||
"github.com/cgrates/cgrates/balancer"
|
||||
"net/rpc"
|
||||
"time"
|
||||
)
|
||||
|
||||
@@ -288,7 +288,7 @@ func (cd *CallDescriptor) GetMaxSessionTime() (seconds float64, err error) {
|
||||
return -1, nil
|
||||
} else {
|
||||
userBudget.mux.RLock()
|
||||
availableCredit = userBudget.Credit
|
||||
availableCredit = userBudget.BalanceMap[CREDIT]
|
||||
availableSeconds, _ = userBudget.getSecondsForPrefix(cd.storageGetter, cd.DestinationPrefix)
|
||||
userBudget.mux.RUnlock()
|
||||
}
|
||||
|
||||
@@ -24,14 +24,19 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
const (
|
||||
CREDIT = "CREDIT"
|
||||
SMS = "SMS"
|
||||
TRAFFIC = "TRAFFIC"
|
||||
)
|
||||
|
||||
/*
|
||||
Structure describing a tariff plan's number of bonus items. It is uset to restore
|
||||
these numbers to the user budget every month.
|
||||
*/
|
||||
type TariffPlan struct {
|
||||
Id string
|
||||
SmsCredit float64
|
||||
Traffic float64
|
||||
balanceMap map[string]float64
|
||||
Bonuses []*Bonus
|
||||
MinuteBuckets []*MinuteBucket
|
||||
VolumeDiscountThresholds []*VolumeDiscount
|
||||
|
||||
@@ -36,12 +36,10 @@ Structure conatining information about user's credit (minutes, cents, sms...).'
|
||||
*/
|
||||
type UserBudget struct {
|
||||
Id string
|
||||
Type string // prepaid/postpaid
|
||||
Credit float64
|
||||
SmsCredit float64
|
||||
Traffic float64
|
||||
OutboundVolumes []*Volume
|
||||
InboundVolumes []*Volume
|
||||
Type string // prepaid-postpaid
|
||||
BalanceMap map[string]float64
|
||||
OutboundVolumes []*TrafficVolume
|
||||
InboundVolumes []*TrafficVolume
|
||||
ResetDayOfTheMonth int
|
||||
TariffPlanId string
|
||||
tariffPlan *TariffPlan
|
||||
@@ -325,4 +323,4 @@ func (ub *UserBudget) resetUserBudget(sg StorageGetter) (err error) {
|
||||
err = sg.SetUserBudget(ub)
|
||||
}
|
||||
return
|
||||
}
|
||||
}
|
||||
@@ -19,13 +19,22 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
package timespans
|
||||
|
||||
import (
|
||||
//"log"
|
||||
//"log"
|
||||
)
|
||||
|
||||
// Amount of a trafic of a certain type (TOR)
|
||||
type TrafficVolume struct {
|
||||
TOR string
|
||||
Units float64
|
||||
DestinationId string
|
||||
}
|
||||
|
||||
// Volume discount to be applyed after the Units are reached
|
||||
// in a certain time period.
|
||||
type VolumeDiscount struct {
|
||||
TOR string
|
||||
DestinationsId string
|
||||
VolumeUnits float64
|
||||
Units float64
|
||||
AbsoulteValue float64 // either this or the procentage below
|
||||
DiscountProcentage float64 // use only one
|
||||
Weight float64
|
||||
@@ -41,26 +50,23 @@ func (vd *VolumeDiscount) getDestination(storage StorageGetter) (dest *Destinati
|
||||
return vd.destination
|
||||
}
|
||||
|
||||
type Volume struct {
|
||||
TOR string
|
||||
Units float64
|
||||
DestinationId string
|
||||
}
|
||||
|
||||
/*
|
||||
Structure to be filled for each tariff plan with the bonus value for received calls minutes.
|
||||
*/
|
||||
type InboundBonus struct {
|
||||
TOR string
|
||||
InboundUnits float64
|
||||
MonetaryUnits, SMSUnits, TrafficUnits float64
|
||||
MinuteBucket *MinuteBucket
|
||||
type Bonus struct {
|
||||
Direction string
|
||||
TOR string
|
||||
Units float64
|
||||
balanceMap map[string]float64
|
||||
MinuteBuckets []*MinuteBucket
|
||||
DestinationsId string
|
||||
destination *Destination
|
||||
}
|
||||
|
||||
/*
|
||||
Serializes the tariff plan for the storage. Used for key-value storages.
|
||||
*/
|
||||
func (rcb *InboundBonus) store() (result string) {
|
||||
func (rcb *Bonus) store() (result string) {
|
||||
result += strconv.FormatFloat(rcb.Credit, 'f', -1, 64) + ","
|
||||
result += strconv.FormatFloat(rcb.SmsCredit, 'f', -1, 64) + ","
|
||||
result += strconv.FormatFloat(rcb.Traffic, 'f', -1, 64)
|
||||
@@ -74,7 +80,7 @@ func (rcb *InboundBonus) store() (result string) {
|
||||
/*
|
||||
De-serializes the tariff plan for the storage. Used for key-value storages.
|
||||
*/
|
||||
func (rcb *RecivedCallBonus) restore(input string) {
|
||||
func (rcb *Bonus) restore(input string) {
|
||||
elements := strings.Split(input, ",")
|
||||
rcb.Credit, _ = strconv.ParseFloat(elements[0], 64)
|
||||
rcb.SmsCredit, _ = strconv.ParseFloat(elements[1], 64)
|
||||
@@ -84,12 +90,3 @@ func (rcb *RecivedCallBonus) restore(input string) {
|
||||
rcb.MinuteBucket.restore(elements[3])
|
||||
}
|
||||
}
|
||||
|
||||
type OutboundBonus struct {
|
||||
TOR string
|
||||
OutboundUnits float64
|
||||
DestinationsId string
|
||||
destination *Destination
|
||||
MonetaryUnits, SMSUnits, TrafficUnits float64
|
||||
MinuteBucket *MinuteBucket
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user