Toggle navigation
Toggle navigation
This project
Loading...
Sign in
2020-2-capstone-design1
/
JJS_project1
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
Ma Suhyeon
2020-12-05 11:51:35 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
1c2d911fcfd1d136ee19a4656e1bd307bc95e9dc
1c2d911f
1 parent
d30da8eb
Fix API
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
22 additions
and
9 deletions
source/server/.gitignore
source/server/.vscode/settings.json
source/server/app.go
source/server/data.go
source/server/go.mod
source/server/go.sum
source/server/.gitignore
View file @
1c2d911
...
...
@@ -35,4 +35,5 @@
__debug_bin
config.json
data
\ No newline at end of file
data
mf-server
\ No newline at end of file
...
...
source/server/.vscode/settings.json
0 → 100644
View file @
1c2d911
{
"go.inferGopath"
:
false
}
\ No newline at end of file
source/server/app.go
View file @
1c2d911
...
...
@@ -4,6 +4,7 @@ import (
"fmt"
"net/http"
"github.com/gorilla/handlers"
"github.com/gorilla/mux"
_
"github.com/go-sql-driver/mysql"
...
...
@@ -43,5 +44,8 @@ func NewApp(config Config) *App {
}
func
(
app
*
App
)
Serve
()
{
http
.
ListenAndServe
(
fmt
.
Sprintf
(
":%d"
,
app
.
Config
.
Port
),
app
.
router
)
http
.
ListenAndServe
(
fmt
.
Sprintf
(
":%d"
,
app
.
Config
.
Port
),
handlers
.
CORS
(
handlers
.
AllowedMethods
([]
string
{
"GET"
,
"POST"
,
"UPDATE"
,
"DELETE"
}),
handlers
.
AllowedOrigins
([]
string
{
"*"
}),
)(
app
.
router
))
}
...
...
source/server/data.go
View file @
1c2d911
...
...
@@ -75,7 +75,7 @@ type AppInfo struct {
WifiUsage
int
`json:"wifi_usage" db:"wifiusage"`
CellularUsage
int
`json:"cellular_usage" db:"cellularusage"`
LastUsed
time
.
Time
`json:"last_used" db:"lasttimeused"`
ForegroundTime
int
`json:"foreground_time" db:"totaltimeforeground"`
ForegroundTime
int
64
`json:"foreground_time" db:"totaltimeforeground"`
}
func
(
app
*
App
)
GetAppsAnalyses
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
...
...
@@ -92,8 +92,8 @@ func (app *App) GetAppsAnalyses(w http.ResponseWriter, r *http.Request) {
query
:=
`SELECT
a.packagename, a.name, a.version, a.wifiusage, a.cellularusage,
u.lasttimeused, u.totaltimeforeground
FROM AppInfo a JOIN AppUsageYear u
ORDER BY
totaltimeforeground DESC
`
FROM AppInfo a JOIN AppUsageYear u
ON a.packagename=u.packagename
ORDER BY
u.totaltimeforeground DESC LIMIT 0, 100
`
db
.
Select
(
&
apps
,
query
)
WriteJson
(
w
,
apps
)
...
...
@@ -125,9 +125,9 @@ func (app *App) GetMessages(w http.ResponseWriter, r *http.Request) {
}
type
MessageStats
struct
{
Address
string
`json:"
number" db:"number
"`
Receive
int
`json:"
incoming" db:"incoming
"`
Send
int
`json:"
outgoing" db:"outgoing
"`
Address
string
`json:"
address" db:"address
"`
Receive
int
`json:"
receive" db:"receive
"`
Send
int
`json:"
send" db:"send
"`
}
func
(
app
*
App
)
GetMessagesAnalyses
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
...
...
@@ -145,7 +145,7 @@ func (app *App) GetMessagesAnalyses(w http.ResponseWriter, r *http.Request) {
(SELECT COUNT(1) FROM sms m WHERE m.address=s.address AND m.type=1) receive,
(SELECT COUNT(1) FROM sms m WHERE m.address=s.address AND m.type=2) send
FROM sms s GROUP BY address ORDER BY receive + send DESC`
db
.
Select
(
&
messages
,
query
)
fmt
.
Println
(
db
.
Select
(
&
messages
,
query
)
)
WriteJson
(
w
,
messages
)
}
...
...
source/server/go.mod
View file @
1c2d911
...
...
@@ -6,6 +6,7 @@ require (
github.com/dgrijalva/jwt-go v3.2.0+incompatible
github.com/go-sql-driver/mysql v1.5.0
github.com/google/uuid v1.1.2
github.com/gorilla/handlers v1.5.1
github.com/gorilla/mux v1.8.0
github.com/jmoiron/sqlx v1.2.0
github.com/mattn/go-sqlite3 v1.9.0
...
...
source/server/go.sum
View file @
1c2d911
github.com/dgrijalva/jwt-go v1.0.2 h1:KPldsxuKGsS2FPWsNeg9ZO18aCrGKujPoWXn2yo+KQM=
github.com/dgrijalva/jwt-go v3.2.0+incompatible h1:7qlOGliEKZXTDg6OTjfoBKDXWrumCAMpl/TFQ4/5kLM=
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
github.com/felixge/httpsnoop v1.0.1 h1:lvB5Jl89CsZtGIWuTcDM1E/vkVs49/Ml7JJe07l8SPQ=
github.com/felixge/httpsnoop v1.0.1/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U=
github.com/go-sql-driver/mysql v1.4.0/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w=
github.com/go-sql-driver/mysql v1.5.0 h1:ozyZYNQW3x3HtqT1jira07DN2PArx2v7/mN66gGcHOs=
github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
github.com/google/uuid v1.1.2 h1:EVhdT+1Kseyi1/pUmXKaFxYsDNy9RQYkMWRH68J/W7Y=
github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/gorilla/handlers v1.5.1 h1:9lRY6j8DEeeBT10CvO9hGW0gmky0BprnvDI5vfhUHH4=
github.com/gorilla/handlers v1.5.1/go.mod h1:t8XrUpc4KVXb7HGyJ4/cEnwQiaxrX/hz1Zv/4g96P1Q=
github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI=
github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So=
github.com/jmoiron/sqlx v1.2.0 h1:41Ip0zITnmWNR/vHV+S4m+VoUivnWY5E4OJfLZjCJMA=
...
...
Please
register
or
login
to post a comment