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

api: railjson V3 #1933

Merged
merged 13 commits into from
Oct 4, 2022
Merged
9 changes: 7 additions & 2 deletions .github/workflows/integration_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ jobs:
- name: Checkout
uses: actions/checkout@v3

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.9"
cache: pip
- run: pip install geojson-pydantic requests

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

Expand All @@ -35,7 +42,5 @@ jobs:
DOCKER_BUILDKIT: 1
COMPOSE_DOCKER_CLI_BUILD: 1

- run: pip install -r core/examples/generated/lib/requirements.txt

- name: Run tests
run: "python3 tests/run_integration_tests.py"
6 changes: 2 additions & 4 deletions api/osrd_infra/management/commands/setup_dummy_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def handle(self, *args, **options):
bf = BufferStop(
id=f"bf.{position}",
applicable_directions=ApplicableDirections.BOTH,
track=track_section.ref(),
track=track_section.id,
position=position,
geo=Point(coordinates=(position, position)),
sch=Point(coordinates=(position, position)),
Expand All @@ -67,9 +67,7 @@ def handle(self, *args, **options):
entry_point=waypoints[0].ref(),
exit_point=waypoints[1].ref(),
release_detectors=[],
path=[
DirectionalTrackRange(track=track_section.ref(), begin=0, end=1000, direction=Direction.START_TO_STOP)
],
path=[DirectionalTrackRange(track=track_section.id, begin=0, end=1000, direction=Direction.START_TO_STOP)],
geo=LineString(coordinates=[(0, 0), (1, 1)]),
sch=LineString(coordinates=[(0, 0), (1, 1)]),
)
Expand Down
26 changes: 26 additions & 0 deletions api/osrd_infra/migrations/0006_railjson_v3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Generated by Django 4.0.7 on 2022-10-04 10:56

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('osrd_infra', '0005_rollingstock_add_electrification'),
]

operations = [
migrations.RemoveField(
model_name='errorlayer',
name='obj_id',
),
migrations.RemoveField(
model_name='errorlayer',
name='obj_type',
),
migrations.AlterField(
model_name='infra',
name='railjson_version',
field=models.CharField(default='3.0.0', editable=False, max_length=16),
),
]
2 changes: 0 additions & 2 deletions api/osrd_infra/models/generated.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
class ErrorLayer(models.Model):
OBJ_TYPE_CHOICES = [(obj_type.__name__, obj_type.__name__) for obj_type in ALL_OBJECT_TYPES]
infra = models.ForeignKey("Infra", on_delete=models.CASCADE)
obj_type = models.CharField(max_length=32, choices=OBJ_TYPE_CHOICES)
obj_id = models.CharField(max_length=255)
geographic = models.GeometryField(srid=settings.MAPBOX_SRID, null=True)
schematic = models.GeometryField(srid=settings.MAPBOX_SRID, null=True)
information = models.JSONField(validators=[PydanticValidator(InfraError)])
Expand Down
6 changes: 3 additions & 3 deletions api/osrd_infra/models/path.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,17 @@ def get_initial_location(self):
path = self.payload["route_paths"]
track_range = path[0]["track_sections"][0]
return {
"track_section": track_range["track"]["id"],
"track_section": track_range["track"],
"offset": track_range["begin"],
}

def get_end_location(self):
path = self.payload["route_paths"]
track_range = path[-1]["track_sections"][-1]
return {
"track_section": track_range["track"]["id"],
"track_section": track_range["track"],
"offset": track_range["end"],
}

def get_initial_route(self):
return self.payload["route_paths"][0]["route"]["id"]
return self.payload["route_paths"][0]["route"]
34 changes: 22 additions & 12 deletions api/osrd_infra/schemas/generated.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,34 @@
from typing import Literal, Tuple, Union
from typing import Annotated, Literal, Tuple, Union

from pydantic import BaseModel, Field
from pydantic import BaseModel, Field, constr

from osrd_infra.schemas import infra
from osrd_infra.schemas.infra import Identifier


class ObjectReference(BaseModel):
id: Identifier = Field(description="Identifier of the referenced object")
type: str = Field(description="Type of the attribute of the referenced object")


# TRAITS
class InfraErrorTrait(BaseModel):
is_warning: Literal[False] = Field(default=False)
field: str
obj_id: constr(max_length=255) = Field(description="Identifier of the object that caused the error")
obj_type: constr(max_length=32) = Field(description="Type of the object that caused the error")
field: constr(max_length=255) = Field(description="Field of the object that caused the error")


class InfraWarningTrait(BaseModel):
is_warning: Literal[True] = Field(default=True)
field: str
obj_id: constr(max_length=255) = Field(description="Identifier of the object that caused the warning")
obj_type: constr(max_length=32) = Field(description="Type of the object that caused the warning")
field: constr(max_length=255) = Field(description="Field of the object that caused the warning")


# Errors
class InvalidReference(InfraErrorTrait):
error_type: Literal["invalid_reference"] = Field(default="invalid_reference")
reference: infra.ObjectReference
reference: ObjectReference


class OutOfRange(InfraErrorTrait):
Expand Down Expand Up @@ -56,7 +65,7 @@ class InvalidSwitchPorts(InfraErrorTrait):

class OverlappingSwitches(InfraErrorTrait):
error_type: Literal["overlapping_switches"] = Field(default="overlapping_switches")
reference: infra.ObjectReference
reference: ObjectReference


# Warnings
Expand Down Expand Up @@ -84,12 +93,11 @@ class NoBufferStop(InfraWarningTrait):

class OverlappingTrackLinks(InfraWarningTrait):
error_type: Literal["overlapping_track_links"] = Field(default="overlapping_track_links")
reference: infra.ObjectReference
reference: ObjectReference


# Generic error
class InfraError(BaseModel):
__root__: Union[
InfraError = Annotated[
Union[
InvalidReference,
OutOfRange,
ObjectOutsideOfPath,
Expand All @@ -104,4 +112,6 @@ class InfraError(BaseModel):
NoBufferStop,
OverlappingSwitches,
OverlappingTrackLinks,
] = Field(discriminator="error_type")
],
Field(discriminator="error_type"),
]
Loading