Working with data


#1

I have a data file containing contributions of users per day. Its like this:

contributions:
- date: 2018.01.01
  user: user1
  contribution: .01
- date: 2018.01.01
  user: user2
  contribution: .02
- date: 2018.01.02
  user: user1
  contribution: .01
- date: 2018.01.02
  user: user2
  contribution: .03
- date: 2018.01.03
  user: user3
  contribution: .03
- date: 2018.01.03
  user: user4
  contribution: .02

Now I want to sum all contributions of each user and sort them and show some of the most active users. I want to do this all with liquid tags however I am a little confused and cant figure it out. Can someone expert with data files help me?


#2

do you know the number of users? are they the same? just a few of them?

it looks like a lot of work no matter what, I don’t have any help for you unfortunately, but you could also output that file as json and work with it in JS instead of liquid, that is probably where I would start - I would think this type of thing would be easier in JS than liquid.


#3

I think my confusion is because of the lack of supporting associative arrays in liquid language. Am I right? If it was supported, it would have been very easy to do this job. I may go for a plugin to do this. I don’t want to do it with js.


#4

If you use group_by you can group on the user field and then could calculate the sum by iterating that way for each user but I cannot think of how best to order that newly calculated information so that you can output the top users.

How are you generating this contributions data file anyways?