Click here to Skip to main content
15,881,898 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.
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