Browse Source

Import notes

master
Gerdriaan Mulder 6 years ago
parent
commit
bf5e2d6211
  1. 49
      import.go
  2. 14
      record.go

49
import.go

@ -1 +1,50 @@
package cdr
import (
"encoding/csv"
)
// Some assumptions on our input, since encoding/csv reads everything as string. We expect 17 entries per line:
// cid,time,type,cli,from,to,account,usage,costs,source,destination,leg,reason,package,package_costs,network_costs,service_costs
//
// - cid is free text, could be argued to be unique, but there are no guarantees.
// - time is a timestamp formatted YYYY-MM-DD hh:mm:sd
// - type is in {Voice,Data,SMS}, of course the header line is "type"
// - cli,from should be \d+ (eg 31676012321)
// - to is either [0-9*]+ for a (partially shielded/) phonenumber, or .+ for APN or Voicemail, or the likes
// - account is free text (non-empty)
// - usage is an integer >= 0
// - costs is a float with four decimal digits. We strip the dot and interpret it as an integer, to avoid weird rounding errors during processing
// - source,destination are free text, but typically either empty or take the form "word(s) - word(s) - word(s)"
// - leg is an integer >= 1
// - reason is in {ORIG,CFIM,CFOR,CFNA,CFBS,ROAM,PBXOR}, but there might be other ones
// - package is free text (or empty)
// - {package,network,service}_costs are either empty or conform to the "costs" column
// FieldsPerLine are the expected number of fields in each CSV line.
const FieldsPerLine = 17
// ImportIndex keeps track of what column corresponds to what data.
type ImportIndex int
// These are our numbered input fields
const (
ImportUnknown ImportIndex = iota
ImportCid
ImportTime
ImportType
ImportCLI
ImportFrom
ImportTo
ImportAccount
ImportUsage
ImportCosts
ImportSource
ImportDestination
ImportLeg
ImportReason
ImportPackage
ImportPackageCosts
ImportNetworkCosts
ImportServiceCosts
)

14
record.go

@ -41,7 +41,7 @@ const (
PBXOR
)
// Line contains common metadata for a record
// Line contains the original metadata of a (call) detail record
type Line struct {
Id string
Time time.Time
@ -51,9 +51,17 @@ type Line struct {
Account string
Source string
Destination string
Reason ReasonKind
RawCount int
RawCosts int
Leg int
Reason ReasonKind
Kind LineKind
// non-public properties
pkg string
package_cost int
network_cost int
service_cost int
}
// PricedLine connects a cost (buy) and price (sell) to a particular Line
@ -68,7 +76,7 @@ type PricedLine struct {
type Call struct {
From string
To string
Duration int
Duration time.Duration
Cost int
Price int
Legs []PricedLine

Loading…
Cancel
Save