cdr文件的格式

时间:2016-01-25 05:16:55

标签: file format call record

我想准备关于呼叫数据记录(cdr)日志文件的演示文稿。我在网上搜索但无法找到cdr文件的格式。

1 个答案:

答案 0 :(得分:1)

我知道这是一个老问题,但我制作了一个生成CDR记录的java应用程序,它可能会帮助其他人

import org.fluttercode.datafactory.impl.DataFactory;
import org.joda.time.DateTime;
import org.joda.time.LocalDate;
import org.joda.time.LocalTime;
import java.io.*;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.file.Files;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.io.IOException;
import java.nio.file.FileAlreadyExistsException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;


public class App {
    public static void main(String[] args) throws InterruptedException {
// Object Instances     
        DataFactory df = new DataFactory();
        Random r = new Random();

//Input Scanner
        Scanner cdr = new Scanner (System.in);
        System.out.println("Please Enter No of Record You Want to Generate");
        int b = cdr.nextInt();
//Float charge = r.nextFloat();
            Formatter x1 = new Formatter();

            try{
                x1 = new Formatter("F:\\CDR\\cdr.txt");
                System.out.println("File is created");
            }catch(Exception e){
                System.out.println("Please check your prog");
            }
//now check if file is created or not
            System.out.println("\t ############Check new file is create or not############");
            File x2 = new File("F:\\CDR\\cdr.txt");

            if(x2.exists()){
                System.out.println(x2.getName() + "   its file name and present in this directory ");
            }else{
                System.out.println("File doesnt exist");
                }
            //==========================add Record to file to created file
            //for(int a=0;a<=100;a++){
//Loop to repeat every logic (Remeber every loop will generate random numbers and Datetime)             
            int a=0;
            int c = 0;
            //do{   
            while (a<b){
//Random number generator               
                int id = a ;
                System.out.println(id);
                String calling_num = df.getNumberText(7);
                String called_num = df.getNumberText(7);
//Date Time generator               
                long t1 = System.currentTimeMillis() + r.nextInt();
                long t2 = t1 + 2 * 60 * 1000 + r.nextInt(60 * 1000) + 1;
//Converion to Datetime             
                DateTime d1 = new DateTime(t1);
                DateTime d2 = new DateTime(t2);
// Declaring Cnditional Column types
                String callType = "";
                String MNP = "";
                String callTerm = "";
//Date Time Conversion to make it compatible for hive db
//Date              
                LocalDate d3 = d1.toLocalDate();
                LocalDate d4 = d2.toLocalDate();
//Time
                LocalTime d5 = d1.toLocalTime();
                LocalTime d6 = d2.toLocalTime();
//Tagging data as voice or sms              
            if ( r.nextInt() % 2 == 0){
                    callType = "1";
                } else {
                    callType = "7";
                }
// Network Port MNP Tagging         
            if ( r.nextInt() % 13 == 0){
                MNP = "P";
            } else {
                MNP = "NP";
            }

            if ("7" == callType) {
                d2 = new DateTime(t1);  
            }
            String callResult = "ANSWERED_SEND";
// Call/sms Drop Tagging                    
//Calls
            if ((a % 10 )== 0 && callType == "1") {
                callResult = "CALL DROPPED";
                d2 = new DateTime(t1);  
            }
//Sms           
            if ((a % 10 )== 0 && callType == "7") {
                callResult = "NOT DELIVERED";
                d2 = new DateTime(t1);  
            }

// Call/Sms Termination Tagging         
//Calls
            if ((a % 10 )== 0 && callType == "1") {
                callTerm = "C_Term1";
                d2 = new DateTime(t1);  
            } 

            if ((a % 20 )== 0 && callType == "1") {
                callTerm = "C_Term2";
                d2 = new DateTime(t1);  
            }

            if((a % 10)!= 0 && (a% 20) != 0 && callType == "1"){
                callTerm = "Success";
            }

//SMS           
            if ((a % 10 )== 0 && callType == "7") {
                callTerm = "M_Term1";
                d2 = new DateTime(t1);  
            }
            if ((a % 20 )== 0 && callType == "7") {
                callTerm = "M_Term2";
                d2 = new DateTime(t1);  
            }


            if((a % 10)!= 0 && (a% 20) != 0 && callType == "7"){
                callTerm = "Success";
            }
//Random charges                
                Float charge = r.nextFloat();
            if (callType == "1") {
                charge = 5* r.nextFloat();
                d2 = new DateTime(t1);
                d2 = new DateTime(t2);
                }               
// Now we are tagging network to random generated numbers in condition
            if (a<10000){
                if(a<5000){
                           x1.format("%s \n", callType+"|"+id+"|"+"0331"+calling_num+"|"+"0300"+called_num+"|"+d3.toString()+" "+d5.toString()+"|"+d4.toString()+" "+d6+"|"+callType+"|"+(charge)+"|"+callResult+"|"+MNP+"|"+callTerm);
                         }else{
                           x1.format("%s \n", callType+"|"+id+"|"+"0332"+calling_num+"|"+"0301"+called_num+"|"+d3.toString()+" "+d5.toString()+"|"+d4.toString()+" "+d6+"|"+callType+"|"+(charge)+"|"+callResult+"|"+MNP+"|"+callTerm);
                         }
            }else if(a>=10000 && a<20000){
                if(a>=10000 && a<15000){
                            x1.format("%s \n", callType+"|"+id+"|"+"0333"+calling_num+"|"+"0321"+called_num+"|"+d3.toString()+" "+d5.toString()+"|"+d4.toString()+" "+d6+"|"+callType+"|"+charge+"|"+callResult+"|"+MNP+"|"+callTerm);
                          }else{
                            x1.format("%s \n", callType+"|"+id+"|"+"0334"+calling_num+"|"+"0322"+called_num+"|"+d3.toString()+" "+d5.toString()+"|"+d4.toString()+" "+d6+"|"+callType+"|"+charge+"|"+callResult+"|"+MNP+"|"+callTerm);
                          }
            }else if(a>=20001 && a<40000){
                if(a>=20001 && a<30000){
                            x1.format("%s \n", callType+"|"+id+"|"+"0345"+calling_num+"|"+"0345"+called_num+"|"+d3.toString()+" "+d5.toString()+"|"+d4.toString()+" "+d6+"|"+callType+"|"+charge+"|"+callResult+"|"+MNP+"|"+callTerm);
                          }else{
                            x1.format("%s \n", callType+"|"+id+"|"+"0300"+calling_num+"|"+"0346"+called_num+"|"+d3.toString()+" "+d5.toString()+"|"+d4.toString()+" "+d6+"|"+callType+"|"+charge+"|"+callResult+"|"+MNP+"|"+callTerm);
                          }
            }                           
                 a++;   
                 x1.flush();
                 Thread.sleep(50);


            }//while(a<b);
            System.out.println( a +" Records are added Please Open File to Review" );
            //=================close file when record added
            x1.close();      
        }
    }