Exemple #1
0
        static void run_test()
        {
            // Essentially runs formatter program directly in test
              string[] args = new string[0];
              Formatter.Main(args);

              FileStream expected_data_stream = new FileStream("fixtures/persisted_data_by_position/expected_output_2.txt", FileMode.Open, FileAccess.Read);
              FileStream actual_data_stream = new FileStream("fixtures/persisted_data_by_position/generated_data_by_signal_strength.txt", FileMode.Open, FileAccess.Read);
              PersistedDataBySignalStrength expected = new PersistedDataBySignalStrength(expected_data_stream);
              PersistedDataBySignalStrength actual = new PersistedDataBySignalStrength(actual_data_stream);
              List<Location>[, ,] expected_data = expected.load();
              List<Location>[, ,] actual_data = actual.load();
              expected_data_stream.Close();
              actual_data_stream.Close();

              string a = to_string(actual_data);
              string b = to_string(expected_data);
              if (a == b)
              {
            Console.WriteLine("correct!");
              }
              else
              {
            Console.WriteLine("incorrect!");
              }
        }
        protected void run_test(string expected_output)
        {
            // Essentially runs formatter program directly in test
              //string path = "../../../bin/Release/";
              string[] args = new string[0];
              Formatter.Main(args);

              FileStream expected_data_stream = new FileStream("fixtures/persisted_data_by_position/" + expected_output, FileMode.Open, FileAccess.Read);
              FileStream actual_data_stream = new FileStream("fixtures/persisted_data_by_position/generated_data_by_signal_strength.txt", FileMode.Open, FileAccess.Read);
              PersistedDataBySignalStrength expected = new PersistedDataBySignalStrength(expected_data_stream);
              PersistedDataBySignalStrength actual = new PersistedDataBySignalStrength(actual_data_stream);
              List<Location>[, ,] expected_data = expected.load();
              List<Location>[, ,] actual_data = actual.load();
              expected_data_stream.Close();
              actual_data_stream.Close();
              Specify.That(to_string(actual_data)).ShouldEqual(to_string(expected_data));
        }
        public void file_format_test()
        {
            FileStream s9 = new FileStream("fixtures/persisted_text_file/file_format.txt", FileMode.Open, FileAccess.Read);
              PersistedDataBySignalStrength p9 = new PersistedDataBySignalStrength(s9);

              List<Location>[, ,] expected_loc;
              List<Location>[, ,] actual_loc;

              expected_loc = new List<Location>[1, 1, 1];
              expected_loc[0, 0, 0] = new List<Location>();
              expected_loc[0, 0, 0].Add(new Location(1, 1));
              expected_loc[0, 0, 0].Add(new Location(1, 2));

              actual_loc = p9.load();

              Specify.That(actual_loc[0, 0, 0][0]).ShouldEqual(expected_loc[0, 0, 0][0]);
              Specify.That(actual_loc[0, 0, 0][1]).ShouldEqual(expected_loc[0, 0, 0][1]);
        }
