4 changed files with 153 additions and 19 deletions
@ -0,0 +1,71 @@ |
|||
package cdr |
|||
|
|||
import ( |
|||
"fmt" |
|||
) |
|||
|
|||
type ExportLineIndex int |
|||
|
|||
var ( |
|||
ExportLineSize = 9 |
|||
ExportLineTypeCall = "CALL" |
|||
ExportLineTypeText = "TEXT" |
|||
ExportLineTypeData = "DATA" |
|||
ExportLineHeader = []string{ |
|||
"Type", "Timestamp", "From", "To", "Units", "Account", "Cost", "Price", "Description", |
|||
} |
|||
) |
|||
|
|||
const ( |
|||
ExportLineType ExportLineIndex = iota |
|||
ExportLineTimestamp |
|||
ExportLineFrom |
|||
ExportLineTo |
|||
ExportLineUnits |
|||
ExportLineAccount |
|||
ExportLineCost |
|||
ExportLinePrice |
|||
ExportLineDescription |
|||
) |
|||
|
|||
func ExportCall(c Call) []string { |
|||
ret := make([]string, ExportLineSize) |
|||
ret[ExportLineType] = ExportLineTypeCall |
|||
ret[ExportLineTimestamp] = c.Time.Format(DateTimeFormat) |
|||
ret[ExportLineFrom] = c.From |
|||
ret[ExportLineTo] = c.To |
|||
ret[ExportLineUnits] = fmt.Sprintf("%.0f", c.Duration.Seconds()) |
|||
ret[ExportLineAccount] = c.Account |
|||
ret[ExportLineCost] = fmt.Sprintf("%d", c.Cost) |
|||
ret[ExportLinePrice] = fmt.Sprintf("%d", c.Price) |
|||
ret[ExportLineDescription] = c.Description |
|||
return ret |
|||
} |
|||
|
|||
func ExportText(t Text) []string { |
|||
ret := make([]string, ExportLineSize) |
|||
ret[ExportLineType] = ExportLineTypeText |
|||
ret[ExportLineTimestamp] = t.Time.Format(DateTimeFormat) |
|||
ret[ExportLineFrom] = t.From |
|||
ret[ExportLineTo] = t.To |
|||
ret[ExportLineUnits] = "1" |
|||
ret[ExportLineAccount] = t.Account |
|||
ret[ExportLineCost] = fmt.Sprintf("%d", t.Cost) |
|||
ret[ExportLinePrice] = fmt.Sprintf("%d", t.Price) |
|||
ret[ExportLineDescription] = "SMS" |
|||
return ret |
|||
} |
|||
|
|||
func ExportData(d Data) []string { |
|||
ret := make([]string, ExportLineSize) |
|||
ret[ExportLineType] = ExportLineTypeData |
|||
ret[ExportLineTimestamp] = d.Time.Format(DateTimeFormat) |
|||
ret[ExportLineFrom] = "" |
|||
ret[ExportLineTo] = "" |
|||
ret[ExportLineUnits] = fmt.Sprintf("%d", d.Kilobytes) |
|||
ret[ExportLineAccount] = d.Account |
|||
ret[ExportLineCost] = fmt.Sprintf("%d", d.PricedLine.Cost) |
|||
ret[ExportLinePrice] = fmt.Sprintf("%d", d.PricedLine.Price) |
|||
ret[ExportLineDescription] = "Data" |
|||
return ret |
|||
} |
|||
Loading…
Reference in new issue