grass icon indicating copy to clipboard operation
grass copied to clipboard

r.stats: add JSON output

Open kritibirda opened this issue 1 year ago • 8 comments

Using parson, add JSON output support to r.stats module.

For cell stats, the output looks like:

[
    {
        "labels": [
            {
                "value": 1,
                "label": "CARY",
                "name": "towns"
            },
            {
                "value": 55,
                "label": "",
                "name": "urban"
            }
        ],
        "area": 23475900,
        "count": 234759,
        "percent": 11.651235678463038
    },
    {
        "labels": [
            {
                "value": 2,
                "label": "GARNER",
                "name": "towns"
            },
            {
                "value": 55,
                "label": "",
                "name": "urban"
            }
        ],
        "area": 14142700,
        "count": 141427,
        "percent": 7.0191102718021128
    },
    {
        "labels": [
            {
                "value": 3,
                "label": "APEX",
                "name": "towns"
            },
            {
                "value": 55,
                "label": "",
                "name": "urban"
            }
        ],
        "area": 1519700,
        "count": 15197,
        "percent": 0.75423659414805311
    }
]

For raw stats, the output looks like:

[
    {
        "easting": 639315,
        "northing": 228495,
        "col": 932,
        "row": 1,
        "labels": [
            {
                "value": 6,
                "label": "RALEIGH-WEST",
                "name": "towns"
            },
            {
                "value": 55,
                "label": "",
                "name": "urban"
            }
        ]
    },
    {
        "easting": 639325,
        "northing": 228495,
        "col": 933,
        "row": 1,
        "labels": [
            {
                "value": 6,
                "label": "RALEIGH-WEST",
                "name": "towns"
            },
            {
                "value": 55,
                "label": "",
                "name": "urban"
            }
        ]
    }
]

The labels array has the numerical value, categorical name, and the name of the inputs associated with the stat. I am unsure if these fields can be named better.

Once the JSON format is decided, I will add tests and update the documentation as well.

kritibirda avatar Jun 18 '24 10:06 kritibirda

@kritibirda26 let's pick up on r.report first ( PR: https://github.com/OSGeo/grass/pull/3033) before starting on r.stats. It should be simpler and will help figure out how to address r.stats.

cwhite911 avatar Jun 18 '24 14:06 cwhite911

Makes sense @cwhite911

kritibirda avatar Jun 18 '24 16:06 kritibirda

I have added a comment on the r.report PR to discuss the schema further.

kritibirda avatar Jun 18 '24 16:06 kritibirda

Welcome to Codecov :tada:

Once you merge this PR into your default branch, you're all set! Codecov will compare coverage reports and display results in all future pull requests.

Thanks for integrating Codecov - We've got you covered :open_umbrella:

codecov[bot] avatar Jun 28 '24 16:06 codecov[bot]

The codecov shouldn't be sending comments, it was explicitly disabled in config. Is it because the branch doesn't include the config file (not enough updated from main)?

echoix avatar Jun 28 '24 16:06 echoix

Seems like it was the case..

echoix avatar Jun 28 '24 16:06 echoix

@cwhite911 The PR is ready for review.

kritibirda avatar Aug 13 '24 10:08 kritibirda

Before merging, can you make sure that your PRs are either formatted according to clang format 18 (changed 2 days ago), or merged from main?

echoix avatar Aug 16 '24 10:08 echoix

Solved conflicts. Also renamed the test folder so it can be collected by gunittest

echoix avatar Dec 12 '24 01:12 echoix