Merge branch 'master' of github.com:cgrates/cgrates

This commit is contained in:
Radu Ioan Fericean
2013-07-14 17:59:22 +03:00
6 changed files with 303 additions and 56 deletions

View File

@@ -39,15 +39,17 @@ CREATE TABLE `tp_rates` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`tpid` char(40) NOT NULL,
`tag` varchar(24) NOT NULL,
`connect_fee` DECIMAL(5,4) NOT NULL,
`rate` DECIMAL(5,4) NOT NULL,
`rated_units` INT(11) NOT NULL,
`rate_increments` INT(11) NOT NULL,
`weight` DECIMAL(5,2) NOT NULL,
`connect_fee` decimal(5,4) NOT NULL,
`rate` decimal(5,4) NOT NULL,
`rated_units` int(11) NOT NULL,
`rate_increments` int(11) NOT NULL,
`rounding_method` varchar(255) NOT NULL,
`rounding_decimals` tinyint(4) NOT NULL,
`weight` decimal(5,2) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `tpid_tag_rate_weight` (`tpid`,`tag`,`weight`),
KEY `tpid` (`tpid`),
KEY `tpid_tag` (`tpid`,`tag`),
UNIQUE KEY `tpid_tag_rate_weight` (`tpid`,`tag`,`weight`)
KEY `tpid_tag` (`tpid`,`tag`)
);
--

235
docs/api_tprateprofiles.rst Normal file
View File

@@ -0,0 +1,235 @@
Apier.SetTPRateProfile
++++++++++++++++++++++
Creates a new RateProfile within a tariff plan.
**Request**:
Data:
::
type TPRateProfile struct {
TPid string // Tariff plan id
RateProfileId string // RateProfile id
Tenant string // Tenant's Id
TOR string // TypeOfRecord
Direction string // Traffic direction, OUT is the only one supported for now
Subject string // Rating subject, usually the same as account
RatesFallbackSubject string // Fallback on this subject if rates not found for destination
RatingActivations []RatingActivation // Activate rate profiles at specific time
}
type RatingActivation struct {
ActivationTime int64 // Time when this profile will become active, defined as unix epoch time
DestRateTimingId string // Id of DestRateTiming profile
}
Mandatory parameters: ``[]string{"TPid", "RateProfileId", "Tenant", "TOR", "Direction", "Subject", "RatingActivations"}``
*JSON sample*:
::
{
"id": 3,
"method": "Apier.SetTPRateProfile",
"params": [
{
"Direction": "OUT",
"RateProfileId": "SAMPLE_RP_2",
"RatingActivations": [
{
"ActivationTime": 1373609003,
"DestRateTimingId": "DSTRTTIME_1"
},
{
"ActivationTime": 1373609004,
"DestRateTimingId": "DSTRTTIME_2"
}
],
"Subject": "dan",
"TOR": "CALL",
"TPid": "SAMPLE_TP",
"Tenant": "Tenant1"
}
]
}
**Reply**:
Data:
::
string
Possible answers:
``OK`` - Success.
*JSON sample*:
::
{
"error": null,
"id": 3,
"result": "OK"
}
**Errors**:
``MANDATORY_IE_MISSING`` - Mandatory parameter missing from request.
``SERVER_ERROR`` - Server error occurred.
``DUPLICATE`` - The specified combination of TPid/RateProfileId already exists in StorDb.
Apier.GetTPRateProfile
++++++++++++++++++++++
Queries specific RateProfile on tariff plan.
**Request**:
Data:
::
type AttrGetTPRateProfile struct {
TPid string // Tariff plan id
RateProfileId string // RateProfile id
}
Mandatory parameters: ``[]string{"TPid", "RateProfileId"}``
*JSON sample*:
::
{
"id": 0,
"method": "Apier.GetTPRateProfile",
"params": [
{
"RateProfileId": "SAMPLE_RP_2",
"TPid": "SAMPLE_TP"
}
]
}
**Reply**:
Data:
::
type TPRateProfile struct {
TPid string // Tariff plan id
RateProfileId string // RateProfile id
Tenant string // Tenant's Id
TOR string // TypeOfRecord
Direction string // Traffic direction, OUT is the only one supported for now
Subject string // Rating subject, usually the same as account
RatesFallbackSubject string // Fallback on this subject if rates not found for destination
RatingActivations []RatingActivation // Activate rate profiles at specific time
}
type RatingActivation struct {
ActivationTime int64 // Time when this profile will become active, defined as unix epoch time
DestRateTimingId string // Id of DestRateTiming profile
}
*JSON sample*:
::
{
"error": null,
"id": 0,
"result": {
"Direction": "OUT",
"RateProfileId": "SAMPLE_RP_2",
"RatesFallbackSubject": "",
"RatingActivations": [
{
"ActivationTime": 1373609003,
"DestRateTimingId": "DSTRTTIME_1"
},
{
"ActivationTime": 1373609004,
"DestRateTimingId": "DSTRTTIME_2"
}
],
"Subject": "dan",
"TOR": "CALL",
"TPid": "SAMPLE_TP",
"Tenant": "Tenant1"
}
}
**Errors**:
``MANDATORY_IE_MISSING`` - Mandatory parameter missing from request.
``SERVER_ERROR`` - Server error occurred.
``NOT_FOUND`` - Requested RateProfile profile not found.
Apier.GetTPRateProfileIds
+++++++++++++++++++++++++
Queries specific RateProfile on tariff plan. Attribute parameters used as extra filters.
**Request**:
Data:
::
type AttrTPRateProfileIds struct {
TPid string // Tariff plan id
Tenant string // Tenant's Id
TOR string // TypeOfRecord
Direction string // Traffic direction
Subject string // Rating subject, usually the same as account
}
Mandatory parameters: ``[]string{"TPid"}``
*JSON sample*:
::
{
"id": 0,
"method": "Apier.GetTPRateProfileIds",
"params": [
{
"Subject": "dan",
"TPid": "SAMPLE_TP",
"Tenant": "Tenant1"
}
]
}
**Reply**:
Data:
::
[]string
*JSON sample*:
::
{
"error": null,
"id": 0,
"result": [
"SAMPLE_RP_1",
"SAMPLE_RP_2"
]
}
**Errors**:
``MANDATORY_IE_MISSING`` - Mandatory parameter missing from request.
``SERVER_ERROR`` - Server error occurred.
``NOT_FOUND`` - There is no data to be returned based on filters set.

View File

@@ -19,6 +19,8 @@ Creates a new rate within a tariff plan.
Rate float64 // Rate applied
RatedUnits int // Number of billing units this rate applies to
RateIncrements int // This rate will apply in increments of duration
RoundingMethod string // Use this method to round the cost
RoundingDecimals int // Round the cost number of decimals
Weight float64 // Rate's priority when dealing with grouped rates
}
@@ -28,25 +30,29 @@ Creates a new rate within a tariff plan.
::
{
"id": 0,
"id": 1,
"method": "Apier.SetTPRate",
"params": [
{
"RateId": "SAMPLE_RATE_4",
"RateId": "SAMPLE_RATE_2",
"RateSlots": [
{
"ConnectFee": 0,
"Rate": 1.2,
"ConnectFee": 0.2,
"Rate": 2,
"RateIncrements": 1,
"RatedUnits": 60,
"Weight": 10
"RatedUnits": 1,
"RoundingDecimals": 2,
"RoundingMethod": "*up",
"Weight": 10.0
},
{
"ConnectFee": 0,
"Rate": 2.2,
"ConnectFee": 0.2,
"Rate": 2.1,
"RateIncrements": 1,
"RatedUnits": 60,
"Weight": 20
"RatedUnits": 1,
"RoundingDecimals": 2,
"RoundingMethod": "*up",
"Weight": 20.0
}
],
"TPid": "SAMPLE_TP"
@@ -129,6 +135,8 @@ Queries specific rate on tariff plan.
Rate float64 // Rate applied
RatedUnits int // Number of billing units this rate applies to
RateIncrements int // This rate will apply in increments of duration
RoundingMethod string // Use this method to round the cost
RoundingDecimals int // Round the cost number of decimals
Weight float64 // Rate's priority when dealing with grouped rates
}
@@ -137,22 +145,26 @@ Queries specific rate on tariff plan.
{
"error": null,
"id": 1,
"id": 2,
"result": {
"RateId": "SAMPLE_RATE_4",
"RateId": "SAMPLE_RATE_2",
"RateSlots": [
{
"ConnectFee": 0,
"Rate": 1.2,
"ConnectFee": 0.2,
"Rate": 2,
"RateIncrements": 1,
"RatedUnits": 60,
"RatedUnits": 1,
"RoundingDecimals": 2,
"RoundingMethod": "*up",
"Weight": 10
},
{
"ConnectFee": 0,
"Rate": 2.2,
"ConnectFee": 0.2,
"Rate": 2.1,
"RateIncrements": 1,
"RatedUnits": 60,
"RatedUnits": 1,
"RoundingDecimals": 2,
"RoundingMethod": "*up",
"Weight": 20
}
],

View File

@@ -166,8 +166,8 @@ DestinationRates
api_tpdestinationrates
DestinationRateTiming
~~~~~~~~~~~~~~~~~~~~~
DestinationRateTimings
~~~~~~~~~~~~~~~~~~~~~~
.. toctree::
:maxdepth: 2
@@ -175,18 +175,13 @@ DestinationRateTiming
api_tpdestratetimings
GetTPRatingProfile
RateProfiles
~~~~~~~~~~~~
SetTPRatingProfile
.. toctree::
:maxdepth: 2
DeleteTPProfile
GetAllTPRatingProfiles
ImportWithOverride
ImportWithFlush
api_tprateprofiles
6.1.5. Management API

View File

@@ -210,9 +210,9 @@ func (self *SQLStorage) ExistsTPRate(tpid, rtId string) (bool, error) {
func (self *SQLStorage) SetTPRate(rt *utils.TPRate) error {
for _, rtSlot := range rt.RateSlots {
if _, err := self.Db.Exec(fmt.Sprintf("INSERT INTO %s (tpid, tag, connect_fee, rate, rated_units, rate_increments, weight) VALUES ('%s', '%s', %f, %f, %d, %d, %f)",
utils.TBL_TP_RATES, rt.TPid, rt.RateId, rtSlot.ConnectFee, rtSlot.Rate, rtSlot.RatedUnits, rtSlot.RateIncrements,
rtSlot.Weight)); err != nil {
if _, err := self.Db.Exec(fmt.Sprintf("INSERT INTO %s (tpid, tag, connect_fee, rate, rated_units, rate_increments, rounding_method, rounding_decimals, weight) VALUES ('%s', '%s', %f, %f, %d, %d,'%s', %d, %f)",
utils.TBL_TP_RATES, rt.TPid, rt.RateId, rtSlot.ConnectFee, rtSlot.Rate, rtSlot.RatedUnits, rtSlot.RateIncrements,
rtSlot.RoundingMethod, rtSlot.RoundingDecimals, rtSlot.Weight)); err != nil {
return err
}
}
@@ -220,7 +220,7 @@ func (self *SQLStorage) SetTPRate(rt *utils.TPRate) error {
}
func (self *SQLStorage) GetTPRate(tpid, rtId string) (*utils.TPRate, error) {
rows, err := self.Db.Query(fmt.Sprintf("SELECT connect_fee, rate, rated_units, rate_increments, weight FROM %s WHERE tpid='%s' AND tag='%s'", utils.TBL_TP_RATES, tpid, rtId))
rows, err := self.Db.Query(fmt.Sprintf("SELECT connect_fee, rate, rated_units, rate_increments, rounding_method, rounding_decimals, weight FROM %s WHERE tpid='%s' AND tag='%s'", utils.TBL_TP_RATES, tpid, rtId))
if err != nil {
return nil, err
}
@@ -230,12 +230,13 @@ func (self *SQLStorage) GetTPRate(tpid, rtId string) (*utils.TPRate, error) {
for rows.Next() {
i++ //Keep here a reference so we know we got at least one prefix
var connectFee, rate, weight float64
var ratedUnits, rateIncrements int
err = rows.Scan(&connectFee, &rate, &ratedUnits, &rateIncrements, &weight)
var ratedUnits, rateIncrements, roundingDecimals int
var roundingMethod string
err = rows.Scan(&connectFee, &rate, &ratedUnits, &rateIncrements, &roundingMethod, &roundingDecimals, &weight)
if err != nil {
return nil, err
}
rt.RateSlots = append(rt.RateSlots, utils.RateSlot{connectFee, rate, ratedUnits, rateIncrements, weight})
rt.RateSlots = append(rt.RateSlots, utils.RateSlot{connectFee, rate, ratedUnits, rateIncrements, roundingMethod, roundingDecimals, weight})
}
if i == 0 {
return nil, nil

View File

@@ -31,6 +31,8 @@ type RateSlot struct {
Rate float64 // Rate applied
RatedUnits int // Number of billing units this rate applies to
RateIncrements int // This rate will apply in increments of duration
RoundingMethod string // Use this method to round the cost
RoundingDecimals int // Round the cost number of decimals
Weight float64 // Rate's priority when dealing with grouped rates
}
@@ -58,25 +60,25 @@ type DestRateTiming struct {
}
type TPRateProfile struct {
TPid string // Tariff plan id
RateProfileId string // RateProfile id
Tenant string // Tenant's Id
TOR string // TypeOfRecord
Direction string // Traffic direction, OUT is the only one supported for now
Subject string // Rating subject, usually the same as account
RatesFallbackSubject string // Fallback on this subject if rates not found for destination
RatingActivations []RatingActivation // Activate rate profiles at specific time
TPid string // Tariff plan id
RateProfileId string // RateProfile id
Tenant string // Tenant's Id
TOR string // TypeOfRecord
Direction string // Traffic direction, OUT is the only one supported for now
Subject string // Rating subject, usually the same as account
RatesFallbackSubject string // Fallback on this subject if rates not found for destination
RatingActivations []RatingActivation // Activate rate profiles at specific time
}
type RatingActivation struct {
ActivationTime int64 // Time when this profile will become active, defined as unix epoch time
ActivationTime int64 // Time when this profile will become active, defined as unix epoch time
DestRateTimingId string // Id of DestRateTiming profile
}
type AttrTPRateProfileIds struct {
TPid string // Tariff plan id
Tenant string // Tenant's Id
TOR string // TypeOfRecord
TPid string // Tariff plan id
Tenant string // Tenant's Id
TOR string // TypeOfRecord
Direction string // Traffic direction
Subject string // Rating subject, usually the same as account
}