Exemple #1
0
        public void write_subj_to_file(Subj_Data S)
        {
            Console.WriteLine("WRITING GAZE PT DATA TO FILE");
            //String out_path = Path.GetFullPath(System.Environment.GetCommandLineArgs()[1]);
            //String filename = out_path + "\\OUT_S" + Convert.ToString(S.get_ID()) + ".txt";

            String filename = @"C:\Users\pkhorra2\Documents\AvaScholar\Attention_Detector\C#_Proj\Server_Mult_Version\MultiThreadServer_w_log\out.txt";

            StreamWriter sW = new StreamWriter(filename);
            //ArrayList gaze_pts = S.get_gaze_pts();
            List<Exp_Data_Pt> gaze_pts = S.get_pt_list();
            for (int i = 0; i < gaze_pts.Count; i++)
            {
                //Point_Obj g = gaze_pts[i].gaze_pt;
                //DateTime T = gaze_pts[i].time_stamp;
                //sW.WriteLine("({0}, {1}) -- TIME: " + T.ToString(), g.get_x(), g.get_y()); //T.ToString());
                //sW.WriteLine("TICKS: {0}", T.Ticks);
            }
            sW.Flush();
            sW.Close();
            Console.WriteLine("DONE WRITING");
        }
Exemple #2
0
        public void serve_client(TcpClient client, int ID)
        {
            write_to_msg_box("Client " + Convert.ToString(ID) + " Connected!!\n");
            NetworkStream stream = client.GetStream();
            // Array to store incoming data
            Byte[] bytes = new Byte[PACKET_LENGTH];

            // Object to store information about subject
            Subj_Data S = new Subj_Data(client, ID);
            // Object to get confid values based on 2D Gaussian
            int i;

            clear_chart(ID);

            try
            {
                while ((i = stream.Read(bytes, 0, PACKET_LENGTH)) != 0)
                {
                    // Convert byte array to float
                    float[] float_array = new float[NUM_FLOATS];
                    Console.Write("\n"+Convert.ToString(ID)+" - ");
                    for (int ii = 0; ii < float_array.Length; ii++)
                    {
                        float_array[ii] = BitConverter.ToSingle(bytes, ii * sizeof(float));
                        if (ii < 11)
                            Console.Write(float_array[ii] + " ");
                    }
                    //Console.Write("\n");

                    Console.Write("\n" + Convert.ToString(ID) + " - ");
                    for (int ii = 256; ii < float_array.Length; ii++)
                    {
                        float_array[ii] = BitConverter.ToSingle(bytes, ii * sizeof(float));
                        if (ii < 267)
                            Console.Write(float_array[ii] + " ");
                    }
                    Console.Write("\n");

                    // Process float array and add exp scores to subj. list
                    //Console.WriteLine("{0} - elements in S", S.get_pt_list().Count);
                    float success_flag = process_float_data(float_array, S);
                    //Console.WriteLine("{0} - elements in S", S.get_pt_list().Count);

                    // Plot/log expression scores
                    if (success_flag == 1.0F)
                    {
                        write_pt_to_hist(S);
                    }

                }

                stream.Close();
                client.Close();
                write_to_msg_box("Connection to Client " + Convert.ToString(S.get_ID()) + " Closed");

                // Set occupied flag back to 0 (need thread-safe call)
                mut.WaitOne();
                occupied_flags[ID] = 0; // atomic (?)
                write_to_msg_box("CLIENT FLAG ARRAY: " + occupied_flags[0].ToString() + " " + occupied_flags[1].ToString()+" "+occupied_flags[2].ToString());
                sC.all_subj.Add(S);
                mut.ReleaseMutex();

                //File_IO F = new File_IO();
                //F.write_subj_to_file(S);

            }
            catch (Exception EE)
            {
                Console.WriteLine("EXCEPTION: {0}\n", EE.Message);
                //all_subj.Add(S);
                stream.Close();
                client.Close();
                write_to_msg_box("Connection to Client "+Convert.ToString(S.get_ID())+" Closed");

                // Set occupied flag back to 0 (need thread-safe call)
                mut.WaitOne();
                occupied_flags[ID] = 0; // atomic (?)
                write_to_msg_box("CLIENT FLAG ARRAY: " + occupied_flags[0].ToString() + " " + occupied_flags[1].ToString()+" "+occupied_flags[2].ToString());
                sC.all_subj.Add(S);
                mut.ReleaseMutex();

                //File_IO F = new File_IO();
                //F.write_subj_to_file(S);

            }
        }
