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

pydantic models for input and output? #39

Open
hklarner opened this issue Jan 25, 2022 · 5 comments
Open

pydantic models for input and output? #39

hklarner opened this issue Jan 25, 2022 · 5 comments
Labels
enhancement New feature or request

Comments

@hklarner
Copy link

Is there a place somewhere to keep pydantic models of vroom input and output? I need them anyways so I thought I could share them. Looks something like this:

from pydantic import BaseModel


class Vehicle(BaseModel):
    id: int

    profile: Optional[str] = None
    description: Optional[str] = None
    start_index: Optional[int] = None
    end_index: Optional[int] = None
    capacity: Optional[Tuple[int]] = None
    skills: Optional[Tuple[int]] = None
    time_window: Optional[Tuple[int, int]] = None  # timestamp or relative seconds
    max_tasks: Optional[int] = None


class Matrix(BaseModel):
    durations: List[List[int]]


class Job(BaseModel):
    id: int
    location_index: int

    description: Optional[str] = None
    service: Optional[int] = None


class VroomRequest(BaseModel):
    vehicles: List[Vehicle]
    matrices: Dict[str, Matrix]
    jobs: List[Job]
@jcoupey
Copy link
Contributor

jcoupey commented Jan 26, 2022

This does not really belong in the core C++ repo, but we have a WIP repo with python bindings. Best would be to sync with @jonathf over there.

@jonathf jonathf transferred this issue from VROOM-Project/vroom Jan 26, 2022
@jonathf
Copy link
Collaborator

jonathf commented Jan 26, 2022

Hello @hklarner,

I'm going to assume that the idea here is to do validation against the JSON input and output.

Specially for input, that would be quite useful, as it can give much better client side validation even if the execution is server side.

Not that it is a huge jub, but I haven't gotten around to porting JSON I/O to the Python interface. But when I do, adding something like this is a good idea.

I'll keep this issue open for when I get to to that task.

Related to: #5.

@jonathf jonathf added the enhancement New feature or request label Jan 26, 2022
@hklarner
Copy link
Author

Hi @jonathf
yes, I use the input model for validation but I also use them for code completion in the IDE and as a schema. I am testing VROOM as a service inside an existing project so I have to generate the vroom input and also convert the vroom output into my own output.

@hklarner
Copy link
Author

hklarner commented Jan 26, 2022

Eventually, of course, I can use pyvroom instead of having vroom-express running ..

@jonathf
Copy link
Collaborator

jonathf commented Jan 26, 2022

Yeah, sounds like you would benefit a lot from the python interface.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants