utils

package
v0.0.0-...-48d1953 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 4, 2013 License: GPL-3.0 Imports: 11 Imported by: 0

Documentation

Overview

Rating system designed to be used in VoIP Carriers World Copyright (C) 2013 ITsysCOM

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 <http://www.gnu.org/licenses/>

Index

Constants

View Source
const (
	VERSION                  = "0.9.1rc3"
	POSTGRES                 = "postgres"
	MYSQL                    = "mysql"
	MONGO                    = "mongo"
	REDIS                    = "redis"
	LOCALHOST                = "127.0.0.1"
	FSCDR_FILE_CSV           = "freeswitch_file_csv"
	FSCDR_HTTP_JSON          = "freeswitch_http_json"
	NOT_IMPLEMENTED          = "not implemented"
	PREPAID                  = "prepaid"
	POSTPAID                 = "postpaid"
	PSEUDOPREPAID            = "pseudoprepaid"
	RATED                    = "rated"
	ERR_NOT_IMPLEMENTED      = "NOT_IMPLEMENTED"
	ERR_SERVER_ERROR         = "SERVER_ERROR"
	ERR_NOT_FOUND            = "NOT_FOUND"
	ERR_MANDATORY_IE_MISSING = "MANDATORY_IE_MISSING"
	ERR_DUPLICATE            = "DUPLICATE"
	TBL_TP_TIMINGS           = "tp_timings"
	TBL_TP_DESTINATIONS      = "tp_destinations"
	TBL_TP_RATES             = "tp_rates"
	TBL_TP_DESTINATION_RATES = "tp_destination_rates"
	TBL_TP_DESTRATE_TIMINGS  = "tp_destrate_timings"
	TBL_TP_RATE_PROFILES     = "tp_rating_profiles"
	TBL_TP_ACTIONS           = "tp_actions"
	TBL_TP_ACTION_TIMINGS    = "tp_action_timings"
	TBL_TP_ACTION_TRIGGERS   = "tp_action_triggers"
	TBL_TP_ACCOUNT_ACTIONS   = "tp_account_actions"
	TBL_COST_DETAILS         = "cost_details"
	TBL_RATED_CDRS           = "rated_cdrs"
	TIMINGS_CSV              = "Timings.csv"
	DESTINATIONS_CSV         = "Destinations.csv"
	RATES_CSV                = "Rates.csv"
	DESTINATION_RATES_CSV    = "DestinationRates.csv"
	DESTRATE_TIMINGS_CSV     = "DestinationRateTimings.csv"
	RATE_PROFILES_CSV        = "RatingProfiles.csv"
	ACTIONS_CSV              = "Actions.csv"
	ACTION_TIMINGS_CSV       = "ActionTimings.csv"
	ACTION_TRIGGERS_CSV      = "ActionTriggers.csv"
	ACCOUNT_ACTIONS_CSV      = "AccountActions.csv"
	TIMINGS_NRCOLS           = 6
	DESTINATIONS_NRCOLS      = 2
	RATES_NRCOLS             = 9
	DESTINATION_RATES_NRCOLS = 3
	DESTRATE_TIMINGS_NRCOLS  = 4
	RATE_PROFILES_NRCOLS     = 7
	ACTIONS_NRCOLS           = 11
	ACTION_TIMINGS_NRCOLS    = 4
	ACTION_TRIGGERS_NRCOLS   = 8
	ACCOUNT_ACTIONS_NRCOLS   = 5
	ROUNDING_UP              = "*up"
	ROUNDING_MIDDLE          = "*middle"
	ROUNDING_DOWN            = "*down"
	COMMENT_CHAR             = '#'
)

Variables

This section is empty.

Functions

func ConvertMapValStrIf

func ConvertMapValStrIf(inMap map[string]string) map[string]interface{}

Converts map[string]string into map[string]interface{}

func FSCgrId

func FSCgrId(uuid string) string

func FirstNonEmpty

func FirstNonEmpty(vals ...string) string

Returns first non empty string out of vals. Useful to extract defaults

func GenUUID

func GenUUID() string

helper function for uuid generation

func IsSliceMember

func IsSliceMember(ss []string, s string) bool

Binary string search in slice

func MapKeys

func MapKeys(m map[string]string) []string

Return map keys

func MirrorMap

func MirrorMap(mapIn map[string]string) (map[string]string, error)