Exemple #3
0
        private void write_pt_to_hist(Subj_Data S)
        {
            int frame_num = S.get_pt_list().Last().frame_num;
            int ID = S.get_ID();
            if (((Chart)this.hist_chart_list[ID]).InvokeRequired)
            {
                ChartHistCallback cH = new ChartHistCallback(write_pt_to_hist);
                this.Invoke(cH, new object[] { S });
            }
            else
            {
                Exp_Data_Pt exp_pt = S.get_pt_list().Last();

                Chart chart = (Chart)this.hist_chart_list[ID];
                chart.ChartAreas[0].AxisX.Maximum = frame_num; // display points up to current frame

                float SUM = (exp_pt.neu_score + exp_pt.neg_score + exp_pt.pos_score + exp_pt.surp_score);

                chart.Series[0].Points.AddXY(frame_num, exp_pt.neu_score/SUM);
                chart.Series[1].Points.AddXY(frame_num, exp_pt.neg_score/SUM);
                chart.Series[2].Points.AddXY(frame_num, exp_pt.pos_score/SUM);
                chart.Series[3].Points.AddXY(frame_num, exp_pt.surp_score/SUM);

                if (frame_num > 50)
                {
                    chart.ChartAreas[0].AxisX.Minimum = chart.ChartAreas[0].AxisX.Maximum - 50;
                }
            }
        }
Exemple #4
0
        private float process_float_data(float[] input_array, Subj_Data S)
        {
            float frame_num = input_array[0];
            float success_flag = input_array[1];

            int ID = S.get_ID();

            if (success_flag == 0.0)
            {
                Console.WriteLine("{0}: Tracking Failure", Convert.ToInt32(frame_num));
                S.add_to_pt_list(new Exp_Data_Pt((int)frame_num, DateTime.Now, 0.0F, 0.0F, 0.0F, 0.0F));
            }
            else if (success_flag == 1.0)
            {
                float neu_score = input_array[2];
                float neg_score = input_array[3];
                float pos_score = input_array[4];
                float surp_score = input_array[5];

                Console.Write("{0}: Tracking Package", Convert.ToInt32(frame_num));
                S.add_to_pt_list(new Exp_Data_Pt((int)frame_num, DateTime.Now, neu_score, neg_score, pos_score, surp_score));
            }
            else if (success_flag == 2.0)
            {
                float age = input_array[2];
                float gender = input_array[3];

                Console.WriteLine("{0}: Age/Gender Package", Convert.ToInt32(frame_num));
                S.set_age(Convert.ToInt32(age));

                if (gender >= 0.5F)
                {
                    // Male
                    S.set_gender('M');
                }
                else
                {
                    // Female
                    S.set_gender('F');
                }
                disp_age(S);
                disp_gender(S);

            }
            return success_flag;
        }
Exemple #5
0
 private void disp_gender(Subj_Data S)
 {
     int ID = S.get_ID();
     if (((TextBox)this.gender_list[ID]).InvokeRequired)
     {
         GenderBoxCallback g = new GenderBoxCallback(disp_gender);
         this.Invoke(g, new object[] { S });
     }
     else
     {
         TextBox t = (TextBox)this.gender_list[ID];
         //t.Text = Math.Round(S.get_age()).ToString();
         char gender = S.get_gender();
         if (gender == 'F')
         {
             t.BackColor = Color.Indigo;
             t.ForeColor = Color.White;
             t.Text = "FEMALE";
         }
         else
         {
             t.BackColor = Color.DimGray;
             t.ForeColor = Color.White;
             t.Text = "MALE";
         }
     }
 }
Exemple #6
0
 private void disp_age(Subj_Data S)
 {
     int ID = S.get_ID();
     if (((TextBox)this.age_list[ID]).InvokeRequired)
     {
         AgeBoxCallback a = new AgeBoxCallback(disp_age);
         this.Invoke(a, new object[]{ S });
     }
     else
     {
         TextBox t = (TextBox)this.age_list[ID];
         t.Text = Math.Round(S.get_age()).ToString();
     }
 }