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

v.category: add JSON support #4020

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

kritibirda26
Copy link
Contributor

Add JSON support to v.category module. The JSON output looks like this:

[
    {
        "type": "line",
        "field": 1,
        "count": 1379,
        "min": 1,
        "max": 1379
    },
    {
        "type": "all",
        "field": 1,
        "count": 1379,
        "min": 1,
        "max": 1379
    }
]

@github-actions github-actions bot added vector Related to vector data processing Python Related code is in Python C Related code is in C HTML Related code is in HTML module docs tests Related to Test Suite labels Jul 10, 2024
@echoix echoix changed the title v.category: add json support v.category: add JSON support Jul 10, 2024
Copy link
Contributor

@cwhite911 cwhite911 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kritibirda26 let's change the output when the action parameter is set to print to return json. The action=print description is the the following

print category values, layers are separated by '|', more cats in the same layer are separated by '/'

Here is a proposed data schema.

{
    "categories": [
          {
                "cat": 1,
                "layers": [
                         {
                              "id": 1,
                              "additional_cats": []
                         }
                   ],
          }
     ]
}

@kritibirda26
Copy link
Contributor Author

@cwhite911 should I use cat as key name or category? I have used category in r.category module.

@kritibirda26
Copy link
Contributor Author

@cwhite911 I think that format would be wrong because / represent additional categories in the same layer, not different layers. Also, for the cat value, which category value should be assigned to it? The first category value of the first layer?

{
  "layers": [
     {
        "layer": 1,
        "categories": [
                {
                      "cat": 1,
                      "additional_cats": [2, 3] 
                }
        ],
     }
  ]
}

What do you think?

@echoix
Copy link
Member

echoix commented Jul 31, 2024

Is the cat key used uniformly across the JSON PRs (vs category)?

@kritibirda26
Copy link
Contributor Author

IIRC it is cat except for 1 PR.

"v.category", input="bridges", option="report", format="json"
)
self.assertListEqual(expected, json.loads(output))

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The option print does not respect the format. Add a test case for option="print", format="json".

It can return an array of category numbers.

{
   "categories": [1,2,3,4,5,..]
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same should be done when the option is set to layers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C Related code is in C docs HTML Related code is in HTML module Python Related code is in Python tests Related to Test Suite vector Related to vector data processing
Projects
Status: In Progress
Development

Successfully merging this pull request may close these issues.

3 participants