2

I am trying to visualize a flickr dataset using protovis. I do understand the visualization part, but i have a question about accessing the data however. I was provided an example visualization and it accesses the data as folllowing:

var data = pv.range(250).map(function(row) {
    return {
        views: parseInt(Data.data(row, 2)), //refers to the 4 row and 2nd collumn in CSV
        users: Data.data(row, 6),
        date:  Data.data(row, 8))), //more collumns excist but for now we only use these
     };
  });

As i understand a part of the data set is now stored in the variable data, namely views, users and date. Is this variable able to beaccessed like a dictionary?

What i am trying to do is checking whether there are date on which one user occurs more than 2 times. I thought of looping through the var data as follows:

dateUserDict {};

for (d=0; d < data.date.length; d++ ){
    for (i=0; i < data.users.length; i++ ){
        for (j=0; j < data.users.length; j++){
            if (data.users[i] == data.users[j]){
                userCounter++ //this should count the number of occurences of a specific user on a specific date
                dateUserDict[data.date] = [data.user][userCounter]}
        }
    }
}

This does not seem to work. I am trying to store the events (the number of times a user occurs on a specific date) in a dictionary. If i get the dictionary as described i can easily visualise the whole thing. But it is this conversion from the first dict (data) to the second (dateUserDict) which bugs me!

Any help or a push is highly appreciated!

Thanks

jorrit

1 Answer 1

1

The function you provided will product a Javascript array of objects.

var data = pv.range(250).map(function(row) {
  return {
    views: parseInt(Data.data(row, 2)), //refers to the 4 row and 2nd collumn in CSV
    users: Data.data(row, 6),
    date:  Data.data(row, 8))), //more collumns excist but for now we only use these
  };
});

The result will look something like this:

var data = [ {views:10, users: 9, date: '09/13/1975'}, ... ]

So instead of using data.users.length, use data.length, and instead of data.users[i], you should be using data[i].users, etc.

1
  • sorry for the late reaction, but you're right. 2d objects always confuse me ;)
    – jorrebor
    Jul 7, 2011 at 21:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.