started balance actions importing

This commit is contained in:
Radu Ioan Fericean
2012-06-12 18:26:38 +03:00
parent 4b7dfbe00f
commit 05c3229920
11 changed files with 41 additions and 162 deletions

View File

@@ -19,24 +19,20 @@ package main
import (
"encoding/csv"
"github.com/cgrates/cgrates/timespans"
"log"
"os"
)
var (
volumeDiscounts = make(map[string][]string)
volumeRates = make(map[string][]string)
inboundBonuses = make(map[string][]string)
outboundBonuses = make(map[string][]string)
recurrentDebits = make(map[string][]string)
recurrentTopups = make(map[string][]string)
balanceProfiles = make(map[string][]string)
primaryBalanceActions []*timespans.Action
destinatioBalanceActions []*timespans.Action
)
func loadVolumeDicounts() {
fp, err := os.Open(*volumediscountsFn)
func loadPrimaryBalanceActions() {
fp, err := os.Open(*primaryBalanceActionsFn)
if err != nil {
log.Printf("Could not open volume discounts file: %v", err)
log.Printf("Could not open primary balance actions file: %v", err)
return
}
defer fp.Close()
@@ -48,15 +44,15 @@ func loadVolumeDicounts() {
// skip header line
continue
}
volumeDiscounts[tag] = append(volumeDiscounts[tag], record[1:]...)
log.Print(tag, volumeDiscounts[tag])
//primaryBalanceActions = append(primaryBalanceActions, record[1:]...)
log.Print(tag, primaryBalanceActions)
}
}
func loadVolumeRates() {
fp, err := os.Open(*volumeratesFn)
func loadDestinationBalanceActions() {
fp, err := os.Open(*destinationBalanceActionsFn)
if err != nil {
log.Printf("Could not open volume rates file: %v", err)
log.Printf("Could not open destination balance actions file: %v", err)
return
}
defer fp.Close()
@@ -68,107 +64,7 @@ func loadVolumeRates() {
// skip header line
continue
}
volumeRates[tag] = append(volumeRates[tag], record[1:]...)
log.Print(tag, volumeRates[tag])
}
}
func loadInboundBonuses() {
fp, err := os.Open(*inboundbonusesFn)
if err != nil {
log.Printf("Could not open inbound bonueses 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
}
inboundBonuses[tag] = append(inboundBonuses[tag], record[1:]...)
log.Print(tag, inboundBonuses[tag])
}
}
func loadOutboundBonuses() {
fp, err := os.Open(*inboundbonusesFn)
if err != nil {
log.Printf("Could not open outbound bonueses 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
}
outboundBonuses[tag] = append(outboundBonuses[tag], record[1:]...)
log.Print(tag, outboundBonuses[tag])
}
}
func loadRecurrentDebits() {
fp, err := os.Open(*recurrentdebitsFn)
if err != nil {
log.Printf("Could not open recurent debits 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
}
recurrentDebits[tag] = append(recurrentDebits[tag], record[1:]...)
log.Print(tag, recurrentDebits[tag])
}
}
func loadRecurrentTopups() {
fp, err := os.Open(*recurrenttopupsFn)
if err != nil {
log.Printf("Could not open recurent topups 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
}
recurrentTopups[tag] = append(recurrentTopups[tag], record[1:]...)
log.Print(tag, recurrentTopups[tag])
}
}
func loadBalanceProfiles() {
fp, err := os.Open(*balanceprofilesFn)
if err != nil {
log.Printf("Could not open balance profiles 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 == "Account" {
// skip header line
continue
}
balanceProfiles[tag] = append(balanceProfiles[tag], record...)
log.Print(tag, balanceProfiles[tag])
//destinatioBalanceActions = append(destinatioBalanceActions, record[1:]...)
log.Print(tag, destinatioBalanceActions)
}
}

View File