Exemple #4
0
        public UI()
        {
            InitializeComponent();
              if (!Constant.TESTING)
              {
            xb = new Xbee();
            xb.open();
            xb.enter_api_mode();
              }

              //Initiates C# built-in double buffering
              this.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.DoubleBuffer, true);

              this.Invalidate();
              PersistedDataBySignalStrength d = new PersistedDataBySignalStrength(new FileStream("resources/generated_data_by_signal_strength.txt", FileMode.Open, FileAccess.Read));
              loc = new ArrayBasedLocations(d.load());

              panel1.Visible = false;

              this.room = new BasicRoom();
              this.room.location = new Point(panel1.Location.X, panel1.Location.Y);
              room.size = new Size(panel1.Size.Width, panel1.Size.Height);

              // Initialized displayed orientations
              display_north = true;
              display_east = true;
              display_south = true;
              display_west = true;

              generate_new_location_list_from_signal_strength();
              sld_cluster_radius.set_range(0, 6);
              sld_cluster_radius.value = 1;
              this.clusters = Clusterer.cluster(this.locations, (float)sld_cluster_radius.value);
              sld_num_clusters.set_range(1, clusters.Count);
              sld_num_clusters.value = sld_num_clusters.Maximum;
              lbl_cluster_radius.Text = sld_cluster_radius.value.ToString();
              lbl_num_clusters.Text = sld_num_clusters.value.ToString();

              // Initialize renderer type
              this.room.set_renderer_type(Constant.HEAT_MAP_RENDERER);
        }
        static void Main(string[] args)
        {
            Boolean display_north = false;
              Boolean display_east = false;
              Boolean display_south = false;
              Boolean display_west = false;

              PersistedDataBySignalStrength d = new PersistedDataBySignalStrength
            (new FileStream("resources/generated_data_by_signal_strength.txt", FileMode.Open, FileAccess.Read));
              ILocations loc = new ArrayBasedLocations(d.load());
              List<Location> locations = new List<Location>();
              List<Location> l = new List<Location>();

              string orientation = "";
              int diameter = -1;
              if(args.Length == 2)
              {
            orientation = args[0];
            try
            {
              diameter = Convert.ToInt32(args[1]);
            }
            catch
            {
              Console.WriteLine(program_usage("A valid cluster radius was not entered."));
              return;
            }
              }
              else
              {
            Console.WriteLine(program_usage("Incorrect number of arguments specified."));
            return;
              }

              // Determine Orientation
            if      (orientation == "North"   || orientation == "north")
              display_north = true;
            else if (orientation == "South"   || orientation == "south")
              display_south = true;
            else if (orientation == "East"    || orientation == "east")
              display_east  = true;
            else if (orientation == "West"    || orientation == "west")
              display_west  = true;
            else if (orientation == "Unknown" || orientation == "unknown")
            {
              display_north = true;
              display_east  = true;
              display_south = true;
              display_west  = true;
            }
            else
            {
              Console.WriteLine(program_usage("A valid orientation was not entered."));
              return;
            }

              if (!Constant.TESTING)  //Can turn on/off real code and test code
              {
            Xbee xb = new Xbee();
            xb.open();
            xb.enter_api_mode();

            SignalStrengthReceiver receiver;
            if (xb.get_valid_signal_strengths()[Constant.NUM_NODES] > 0)
            {
              receiver = new RelaySignalStrengthReceiver(xb);
            }
            else
            {
              receiver = new DirectSignalStrengthReceiver(xb);
            }

            uint[] avg_signals = new uint[8];

            avg_signals = receiver.get_avg_signal_strength(2, 200);

            if (display_north)
            {
              for (int i = 0; i < avg_signals.Length; i++)
            l.AddRange(loc.get_locations(i, Orientation.North, avg_signals[i]));
            }
            if (display_south)
            {
              for (int i = 0; i < avg_signals.Length; i++)
            l.AddRange(loc.get_locations(i, Orientation.South, avg_signals[i]));
            }
            if (display_east)
            {
              for (int i = 0; i < avg_signals.Length; i++)
            l.AddRange(loc.get_locations(i, Orientation.East, avg_signals[i]));
            }
            if (display_west)
            {
              for (int i = 0; i < avg_signals.Length; i++)
            l.AddRange(loc.get_locations(i, Orientation.West, avg_signals[i]));
            }
              }
              else
              {
            //Test Code
            if (display_north)
            {
              l.AddRange(loc.get_locations(0, Orientation.North, 55));
              l.AddRange(loc.get_locations(1, Orientation.North, 55));
              l.AddRange(loc.get_locations(2, Orientation.North, 55));
              l.AddRange(loc.get_locations(3, Orientation.North, 55));
            }
            if (display_south)
            {
              l.AddRange(loc.get_locations(0, Orientation.South, 60));
              l.AddRange(loc.get_locations(1, Orientation.South, 60));
              l.AddRange(loc.get_locations(2, Orientation.South, 60));
              l.AddRange(loc.get_locations(3, Orientation.South, 60));
            }
            if (display_east)
            {
              l.AddRange(loc.get_locations(0, Orientation.East, 71));
              l.AddRange(loc.get_locations(1, Orientation.East, 71));
              l.AddRange(loc.get_locations(2, Orientation.East, 71));
              l.AddRange(loc.get_locations(3, Orientation.East, 71));
            }
            if (display_west)
            {
              l.AddRange(loc.get_locations(0, Orientation.West, 59));
              l.AddRange(loc.get_locations(1, Orientation.West, 59));
              l.AddRange(loc.get_locations(2, Orientation.West, 59));
              l.AddRange(loc.get_locations(3, Orientation.West, 59));
            }
              }

              l.Sort();
              locations = l;

              List<Cluster> clusters = Clusterer.cluster(locations, diameter);
              List<PositionWithProb> loc_probs = new List<PositionWithProb>();
              for (int i = 0; i < clusters.Count; i++)
              {
            loc_probs.Add(new PositionWithProb(clusters[i].location, clusters[i].probability));
              }
              PositionWithProbComparer compaerer = new PositionWithProbComparer();
              loc_probs.Sort(compaerer);

              Console.WriteLine();
              Console.WriteLine("{0} {1, 16}", "Position", "Probability");
              Console.WriteLine("{0} {1, 13}", "-----------", "-----------");
              Console.WriteLine("{0, 4} {1, 5}", "X", "Y");
              for (int i = 0; i < clusters.Count; i++)
              {
            Console.WriteLine("{0, 4:0.00}, {1, 5:0.00}: {2, 9:0.000}%", loc_probs[i].location.x,
              loc_probs[i].location.y, loc_probs[i].probability * 100);
              }
        }
        public void controlled_clusterer_test()
        {
            PersistedDataBySignalStrength d = new PersistedDataBySignalStrength(new FileStream("fixtures/clusterer/training_data.txt", FileMode.Open, FileAccess.Read));

              List<Location>[, ,] locations = d.load();

              Location[] expected_clusters1 =
            { l(0,2), l(0,2), l(1,2), l(1,2),
              l(0,2), l(0,2), l(1,2), l(1,2), l(2,2), l(2,2), l(2,2), l(2,2),
              l(2,0), l(2,0), l(2,1), l(2,1),
              l(2,0), l(2,0), l(2,1), l(2,1), l(2,2), l(2,2), l(2,2), l(2,2),
              l(1,2), l(1,2), l(2,1), l(2,1), l(2,2), l(2,2), l(2,2), l(2,2), l(2,3), l(2,3), l(3,2), l(3,2),
              l(2,2), l(2,2), l(2,2), l(2,2), l(2,3), l(2,3), l(2,4), l(2,4),
              l(2,3), l(2,3), l(2,4), l(2,4),
              l(2,2), l(2,2), l(2,2), l(2,2), l(3,2), l(3,2), l(4,2), l(4,2),
              l(3,2), l(3,2), l(4,2), l(4,2)
            };
              uint[] sig_strs1 = { 2, 2, 2, 2 };

              Location[] expected_clusters2 =
            {
              l(0,0), l(0,0), l(0,1), l(1,0),
              l(0,0), l(0,0), l(0,1), l(0,2),
              l(0,1), l(0,2), l(0,3),
              l(0,2), l(0,3), l(0,4), l(0,4),
              l(0,3), l(0,4), l(0,4), l(1,4), l(1,4),
              l(0,0), l(0,0), l(1,0), l(2,0),
              l(0,4), l(0,4), l(1,4), l(1,4), l(2,4), l(2,4),
              l(1,0), l(2,0), l(3,0),
              l(1,4), l(1,4), l(2,4), l(2,4), l(3,4), l(3,4),
              l(2,0), l(3,0), l(4,0), l(4,0),
              l(2,4), l(2,4), l(3,4), l(3,4), l(4,4), l(4,4), l(4,4), l(4,4),
              l(3,0), l(4,0), l(4,0), l(4,1), l(4,1),
              l(4,0), l(4,0), l(4,1), l(4,1), l(4,2), l(4,2),
              l(4,1), l(4,1), l(4,2), l(4,2), l(4,3), l(4,3),
              l(4,2), l(4,2), l(4,3), l(4,3), l(4,4), l(4,4), l(4,4), l(4,4),
              l(3,4), l(3,4), l(4,3), l(4,3), l(4,4), l(4,4), l(4,4), l(4,4)
            };
              uint[] sig_strs2 = { 4, 4, 4, 0 };

              Location[] expected_clusters3 =
            {
              l(0,0),
              l(0,4),
              l(4,0),
              l(4,4)
            };
              uint[] sig_strs3 = { 0, 0, 0, 0 };

              Location[] expected_clusters4 =
            {
              l(0,0), l(0,4), l(4,0),
              l(0,0), l(0,4), l(4,4),
              l(0,0), l(4,0), l(4,4),
              l(0,4), l(4,0), l(4,4)
            };
              uint[] sig_strs4 = { 0, 0, 0, 0 };

              Location[] expected_clusters5 =
            {
              l(0,2), l(0,3), l(1,2),
              l(0,2), l(0,3), l(1,3),
              l(0,2), l(1,2), l(1,3), l(2,2), l(2,2),
              l(0,3), l(1,2), l(1,3), l(1,4),
              l(1,3), l(1,4),
              l(2,0), l(2,0), l(2,1), l(2,1),
              l(2,0), l(2,0), l(2,1), l(2,1), l(2,2), l(2,2),
              l(1,2), l(2,1), l(2,1), l(2,2), l(2,2), l(3,2),
              l(2,2), l(2,2), l(3,2), l(3,3), l(4,2),
              l(3,2), l(3,3), l(3,4), l(4,3),
              l(3,3), l(3,4),
              l(3,2), l(4,2), l(4,3),
              l(3,3), l(4,2), l(4,3)
            };
              uint[] sig_strs5 = { 2, 1, 2, 1 };

              List<Location> expected_clusters = new List<Location>();

              expected_clusters.AddRange(expected_clusters1);
              run_test_on(sig_strs1, expected_clusters, locations, 1);
              expected_clusters.Clear();

              expected_clusters.AddRange(expected_clusters2);
              run_test_on(sig_strs2, expected_clusters, locations, 1);
              expected_clusters.Clear();

              expected_clusters.AddRange(expected_clusters3);
              run_test_on(sig_strs3, expected_clusters, locations, 1);
              expected_clusters.Clear();

              expected_clusters.AddRange(expected_clusters4);
              run_test_on(sig_strs4, expected_clusters, locations, 4);
              expected_clusters.Clear();

              expected_clusters.AddRange(expected_clusters5);
              run_test_on(sig_strs5, expected_clusters, locations, 1);
              expected_clusters.Clear();
        }