Mirrors key/val

func MissingMapKeys

func MissingMapKeys(inMap map[string]string, requiredKeys []string) []string

Returns mising keys in a map

func MissingStructFields

func MissingStructFields(s interface{}, mandatories []string) []string

Detects missing field values based on mandatory field names, s should be a pointer to a struct

func NewTPid

func NewTPid() string

func NonemptyStructFields

func NonemptyStructFields(s interface{}) map[string]interface{}

Detects nonempty struct fields, s should be a pointer to a struct Useful to not overwrite db fields with non defined params in api

func ParseDate

func ParseDate(date string) (expDate time.Time, err error)

func Round

func Round(x float64, prec int, method string) float64

Round return rounded version of x with prec precision.

Special cases are:

Round(±0) = ±0
Round(±Inf) = ±Inf
Round(NaN) = NaN

func RoundToMinute

func RoundToMinute(seconds float64) float64

func SliceMemberHasPrefix

func SliceMemberHasPrefix(ss []string, prfx string) bool

Iterates over slice members and returns true of one starts with prefix

func StrucToMap

func StrucToMap(s interface{}) map[string]interface{}

Converts a struct to map

func UpdateStructWithStrMap

func UpdateStructWithStrMap(s interface{}, m map[string]string) []string

Update struct with map fields, returns not matching map keys, s is a struct to be updated

Types

type Action

type Action struct {
	Identifier    string  // Identifier mapped in the code
	BalanceType   string  // Type of balance the action will operate on
	Direction     string  // Balance direction
	Units         float64 // Number of units to add/deduct
	ExpiryTime    string  // Time when the units will expire
	DestinationId string  // Destination profile id
	RateType      string  // Type of rate <*absolute|*percent>
	Rate          float64 // Price value
	MinutesWeight float64 // Minutes weight
	Weight        float64 // Action's weight
}

type ApiActionTiming

type ApiActionTiming struct {
	ActionsId string  // Actions id
	TimingId  string  // Timing profile id
	Weight    float64 // Binding's weight
}

type ApiActionTrigger

type ApiActionTrigger struct {
	BalanceType    string  // Type of balance this trigger monitors
	Direction      string  // Traffic direction
	ThresholdType  string  // This threshold type
	ThresholdValue float64 // Threshold
	DestinationId  string  // Id of the destination profile
	ActionsId      string  // Actions which will execute on threshold reached
	Weight         float64 // weight
}

type ApiTPAccountActions

type ApiTPAccountActions struct {
	TPid             string // Tariff plan id
	AccountActionsId string // AccountActions id
	Tenant           string // Tenant's Id
	Account          string // Account name
	Direction        string // Traffic direction
	ActionTimingsId  string // Id of ActionTimings profile to use
	ActionTriggersId string // Id of ActionTriggers profile to use
}

type ApiTPActionTimings

type ApiTPActionTimings struct {
	TPid            string            // Tariff plan id
	ActionTimingsId string            // ActionTimings id
	ActionTimings   []ApiActionTiming // Set of ActionTiming bindings this profile will group
}

type ApiTPActionTriggers

type ApiTPActionTriggers struct {
	TPid             string             // Tariff plan id
	ActionTriggersId string             // Profile id
	ActionTriggers   []ApiActionTrigger // Set of triggers grouped in this profile

}

type AttrTPRatingProfileIds

type AttrTPRatingProfileIds 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
}

type CDR

type CDR interface {
	GetCgrId() string
	GetAccId() string
	GetCdrHost() string
	GetDirection() string
	GetOrigId() string
	GetSubject() string
	GetAccount() string
	GetDestination() string
	GetTOR() string
	GetTenant() string
	GetReqType() string
	GetAnswerTime() (time.Time, error)
	GetDuration() int64
	GetFallbackSubj() string
	GetExtraFields() map[string]string //Stores extra CDR Fields
}

type DestRateTiming

type DestRateTiming struct {
	DestRatesId string  // The DestinationRate identity
	TimingId    string  // The timing identity
	Weight      float64 // Binding priority taken into consideration when more DestinationRates are active on a time slot
}

type DestinationRate

type DestinationRate struct {
	DestinationId string // The destination identity
	RateId        string // The rate identity
}

type GenericCdr

type GenericCdr map[string]string

func (GenericCdr) GetAccId

