Commit 3e12f97e authored by dagal's avatar dagal
Browse files

Working X to Y

parent 5a805fd9
......@@ -114,4 +114,15 @@ uint64_t CTR_board(void * ctr, uint32_t s, uint32_t h_start, uint32_t h_end) {
query->subtype = 0;
if (h_end) query->subtype |= XY_TIME_START;
return get_uses_x(ctr, query);
}
\ No newline at end of file
}
uint64_t CTR_xy(void * ctr, uint32_t s1, uint32_t s2, uint32_t h_start, uint32_t h_end) {
query->values[1] = s1;
query->values[3] = s2;
query->time->h_start = h_start;
query->time->h_end = h_end;
query->subtype = 0;
if (h_end) query->subtype |= XY_TIME_START;
// TODO XY_TIME_END
return get_from_x_to_y(ctr, query);
}
......@@ -13,6 +13,7 @@ uint64_t CTR_start(void *ctr, uint32_t s, uint32_t h_start, uint32_t h_end);
uint64_t CTR_end(void *ctr, uint32_t s, uint32_t h_start, uint32_t h_end);
uint64_t CTR_switch(void *ctr, uint32_t s, uint32_t h_start, uint32_t h_end);
uint64_t CTR_board(void *ctr, uint32_t s, uint32_t h_start, uint32_t h_end);
uint64_t CTR_xy(void *ctr, uint32_t s1, uint32_t s2, uint32_t h_start, uint32_t h_end);
#ifdef __cplusplus
}
......
......@@ -81,3 +81,16 @@ func GetStopStats(c *gin.Context) {
"board": boardCTR,
})
}
func GetXY(c *gin.Context) {
x := Atoi32(c.Query("x"), c)
y := Atoi32(c.Query("y"), c)
fromTime := Atoi32(c.DefaultQuery("from_time", "0"), c)
toTime := Atoi32(c.DefaultQuery("to_time", "0"), c)
xy := CTRXY(x, y, fromTime, toTime)
c.JSON(200, gin.H{
"xy": xy,
})
}
......@@ -49,3 +49,7 @@ func CTRSwitch(s uint32, fromTime uint32, toTime uint32) uint64 {
func CTRBoard(s uint32, fromTime uint32, toTime uint32) uint64 {
return uint64(C.CTR_board(ctr, C.uint(s), C.uint(fromTime), C.uint(toTime)))
}
func CTRXY(x uint32, y uint32, fromTime uint32, toTime uint32) uint64 {
return uint64(C.CTR_xy(ctr, C.uint(x), C.uint(y), C.uint(fromTime), C.uint(toTime)))
}
......@@ -42,6 +42,7 @@ func main() {
router.GET("/index", ShowIndex)
router.GET("/", ShowIndex)
router.GET("/stop_stats/:id", GetStopStats)
router.GET("/xy", GetXY)
err := router.Run()
LogAndQuit(err)
}
......
......@@ -17,6 +17,7 @@
</div>
<stop-popup ref="hiddenStopPopup" v-bind:stop="selectedStop"></stop-popup>
<x-y-popup ref="hiddenXYPopup" v-bind:stop-x="startStop" v-bind:stop-y="endStop"></x-y-popup>
</div>
<script src="bundle.js"></script>
......
<template>
<div class="stop-popup" v-show="stop.name">
<div class="stop-popup" v-if="stop && stop.name">
<div class="stop-popup-title">{{stop.name}}</div>
<pulse-loader :loading="isLoading" color="#102938" size="12px"></pulse-loader>
<div class="stop-popup-stats" v-show="!isLoading">
......
<template>
<div class="stop-popup" v-if="stopX && stopY && stopX.name && stopY.name">
<div class="stop-popup-title">{{stopX.name}}</div>
<div class="stop-popup-title">to</div>
<div class="stop-popup-title">{{stopY.name}}</div>
<pulse-loader :loading="isLoading" color="#102938" size="12px"></pulse-loader>
<div class="stop-popup-stats" v-show="!isLoading">
<div class="stop-popup-counter">{{stats.xy}} trips</div>
</div>
</div>
</template>
<script>
let getty = require("../getty");
let PulseLoader = require("vue-spinner/dist/vue-spinner.min").PulseLoader;
module.exports = {
name: "XYPopup",
components: {PulseLoader},
props: {
stopX: {
//required: true
},
stopY: {
//required: true
}
},
data() {
return {
isLoading: true,
}
},
methods: {
secondsFromMinDate(d) {
if (this.$root.minDate) {
return (d.getTime() - this.$root.minDate.getTime())/1000;
} else {
return -1;
}
}
},
asyncComputed: {
stats: {
get () {
if (!this.stopX || this.stopX.id === 0 || !this.stopY || this.stopY.id === 0) {
return {};
}
this.isLoading = true;
var startDate = new Date(0);
var endDate = new Date(0);
if (this.$root.selectedDate.startDate || this.$root.selectedDate.endDate) {
startDate = this.$root.selectedDate.startDate || this.$root.minDate;
endDate = this.$root.selectedDate.endDate || this.$root.maxDate;
}
return getty.getXY(this.stopX.id,
this.stopY.id,
this.secondsFromMinDate(startDate),
this.secondsFromMinDate(endDate)).then(x => {
this.isLoading = false;
return x;
});
},
default() {
return {};
}
}
}
}
</script>
<style scoped>
.stop-popup {
min-width: 200px;
max-width: 200px;
}
</style>
......@@ -55,4 +55,25 @@ function getStopStats(idStop, fromTime, toTime) {
return jsonGet(url);
}
module.exports = {simplyGet, jsonGet, getStopStats};
function getXY(x, y, fromTime, toTime) {
var url = "/xy";
let params = {x: x, y: y};
if (fromTime && fromTime >= 0) {
params["from_time"] = fromTime;
}
if (toTime && toTime >= 0) {
params["to_time"] = toTime;
}
let paramsString = new URLSearchParams(params).toString();
if (paramsString) {
url += "?" + paramsString;
}
return jsonGet(url);
}
module.exports = {simplyGet, jsonGet, getStopStats, getXY};
......@@ -4,6 +4,7 @@ let LContextMenu = require("leaflet-contextmenu");
let Vue = require("vue");
let Hello = require("./components/Hello.vue");
let StopPopup = require("./components/StopPopup.vue");
let XYPopup = require("./components/XYPopup.vue");
let DateTimePicker = require("./components/DateTimePicker.vue");
let TimeFilter = require("./components/TimeFilter.vue");
let StopSearch = require("./components/StopSearch.vue");
......@@ -23,7 +24,7 @@ Vue.use(VueRouter);
let app = new Vue({
el: '#app',
router,
components: {Hello, StopPopup, DateTimePicker, TimeFilter, StopSearch, Datepicker, PulseLoader, VueTimepicker, Autocomplete},
components: {Hello, StopPopup, XYPopup, DateTimePicker, TimeFilter, StopSearch, Datepicker, PulseLoader, VueTimepicker, Autocomplete},
data: {
minDate: new Date(0),
maxDate: null,
......@@ -43,8 +44,6 @@ let app = new Vue({
},
methods: {
selectStop(s, isEndStop) {
console.log(s);
if (!s) {
return;
}
......@@ -64,8 +63,8 @@ let app = new Vue({
weight: 3,
renderer: canvasRenderer,
}).addTo(map).bindPopup(() => {
return "Number of X to Y trips!"
}).openPopup();
return app.$refs.hiddenXYPopup.$el;
}, {maxWidth: "auto"}).openPopup();
line.on("popupclose", () => line.removeFrom(map));
} else {
let marker = this.stopMarkers[s.id];
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment