Skip to content

Commit ddbf87f

Browse files
Tguisnetflomonster
authored andcommitted
chartos: add condition in config
1 parent c4d4ecf commit ddbf87f

File tree

3 files changed

+32
-20
lines changed

3 files changed

+32
-20
lines changed

chartos/chartos.yml

+25-20
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,12 @@
2525
on_field: geographic
2626
cache_duration: 3600
2727
data_expr: signal.data
28-
exclude_fields: [geo, sch]
2928
joins:
3029
- inner join osrd_infra_signalmodel signal on signal.obj_id = layer.obj_id and signal.infra_id = layer.infra_id
3130
- name: sch
3231
on_field: schematic
3332
cache_duration: 3600
3433
data_expr: signal.data
35-
exclude_fields: [geo, sch]
3634
joins:
3735
- inner join osrd_infra_signalmodel signal on signal.obj_id = layer.obj_id and signal.infra_id = layer.infra_id
3836

@@ -44,16 +42,39 @@
4442
on_field: geographic
4543
cache_duration: 3600
4644
data_expr: speed_section.data
47-
exclude_fields: [geo, sch]
4845
joins:
4946
- inner join osrd_infra_speedsectionmodel speed_section on speed_section.obj_id = layer.obj_id and speed_section.infra_id = layer.infra_id
47+
where:
48+
- not (speed_section.data @? '$.extensions.lpv_sncf.z')
5049
- name: sch
5150
on_field: schematic
5251
cache_duration: 3600
5352
data_expr: speed_section.data
54-
exclude_fields: [geo, sch]
5553
joins:
5654
- inner join osrd_infra_speedsectionmodel speed_section on speed_section.obj_id = layer.obj_id and speed_section.infra_id = layer.infra_id
55+
where:
56+
- not (speed_section.data @? '$.extensions.lpv_sncf.z')
57+
58+
- name: lpv
59+
table_name: osrd_infra_speedsectionlayer
60+
id_field: id
61+
views:
62+
- name: geo
63+
on_field: geographic
64+
cache_duration: 3600
65+
data_expr: speed_section.data
66+
joins:
67+
- inner join osrd_infra_speedsectionmodel speed_section on speed_section.obj_id = layer.obj_id and speed_section.infra_id = layer.infra_id
68+
where:
69+
- speed_section.data @? '$.extensions.lpv_sncf.z'
70+
- name: sch
71+
on_field: schematic
72+
cache_duration: 3600
73+
data_expr: speed_section.data
74+
joins:
75+
- inner join osrd_infra_speedsectionmodel speed_section on speed_section.obj_id = layer.obj_id and speed_section.infra_id = layer.infra_id
76+
where:
77+
- speed_section.data @? '$.extensions.lpv_sncf.z'
5778

5879
- name: track_section_links
5980
table_name: osrd_infra_tracksectionlinklayer
@@ -63,14 +84,12 @@
6384
on_field: geographic
6485
cache_duration: 3600
6586
data_expr: track_section_link.data
66-
exclude_fields: [geo, sch]
6787
joins:
6888
- inner join osrd_infra_tracksectionlinkmodel track_section_link on track_section_link.obj_id = layer.obj_id and track_section_link.infra_id = layer.infra_id
6989
- name: sch
7090
on_field: schematic
7191
cache_duration: 3600
7292
data_expr: track_section_link.data
73-
exclude_fields: [geo, sch]
7493
joins:
7594
- inner join osrd_infra_tracksectionlinkmodel track_section_link on track_section_link.obj_id = layer.obj_id and track_section_link.infra_id = layer.infra_id
7695

@@ -82,14 +101,12 @@
82101
on_field: geographic
83102
cache_duration: 3600
84103
data_expr: switch.data
85-
exclude_fields: [geo, sch]
86104
joins:
87105
- inner join osrd_infra_switchmodel switch on switch.obj_id = layer.obj_id and switch.infra_id = layer.infra_id
88106
- name: sch
89107
on_field: schematic
90108
cache_duration: 3600
91109
data_expr: switch.data
92-
exclude_fields: [geo, sch]
93110
joins:
94111
- inner join osrd_infra_switchmodel switch on switch.obj_id = layer.obj_id and switch.infra_id = layer.infra_id
95112

@@ -101,14 +118,12 @@
101118
on_field: geographic
102119
cache_duration: 3600
103120
data_expr: detector.data
104-
exclude_fields: [geo, sch]
105121
joins:
106122
- inner join osrd_infra_detectormodel detector on detector.obj_id = layer.obj_id and detector.infra_id = layer.infra_id
107123
- name: sch
108124
on_field: schematic
109125
cache_duration: 3600
110126
data_expr: detector.data
111-
exclude_fields: [geo, sch]
112127
joins:
113128
- inner join osrd_infra_detectormodel detector on detector.obj_id = layer.obj_id and detector.infra_id = layer.infra_id
114129

