graph.go
1010 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package main
import (
"net/http"
"strconv"
"strings"
"github.com/labstack/echo/v4"
)
func (app *App) GetGraph(c echo.Context) error {
sep := strings.Split(c.Param("extractions"), ",")
extractions := map[string]uint64{}
for _, s := range sep {
var phone string
app.db.Get(&phone, "SELECT phone FROM extractions WHERE `no`=?", s)
extractions[phone], _ = strconv.ParseUint(s, 10, 64)
}
calls := map[[2]string]int{}
for p, e := range extractions {
rows, _ := app.db.Query("SELECT `number`, COUNT(1) FROM calls WHERE extraction_no=? GROUP BY `number`", e)
for rows.Next() {
var number string
var count int
rows.Scan(&number, &count)
if _, ok := calls[[2]string{p, number}]; ok {
continue
}
calls[[2]string{p, number}] = count
calls[[2]string{number, p}] = count
}
}
result := []interface{}{}
for k, c := range calls {
if k[0] < k[1] && c >= 5 {
result = append(result, echo.Map{"numbers": k, "calls": c})
}
}
return c.JSON(http.StatusOK, result)
}