diff --git a/cmd/cgr-loader/cgr-loader.go b/cmd/cgr-loader/cgr-loader.go
index e71067d79..74fdafc1f 100644
--- a/cmd/cgr-loader/cgr-loader.go
+++ b/cmd/cgr-loader/cgr-loader.go
@@ -18,142 +18,34 @@ along with this program. If not, see
package main
import (
- "encoding/json"
"flag"
- "github.com/rif/cgrates/timespans"
+ // "github.com/rif/cgrates/timespans"
"log"
"os"
+ "encoding/csv"
)
var (
- storage = flag.String("storage", "all", "kyoto|redis|mongo")
- kyotofile = flag.String("kyotofile", "storage.kch", "kyoto storage file (storage.kch)")
- 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)")
- mongoserver = flag.String("mongoserver", "127.0.0.1:27017", "mongo server address (127.0.0.1:27017)")
- mongodb = flag.String("mdb", "test", "mongo database name (test)")
- redispass = flag.String("pass", "", "redis database password")
- apfile = flag.String("apfile", "ap.json", "Activation Periods containing intervals file")
- destfile = flag.String("destfile", "dest.json", "Destinations file")
- tpfile = flag.String("tpfile", "tp.json", "Tariff plans file")
- ubfile = flag.String("ubfile", "ub.json", "User budgets file")
+ 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")
+ months = flag.String("month", "Months.csv", "Months file")
)
-func writeToStorage(storage timespans.StorageGetter,
- callDescriptors []*timespans.CallDescriptor,
- destinations []*timespans.Destination,
- tariffPlans []*timespans.TariffPlan,
- userBudgets []*timespans.UserBudget) {
- for _, cd := range callDescriptors {
- storage.SetActivationPeriodsOrFallback(cd.GetKey(), cd.ActivationPeriods, cd.FallbackKey)
- log.Printf("Storing activation periods for %q", cd.GetKey())
- }
- for _, d := range destinations {
- storage.SetDestination(d)
- log.Printf("Storing destination: %q", d.Id)
- }
- for _, tp := range tariffPlans {
- storage.SetTariffPlan(tp)
- log.Printf("Storing tariff plan: %q", tp.Id)
- }
- for _, ub := range userBudgets {
- storage.SetUserBudget(ub)
- log.Printf("Storing user budget: %q", ub.Id)
- }
-}
-
func main() {
flag.Parse()
- log.Printf("Reading from %s, %s, %s", *apfile, *destfile, *tpfile)
-
- // reading activation periods
- fin, err := os.Open(*apfile)
-
+ fp, err := os.Open(*months)
if err != nil {
- log.Print("Cannot open activation periods input file", err)
+ log.Printf("Could not open months file: %v", err)
}
-
- dec := json.NewDecoder(fin)
-
- var callDescriptors []*timespans.CallDescriptor
- if err := dec.Decode(&callDescriptors); err != nil {
- log.Println(err)
- return
- }
- fin.Close()
-
- // reading destinations
- fin, err = os.Open(*destfile)
-
- if err != nil {
- log.Print("Cannot open destinations input file", err)
- }
-
- dec = json.NewDecoder(fin)
-
- var destinations []*timespans.Destination
- if err := dec.Decode(&destinations); err != nil {
- log.Println(err)
- return
- }
- fin.Close()
-
- // reading triff plans
- fin, err = os.Open(*tpfile)
-
- if err != nil {
- log.Print("Cannot open tariff plans input file", err)
- }
-
- dec = json.NewDecoder(fin)
-
- var tariffPlans []*timespans.TariffPlan
- if err := dec.Decode(&tariffPlans); err != nil {
- log.Println(err)
- return
- }
- fin.Close()
-
- // reading user budgets
- fin, err = os.Open(*ubfile)
-
- if err != nil {
- log.Print("Cannot open user budgets input file", err)
- }
-
- dec = json.NewDecoder(fin)
-
- var userBudgets []*timespans.UserBudget
- if err := dec.Decode(&userBudgets); err != nil {
- log.Println(err)
- return
- }
- fin.Close()
-
- switch *storage {
- case "kyoto":
- storage, _ := timespans.NewKyotoStorage(*kyotofile)
- defer storage.Close()
- writeToStorage(storage, callDescriptors, destinations, tariffPlans, userBudgets)
- case "mongo":
- storage, _ := timespans.NewMongoStorage(*mongoserver, *mongodb)
- defer storage.Close()
- writeToStorage(storage, callDescriptors, destinations, tariffPlans, userBudgets)
- case "redis":
- storage, _ := timespans.NewRedisStorage(*redisserver, *redisdb)
- defer storage.Close()
- writeToStorage(storage, callDescriptors, destinations, tariffPlans, userBudgets)
- default:
- kyoto, _ := timespans.NewKyotoStorage(*kyotofile)
- writeToStorage(kyoto, callDescriptors, destinations, tariffPlans, userBudgets)
- kyoto.Close()
- if mongo, err := timespans.NewMongoStorage(*mongoserver, *mongodb); err == nil {
- writeToStorage(mongo, callDescriptors, destinations, tariffPlans, userBudgets)
- mongo.Close()
- }
- if redis, _ := timespans.NewRedisStorage(*redisserver, *redisdb); err == nil {
- writeToStorage(redis, callDescriptors, destinations, tariffPlans, userBudgets)
- redis.Close()
+ csv := csv.NewReader(fp)
+ csv.Comma = rune(*separator)
+ for record, err := csv.Read(); err == nil; record, err = csv.Read() {
+ if record[0] == "Tag" {
+ // skip header line
+ continue
}
+ log.Print(record)
}
}
diff --git a/cmd/cgr-scheduler/cgr-scheduler.go b/cmd/cgr-scheduler/cgr-scheduler.go
new file mode 100644
index 000000000..a2a4af2b3
--- /dev/null
+++ b/cmd/cgr-scheduler/cgr-scheduler.go
@@ -0,0 +1,27 @@
+/*
+Rating system designed to be used in VoIP Carriers World
+Copyright (C) 2012 Radu Ioan Fericean
+
+This program is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program. If not, see
+*/
+
+package main
+
+import (
+ "log"
+)
+
+func main() {
+ log.Print("CGR Scheduler")
+}
diff --git a/data/BalanceProfiles.csv b/data/BalanceProfiles.csv
new file mode 100644
index 000000000..09cc0f357
--- /dev/null
+++ b/data/BalanceProfiles.csv
@@ -0,0 +1,3 @@
+Account;AccountType;MonetaryBalance;SMSBalance;TrafficBalance;MonthsTag;MonthDaysTag;WeekDaysTag;StartTime;RecurrentTopupTag;RecurrentClears
+rif;postpaid;10;50;100;ALL;20th;ALL;00:00:00;STARTER_PACK;1
+danb;prepaid;10;50;500;ALL;20th;ALL;00:00:00;STARTER_PACK;1
diff --git a/data/Destinations.csv b/data/Destinations.csv
new file mode 100644
index 000000000..e134bbd1b
--- /dev/null
+++ b/data/Destinations.csv
@@ -0,0 +1,3 @@
+Tag;Prefix
+GERMANY;49
+GERMANY_MOBILE_O2;49176
diff --git a/data/InboundBonuses.csv b/data/InboundBonuses.csv
new file mode 100644
index 000000000..c1ec154d4
--- /dev/null
+++ b/data/InboundBonuses.csv
@@ -0,0 +1,3 @@
+Tag;TOR;InboundUnits;MonetaryUnits;SMSUnits;TrafficUnits
+STARTER_BONUSES;0;60;0.01;0;0
+STARTER_BONUSES;100;1;0.01;0;0
diff --git a/data/MonthDays.csv b/data/MonthDays.csv
new file mode 100644
index 000000000..15e732272
--- /dev/null
+++ b/data/MonthDays.csv
@@ -0,0 +1,6 @@
+Tag;1;2;3;4;5;6;7;8;9;10;11;12;13;14;15;16;17;18;19;20;21;22;23;24;25;26;27;28;29;30;31
+ALL;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1
+CHRISTMAS_DAY;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;1;0;0;0;0;0;0
+VALENTINES_DAY;0;0;0;0;0;0;0;0;0;0;0;0;0;1;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0
+20th;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;1;0;0;0;0;0;0;0;0;0;0;0
+FIRST;1;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0
diff --git a/data/Months.csv b/data/Months.csv
new file mode 100644
index 000000000..eb177064b
--- /dev/null
+++ b/data/Months.csv
@@ -0,0 +1,7 @@
+Tag;January;February;March;April;May;June;Jully;August;September;October;November;December
+ALL;1;1;1;1;1;1;1;1;1;1;1;1
+WINTER;1;1;0;0;0;0;0;0;0;0;0;1
+SPRING;0;0;1;1;1;0;0;0;0;0;0;0
+SUMMER;0;0;0;0;0;1;1;1;0;0;0;0
+AUTUMN;0;0;0;0;0;0;0;0;1;1;1;0
+JANUARY;1;0;0;0;0;0;0;0;0;0;0;0
diff --git a/data/OutboundBonuses.csv b/data/OutboundBonuses.csv
new file mode 100644
index 000000000..067a92c7c
--- /dev/null
+++ b/data/OutboundBonuses.csv
@@ -0,0 +1,3 @@
+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
diff --git a/data/Rates.csv b/data/Rates.csv
new file mode 100644
index 000000000..bf42eaa5b
--- /dev/null
+++ b/data/Rates.csv
@@ -0,0 +1,4 @@
+Tag;MonthsTag;MonthDaysTag;WeekDaysTag;StartTime;ConnectFee;Price;BillingUnit;Weight
+STANDARD;ALL;ALL;WORKDAYS;00:00:00;0;0.2;1;10
+STANDARD;ALL;ALL;WORKDAYS;18:00:00;0;0.1;1;10
+STANDARD;ALL;ALL;WEEKENDS;00:00:00;0;0.1;1;10
diff --git a/data/RatingProfiles.csv b/data/RatingProfiles.csv
new file mode 100644
index 000000000..2aad9e464
--- /dev/null
+++ b/data/RatingProfiles.csv
@@ -0,0 +1,3 @@
+Tenant;Subject;TOR;DestinationsTag;RatesTag;ActivationTime
+CUSTOMER_1;rif;0;GERMANY;STANDARD;2012-01-01T00:00:00:00.00000
+CUSTOMER_2;danb;0;GERMANY_O2;STANDARD;2012-01-01T00:00:00:00.00000
diff --git a/data/RecurrentDebits.csv b/data/RecurrentDebits.csv
new file mode 100644
index 000000000..9b2561b3b
--- /dev/null
+++ b/data/RecurrentDebits.csv
@@ -0,0 +1,2 @@
+Tag;MonetaryUnits;SMSUnits;TrafficUnits
+DEBIT_5;5;0;0
diff --git a/data/RecurrentTopups.csv b/data/RecurrentTopups.csv
new file mode 100644
index 000000000..8971b3178
--- /dev/null
+++ b/data/RecurrentTopups.csv
@@ -0,0 +1,2 @@
+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
diff --git a/data/VolumeDiscounts.csv b/data/VolumeDiscounts.csv
new file mode 100644
index 000000000..de575fbf8
--- /dev/null
+++ b/data/VolumeDiscounts.csv
@@ -0,0 +1,2 @@
+Tag;TOR;DestinationsTag;VolumeUnits;Discount;Weight
+UPTO_2000_GERMANY_10PERC;0;GERMANY;2000;10;10
diff --git a/data/VolumeRates.csv b/data/VolumeRates.csv
new file mode 100644
index 000000000..a68a72c31
--- /dev/null
+++ b/data/VolumeRates.csv
@@ -0,0 +1,2 @@
+Tag;TOR;DestinationsTag;VolumeUnits;Price;Weight
+GERMANY_100_LANDLINE_MINUTES;0;GERMANY;100;0;10
diff --git a/data/WeekDays.csv b/data/WeekDays.csv
new file mode 100644
index 000000000..90959f732
--- /dev/null
+++ b/data/WeekDays.csv
@@ -0,0 +1,4 @@
+Tag;Monday;Tuesday;Wednesday;Thursday;Friday;Saturday;Sunday
+ALL;1;1;1;1;1;1;1
+WORKDAYS;1;1;1;1;1;0;0
+WEEKENDS;0;0;0;0;0;1;1
diff --git a/timespans/interval.go b/timespans/interval.go
index 02c5175a7..a3164cf3d 100644
--- a/timespans/interval.go
+++ b/timespans/interval.go
@@ -25,6 +25,8 @@ import (
//"log"
)
+type Months []time.Month
+
/*
Defines a time interval for which a certain set of prices will apply
*/