-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
253 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
data/* | ||
__pycache__ | ||
|
||
.DS_Store | ||
node_modules | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import gzip | ||
import xml.sax | ||
|
||
class PopulationReader(xml.sax.handler.ContentHandler): | ||
def __init__(self): | ||
self.population = [] | ||
|
||
self.person = None | ||
self.process_activities = False | ||
|
||
def startElement(self, name, attributes): | ||
if name == "person": | ||
self.person = { "id": attributes["id"], "activities": [] } | ||
self.process_activities = False | ||
|
||
elif name == "plan": | ||
self.process_activities = attributes["selected"] == "yes" | ||
|
||
elif name == "activity": | ||
self.person["activities"].append({ | ||
"purpose": attributes["type"], | ||
"x": float(attributes["x"]), | ||
"y": float(attributes["y"]) | ||
}) | ||
|
||
def endElement(self, name): | ||
if name == "person": | ||
self.population.append(self.person) | ||
self.person = None | ||
|
||
def read_population(path): | ||
with gzip.open(path) as f: | ||
reader = PopulationReader() | ||
xml.sax.parse(f, reader) | ||
return reader.population |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
<template> | ||
<g class="layer"> | ||
<circle | ||
v-for="person in selectedPersons" | ||
v-bind:key="person.id" | ||
v-bind:cx="person.x" | ||
v-bind:cy="person.y" | ||
r="4" | ||
stroke="white" stroke-width="1" fill="rgba(255, 0, 0, 0.1)" | ||
v-on:mouseenter="selectPerson(person)" | ||
/> | ||
<circle | ||
v-if="layerState.selectedPerson" | ||
v-bind:cx="layerState.selectedPerson.x" | ||
v-bind:cy="layerState.selectedPerson.y" | ||
r="8" | ||
stroke="white" stroke-width="1" fill="rgba(255, 0, 0, 1.0)" | ||
/> | ||
<g v-if="selectedActivities"> | ||
<circle | ||
v-for="point in selectedActivities.points" | ||
v-bind:key="point.index" | ||
v-bind:cx="point.x" | ||
v-bind:cy="point.y" | ||
r="4" | ||
stroke="white" stroke-width="1" fill="rgb(255, 0, 0)" | ||
/> | ||
</g> | ||
<path | ||
v-if="selectedActivities" | ||
v-bind:d="selectedActivities.geometry" | ||
stroke="red" stroke-width="2" fill="none" /> | ||
</g> | ||
</template> | ||
|
||
<script> | ||
// import * as d3 from "d3"; | ||
import * as _ from "lodash"; | ||
import * as axios from "axios"; | ||
import * as d3 from "d3"; | ||
export default { | ||
name: "ActivitiesLayer", | ||
data() { | ||
return { | ||
width: 0, height: 0, | ||
selectedPersons: [], | ||
selectedActivities: [] | ||
}; | ||
}, | ||
props: ["layerState"], | ||
watch: { | ||
"layerState.scale": _.debounce(function() { this.redraw(); }, 100), | ||
"layerState.persons": _.debounce(function() { | ||
var self = this; | ||
this.layerState.persons.forEach(function(person) { | ||
if (person.id == "8902471") { | ||
self.selectPerson(person); | ||
} | ||
}); | ||
this.redraw(); | ||
}, 100), | ||
"layerState.offset": _.debounce(function() { this.redraw(); }, 100), | ||
}, | ||
methods: { | ||
redraw() { | ||
var scale = this.layerState.scale; | ||
var width = this.width; | ||
var height = this.height; | ||
var offset = this.layerState.offset; | ||
var projection = function(x, y) { | ||
return [ | ||
(x - 651791.0) * scale + width * 0.5 + offset[0], | ||
(y - 6862293.0) * scale + height * 0.5 + offset[1] | ||
]; | ||
} | ||
this.selectedPersons = this.layerState.persons.map((item) => { | ||
var person = { id: item.id }; | ||
var coordinates = projection(item.x, item.y); | ||
person["x"] = coordinates[0]; | ||
person["y"] = coordinates[1]; | ||
return person; | ||
}); | ||
}, | ||
onResize() { | ||
this.width = this.$el.parentNode.clientWidth; | ||
this.height = this.$el.parentNode.clientHeight; | ||
this.redraw(); | ||
}, | ||
selectPerson: _.debounce(function(person) { | ||
this.layerState.selectedPerson = person; | ||
var url = window.location.protocol + "//" + window.location.hostname + ":5000"; | ||
axios.get( | ||
url + "/activities/" + person.id).then((response) => { | ||
var scale = this.layerState.scale; | ||
var width = this.width; | ||
var height = this.height; | ||
var offset = this.layerState.offset; | ||
var line = d3.line() | ||
.x(function(d) { return (d.x - 651791.0) * scale + width * 0.5 + offset[0]; }) | ||
.y(function(d) { return (d.y - 6862293.0) * scale + height * 0.5 + offset[1]; }); | ||
var points = response.data.map(function(item) { | ||
return { | ||
x: (item.x - 651791.0) * scale + width * 0.5 + offset[0], | ||
y: (item.y - 6862293.0) * scale + height * 0.5 + offset[1], | ||
}; | ||
}); | ||
var selectedActivities = response.data; | ||
selectedActivities.geometry = line(selectedActivities); | ||
selectedActivities.points = points; | ||
this.selectedActivities = selectedActivities; | ||
}); | ||
}, 100) | ||
}, | ||
mounted() { | ||
this.onResize(); | ||
window.addEventListener('resize', this.onResize); | ||
} | ||
} | ||
</script> | ||
|
||
<style scoped> | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<template> | ||
<div> | ||
<div class="panel-title"> | ||
Activities | ||
<b-spinner v-if="layerState.loading" small label="Spinning"></b-spinner> | ||
</div> | ||
<div v-if="layerState.selectedPerson"> | ||
Person: {{ layerState.selectedPerson.id }} | ||
</div> | ||
<b-form> | ||
<!--b-form-group label="Time" label-cols="3"> | ||
<b-form-input id="range-1" v-model="layerState.time" type="range" min="0" max="86400" :disabled="layerState.loading"></b-form-input> | ||
<span> | ||
{{ (Math.round(layerState.time / 3600) + "").padStart(2, "0") }}:{{ (Math.round((layerState.time % 3600) / 60) + "").padStart(2, "0") }}:{{ (Math.round(layerState.time % 60) + "").padStart(2, "0") }} | ||
</span> | ||
</b-form-group--> | ||
</b-form> | ||
</div> | ||
</template> | ||
|
||
<script> | ||
export default { | ||
name: "ActivitiesLayerPanel", | ||
props: ["layerState"] | ||
} | ||
</script> |