Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Average Age of date objects #81

Closed
TuSKan opened this issue Dec 5, 2018 · 2 comments
Closed

Average Age of date objects #81

TuSKan opened this issue Dec 5, 2018 · 2 comments

Comments

@TuSKan
Copy link

TuSKan commented Dec 5, 2018

Hello,
In my problem I need to compute the average age of a sub population.

{  
    "peoples":[  
        {  
            "name":"Kelly Robertson",
            "birthDate":"1980-05-11 04:22:33"
        },
        {  
            "name":"Trevin Haley",
            "birthDate":"1985-09-12 12:03:10"
        }
    ]
}

It works for

avg(age(dateTime($.peoples.birthDate.*[1],'%Y-%m-%d %H:%M:%S')))

but not for all elements

avg(age(dateTime($.peoples.birthDate,'%Y-%m-%d %H:%M:%S')))
@adriank
Copy link
Owner

adriank commented Dec 5, 2018 via email

@TuSKan
Copy link
Author

TuSKan commented Dec 6, 2018

It could be this way ?

avg(age(map(dateTime, $.peoples.birthDate, args = '%Y-%m-%d %H:%M:%S')))

A map function could be very helpful.
Could implement map as:

def map(f, array, args = None):
    return map(lambda x: f(x, args), array)

TuSKan added a commit to TuSKan/ObjectPath that referenced this issue Dec 19, 2018
@adriank adriank closed this as completed Aug 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants