I have been trying to calculate the "top keyword movers". For example, the following documents in a date range from 2013-12-19 to 2013-12-23:
{
"domain" : "www.mytestingdomain.com",
"keyword" : "elegant",
"google_rank" : 10,
"date" : ISODate("2013-12-19T00:00:00Z")
}
{
"domain" : "www.mytestingdomain.com",
"keyword" : "elegant",
"google_rank" : 5,
"date" : ISODate("2013-12-20T00:00:00Z")
}
{
"domain" : "www.mytestingdomain.com",
"keyword" : "elegant",
"google_rank" : 1,
"date" : ISODate("2013-12-21T00:00:00Z")
}
{
"domain" : "www.mytestingdomain.com",
"keyword" : "elegant",
"google_rank" : 5,
"date" : ISODate("2013-12-22T00:00:00Z")
}
{
"domain" : "www.mytestingdomain.com",
"keyword" : "elegant",
"google_rank" : 1,
"date" : ISODate("2013-12-23T00:00:00Z")
}
Displays how a particular keyword "elegant" has moved in this specific date range.
My question (Using Mongo Aggregate framework):
There is a way to calculate this movements? For example:
10 - 5 = 5
5 - 1 = 4
1 - 5 = -4 --> abs --> 4
5 - 1 = 4
---------------------------
absolute total: 5 + 4 + 4 + 4 = 17 --> in this case "seventeen" is the absolute sum of moves that I am looking for.