Ejemplo n.º 1
0
        public void Write(train t)
        {
            string str = "insert into " + train_table + " values(" + t.id + "," + t.d + ",";

            for (int i = 0; i < t.d; ++i)
            {
                str += t.msg1[i] + ",";
            }
            for (int i = 0; i < t.d; ++i)
            {
                str += t.msg2[i] + ",";
            }
            str += t.flag + ")";

            if (sqlconnection == null)
            {
                log("database is closing");
                train_id--;
            }
            else
            {
                log(str);
            }

            MySqlCommand command = new MySqlCommand(str, sqlconnection);

            command.CommandText = str;
            command.ExecuteNonQuery();
        }
Ejemplo n.º 2
0
        private void test(object sender, RoutedEventArgs e)
        {
            if (debug == 0)
            {
                string text = "test";
                SendData(sdr, text);
                log("send " + "\"" + text + "\"" + " to " + sdr.ip);
            }
            else if (debug == 1)
            {
                Random   random = new Random();
                double[] msg1   = new double[M];
                double[] msg2   = new double[M];
                for (int i = 0; i < M; ++i)
                {
                    msg1[i] = random.NextDouble();
                    msg2[i] = random.NextDouble();
                }
                train t = new train(train_id++, M, msg1, msg2, true);
                Write(t);
                log("insert a test data(" + t.id + ") to database");
            }
            else if (debug == 2)
            {
                string text = "server@1";
                SendData(sdr, text);
                log("send " + "\"" + text + "\"" + " to " + sdr.ip);
            }
            else if (debug == 3)
            {
                if (sqlconnection == null)
                {
                    log("database is close");
                }
                else if (ReadTrain())
                {
                    List <train> train_tmp;
                    List <train> validacation_tmp;
                    CrossValidation(out train_tmp, out validacation_tmp, train_set);
                    TrianModelList(train_tmp);
                    validition_tmp = validacation_tmp;
                }



                // if (ReadValidation())  //改一下
                //    AnalystValidationData();
            }
        }
Ejemplo n.º 3
0
        public void operateModeA(Client client, String data)
        {
            string getfromSDS1 = "web@Mode1@d#Msg1#flag";
            string sendtoSDR1  = "server@Mode1";
            string getfromSDR1 = "android@Model@d#Msg2";
            string sendtoDB1   = "send train data to database";


            string getfromSDS2 = "web@Mode2@d#Msg1";
            string sendtoSDR2  = "server@Mode2";
            string getfromSDR2 = "android@Mode2@d#Msg2";
            string sendtoNB2   = "send validation data to naive bayes and get flag";

            string sendtoSDS3  = "server@Model3@flag";
            string getfromSDS3 = "web@Model3@flagR";
            string sendtoDB3   = "send validation data to database";

            string sendtoSDS4 = "server@Model4"; // SDR is not connected
            string sendtoSDS5 = "server@Model5"; //Model is not exist
            string sendtoSDS6 = "server@Model6"; //flagR is not allowed

            log("get \"" + data + "\"" + " from " + client.ip);

            string[] ss = data.Split('@');

            if (ss[0] == "android" && ss[1] == "1")
            {
                string[] tt = ss[2].Split('#');
                d    = int.Parse(tt[0]);
                Msg2 = new double[d];
                string[] rr = tt[1].Split(',');
                for (int i = 0; i < d; ++i)
                {
                    Msg2[i] = double.Parse(rr[i]);
                }

                train t = new train(train_id++, d, Msg1, Msg2, flag);
                Write(t);
            }
            if (ss[0] == "android" && ss[1] == "2")
            {
                string[] tt = ss[2].Split('#');
                d    = int.Parse(tt[0]);
                Msg2 = new double[d];
                string[] rr = tt[1].Split(',');
                for (int i = 0; i < d; ++i)
                {
                    Msg2[i] = double.Parse(rr[i]);
                }

                data        validation_data = new data(d, Msg1, Msg2);
                List <bool> flagList        = ClassifierList(validation_data);
                string      flaglist        = "";
                int         flen            = flagList.Count;
                for (int i = 0; i < flen; ++i)
                {
                    if (i < flen - 1)
                    {
                        flaglist += flagList[i] + "#";
                    }
                    else
                    {
                        flaglist += flagList[i];
                    }
                }
                this.flaglist = flaglist;
                string text = "server@3@" + flaglist;
                iwsc.Send(text);
                log("send " + "\"" + text + "\"" + " to " + iwsc.ConnectionInfo.ClientIpAddress);

                IsflagRopen = true;
            }


            // MessageBox.Show(data);
            if (client.ip != "192.168.1.108") //第二台有效坐标
            {
            }
            else if (client.ip == "192.168.1.108") //第一台有效坐标
            {
            }
        }