Ma Suhyeon

Implement calendar API

...@@ -81,6 +81,7 @@ func NewApp(config Config) *App { ...@@ -81,6 +81,7 @@ func NewApp(config Config) *App {
81 extraction.GET("/messages/analyses", app.GetMessagesAnalyses) 81 extraction.GET("/messages/analyses", app.GetMessagesAnalyses)
82 extraction.GET("/processes", app.GetProcesses) 82 extraction.GET("/processes", app.GetProcesses)
83 extraction.GET("/alarms", app.GetAlarms) 83 extraction.GET("/alarms", app.GetAlarms)
84 + extraction.GET("/schedules", app.GetSchedules)
84 85
85 app.echo.GET("/graph/:extractions", app.GetGraph) 86 app.echo.GET("/graph/:extractions", app.GetGraph)
86 87
......
...@@ -306,3 +306,20 @@ func (app *App) GetAlarms(c echo.Context) error { ...@@ -306,3 +306,20 @@ func (app *App) GetAlarms(c echo.Context) error {
306 306
307 return c.JSON(http.StatusOK, results) 307 return c.JSON(http.StatusOK, results)
308 } 308 }
309 +
310 +type Schedule struct {
311 + ID int `json:"id" db:"id"`
312 + Name string `json:"name" db:"name"`
313 + Begin time.Time `json:"begin" db:"begin"`
314 + End time.Time `json:"end" db:"end"`
315 +}
316 +
317 +func (app *App) GetSchedules(c echo.Context) error {
318 + schedules := []Schedule{}
319 + query := "SELECT * FROM schedules WHERE `extraction_no`=?"
320 + if err := app.db.Unsafe().Select(&schedules, query, c.Param("no")); err != nil {
321 + return err
322 + }
323 +
324 + return c.JSON(http.StatusOK, schedules)
325 +}
......
...@@ -84,11 +84,11 @@ func (app *App) PostExtractions(c echo.Context) error { ...@@ -84,11 +84,11 @@ func (app *App) PostExtractions(c echo.Context) error {
84 } 84 }
85 } 85 }
86 86
87 - sql := `SELECT 87 + query := `SELECT
88 a.packagename, a.name, a.version, a.wifiusage, a.cellularusage, 88 a.packagename, a.name, a.version, a.wifiusage, a.cellularusage,
89 u.lasttimeused, u.totaltimeforeground 89 u.lasttimeused, u.totaltimeforeground
90 FROM AppInfo a JOIN AppUsageYear u ON a.packagename=u.packagename` 90 FROM AppInfo a JOIN AppUsageYear u ON a.packagename=u.packagename`
91 - rows, err = db.Queryx(sql) 91 + rows, err = db.Queryx(query)
92 if err == nil { 92 if err == nil {
93 for rows.Next() { 93 for rows.Next() {
94 vals, _ := rows.SliceScan() 94 vals, _ := rows.SliceScan()
...@@ -121,13 +121,23 @@ func (app *App) PostExtractions(c echo.Context) error { ...@@ -121,13 +121,23 @@ func (app *App) PostExtractions(c echo.Context) error {
121 121
122 rows, err = db.Queryx("SELECT PID, UID, PPID, STIME, TIME, CMD FROM process") 122 rows, err = db.Queryx("SELECT PID, UID, PPID, STIME, TIME, CMD FROM process")
123 if err == nil { 123 if err == nil {
124 -
125 for rows.Next() { 124 for rows.Next() {
126 vals, _ := rows.SliceScan() 125 vals, _ := rows.SliceScan()
127 tx.Exec("INSERT INTO processes VALUES (?, ?, ?, ?, ?, ?, ?)", append([]interface{}{extNo}, vals...)...) 126 tx.Exec("INSERT INTO processes VALUES (?, ?, ?, ?, ?, ?, ?)", append([]interface{}{extNo}, vals...)...)
128 } 127 }
129 } 128 }
130 129
130 + query = "SELECT `id`, `calendar_id`, `dtstart`, `dtend` FROM calendar " +
131 + "WHERE `calendar_id` != '' " +
132 + "AND owner_name NOT IN ('local', 'ko.south_korea#holiday@group.v.calendar.google.com')"
133 + rows, err = db.Queryx(query)
134 + if err == nil {
135 + for rows.Next() {
136 + vals, _ := rows.SliceScan()
137 + tx.Exec("INSERT INTO schedules VALUES (?, ?, ?, ?, ?)", append([]interface{}{extNo}, vals...)...)
138 + }
139 + }
140 +
131 /*alarms := map[string]Alarm{} 141 /*alarms := map[string]Alarm{}
132 rows, _ = db.Queryx("SELECT * FROM alarm ORDER BY TIME") 142 rows, _ = db.Queryx("SELECT * FROM alarm ORDER BY TIME")
133 143
......