func (gcdr GenericCdr) GetAccId() string

func (GenericCdr) GetAccount

func (gcdr GenericCdr) GetAccount() string

func (GenericCdr) GetAnswerTime

func (gcdr GenericCdr) GetAnswerTime() (time.Time, error)

func (GenericCdr) GetCdrHost

func (gcdr GenericCdr) GetCdrHost() string

func (GenericCdr) GetCgrId

func (gcdr GenericCdr) GetCgrId() string

func (GenericCdr) GetDestination

func (gcdr GenericCdr) GetDestination() string

func (GenericCdr) GetDirection

func (gcdr GenericCdr) GetDirection() string

func (GenericCdr) GetDuration

func (gcdr GenericCdr) GetDuration() int64

func (GenericCdr) GetExtraFields

func (gcdr GenericCdr) GetExtraFields() map[string]string

func (GenericCdr) GetFallbackSubj

func (gcdr GenericCdr) GetFallbackSubj() string

func (GenericCdr) GetOrigId

func (gcdr GenericCdr) GetOrigId() string

func (GenericCdr) GetReqType

func (gcdr GenericCdr) GetReqType() string

func (GenericCdr) GetSubject

func (gcdr GenericCdr) GetSubject() string

func (GenericCdr) GetTOR

func (gcdr GenericCdr) GetTOR() string

func (GenericCdr) GetTenant

func (gcdr GenericCdr) GetTenant() string

type LoggerInterface

type LoggerInterface interface {
	Alert(m string) error
	Close() error
	Crit(m string) error
	Debug(m string) error
	Emerg(m string) error
	Err(m string) error
	Info(m string) error
	Notice(m string) error
	Warning(m string) error
}

type RateSlot

type RateSlot struct {
	ConnectFee         float64 // ConnectFee applied once the call is answered
	Rate               float64 // Rate applied
	RatedUnits         string  //  Number of billing units this rate applies to
	RateIncrements     string  // This rate will apply in increments of duration
	GroupIntervalStart string  // Group position
	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
}

type RatingActivation

type RatingActivation struct {
	ActivationTime   string // Time when this profile will become active, defined as unix epoch time
	DestRateTimingId string // Id of DestRateTiming profile
}

type StdLogger

type StdLogger struct{}

Logs to standard output

func (*StdLogger) Alert

func (sl *StdLogger) Alert(m string) (err error)

func (*StdLogger) Close

func (sl *StdLogger) Close() (err error)

func (*StdLogger) Crit

func (sl *StdLogger) Crit(m string) (err error)

func (*StdLogger) Debug

func (sl *StdLogger) Debug(m string) (err error)

func (*StdLogger) Emerg

func (sl *StdLogger) Emerg(m string) (err error)

func (*StdLogger) Err

func (sl *StdLogger) Err(m string) (err error)

func (*StdLogger) Info

func (sl *StdLogger) Info(m string) (err error)

func (*StdLogger) Notice

func (sl *StdLogger) Notice(m string) (err error)

func (*StdLogger) Warning

func (sl *StdLogger) Warning(m string) (err error)

type TPActionTimingsRow

type TPActionTimingsRow struct {
	ActionsId string  // Actions id
	TimingId  string  // Timing profile id
	Weight    float64 // Binding's weight
}

Represents a single row in .csv or storDb, id will be used as key in the map holding all rows

type TPActions

type TPActions struct {
	TPid      string   // Tariff plan id
	ActionsId string   // Actions id
	Actions   []Action // Set of actions this Actions profile will perform
}

type TPDestRateTiming

type TPDestRateTiming struct {
	TPid             string           // Tariff plan id
	DestRateTimingId string           // DestinationRate profile id
	DestRateTimings  []DestRateTiming // Set of destinationid-rateid bindings
}

type TPDestinationRate

type TPDestinationRate struct {
	TPid              string            // Tariff plan id
	DestinationRateId string            // DestinationRate profile id
	DestinationRates  []DestinationRate // Set of destinationid-rateid bindings
}

type TPRate

type TPRate struct {
	TPid      string     // Tariff plan id
	RateId    string     // Rate id
	RateSlots []RateSlot // One or more RateSlots
}

type TPRatingProfile

type TPRatingProfile struct {
	TPid                 string             // Tariff plan id
	RatingProfileId      string             // RatingProfile 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
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL