locked
How to filter CSV data by LINQ RRS feed

  • Question

  • User264732274 posted

    here i am giving a idea how my csv file has data

    Call start       Call duration    Ring duration       Direction     Is_Internal   Continuation    Party1Name
    ----------      -------------     -------------       ---------     -----------  ------------    -----------
    09-06-15 7:27     0:00:06           0                   I              1             1             ACC
    09-06-15 7:27     0:00:06           0                   I              0             1             ACC
    09-06-15 11:27    0:00:06           0                   )              0             1             Sales
    09-06-15 7:27     0:00:06           0                   I              0             1             ACC
    09-06-15 7:27     0:00:06           0                   I              1             0             Suzzy
    09-06-15 03:27    0:00:06           0                   I              0             1             Suzzy
    09-06-15 7:27     0:00:06           0                   I              0             1             ACC
    09-06-15 7:27     0:00:06           0                   O              0             0             Sales
    09-06-15 7:27     0:00:06           0                   I              1             1             ACC
    09-06-15 12:27    0:00:06           0                   I              0             1             Matt
    09-06-15 10:27    0:00:06           0                   I              0             1             VM Channel
    09-06-15 7:27     0:00:06           0                   )              0             0             VM Channel
    09-06-15 7:27     0:00:06           0                   I              0             1             Voice Mail

    Now i want to show employee wise data like below

    CSR Name       Incomming      outgoing    call transfer
    --------       ----------     --------    -------------
    ACC               10               12           11
    SALES             05               06           02
    Suzy              7                 5            5
    Matt              2                 2            2

    my condition would be
    1) for incoming direction has to be I and for outgoing direction will be O
    2) employee name VM Channel and Voice mail will not be consider

    and more

    i am not good in linq and that is why posting this question for help. i have linq query sample which is bit similar but still no idea what to rectify in it or add to get my desired out put.

    here is linq code

    void Main()
    {
        var csvlines = File.ReadAllLines(@"M:\smdr(backup08-06-2015).csv");   
        var csvLinesData = csvlines.Skip(1).Select(l => l.Split(',').ToArray());
    
        //int iDir = csvLinesData.Count(w => w.direction='I');
        var users = csvLinesData.Select(data => new User
        {
                    CSRName =   data[12],
                    Incomming = csvLinesData.Count(w => w[4] == "I"),
                    outgoing = csvLinesData.Count(w => w[4] == "O")
        }).ToList();
        users.Dump();
    }
    
    class User
    {
        public string CSRName;
        public int outgoing;
        public int Incomming;
        public int calltransfer;
    }

    how to remove employee name VM Channel and Voice mail from the result. in sql we can use not like and not in clause but what similar things available in linq ?

    how to fetch employee name wise data

    CSRName = data[12],
    Incomming = csvLinesData.Count(w => w[4] == "I")

    if this line

    CSRName = data[12]

    return suzy then suzy related incoming data will be stored in

    Incomming

    variable. how to achieve it.

    just wonder if anyone can help with linq query.

    Tuesday, June 16, 2015 2:24 PM

Answers

  • User61956409 posted

    Hi sudip_inn,

    Thanks for your post.

    how to remove employee name VM Channel and Voice mail from the result. in sql we can use not like and not in clause but what similar things available in linq ?

    You could use . Where() method to filter records like this.

    users.Where(c => !c.CSRName.Contains("VM Channel"))

    Best Regards,

    Fei Han

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, June 17, 2015 4:43 AM