Commit 052678b9 authored by dagal's avatar dagal
Browse files

Working X area to Y area!

parent a69937e4
......@@ -137,3 +137,27 @@ uint64_t CTR_xy(void * ctr, uint32_t s1, uint32_t s2, uint32_t h_start, uint32_t
freeQuery(query);
return result;
}
uint64_t CTR_xy_area(void *ctr, uint32_t *s1, uint32_t n_s1, uint32_t *s2, uint32_t n_s2, uint32_t h_start, uint32_t h_end) {
TimeQuery *query = prepareQuery();
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
uint64_t result = 0;
for (uint32_t i = 0; i < n_s1; i++) {
query->values[1] = s1[i];
for (uint32_t j = 0; j < n_s2; j++) {
query->values[3] = s2[j];
result += get_from_x_to_y(ctr, query);
}
}
freeQuery(query);
return result;
}
......@@ -14,6 +14,7 @@ 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);
uint64_t CTR_xy_area(void *ctr, uint32_t *s1, uint32_t n_s1, uint32_t *s2, uint32_t n_s2, uint32_t h_start, uint32_t h_end);
#ifdef __cplusplus
}
......
......@@ -122,14 +122,14 @@ func GetXY(c *gin.Context) {
}
type TimeWindow struct {
From int32 `json:"from"`
To int32 `json:"to"`
From uint32 `json:"from"`
To uint32 `json:"to"`
}
type XYAreaRequest struct {
Time TimeWindow `json:"time"`
StartStops []int32 `json:"start_stops"`
EndStops []int32 `json:"end_stops"`
StartStops []uint32 `json:"start_stops"`
EndStops []uint32 `json:"end_stops"`
}
func GetXYArea(c *gin.Context) {
......@@ -138,7 +138,25 @@ func GetXYArea(c *gin.Context) {
var data XYAreaRequest
LogAndPanic2(json.Unmarshal(rawRequest, &data), c)
c.JSON(200, gin.H{
"xy": data.StartStops,
})
if data.StartStops == nil || data.EndStops == nil {
c.JSON(400, gin.H{
"message": "incomplete query",
})
} else {
fromTime := uint32(0)
toTime := uint32(0)
//if data.Time != nil {
fromTime = data.Time.From
toTime = data.Time.To
//}
println(fromTime)
println(toTime)
xy := CTRXYArea(data.StartStops, data.EndStops, fromTime, toTime)
c.JSON(200, gin.H{
"xy": xy,
})
}
}
......@@ -53,3 +53,7 @@ func CTRBoard(s uint32, fromTime uint32, toTime uint32) uint64 {
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)))
}
func CTRXYArea(x []uint32, y []uint32, fromTime uint32, toTime uint32) uint64 {
return uint64(C.CTR_xy_area(ctr, (*C.uint)(&x[0]), C.uint(len(x)), (*C.uint)(&y[0]), C.uint(len(y)), C.uint(fromTime), C.uint(toTime)))
}
......@@ -86,14 +86,14 @@ function getXYArea(x, y, fromTime, toTime) {
var time = {};
if (fromTime && fromTime >= 0) {
time["from_time"] = fromTime;
time["from"] = fromTime;
}
if (toTime && toTime >= 0) {
time["to_time"] = toTime;
time["to"] = toTime;
}
if (time["from_time"] || time["to_time"]) {
if (time["from"] || time["to"]) {
data["time"] = time;
}
......
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