package android

import (
	"fmt"
	"database/sql"
	_ "go-sqlite3-master"
	"pkg/app"

	"github.com/gin-gonic/gin"
)

func updateAverage () {
	macAddress = getMacAddress()
	db, err := sql.Open("sqlite3", "info.db")
	if err != nil {
		fmt.Println(err)
	}
	defer db.Close()
	db.Exec(`update Endpoint set times = times + 1 where macAddress = ?;`, macAddress)
	rows, err := db.Query(`select SUM( times ) from Endpoint`)
	defer rows.Close()
	var sumOfTimes int
	rows.Next()
	rows.Scan(&sumOfTimes)
	rows, err = db.Query(`select COUNT( macAddress ) from Endpoint;`)
	defer rows.Close()
	var countOfMacAddress int
	rows.Next()
	rows.Scan(&countOfMacAddress)
	db.Exec(`update Average set average = ?/?;`sumOfTimes, countOfMacAddress)
}

func wordSend (c *gin.Context) {
	appG := app.Gin{C: c}
	//这里获取转化好的数据
	data := mediaPipe().data
	updateAverage()
	appG.Response(http.StatusOK, "true", data)
}