diff --git a/db.go b/db.go deleted file mode 100644 index 94fb070..0000000 --- a/db.go +++ /dev/null @@ -1,6 +0,0 @@ -package main - -import ( -) - - diff --git a/logic/tasks/list.go b/logic/tasks/list.go index 4f79f21..0343ae4 100644 --- a/logic/tasks/list.go +++ b/logic/tasks/list.go @@ -8,12 +8,32 @@ import ( ) func handleList(handler *Handle) { + + handler.PostAuth("/tasks/task", 1, func(c *Context) *Error { + var getId JustId + if _err := c.ToJSON(&getId); _err != nil { + return _err + } + + var task Task + + err := GetDBOnce(c, &task, "tasks where id=$1;", getId.Id) + if err == NotFoundError { + return c.JsonBadRequest("Did not found task id") + } else if err != nil { + return c.E500M("Faied to get task", err) + } + + c.ShowMessage = false + return c.SendJSON(task) + }) + handler.PostAuth("/tasks/list", 1, func(c *Context) *Error { - var err error = nil + var err error = nil var requestData struct { ModelId string `json:"model_id"` - Page int `json:"page"` + Page int `json:"page"` } if _err := c.ToJSON(&requestData); _err != nil { @@ -33,29 +53,29 @@ func handleList(handler *Handle) { } } - var rows []*Task = nil + var rows []*Task = nil if requestData.ModelId != "" { - rows, err = GetDbMultitple[Task](c, "tasks where model_id=$1 order by created_on desc limit 11 offset $2", requestData.ModelId, requestData.Page * 10) + rows, err = GetDbMultitple[Task](c, "tasks where model_id=$1 order by created_on desc limit 11 offset $2", requestData.ModelId, requestData.Page*10) if err != nil { return c.Error500(err) } } else { - rows, err = GetDbMultitple[Task](c, "tasks order by created_on desc limit 11 offset $1", requestData.Page * 10) + rows, err = GetDbMultitple[Task](c, "tasks order by created_on desc limit 11 offset $1", requestData.Page*10) if err != nil { return c.Error500(err) } } max_len := min(11, len(rows)) - - c.ShowMessage = false + + c.ShowMessage = false return c.SendJSON(struct { - TaskList []*Task `json:"task_list"` - ShowNext bool `json:"show_next"` - } { - rows[0:max_len], - len(rows) > 10, - }) + TaskList []*Task `json:"task_list"` + ShowNext bool `json:"show_next"` + }{ + rows[0:max_len], + len(rows) > 10, + }) }) } diff --git a/main.go b/main.go index b31e8bf..b2a908d 100644 --- a/main.go +++ b/main.go @@ -8,10 +8,10 @@ import ( _ "github.com/lib/pq" . "git.andr3h3nriqu3s.com/andr3/fyp/logic/models" - . "git.andr3h3nriqu3s.com/andr3/fyp/logic/tasks" models_utils "git.andr3h3nriqu3s.com/andr3/fyp/logic/models/utils" - . "git.andr3h3nriqu3s.com/andr3/fyp/logic/utils" + . "git.andr3h3nriqu3s.com/andr3/fyp/logic/tasks" . "git.andr3h3nriqu3s.com/andr3/fyp/logic/tasks/runner" + . "git.andr3h3nriqu3s.com/andr3/fyp/logic/utils" ) const ( @@ -35,10 +35,10 @@ func main() { defer db.Close() log.Info("Starting server on :5002!") - config := LoadConfig() - log.Info("Config loaded!", "config", config) + config := LoadConfig() + log.Info("Config loaded!", "config", config) - StartRunners(db, config) + StartRunners(db, config) //TODO check if file structure exists to save data handle := NewHandler(db, config) @@ -59,7 +59,7 @@ func main() { usersEndpints(db, handle) HandleModels(handle) - HandleTasks(handle) + HandleTasks(handle) handle.Startup() } diff --git a/webpage/src/lib/Spinner.svelte b/webpage/src/lib/Spinner.svelte new file mode 100644 index 0000000..b9cba68 --- /dev/null +++ b/webpage/src/lib/Spinner.svelte @@ -0,0 +1,34 @@ + + + diff --git a/webpage/src/routes/models/edit/RunModel.svelte b/webpage/src/routes/models/edit/RunModel.svelte index 4575759..36400d2 100644 --- a/webpage/src/routes/models/edit/RunModel.svelte +++ b/webpage/src/routes/models/edit/RunModel.svelte @@ -1,95 +1,111 @@ -
-
- -
- Run image through them model and get the result -
- - - - Upload image - -
- - Image selected - -
-
-
- - - {#if run} - {#await _result} -

- Processing Image {last_task} -

- {:then result} - {#if !result} -
-

- The class was not found -

-
- {:else} -
-

- Result -

- The image was classified as {result.class} with confidence: {result.confidence} -
- {/if} - {/await} - {/if} - +
+
+ +
Run image through them model and get the result
+ + + + Upload image +
+ Image selected +
+
+
+ + + {#if run} + {#await _result} +

+ Processing Image! +

+ {:then result} + {#if result.status == 4} + {@const res = JSON.parse(result.result)} +
+

Result

+ The image was classified as {res.class} with confidence: {res.confidence} +
+ {:else} +
+

There was a problem running the task:

+ {result?.status_message} +
+ {/if} + {/await} + {/if} + diff --git a/webpage/src/routes/models/edit/TasksDataPage.svelte b/webpage/src/routes/models/edit/TasksDataPage.svelte index e0c263b..4d44dd9 100644 --- a/webpage/src/routes/models/edit/TasksDataPage.svelte +++ b/webpage/src/routes/models/edit/TasksDataPage.svelte @@ -1,16 +1,15 @@ -
- table.getList()} /> - + table.getList()} on:taskReload={() => table.getList()} /> +
diff --git a/webpage/src/routes/models/edit/TasksTable.svelte b/webpage/src/routes/models/edit/TasksTable.svelte index ce007c5..f145366 100644 --- a/webpage/src/routes/models/edit/TasksTable.svelte +++ b/webpage/src/routes/models/edit/TasksTable.svelte @@ -8,8 +8,26 @@ user_confirmed: number; compacted: number; type: number; - created: string; - result: string; + created: string; + result: string; + }; + export const TaskType = { + TASK_FAILED_RUNNING: -2, + TASK_FAILED_CREATION: -1, + TASK_PREPARING: 0, + TASK_TODO: 1, + TASK_PICKED_UP: 2, + TASK_RUNNING: 3, + TASK_DONE: 4 + }; + export const TaskTypeStrings: Record = { + [-2]: 'Task failed running', + [-1]: 'Failed to create task', + 0: 'Preparing task', + 1: 'Task to do', + 2: 'Task picked up by a runner', + 3: 'Task running', + 4: 'Task complete' }; @@ -17,34 +35,34 @@ import { post } from 'src/lib/requests.svelte'; import type { Model } from './+page.svelte'; - let { model } = $props<{ model: Model, uploadCounter?: number }>(); + let { model } = $props<{ model: Model; uploadCounter?: number }>(); let page = $state(0); let showNext = $state(false); let task_list = $state([]); - export async function getList() { + export async function getList() { try { - const res = await post('tasks/list', { - id: model.id, - page: page, - }); + const res = await post('tasks/list', { + id: model.id, + page: page + }); showNext = res.show_next; task_list = res.task_list; } catch (e) { console.error('TODO notify user', e); } - } - - $effect(() => { - if (model) { - getList() - } - }) + } + + $effect(() => { + if (model) { + getList(); + } + });
-

Tasks

+

Tasks

@@ -63,11 +81,11 @@ {#each task_list as task} - - - - {/each}
- {#if task.type == 1} - Image Run - {:else} - {task.type} - {/if} + {#if task.type == 1} + Image Run + {:else} + {task.type} + {/if} {#if task.type == 1} @@ -83,42 +101,42 @@ {/if} - {#if task.type == 1} - {#if task.status == 4} - {#if task.user_confirmed == 0} - User has not agreed to the result of this task - {:else if task.user_confirmed == -1} - User has disagred with the result of this task - {:else if task.user_confirmed == 1} - User has aggred with the result of this task - {:else} - TODO {task.user_confirmed} - {/if} - {:else} - - - {/if} - {:else} - TODO Handle {task.type} - {/if} + {#if task.type == 1} + {#if task.status == 4} + {#if task.user_confirmed == 0} + User has not agreed to the result of this task + {:else if task.user_confirmed == -1} + User has disagred with the result of this task + {:else if task.user_confirmed == 1} + User has aggred with the result of this task + {:else} + TODO {task.user_confirmed} + {/if} + {:else} + - + {/if} + {:else} + TODO Handle {task.type} + {/if} - {#if task.status == 4} - {#if task.type == 1} - {@const temp = JSON.parse(task.result)} - {temp.class}({temp.confidence * 100}%) - {:else} - {task.result} - {/if} - {/if} + + {#if task.status == 4} + {#if task.type == 1} + {@const temp = JSON.parse(task.result)} + {temp.class}({temp.confidence * 100}%) + {:else} + {task.result} + {/if} + {/if} - {task.status} + + {TaskTypeStrings[task.status]} - {task.status_message} + + {task.status_message} - {(new Date(task.created)).toLocaleString()} + + {new Date(task.created).toLocaleString()}