Skip to content

Feature/multi stats #24

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

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 20 additions & 23 deletions obs/face/geojson/ExportRoadAnnotations.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,26 @@ def add_measurements(self, measurements):
for sample in measurements:
self.n_samples += 1
# filter measurements
if not ("OSM_way_id" in sample):
continue;
way_id = sample["OSM_way_id"]
way_orientation = 1 if sample["OSM_way_orientation"] == -1 else 0

if sample["latitude"] is None or sample["longitude"] is None or sample["distance_overtaker"] is None \
or self.only_confirmed_measurements and (sample["confirmed"] is not True) \
or not sample["has_OSM_annotations"]:
if not (way_id in self.way_statistics):
way = self.map_source.get_way_by_id(way_id)
if way:
self.way_statistics[way_id] = WayStatistics(way_id, way)
if way_id in self.way_statistics and sample["speed"] != 0:
self.way_statistics[way_id].n_ticks[way_orientation] += 1

continue

self.n_valid += 1

way_id = sample["OSM_way_id"]
value = sample["distance_overtaker"]
way_orientation = sample["OSM_way_orientation"]

self.map_source.ensure_coverage([sample["latitude"]], [sample["longitude"]])

Expand All @@ -68,13 +78,15 @@ def add_measurements(self, measurements):
self.n_grouped += 1
else:
logging.warning("way not found in map")
self.way_statistics[way_id].n_ticks[way_orientation] += 1

def finalize(self):
log.info("%s samples, %s valid", self.n_samples, self.n_valid)
features = []
for way_stats in self.way_statistics.values():
way_stats.finalize()
if not any(way_stats.valid):
# if not any(way_stats.valid):
if not any(way_stats.n_ticks):
continue

for i in range(1 if way_stats.oneway else 2):
Expand All @@ -91,19 +103,14 @@ def finalize(self):
coordinates = []

feature = {"type": "Feature",
"properties": {"distance_overtaker_mean": way_stats.d_mean[i],
"distance_overtaker_median": way_stats.d_median[i],
"distance_overtaker_minimum": way_stats.d_minimum[i],
"distance_overtaker_n": way_stats.n[i],
"distance_overtaker_n_below_limit": way_stats.n_lt_limit[i],
"distance_overtaker_n_above_limit": way_stats.n_geq_limit[i],
"distance_overtaker_limit": way_stats.d_limit,
"distance_overtaker_measurements": way_stats.samples[i],
"properties": {"distance_overtaker_limit": way_stats.d_limit,
"distance_overtaker_measurements": sorted(way_stats.samples[i], key = float),
"zone": way_stats.zone,
"direction": direction,
"name": way_stats.name,
"way_id": way_stats.way_id,
"valid": way_stats.valid[i],
"ticks": way_stats.n_ticks[i],
},
"geometry": {"type": "LineString", "coordinates": coordinates}}

Expand All @@ -124,12 +131,10 @@ def __init__(self, way_id, way):
self.n = [0, 0]
self.n_lt_limit = [0, 0]
self.n_geq_limit = [0, 0]
self.n_ticks = [0, 0]

self.way_id = way_id
self.valid = [False, False]
self.d_mean = [0, 0]
self.d_median = [0, 0]
self.d_minimum = [0, 0]

self.zone = "unknown"
self.oneway = False
Expand All @@ -156,19 +161,11 @@ def __init__(self, way_id, way):

def add_sample(self, sample, orientation):
if np.isfinite(sample):
i = 1 if orientation == -1 else 0
self.samples[i].append(sample)
self.samples[orientation].append(sample)
return self

def finalize(self):
for i in range(2):
samples = np.array(self.samples[i])
if len(samples) > 0:
self.n[i] = len(samples)
self.d_mean[i] = np.mean(samples)
self.d_median[i] = np.median(samples)
self.d_minimum[i] = np.min(samples)
if self.d_limit is not None:
self.n_lt_limit[i] = int((samples < self.d_limit).sum())
self.n_geq_limit[i] = int((samples >= self.d_limit).sum())
self.valid[i] = True
7 changes: 4 additions & 3 deletions obs/face/osm/DataSource.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,10 @@ def add_tile(self, tile):
# add way objects, and store
for way_id, way in ways.items():
if way_id not in self.ways:
w = Way(way_id, way, nodes)
self.ways[way_id] = w
self.way_container.insert(w)
w = Way.create(way_id, way, nodes, 100)
self.ways.update(w)
for id in w:
self.way_container.insert(w[id])

# update tile list
self.loaded_tiles.append(tile)
Expand Down
41 changes: 38 additions & 3 deletions obs/face/osm/Way.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@


class Way:
def __init__(self, way_id, way, all_nodes):
def __init__(self, way_id, way, nodes_way):
self.way_id = way_id

if "tags" in way:
Expand All @@ -13,8 +13,6 @@ def __init__(self, way_id, way, all_nodes):
self.tags = {}

# determine points
nodes_way = [all_nodes[i] for i in way["nodes"]]

lat = np.array([n["lat"] for n in nodes_way])
lon = np.array([n["lon"] for n in nodes_way])
self.points_lat_lon = np.stack((lat, lon), axis=1)
Expand All @@ -35,10 +33,47 @@ def __init__(self, way_id, way, all_nodes):
# direction
dx = np.diff(x)
dy = np.diff(y)
self.seg_length = np.hypot(dx, dy)
self.direction = np.arctan2(dy, dx)

self.directionality_bicycle, self.directionality_motorized = self.get_way_directionality(way)

@staticmethod
def create(way_id, way, all_nodes, max_len):
ways = {}
# determine points
nodes = [all_nodes[i] for i in way["nodes"]]
lat = np.array([n["lat"] for n in nodes])
lon = np.array([n["lon"] for n in nodes])

# bounding box
a = (min(lat), min(lon))
b = (max(lat), max(lon))

# define the local map around the center of the bounding box
lat_0 = (a[0] + b[0]) * 0.5
lon_0 = (a[1] + b[1]) * 0.5
local_map = LocalMap(lat_0, lon_0)
x, y = local_map.transfer_to(lat, lon)
dx = np.diff(x)
dy = np.diff(y)
seg_length = np.hypot(dx, dy)

slen = 0
first = 0
if len(dx) > 0:
for i in range(len(seg_length)):
slen += seg_length[i]
if (slen > max_len and i != first):
id = str(way_id)+'.'+str(i)
ways[id] = Way(id, way, nodes[first:i+1])
first = i
slen = 0
id = str(way_id)
ways[id] = Way(id, way, nodes[first:])
return ways


def get_axis_aligned_bounding_box(self):
return self.a, self.b

Expand Down
11 changes: 6 additions & 5 deletions visualization/OBS.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,11 +172,12 @@ class Palette {

paletteUrban = new Palette(
{
0.0: [64, 0, 0, 255],
1.4999: [196, 0, 0, 255],
1.5: [196, 196, 0, 255],
2.0: [0, 196, 0, 255],
2.55: [0, 255, 0, 255],
0.0: [196, 0, 0, 255],
0.8: [196, 0, 0, 255],
1.3: [245, 141, 0, 255],
1.5: [94, 188, 7, 255],
2.0: [94, 188, 7, 255],
2.55: [0, 196, 0, 255],
},
[0, 0, 196, 255]
)
Expand Down
122 changes: 67 additions & 55 deletions visualization/measurements.html
Original file line number Diff line number Diff line change
Expand Up @@ -104,43 +104,39 @@ <h4>Visualisierung: Messwerte </h4>
<div id="caption" class="caption">
<b>Bitte einen Messpunkt in der Karte (farbige Kreise) anklicken um detailierte Informationen zu erhalten.</b>
</div>
<div id="legend" class="legend">
<b>Kartenlegende</b><br>
Ring um Messung: <font color="#FFFF00">au&szlig;erorts</a>, <font color="#0000FF">innerorts</a>, <font color="#000000">unbekannt</a>
<br>
Fläche innerhalb kodiert den &Uuml;berholabstand:
<div id="legend_rural" class="legend_rural">&Uuml;berholabstand außerorts<br></div>
<div id="legend_urban" class="legend_urban">&Uuml;berholabstand innerorts<br></div>
</div>
<div class="legend">
<b>Filter</b><br/>
<input id='filter' size='30'/>
</div>
</div>

<script type="text/javascript">

var displayFilter = [];
function annotation(feature){
var s = "<table>";

d = feature.get('distance_overtaker');
s += "<td><b>&Uuml;berholabstand:</b></td><td><b>" + ((d == null)?"n/a":d.toFixed(2)) + " m</b></td></tr>";
s += "<td><div title='distance_overtaker'>&Uuml;berholabstand:</div></td><td><b>" + ((d == null)?"n/a":d.toFixed(2)) + " m</b></td></tr>";
s += "<tr><td>Zeit/Datum der Messung:</td><td>" + feature.get('time') + "</td></tr>";

s += "<tr><td>Benutzer (pseudonymisiert):</td><td>" + feature.get('user_id') + "</td></tr>";
s += "<tr><td><div title='user_id'>Benutzer (pseudonymisiert):</div></td><td>" + feature.get('user_id') + "</td></tr>";
s += "<tr><td>Messungs-ID (pseudonymisiert):</td><td>" + feature.get('measurement_id') + "</td></tr>";

if (feature.get('has_OSM_annotations') == true){
s += "<tr><td>Position der Messung (korrigiert):</td><td>" + feature.get('latitude_projected').toFixed(6) + " " + feature.get('longitude_projected').toFixed(6) + "</td></tr>";
}
s += "<tr><td>Position der Messung (GPS):</td><td>" + feature.get('latitude_GPS').toFixed(6) + " " + feature.get('longitude_GPS').toFixed(6) + "</td></tr>";
s += "<tr><td>Position der Messung (GPS):</td><td>" + feature.get('latitude_GPS') + " " + feature.get('longitude_GPS') + "</td></tr>";

d = feature.get('distance_stationary');
s += "<tr><td>Abstand nach rechts:</td><td>" + ((d == null)?"n/a":d.toFixed(2)) + " m </td></tr>";
s += "<tr><td><div title='distance_stationary'>Abstand nach rechts:</div></td><td>" + ((d == null)?"n/a":d.toFixed(2)) + " m </td></tr>";

s += "<tr><td>"
s += "<tr><td><div title='speed'>"
if (feature.get("egomotion_is_derived") == true){
s += "Eigenbewegung (aus Pos. berechnet)";
} else {
s += "Eigenbewegung (von GPS)";
}
s += "</td><td>";
s += "</div></td><td>";
c = feature.get('course');
s += ((c == null)?"n/a":c.toFixed(0)) + " deg, ";

Expand Down Expand Up @@ -264,7 +260,7 @@ <h4>Visualisierung: Messwerte </h4>

var vectorLayer = new ol.layer.Vector({
source: dataSource,
style: function(feature, resolution){ return styleFunction(feature, resolution, false);}
style: function(feature, resolution){ return styleFunction(feature, resolution, 0);}
})

function styleFunction(feature, resolution, active) {
Expand All @@ -286,10 +282,13 @@ <h4>Visualisierung: Messwerte </h4>
}
}

var r = 5;
if (active < 0) r = 2;
if (active > 0) r = 10;

var style = new ol.style.Style({
image: new ol.style.Circle({
radius: active?10:5,
radius: r,
fill: new ol.style.Fill({color: color}),
stroke: stroke
})
Expand Down Expand Up @@ -337,7 +336,8 @@ <h4>Visualisierung: Messwerte </h4>
var f = new ol.Feature({
geometry: new ol.geom.LineString(
[p1, p2]
)
),
parent: feature
});
// f.setStyle(styles);
arrowLayer.getSource().addFeature(f);
Expand All @@ -354,47 +354,59 @@ <h4>Visualisierung: Messwerte </h4>

arrowLayer.setVisible(true);


function selectNode(feature) {
if (feature != null) {
var prop = feature.getProperties();
if (prop.hasOwnProperty('parent')) feature = prop.parent;
if (dataSource.hasFeature(feature)) {
var coord = feature.getGeometry().getCoordinates();
var props = feature.getProperties();
caption.innerHTML = annotation(feature);
caption.style.alignItems="flex-start";
console.log(annotation_verbose(feature));
feature.setStyle(styleFunction(feature, undefined, 1));
}
}
vectorLayer.getSource().getFeatures().forEach(f=>{
if (f != feature) {
var sel = 0;
if (displayFilter.length > 0) {
var val = f.get(displayFilter[0].key);
if (displayFilter[0].op == "==") {
if (displayFilter[0].val != val) sel = -1;
}
else {
var fval = val ? parseFloat(val) : 2; // map missing to 2m distance
var fcomp = parseFloat(displayFilter[0].val);
if (displayFilter[0].op == "<") { if (fval >= fcomp) sel = -1;}
else if (displayFilter[0].op == ">") { if (fval <= fcomp) sel = -1;}
}
}
f.setStyle(styleFunction(f, undefined, sel));
}
});
}

map.on('singleclick', function(evt) {
var feature = map.forEachFeatureAtPixel(evt.pixel, function(feature, layer) {
return feature;
});
if (feature && dataSource.hasFeature(feature)) {
var coord = feature.getGeometry().getCoordinates();
var props = feature.getProperties();
caption.innerHTML = annotation(feature);
caption.style.alignItems="flex-start";
console.log(annotation_verbose(feature));
}
});


// feature mouse hover handler
var noFeatureActive = false;

map.on('pointermove', function(evt) {
if (evt.dragging) {
return;
}
if (!noFeatureActive){
vectorLayer.getSource().getFeatures().forEach(f=>{
f.setStyle(styleFunction(f, undefined, false));
});
noFeatureActive = true;
}
var pixel = map.getEventPixel(evt.originalEvent);
map.forEachFeatureAtPixel(pixel,function(feature) {
if (dataSource.hasFeature(feature)){
feature.setStyle(styleFunction(feature, undefined, true));
noFeatureActive = false;
}
return feature;
});
var sources = vectorLayer.getSource();
var feature = vectorLayer.getSource().getClosestFeatureToCoordinate(evt.coordinate);
if (feature) selectNode(feature);
return feature;
});

paletteUrban.writeLegend('legend_urban', [0, 1.5, 2.5], 'm');
paletteRural.writeLegend('legend_rural', [0, 2.0, 2.5], 'm');
var input = document.getElementById("filter");
input.addEventListener("keypress", function(event) {
if (event.key === "Enter") {
event.preventDefault();
displayFilter = []
var args = input.value.replace(/\s+/g, ' ').trim().split(' ');
if (args.length >= 3) {
var f = {key:args[0], op:args[1], val:args[2]}
displayFilter.push(f);
}
selectNode(null);
}
});
</script>
</body>
</html>
Expand Down
Loading