@@ -24,27 +24,22 @@ 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")
volumediscountsFn = flag.String("volumediscounts", "VolumeDiscounts.csv", "Volume discounts file")
volumeratesFn = flag.String("volumerates", "VolumeRates.csv", "Volume rates file")
inboundbonusesFn = flag.String("inboundbonuses", "InboundBonuses.csv", "Inbound bonuses file")
outboundbonusesFn = flag.String("outboundbonuses", "OutboundBonuses.csv", "Outound bonuses file")
recurrentdebitsFn = flag.String("recurrentdebits", "RecurrentDebits.csv", "Recurent debits file")
recurrenttopupsFn = flag.String("recurrenttopups", "RecurrentTopups.csv", "Recurent topups file")
balanceprofilesFn = flag.String("balanceprofiles", "BalanceProfiles.csv", "Balance profiles 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")
primaryBalanceActionsFn = flag.String("primaryBalanceActions", "PrimaryBalanceActions.csv", "Primary balance actions file")
destinationBalanceActionsFn = flag.String("destinationBalanceActions", "DestinationBalanceActions.csv", "Destination balance actions file")
sep rune
)
func writeToDatabase() {
@@ -76,12 +71,7 @@ func main() {
loadTimings()
loadRatesTimings()
loadRatingProfiles()
loadVolumeDicounts()
loadVolumeRates()
loadInboundBonuses()
loadOutboundBonuses()
loadRecurrentDebits()
loadRecurrentTopups()
loadBalanceProfiles()
loadPrimaryBalanceActions()
loadDestinationBalanceActions()
writeToDatabase()
}

View File

@@ -1,3 +0,0 @@
Account,AccountType,MonetaryBalance,SMSBalance,TrafficBalance,RecurrentTopupsTag,RecurrentMonthsTag,RecurrentMonthDaysTag,RecurrentWeekDaysTag,RecurrentStartTime,RecurrentClears
rif,postpaid,10,50,100,STARTER_PACK,ALL,20th,ALL,00:00:00,1
danb,prepaid,10,50,500,STARTER_PACK,ALL,20th,ALL,00:00:00,1
1 Account AccountType MonetaryBalance SMSBalance TrafficBalance RecurrentTopupsTag RecurrentMonthsTag RecurrentMonthDaysTag RecurrentWeekDaysTag RecurrentStartTime RecurrentClears
2 rif postpaid 10 50 100 STARTER_PACK ALL 20th ALL 00:00:00 1
3 danb prepaid 10 50 500 STARTER_PACK ALL 20th ALL 00:00:00 1

View File

@@ -0,0 +1,4 @@
TimingTag,Action,Tenant,Account,Direction,DestinationTag,Units,PriceType,PriceValue,Weight
WEEKLY_SAME_TIME,TOPUP_RESET,CUSTOMER_1,rif,OUT,GERMANY,1000,PRECENT,10,10
WEEKLY_SAME_TIME,TOPUP_RESET,CUSTOMER_1,rif,OUT,GERMANY_O2,100,ABSOLUTE,0,10
TRIGGERED,TOPUP_ADD,CUSTOMER_1,rif,OUT,GERMANY_O2,50,THRESHOLD,300,10
1 TimingTag Action Tenant Account Direction DestinationTag Units PriceType PriceValue Weight
2 WEEKLY_SAME_TIME TOPUP_RESET CUSTOMER_1 rif OUT GERMANY 1000 PRECENT 10 10
3 WEEKLY_SAME_TIME TOPUP_RESET CUSTOMER_1 rif OUT GERMANY_O2 100 ABSOLUTE 0 10
4 TRIGGERED TOPUP_ADD CUSTOMER_1 rif OUT GERMANY_O2 50 THRESHOLD 300 10

View File

@@ -1,3 +0,0 @@
Tag,TOR,InboundUnits,MonetaryUnits,SMSUnits,TrafficUnits
STARTER_BONUSES,0,60,0.01,0,0
STARTER_BONUSES,100,1,0.01,0,0
1 Tag TOR InboundUnits MonetaryUnits SMSUnits TrafficUnits
2 STARTER_BONUSES 0 60 0.01 0 0
3 STARTER_BONUSES 100 1 0.01 0 0

View File

@@ -1,3 +0,0 @@
Tag,TOR,OutboundUnits,DestinationsTag,MonetaryUnits,SMSUnits,TrafficUnits
STARTER_BONUSES,0,60,GERMANY,0.01,0,0
STARTER_BONUSES,100,1,GERMANY,0.01,0,0
1 Tag TOR OutboundUnits DestinationsTag MonetaryUnits SMSUnits TrafficUnits
2 STARTER_BONUSES 0 60 GERMANY 0.01 0 0
3 STARTER_BONUSES 100 1 GERMANY 0.01 0 0

View File

@@ -0,0 +1,6 @@
TimingTag,Action,Tenant,Account,Direction,BalanceTag,Units
WEEKLY_SAME_TIME,TOPUP_RESET,CUSTOMER_1,rif,OUT,MONETARY,10
WEEKLY_SAME_TIME,TOPUP_RESET,CUSTOMER_1,rif,OUT,SMS,100
WEEKLY_SAME_TIME,TOPUP_RESET,CUSTOMER_1,rif,OUT,INTERNET,1000
ONE_TIME_RUN,POSTPAID_RESET,CUSTOMER_1,dan,OUT,MONETARY,10
FIRST_DAY_OF_MONTH,DEBIT,CUSTOMER_1,dan,OUT,MONETARY,5
1 TimingTag Action Tenant Account Direction BalanceTag Units
2 WEEKLY_SAME_TIME TOPUP_RESET CUSTOMER_1 rif OUT MONETARY 10
3 WEEKLY_SAME_TIME TOPUP_RESET CUSTOMER_1 rif OUT SMS 100
4 WEEKLY_SAME_TIME TOPUP_RESET CUSTOMER_1 rif OUT INTERNET 1000
5 ONE_TIME_RUN POSTPAID_RESET CUSTOMER_1 dan OUT MONETARY 10
6 FIRST_DAY_OF_MONTH DEBIT CUSTOMER_1 dan OUT MONETARY 5

View File

@@ -1,2 +0,0 @@
Tag,MonetaryUnits,SMSUnits,TrafficUnits
DEBIT_5,5,0,0
1 Tag MonetaryUnits SMSUnits TrafficUnits
2 DEBIT_5 5 0 0

View File

@@ -1,2 +0,0 @@
Tag,RecurrentDebitsTag,MonetaryBalance,SMSBalance,TrafficBalance,VolumeRatesTag,VolumeDiscountsTag,InboundBonusesTag,OutboundBonusesTag
STARTER_PACK,DEBIT_5,2,50,100,GERMANY_100_LANDLINE_MINUTES,UPTO_2000_GERMANY_10PERC,STARTER_BONUSES,STARTER_BONUSES
1 Tag RecurrentDebitsTag MonetaryBalance SMSBalance TrafficBalance VolumeRatesTag VolumeDiscountsTag InboundBonusesTag OutboundBonusesTag
2 STARTER_PACK DEBIT_5 2 50 100 GERMANY_100_LANDLINE_MINUTES UPTO_2000_GERMANY_10PERC STARTER_BONUSES STARTER_BONUSES

View File

@@ -1,2 +0,0 @@
Tag,TOR,DestinationsTag,VolumeUnits,Discount,Weight
UPTO_2000_GERMANY_10PERC,0,GERMANY,2000,10,10
1 Tag TOR DestinationsTag VolumeUnits Discount Weight
2 UPTO_2000_GERMANY_10PERC 0 GERMANY 2000 10 10

View File

@@ -1,2 +0,0 @@
Tag,TOR,DestinationsTag,VolumeUnits,Price,Weight
GERMANY_100_LANDLINE_MINUTES,0,GERMANY,100,0,10
1 Tag TOR DestinationsTag VolumeUnits Price Weight
2 GERMANY_100_LANDLINE_MINUTES 0 GERMANY 100 0 10