public void SetActiveTree(string input)
        {
            NLQ new_query = new NLQ();

            new_query.query_type = SurveyHelper.QueryTypes.GET_TREE;
            // get tree id for new query
            new_query.tree_id = tree_id = GetValidTreeID(input);

            // store whether any input could be parsed as a tree id
            have_tree_id = string.IsNullOrEmpty(tree_id) ? false : true;

            // if no value can be validated as a potential tree id, return
            if (!have_tree_id)
            {
                Toast.MakeText(Application.Context, $"Input is invalid.\nValue: '{input}'", ToastLength.Long);
                return;
            }
            // if a valid tree id does not return any table results, return
            if (!SQLiteHelper.CheckTreeExists(tree_id))
            {
                Toast.MakeText(Application.Context, $"Cannot find tree record associated with ID: '{input}'", ToastLength.Long);
                return;
            }

            session_queries.Add(new_query);
        }
Beispiel #2
0
 private void UpdateCurrentQuery(NLQ current_query)
 {
     edittext_treeid.Text   = current_query.tree_id;
     edittext_property.Text = current_query.property_actioned;
     edittext_oldval.Text   = current_query.property_val_old;
     edittext_newval.Text   = current_query.property_val_new;
 }
Beispiel #3
0
        private static bool ExecuteDeleteRecord(NLQ query)
        {
            if (!CheckTableExistance(SurveyHelper.ActiveSurvey.survey_name))
            {
                return(false);
            }
            if (!CheckTreeExists(query.tree_id))
            {
                return(false);
            }

            try
            {
                connection = new SqliteConnection(GetAppendedConnString());
                connection.Open();

                using (SqliteCommand command = new SqliteCommand(connection))
                {
                    command.CommandText = $"DELETE FROM [{SurveyHelper.ActiveSurvey.survey_name}] WHERE [Tree ID] = :treeid";
                    command.Parameters.Add("treeid", DbType.String).Value = query.tree_id;

                    command.ExecuteNonQuery();
                }

                connection.Close();
                return(true);
            }
            catch (Exception ex)
            {
                Toast.MakeText(Application.Context, $"Delete query for {query.tree_id} has failed.", ToastLength.Long);
                return(false);
            }
        }
        public void ProcessSpeech(string input, out NLQ current_query)
        {
            switch (GetSessionDirective(input))
            {
            case SessionDirective.ADD_PROPERTY:

                break;

            case SessionDirective.EDIT_PROPERTY:
                input = input.ToLower();
                input = input.Replace("edit", "");
                input = input.TrimStart(' ');

                EditProperty(input);
                break;

            case SessionDirective.DELETE_RECORD:

                break;

            case SessionDirective.START_NEW_SESSION:
                NLQ start_query;
                if (!have_tree_id)
                {
                    // add NLQ to mark the start of a session
                    start_query            = new NLQ();
                    start_query.query_type = SurveyHelper.QueryTypes.SESSION_START;
                    session_queries.Add(start_query);

                    SetActiveTree(input.Split(' ')[1]);
                }
                break;

            case SessionDirective.END_SESSION:
                input = input.ToLower();

                NLQ end_query = new NLQ();
                end_query.query_type = SurveyHelper.QueryTypes.SESSION_END;
                session_queries.Add(end_query);

                session_isOpen = false;
                break;

            default:
            case SessionDirective.NULL_Q:
                current_query = null;
                break;
            }

            if (session_queries.Count() > 0)
            {
                current_query = session_queries.Last();
            }
            else
            {
                current_query = null;
            }
        }
        private void EditProperty(string input)
        {
            NLQ new_query = new NLQ();

            string property_to_edit = GetProperty(input);

            if (string.IsNullOrEmpty(property_to_edit))
            {
                Toast.MakeText(Application.Context, $"Cannot find property {input.Split(' ')[0]}", ToastLength.Long);
                return;
            }

            new_query.tree_id           = tree_id;
            new_query.query_type        = SurveyHelper.QueryTypes.EDIT_RECORD;
            new_query.property_actioned = property_to_edit;
            new_query.property_val_new  = input.Substring(property_to_edit.Length);
            new_query.property_val_old  = SQLiteHelper.GetTreeOldValue(tree_id, property_to_edit);

            session_queries.Add(new_query);
        }
Beispiel #6
0
        //public static string GetTreeOldValue(string tree_id, string column_header)
        //{
        //    connection = new SqliteConnection(GetAppendedConnString());
        //    connection.Open();

        //    string return_val = null;

        //    using (SqliteCommand get_old_val = new SqliteCommand(connection))
        //    {
        //        get_old_val.CommandText = string.Format("SELECT [{0}] FROM [{1}] WHERE [Tree ID]='{2}';", column_header, SurveyHelper.ActiveSurvey.survey_name, tree_id);

        //        using (SqliteDataReader reader = get_old_val.ExecuteReader())
        //        {
        //            while (reader.Read())
        //                return reader.GetString(0);
        //        }
        //    }

        //    return null;

        //}

        public static bool ExecuteNLQ(NLQ query)
        {
            bool isSuccess = true;

            switch (query.query_type)
            {
            case SurveyHelper.QueryTypes.ADD_RECORD:
                isSuccess = ExecuteAddRecord(query);
                break;

            case SurveyHelper.QueryTypes.EDIT_RECORD:
                isSuccess = ExecuteEditRecord(query);
                break;

            case SurveyHelper.QueryTypes.DELETE_RECORD:
                isSuccess = ExecuteDeleteRecord(query);
                break;
            }

            return(isSuccess);
        }
