[CS] Add visual queue when training is done
authorJihoon Lee <jhoon.it.lee@samsung.com>
Wed, 23 Sep 2020 09:28:15 +0000 (18:28 +0900)
committerJihoon Lee <jhoon.it.lee@samsung.com>
Mon, 28 Sep 2020 07:07:49 +0000 (16:07 +0900)
**Changes proposed in this PR:**
- Visually notify when training is done
- Add go to main menu when training is done
- Go to main menu button shows the final best accuracy

Resolves #572, #574

**Self evaluation:**
1. Build test: [X]Passed [ ]Failed [ ]Skipped
2. Run test: [X]Passed [ ]Failed [ ]Skipped

Signed-off-by: Jihoon Lee <jhoon.it.lee@samsung.com>
Applications/Tizen_native/CustomShortcut/inc/main.h
Applications/Tizen_native/CustomShortcut/res/edje/main.edc
Applications/Tizen_native/CustomShortcut/src/main.c
Applications/Tizen_native/CustomShortcut/src/view.c

index 03d016e..9ec22c6 100644 (file)
@@ -46,6 +46,18 @@ void presenter_on_routes_request(void *data, Evas_Object *obj EINA_UNUSED,
                                  const char *source);
 
 /**
+ * @brief presenter to handle go home request
+ *
+ * @param data appdata
+ * @param obj not used
+ * @param emission not used
+ * @param source string information that has where to go.
+ */
+void presenter_on_go_main_request(void *data, Evas_Object *obj EINA_UNUSED,
+                                  const char *emission EINA_UNUSED,
+                                  const char *source);
+
+/**
  * @brief presenter to handle canvas submission in the inference
  *
  * @param data appdata
index eb44cd7..97e5ddd 100644 (file)
       state: "default" 0.0; \
       color: 0 0 0 255; \
       rel1 { \
-        relative: 0.3 0.3; \
+        relative: 0.2 0.2; \
         to: button_name"/bg"; \
       } \
       rel2 { \
-        relative: 0.7 0.7; \
+        relative: 0.8 0.8; \
         to: button_name"/bg"; \
       } \
       text { \
         text: label ; \
-        size: 24; \
+        size: 26; \
         align: 0.5 0.5; \
       } \
     } \
@@ -141,10 +141,10 @@ collections {
     }
   }
   group {
-    name: "train_result";
+    name: "train_progress";
     parts {
       part {
-        name: "train_result/epoch";
+        name: "train_progress/epoch";
         type: TEXT;
         description {
           state: "default" 0.0;
@@ -163,7 +163,7 @@ collections {
         }
       }
       part {
-        name: "train_result/accuracy";
+        name: "train_progress/accuracy";
         type: TEXT;
         description {
           state: "default" 0.0;
@@ -178,7 +178,7 @@ collections {
         }
       }
       part {
-        name: "train_result/loss";
+        name: "train_progress/loss";
         type: TEXT;
         description {
           state: "default" 0.0;
@@ -195,6 +195,16 @@ collections {
     }
   }
   group {
+    name: "train_result";
+    parts {
+      PART_TITLE("train_result/title", "train finished")
+      PART_BUTTON("train_result/go_back", "acc: ", 0.1, 0.3, 0.9, 0.7)
+    }
+    programs {
+      PROGRAM_BUTTON("train_result/go_back", "to_main", "")
+    }
+  }
+  group {
     name: "test_result";
     parts {
       PART_TITLE("test_result/title", "test is successfully done")
index bfed84f..356f26e 100644 (file)
@@ -31,14 +31,33 @@ static int routes_to_(appdata_s *ad, const char *source) {
 }
 
 /**
- * @brief thread runner wrapper for adding back callback again
+ * @brief main thread runner wrapper for adding back callback again
  *
  * @param data
  */
-static void add_back_cb_(void *data) {
+static void notify_train_done(void *data) {
   appdata_s *ad = (appdata_s *)data;
+
+  char buf[256];
+
+  const char *source = "train_result";
+  /// Throttle the function to slow down to incorporate with user interaction
+  sleep(1);
+
   eext_object_event_callback_add(ad->naviframe, EEXT_CALLBACK_BACK,
                                  presenter_on_back_button_press, ad);
+
+  int status = view_routes_to(ad, source);
+  if (status != 0) {
+    LOG_E("routing to a new view failed for %s", source);
+    return;
+  }
+
+  elm_layout_signal_callback_add(ad->layout, "to_main", "",
+                                 &presenter_on_go_main_request, ad);
+
+  snprintf(buf, 255, "acc: %.0f%%", ad->best_accuracy);
+  elm_object_part_text_set(ad->layout, "train_result/go_back/label", buf);
 }
 
 static void *train_(void *data) {
@@ -80,7 +99,7 @@ static void *train_(void *data) {
   }
 
 RESTORE_CB:
-  ecore_main_loop_thread_safe_call_async(&add_back_cb_, data);
+  ecore_main_loop_thread_safe_call_async(&notify_train_done, data);
 
   return NULL;
 }
@@ -144,6 +163,13 @@ void presenter_on_routes_request(void *data, Evas_Object *obj EINA_UNUSED,
   init_page_(ad, path);
 }
 
+void presenter_on_go_main_request(void *data, Evas_Object *obj EINA_UNUSED,
+                                  const char *emission EINA_UNUSED,
+                                  const char *source) {
+  appdata_s *ad = (appdata_s *)data;
+  elm_naviframe_item_pop_to(ad->home);
+}
+
 void presenter_on_canvas_submit_inference(void *data, Evas_Object *obj,
                                           const char *emission,
                                           const char *source) {
@@ -173,7 +199,7 @@ void presenter_on_canvas_submit_training(void *data, Evas_Object *obj,
   if (ad->tries == MAX_TRIES - 1) {
     ad->tries = 0;
     elm_naviframe_item_pop(ad->naviframe);
-    routes_to_((appdata_s *)data, "train_result");
+    routes_to_((appdata_s *)data, "train_progress");
     pthread_t train_thread;
     eext_object_event_callback_del(ad->naviframe, EEXT_CALLBACK_BACK,
                                    presenter_on_back_button_press);
index 18d621d..945cced 100644 (file)
@@ -380,12 +380,12 @@ void view_update_result_cb(void *data, void *buffer, unsigned int nbytes) {
   if (result.accuracy > ad->best_accuracy) {
     ad->best_accuracy = result.accuracy;
     snprintf(tmp, 255, "%.0f%%", ad->best_accuracy);
-    elm_object_part_text_set(ad->layout, "train_result/accuracy", tmp);
+    elm_object_part_text_set(ad->layout, "train_progress/accuracy", tmp);
   }
 
   snprintf(tmp, 255, "%d tries", result.epoch);
-  elm_object_part_text_set(ad->layout, "train_result/epoch", tmp);
+  elm_object_part_text_set(ad->layout, "train_progress/epoch", tmp);
 
   snprintf(tmp, 255, "Loss: %.2f", result.train_loss);
-  elm_object_part_text_set(ad->layout, "train_result/loss", tmp);
+  elm_object_part_text_set(ad->layout, "train_progress/loss", tmp);
 }