package cdr import ( "fmt" ) func CombineTextCDRs(cdrLines []Line, prices []Price) ([]Text, error) { numTextCDRs := 0 for _, l := range cdrLines { if l.Kind != TextLine { continue } 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: TEXT_OUTGOING_BUY, Price: TEXT_OUTGOING_SELL, }, } 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) { // 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) numCallCDRs := 0 for _, l := range cdrLines { if l.Kind != VoiceLine { continue } if _, ok := destinationToPriceLine[l.Destination]; !ok { for _, p := range prices { if p.Type != PriceCall { continue } if p.Destination == l.Destination { destinationToPriceLine[l.Destination] = p break } } } numCallCDRs++ } return nil, fmt.Errorf("not yet implemented") }