3 changed files with 110 additions and 16 deletions
@ -0,0 +1,68 @@ |
|||||
|
package cdr |
||||
|
|
||||
|
import ( |
||||
|
"fmt" |
||||
|
) |
||||
|
|
||||
|
func CombineTextCDRs(cdrLines []Line, prices []Price) ([]Text, error) { |
||||
|
// Preprocess the price list into a map of "destination" -> Price, filter out the Text destinations, and count how many Text CDRs we have
|
||||
|
destinationToPriceLine := make(map[string]Price) |
||||
|
numTextCDRs := 0 |
||||
|
for _, l := range cdrLines { |
||||
|
if l.Kind != TextLine { |
||||
|
continue |
||||
|
} |
||||
|
if _, ok := destinationToPriceLine[l.Destination]; !ok { |
||||
|
for _, p := range prices { |
||||
|
if p.Type != PriceText { |
||||
|
continue |
||||
|
} |
||||
|
if p.Destination == l.Destination { |
||||
|
destinationToPriceLine[l.Destination] = p |
||||
|
break |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
numTextCDRs++ |
||||
|
} |
||||
|
|
||||
|
// Now convert each text CDR to a priced Text
|
||||
|
ret := make([]Text, numTextCDRs) |
||||
|
i := 0 |
||||
|
for _, l := range cdrLines { |
||||
|
if l.Kind != TextLine { |
||||
|
continue |
||||
|
} |
||||
|
ret[i] = Text{ |
||||
|
PricedLine{ |
||||
|
Line: l, |
||||
|
Cost: destinationToPriceLine[l.Destination].BuyEach, |
||||
|
Price: destinationToPriceLine[l.Destination].SellEach, |
||||
|
}, |
||||
|
} |
||||
|
i++ |
||||
|
} |
||||
|
|
||||
|
return ret, nil |
||||
|
} |
||||
|
|
||||
|
func CombineDataCDRs(cdrLines []Line, prices []Price) ([]Data, error) { |
||||
|
numDataCDRs := 0 |
||||
|
for _, l := range cdrLines { |
||||
|
if l.Kind != DataLine { |
||||
|
continue |
||||
|
} |
||||
|
numDataCDRs++ |
||||
|
} |
||||
|
ret := make([]Data, numDataCDRs) |
||||
|
return ret, fmt.Errorf("not yet implemented") |
||||
|
} |
||||
|
|
||||
|
func CombineCallCDRs(cdrLines []Line, prices []Price) ([]Call, error) { |
||||
|
for _, l := range cdrLines { |
||||
|
if l.Kind != VoiceLine { |
||||
|
continue |
||||
|
} |
||||
|
} |
||||
|
return nil, fmt.Errorf("not yet implemented") |
||||
|
} |
||||
Loading…
Reference in new issue