mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
imported timings
This commit is contained in:
@@ -22,12 +22,13 @@ import (
|
||||
"github.com/cgrates/cgrates/timespans"
|
||||
"log"
|
||||
"os"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
var (
|
||||
actions = make(map[string][]*timespans.Action)
|
||||
actionsTimings []*timespans.Action
|
||||
actionsTriggers []*timespans.Action
|
||||
actionsTimings = make(map[string][]*timespans.ActionTiming)
|
||||
actionsTriggers = make(map[string][]*timespans.ActionTrigger)
|
||||
accountActions []*timespans.Action
|
||||
)
|
||||
|
||||
@@ -46,13 +47,55 @@ func loadActions() {
|
||||
// skip header line
|
||||
continue
|
||||
}
|
||||
//primaryBalanceActions = append(primaryBalanceActions, record[1:]...)
|
||||
log.Print(tag, actions)
|
||||
units, err := strconv.ParseFloat(record[3], 64)
|
||||
if err != nil {
|
||||
log.Printf("Could not parse action units: %v", err)
|
||||
continue
|
||||
}
|
||||
var a *timespans.Action
|
||||
if record[2] != timespans.MINUTES {
|
||||
a = ×pans.Action{
|
||||
ActionType: record[1],
|
||||
BalanceId: record[2],
|
||||
Units: units,
|
||||
}
|
||||
} else {
|
||||
price, percent := 0.0, 0.0
|
||||
value, err := strconv.ParseFloat(record[6], 64)
|
||||
if err != nil {
|
||||
log.Printf("Could not parse action price: %v", err)
|
||||
continue
|
||||
}
|
||||
if record[5] == timespans.PERCENT {
|
||||
percent = value
|
||||
}
|
||||
if record[5] == timespans.ABSOLUTE {
|
||||
price = value
|
||||
}
|
||||
weight, err := strconv.ParseFloat(record[7], 64)
|
||||
if err != nil {
|
||||
log.Printf("Could not parse action units: %v", err)
|
||||
continue
|
||||
}
|
||||
a = ×pans.Action{
|
||||
ActionType: record[1],
|
||||
BalanceId: record[2],
|
||||
MinuteBucket: ×pans.MinuteBucket{
|
||||
Seconds: units,
|
||||
Weight: weight,
|
||||
Price: price,
|
||||
Percent: percent,
|
||||
DestinationId: record[4],
|
||||
},
|
||||
}
|
||||
}
|
||||
actions[tag] = append(actions[tag], a)
|
||||
}
|
||||
log.Print(actions)
|
||||
}
|
||||
|
||||
func loadActionsTimings() {
|
||||
fp, err := os.Open(*actionstimingsFn)
|
||||
func loadActionTimings() {
|
||||
fp, err := os.Open(*actiontimingsFn)
|
||||
if err != nil {
|
||||
log.Printf("Could not open actions timings file: %v", err)
|
||||
return
|
||||
@@ -66,13 +109,30 @@ func loadActionsTimings() {
|
||||
// skip header line
|
||||
continue
|
||||
}
|
||||
//destinatioBalanceActions = append(destinatioBalanceActions, record[1:]...)
|
||||
log.Print(tag, actionsTimings)
|
||||
ts, exists := timings[record[2]]
|
||||
if !exists {
|
||||
log.Printf("Could not load the timing for tag: %v", record[2])
|
||||
continue
|
||||
}
|
||||
for _, t := range ts {
|
||||
at := ×pans.ActionTiming{
|
||||
Timing: ×pans.Interval{
|
||||
Months: t.Months,
|
||||
MonthDays: t.MonthDays,
|
||||
WeekDays: t.WeekDays,
|
||||
StartTime: t.StartTime,
|
||||
},
|
||||
ActionsId: record[1],
|
||||
}
|
||||
actionsTimings[tag] = append(actionsTimings[tag], at)
|
||||
}
|
||||
|
||||
}
|
||||
log.Print(actionsTimings)
|
||||
}
|
||||
|
||||
func loadActionsTriggers() {
|
||||
fp, err := os.Open(*actionstriggersFn)
|
||||
func loadActionTriggers() {
|
||||
fp, err := os.Open(*actiontriggersFn)
|
||||
if err != nil {
|
||||
log.Printf("Could not open destination balance actions file: %v", err)
|
||||
return
|
||||
@@ -86,9 +146,20 @@ func loadActionsTriggers() {
|
||||
// skip header line
|
||||
continue
|
||||
}
|
||||
//destinatioBalanceActions = append(destinatioBalanceActions, record[1:]...)
|
||||
log.Print(tag, actionsTriggers)
|
||||
value, err := strconv.ParseFloat(record[2], 64)
|
||||
if err != nil {
|
||||
log.Printf("Could not parse action trigger value: %v", err)
|
||||
continue
|
||||
}
|
||||
at := ×pans.ActionTrigger{
|
||||
BalanceId: record[1],
|
||||
ThresholdValue: value,
|
||||
DestinationId: record[3],
|
||||
ActionsId: record[4],
|
||||
}
|
||||
actionsTriggers[tag] = append(actionsTriggers[tag], at)
|
||||
}
|
||||
log.Print(actionsTriggers)
|
||||
}
|
||||
|
||||
func loadAccountActions() {
|
||||
|
||||
@@ -24,24 +24,24 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
separator = flag.String("separator", ",", "Default field separator")
|
||||
redisserver = flag.String("redisserver", "tcp:127.0.0.1:6379", "redis server address (tcp:127.0.0.1:6379)")
|
||||
redisdb = flag.Int("rdb", 10, "redis database number (10)")
|
||||
redispass = flag.String("pass", "", "redis database password")
|
||||
flush = flag.Bool("flush", false, "Flush the database before importing")
|
||||
monthsFn = flag.String("month", "Months.csv", "Months file")
|
||||
monthdaysFn = flag.String("monthdays", "MonthDays.csv", "Month days file")
|
||||
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")
|
||||
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")
|
||||
actionsFn = flag.String("actions", "Actions.csv", "Actions file")
|
||||
actionstimingsFn = flag.String("actionstimings", "ActionsTimings.csv", "Actions timings file")
|
||||
actionstriggersFn = flag.String("actionstriggers", "ActionsTriggers.csv", "Actions triggers file")
|
||||
accountactionsFn = flag.String("accountactions", "AccountActions.csv", "Account actions file")
|
||||
sep rune
|
||||
separator = flag.String("separator", ",", "Default field separator")
|
||||
redisserver = flag.String("redisserver", "tcp:127.0.0.1:6379", "redis server address (tcp:127.0.0.1:6379)")
|
||||
redisdb = flag.Int("rdb", 10, "redis database number (10)")
|
||||
redispass = flag.String("pass", "", "redis database password")
|
||||
flush = flag.Bool("flush", false, "Flush the database before importing")
|
||||
monthsFn = flag.String("month", "Months.csv", "Months file")
|
||||
monthdaysFn = flag.String("monthdays", "MonthDays.csv", "Month days file")
|
||||
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")
|
||||
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")
|
||||
actionsFn = flag.String("actions", "Actions.csv", "Actions file")
|
||||
actiontimingsFn = flag.String("actiontimings", "ActionTimings.csv", "Actions timings file")
|
||||
actiontriggersFn = flag.String("actiontriggers", "ActionTriggers.csv", "Actions triggers file")
|
||||
accountactionsFn = flag.String("accountactions", "AccountActions.csv", "Account actions file")
|
||||
sep rune
|
||||
)
|
||||
|
||||
func writeToDatabase() {
|
||||
@@ -73,8 +73,8 @@ func main() {
|
||||
loadRatesTimings()
|
||||
loadRatingProfiles()
|
||||
loadActions()
|
||||
loadActionsTimings()
|
||||
loadActionsTriggers()
|
||||
loadActionTimings()
|
||||
loadActionTriggers()
|
||||
loadAccountActions()
|
||||
writeToDatabase()
|
||||
}
|
||||
|
||||
@@ -85,7 +85,6 @@ func loadRates() {
|
||||
continue
|
||||
}
|
||||
rates[tag] = append(rates[tag], r)
|
||||
log.Print(tag, rates[tag])
|
||||
}
|
||||
}
|
||||
|
||||
@@ -107,11 +106,6 @@ func loadTimings() {
|
||||
|
||||
t := NewTiming(record[1:]...)
|
||||
timings[tag] = append(timings[tag], t)
|
||||
|
||||
log.Print(tag)
|
||||
for _, i := range timings[tag] {
|
||||
log.Print(i)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -141,10 +135,6 @@ func loadRatesTimings() {
|
||||
rt := NewRateTiming(record[1], t)
|
||||
ratesTimings[tag] = append(ratesTimings[tag], rt)
|
||||
}
|
||||
log.Print(tag)
|
||||
for _, i := range ratesTimings[tag] {
|
||||
log.Print(i)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
ActionTag,BalanceTag,ThresholdValue,DestinationTag,ActionsTag
|
||||
Tag,BalanceTag,ThresholdValue,DestinationTag,ActionsTag
|
||||
STANDARD_TRIGGER,MONETARY,30,*all,SOME_1
|
||||
STANDARD_TRIGGER,SMS,30,*all,SOME_2
|
||||
STANDARD_TRIGGER,MINUTES,10,GERMANY_O2,SOME_1
|
||||
|
||||
|
@@ -1,8 +1,8 @@
|
||||
Tag,Action,BalanceTag,Units,DestinationTag,PriceType,PriceValue,Weight
|
||||
SOME,TOPUP_RESET,MONETARY,10,*all,,,
|
||||
SOME,TOPUP_RESET,SMS,100,*all,,,
|
||||
SOME,TOPUP_RESET,INTERNET,1000,*all,,,
|
||||
SOME,POSTPAID_RESET,MONETARY,10,*all,,,
|
||||
SOME,DEBIT,MONETARY,5,*all,,,
|
||||
SOME,TOPUP_RESET,MONETARY,10,*all,,,
|
||||
SOME,TOPUP_RESET,SMS,100,*all,,,
|
||||
SOME,TOPUP_RESET,INTERNET,1000,*all,,,
|
||||
SOME,POSTPAID_RESET,MONETARY,10,*all,,,
|
||||
SOME,DEBIT,MONETARY,5,*all,,,
|
||||
SOME_1,DEBIT,MINUTES,10,GERMANY_O2,PERCENT,25,10
|
||||
SOME_2,TOPUP_RESET,MINUTES,1000,GERMANY,ABSOLUTE,0.2,10
|
||||
SOME_2,TOPUP_RESET,MINUTES,1000,GERMANY,ABSOLUTE,0.2,10
|
||||
|
||||
|
@@ -59,16 +59,10 @@ func (uc *UnitsCounter) getDestination() (dest *Destination) {
|
||||
Structure to be filled for each tariff plan with the bonus value for received calls minutes.
|
||||
*/
|
||||
type Action struct {
|
||||
Id string
|
||||
ActionType string
|
||||
Direction string
|
||||
TOR string
|
||||
Units float64
|
||||
BalanceMap map[string]float64
|
||||
MinuteBuckets []*MinuteBucket
|
||||
Weight float64
|
||||
DestinationsId string
|
||||
destination *Destination
|
||||
ActionType string
|
||||
BalanceId string
|
||||
Units float64
|
||||
MinuteBucket *MinuteBucket
|
||||
}
|
||||
|
||||
// Structure to store actions according to weight
|
||||
@@ -83,7 +77,7 @@ func (s actionsorter) Swap(i, j int) {
|
||||
}
|
||||
|
||||
func (s actionsorter) Less(j, i int) bool {
|
||||
return s[i].Weight < s[j].Weight
|
||||
return s[i].MinuteBucket.Weight < s[j].MinuteBucket.Weight
|
||||
}
|
||||
|
||||
type ActionTrigger struct {
|
||||
@@ -96,7 +90,7 @@ type ActionTrigger struct {
|
||||
}
|
||||
|
||||
type ActionTiming struct {
|
||||
Id string
|
||||
Timing *Interval
|
||||
ActionsId string
|
||||
actions []*Action
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ type MinuteBucket struct {
|
||||
Seconds float64
|
||||
Weight float64
|
||||
Price float64
|
||||
Percentage float64 // percentage from standard price
|
||||
Percent float64 // percentage from standard price
|
||||
DestinationId string
|
||||
destination *Destination
|
||||
precision int
|
||||
|
||||
@@ -33,6 +33,10 @@ const (
|
||||
CREDIT = "MONETARY"
|
||||
SMS = "SMS"
|
||||
TRAFFIC = "INTERNET"
|
||||
MINUTES = "MINUTES"
|
||||
// Price types
|
||||
PERCENT = "PERCENT"
|
||||
ABSOLUTE = "ABSOLUTE"
|
||||
)
|
||||
|
||||
var (
|
||||
|
||||
Reference in New Issue
Block a user