@@ -120,14 +135,12 @@
120135
on_field: geographic
121136
cache_duration: 3600
122137
data_expr: buffer_stop.data
123-
exclude_fields: [geo, sch]
124138
joins:
125139
- inner join osrd_infra_bufferstopmodel buffer_stop on buffer_stop.obj_id = layer.obj_id and buffer_stop.infra_id = layer.infra_id
126140
- name: sch
127141
on_field: schematic
128142
cache_duration: 3600
129143
data_expr: buffer_stop.data
130-
exclude_fields: [geo, sch]
131144
joins:
132145
- inner join osrd_infra_bufferstopmodel buffer_stop on buffer_stop.obj_id = layer.obj_id and buffer_stop.infra_id = layer.infra_id
133146

@@ -139,14 +152,12 @@
139152
on_field: geographic
140153
cache_duration: 3600
141154
data_expr: route.data
142-
exclude_fields: [geo, sch]
143155
joins:
144156
- inner join osrd_infra_routemodel route on route.obj_id = layer.obj_id and route.infra_id = layer.infra_id
145157
- name: sch
146158
on_field: schematic
147159
cache_duration: 3600
148160
data_expr: route.data
149-
exclude_fields: [geo, sch]
150161
joins:
151162
- inner join osrd_infra_routemodel route on route.obj_id = layer.obj_id and route.infra_id = layer.infra_id
152163

@@ -158,14 +169,12 @@
158169
on_field: geographic
159170
cache_duration: 3600
160171
data_expr: operational_point.data
161-
exclude_fields: [geo, sch]
162172
joins:
163173
- inner join osrd_infra_operationalpointmodel operational_point on operational_point.obj_id = layer.obj_id and operational_point.infra_id = layer.infra_id
164174
- name: sch
165175
on_field: schematic
166176
cache_duration: 3600
167177
data_expr: operational_point.data
168-
exclude_fields: [geo, sch]
169178
joins:
170179
- inner join osrd_infra_operationalpointmodel operational_point on operational_point.obj_id = layer.obj_id and operational_point.infra_id = layer.infra_id
171180

@@ -177,14 +186,12 @@
177186
on_field: geographic
178187
cache_duration: 3600
179188
data_expr: catenary.data
180-
exclude_fields: [geo, sch]
181189
joins:
182190
- inner join osrd_infra_catenarymodel catenary on catenary.obj_id = layer.obj_id and catenary.infra_id = layer.infra_id
183191
- name: sch
184192
on_field: schematic
185193
cache_duration: 3600
186194
data_expr: catenary.data
187-
exclude_fields: [geo, sch]
188195
joins:
189196
- inner join osrd_infra_catenarymodel catenary on catenary.obj_id = layer.obj_id and catenary.infra_id = layer.infra_id
190197

@@ -196,9 +203,7 @@
196203
on_field: geographic
197204
cache_duration: 3600
198205
data_expr: layer.information
199-
exclude_fields: [geo, sch]
200206
- name: sch
201207
on_field: schematic
202208
cache_duration: 3600
203209
data_expr: layer.information
204-
exclude_fields: [geo, sch]

chartos/chartos/config.py

+2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ class View:
2727
exclude_fields: List[str] = field(compare=False)
2828
joins: List[JoinExpr] = field(compare=False)
2929
cache_duration: int = field(compare=False)
30+
where: List[str] = field(compare=False)
3031

3132
@staticmethod
3233
def parse(data):
@@ -37,6 +38,7 @@ def parse(data):
3738
data.get("exclude_fields", []),
3839
data.get("joins", []),
3940
data["cache_duration"],
41+
data.get("where", []),
4042
)
4143

4244
def todict(self):

chartos/chartos/views.py

+5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import json
22
from collections import defaultdict
3+
from functools import reduce
34
from typing import Any, Dict, List, Mapping, NewType, Tuple
45

56
from asyncpg import Connection
@@ -141,6 +142,8 @@ async def mvt_query(psql, layer, infra, view: View, z: int, x: int, y: int) -> b
141142
f"{' '.join(view.joins)} "
142143
# filter by infra
143144
f"WHERE layer.infra_id = $4 "
145+
# Where view conditions
146+
f"{reduce(lambda base, cond: f'{base} AND ({cond}) ', view.where, '')}"
144147
# we only want objects which are inside the tile BBox
145148
f"AND {view.on_field} && bbox.geom "
146149
# exclude geometry collections
@@ -287,6 +290,8 @@ async def get_objects_in_bbox(
287290
f"{' '.join(view.joins)} "
288291
# Filter by infra
289292
"WHERE layer.infra_id = $1 "
293+
# Where view conditions
294+
f"{reduce(lambda base, cond: f'{base} AND ({cond}) ', view.where, '')}"
290295
# Filter by objects inside the bounding box
291296
f"AND layer.{view.on_field} && ST_Transform(ST_MakeEnvelope($2, $3, $4, $5, 4326), 3857)"
292297
)

0 commit comments

Comments
 (0)