Ma Suhyeon

Implement calendar API

......@@ -81,6 +81,7 @@ func NewApp(config Config) *App {
extraction.GET("/messages/analyses", app.GetMessagesAnalyses)
extraction.GET("/processes", app.GetProcesses)
extraction.GET("/alarms", app.GetAlarms)
extraction.GET("/schedules", app.GetSchedules)
app.echo.GET("/graph/:extractions", app.GetGraph)
......
......@@ -306,3 +306,20 @@ func (app *App) GetAlarms(c echo.Context) error {
return c.JSON(http.StatusOK, results)
}
type Schedule struct {
ID int `json:"id" db:"id"`
Name string `json:"name" db:"name"`
Begin time.Time `json:"begin" db:"begin"`
End time.Time `json:"end" db:"end"`
}
func (app *App) GetSchedules(c echo.Context) error {
schedules := []Schedule{}
query := "SELECT * FROM schedules WHERE `extraction_no`=?"
if err := app.db.Unsafe().Select(&schedules, query, c.Param("no")); err != nil {
return err
}
return c.JSON(http.StatusOK, schedules)
}
......
......@@ -84,11 +84,11 @@ func (app *App) PostExtractions(c echo.Context) error {
}
}
sql := `SELECT
query := `SELECT
a.packagename, a.name, a.version, a.wifiusage, a.cellularusage,
u.lasttimeused, u.totaltimeforeground
FROM AppInfo a JOIN AppUsageYear u ON a.packagename=u.packagename`
rows, err = db.Queryx(sql)
rows, err = db.Queryx(query)
if err == nil {
for rows.Next() {
vals, _ := rows.SliceScan()
......@@ -121,13 +121,23 @@ func (app *App) PostExtractions(c echo.Context) error {
rows, err = db.Queryx("SELECT PID, UID, PPID, STIME, TIME, CMD FROM process")
if err == nil {
for rows.Next() {
vals, _ := rows.SliceScan()
tx.Exec("INSERT INTO processes VALUES (?, ?, ?, ?, ?, ?, ?)", append([]interface{}{extNo}, vals...)...)
}
}
query = "SELECT `id`, `calendar_id`, `dtstart`, `dtend` FROM calendar " +
"WHERE `calendar_id` != '' " +
"AND owner_name NOT IN ('local', 'ko.south_korea#holiday@group.v.calendar.google.com')"
rows, err = db.Queryx(query)
if err == nil {
for rows.Next() {
vals, _ := rows.SliceScan()
tx.Exec("INSERT INTO schedules VALUES (?, ?, ?, ?, ?)", append([]interface{}{extNo}, vals...)...)
}
}
/*alarms := map[string]Alarm{}
rows, _ = db.Queryx("SELECT * FROM alarm ORDER BY TIME")
......