Click here to Skip to main content
15,886,873 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Example data from CSV file has data as below:

ScheduledTime,WorkStation_Id,Order_Id,Duration(seconds)
01.01.2016  00:00:00,10A,1,15
01.01.2016  00:00:15,10A,1,25
01.01.2016  00:00:35,10A,1,10
01.01.2016  00:00:45,10A,2,10
01.01.2016  00:00:55,10A,2,10
01.01.2016  00:01:05,10B,1,20
01.01.2016  00:00:25,10B,1,10
01.01.2016  00:00:35,10B,2,20
.....

These are the following I am trying to do but have been unsuccessful:

I am trying to get the Start Time and the sum of duration for each Order_Id based on WorkStation_Id to calculate the End Time. I want to calculate the Start time by adding the Duration.

I want to iterate through the obtained Object key values.

The code I am trying is not giving me the Start and End time properly. Also, since the result obtained in the console is as follows:
[…]
0: {…}
key: "10A"
values: […]
[0…99]
0: {…}
key: "1"
values: […]
0: {…}
key: "1451602800000"
value: 8709616866000
....

Since the result obtained has Key Value pairs, how do I access Start Time and End Time for each Order_Id based on the WorkStation_Id

I am going wrong at a lot of places, but I need guidance as to how I can go about this as I am clueless right now even after trying a lot of online help. I am learning to apply grouping like in SQL query but I think the one I did is not the right approach.
It would be great if someone can suggest ideas as to how to proceed or group data further. If my whole idea of doing it is wrong then someone please tell me the way to do it.

Thank you.

What I have tried:

JavaScript
d3.csv("data/data2.csv", function(data1) {
                 var workStation = d3.nest()
                 .key(function(d) { return d.WorkStation_Id; })
                 .key(function(d) { return d.Order_Id; })
                 .key(function(d) { return d.ScheduledTime; })
                 .rollup(function(v) {
                    return d3.sum(v, function(d) { return d.Duration; });
                }).entries(data1);
       });

I tried to access each key value pair like the code I found online but this is not the result I am looking for:

JavaScript
    var workStation= {
       "name": "World",
       "children": workStation.values.map(function (workStation_Id) {

       return {
           "name": workStation.key,
           "children": workStation.values.map(function (Order_Id) {

              return {
                "name": Order.key,
                "children": Order.values.map(function (ScheduledTime) {

                    return {
                        "name": ScheduledTime.key,
                        "size": ScheduledTime.values
                    };

                }) 
            };

        }) 
    };

}) 

}; 
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900