Beispiel #7
0
        private static bool ExecuteAddRecord(NLQ query)
        {
            if (!CheckTableExistance(SurveyHelper.ActiveSurvey.survey_name))
            {
                return(false);
            }
            if (!CheckTreeExists(query.tree_id))
            {
                return(false);
            }

            try
            {
                connection = new SqliteConnection(GetAppendedConnString());
                connection.Open();


                using (SqliteCommand command = new SqliteCommand(connection))
                {
                    /*
                     * To implement adding a new record efficiently it might be a good idea to design
                     * another Speech Processing segment that's optimised for stating a new TreeID
                     * and then subsequently recording a list of parameters that are then added to a list in
                     * the NLQ class.
                     * The Add query can then be contained within one NLQ instance where the parameter list is
                     * iterated through when adding paramenters to a prepared INSERT statement.
                     */
                }
                return(true);
            }
            catch (Exception ex)
            {
                Toast.MakeText(Application.Context, $"Add query for {query.tree_id} has failed.", ToastLength.Long);
                return(false);
            }
        }
Beispiel #8
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            Xamarin.Essentials.Platform.Init(this, savedInstanceState);
            SetContentView(Resource.Layout.activity_main);


            // Get the control resources from the layout
            frame_home      = FindViewById <FrameLayout>(Resource.Id.frame_home);
            frame_dashboard = FindViewById <FrameLayout>(Resource.Id.frame_dashboard);
            frame_log       = FindViewById <RelativeLayout>(Resource.Id.frame_log);


            upload_btn = (Button)FindViewById(Resource.Id.dashboard_uploadBtn);
            record_btn = (Button)FindViewById(Resource.Id.dashboard_recordBtn);


            textview_status        = FindViewById <TextView>(Resource.Id.dashboard_file_status);
            textview_record_status = FindViewById <TextView>(Resource.Id.dashboard_record_status);


            upload_btn.Click += Upload_btn_Click;
            record_btn.Click += Record_btn_Click;


            edittext_treeid   = FindViewById <EditText>(Resource.Id.current_q_treeid_edittext);
            edittext_property = FindViewById <EditText>(Resource.Id.current_q_property_edittext);
            edittext_oldval   = FindViewById <EditText>(Resource.Id.current_q_oldval_edittext);
            edittext_newval   = FindViewById <EditText>(Resource.Id.current_q_newval_edittext);


            log_listview             = FindViewById <ListView>(Resource.Id.log_listview);
            session_listview_adapter = new SessionAdapter(sessions);
            log_listview.Adapter     = session_listview_adapter;
            log_listview.ItemClick  += Log_listview_ItemClick;


            InterpretationInstance instance;
            NLQ query;

            string[] queryTypes = { "SESSION_START", "GET_TREE", "EDIT_PROPERTY", "SESION_END" };
            Random   rand       = new Random();

            for (int i = 0; i < 10; i++)
            {
                instance                  = new InterpretationInstance();
                instance.survey_name      = "BS5837 Test Survey";
                instance.tree_id          = "T" + rand.Next(1, 100).ToString();
                instance.session_datetime = DateTime.Now;

                int count = 0;
                for (int j = 0; j < 4; j++)
                {
                    query                   = new NLQ();
                    query.tree_id           = instance.tree_id;
                    query.query_type        = queryTypes[count];
                    query.property_actioned = "Maturity";
                    query.property_val_old  = "Young";
                    query.property_val_new  = "Mature";

                    instance.session_queries.Add(query);
                    count++;
                }


                sessions.Add(instance);
            }


            listview_detailed_log            = FindViewById <ListView>(Resource.Id.detailed_listview);
            listview_detailed_log.ItemClick += Listview_detailed_log_ItemClick;
            button_execute_all        = FindViewById <Button>(Resource.Id.button_exe_all);
            button_execute_all.Click += Button_execute_all_Click;


            textview_itemdetail_title     = FindViewById <TextView>(Resource.Id.query_detail_name);
            textview_itemdetail_qtype     = FindViewById <TextView>(Resource.Id.query_detail_querytype_val);
            edittext_itemdetail_prop      = FindViewById <EditText>(Resource.Id.query_detail_property_val);
            edittext_itemdetail_oldval    = FindViewById <EditText>(Resource.Id.query_detail_oldval_val);
            edittext_itemdetail_newval    = FindViewById <EditText>(Resource.Id.query_detail_newval_val);
            button_itemdetail_save        = FindViewById <Button>(Resource.Id.query_detail_save_button);
            button_itemdetail_save.Click += Button_itemdetail_save_Click;


            vf = FindViewById <ViewFlipper>(Resource.Id.viewflipper_logview);


            button_export        = FindViewById <Button>(Resource.Id.button_export);
            button_export.Click += Button_export_Click;


            BottomNavigationView navigation = FindViewById <BottomNavigationView>(Resource.Id.navigation);

            navigation.SetOnNavigationItemSelectedListener(this);
        }