public void by_position_to_by_signal_strength(string by_position_data_file, List<Location>[, ,] transformed_data) { MinMax min_max_signal_strength; uint position_count, node_count, orientation_count; MinMaxSignalStrength min_max = new MinMaxSignalStrength(); PersistedDataByPosition data_in = new PersistedDataByPosition(new FileStream(by_position_data_file, FileMode.Open, FileAccess.Read)); List<uint>[, ,] loaded_data = data_in.load(); position_count = (uint)loaded_data.GetLength(0); node_count = (uint)loaded_data.GetLength(1); orientation_count = (uint)loaded_data.GetLength(2); for (uint position_index = 0; position_index < position_count; ++position_index) { for (uint node = 0; node < node_count; ++node) { for (uint orientation = 0; orientation < orientation_count; ++orientation) { min_max_signal_strength = min_max.calculate_min_max_signal_strength(loaded_data[position_index, node, orientation]); for (uint signal_strength = min_max_signal_strength.min; signal_strength <= min_max_signal_strength.max; ++signal_strength) { if (transformed_data[signal_strength, node, orientation] == null) { transformed_data[signal_strength, node, orientation] = new List<Location>(); } transformed_data[signal_strength, node, orientation].Add(data_in.position_index_to_location(position_index)); transformed_data[signal_strength, node, orientation].Sort(); } } } } }
private void btn_start_collecting_Click(object sender, EventArgs e) { xb.open(); if (xb.get_valid_signal_strengths()[Constant.NUM_NODES] > 0) { sig_strength_receiver = new RelaySignalStrengthReceiver(xb); } else { sig_strength_receiver = new DirectSignalStrengthReceiver(xb); } test_data_path = "../../../formatter/bin/release/data/collected_data/Position_"; test_data_path += nud_x_coord.Value; test_data_path += "_"; test_data_path += nud_y_coord.Value; test_data_path += "_Orientation_"; test_data_path += lst_orientation.SelectedIndex.ToString(); test_data_path += ".txt"; for (int i = 0; i < Constant.NUM_NODES; ++i) { Control[] nodeLabel = this.Controls.Find("lbl_node_" + (i + 1) + "_status", false); nodeLabel[0].Text = "Incomplete"; nodeLabel[0].ForeColor = Color.Maroon; } Location loc = new Location((float)nud_x_coord.Value, (float)nud_y_coord.Value); uint orientation = (uint)lst_orientation.SelectedIndex; //Gets a list of signal strengths. The indices in this array represent the Node ID in which //the signal strengths came. List<uint>[] signal_strengths = new List<uint>[Constant.NUM_NODES]; signal_strengths = sig_strength_receiver.get_signal_strengths(Constant.TIME_SPAN, Constant.MAX_NUM_OF_SIG_STR); xb.close(); for(int i = 0; i < signal_strengths.Length; i++) { if(signal_strengths[i].Count <= 0) { string error_message = "Node " + i + " is not broadcasting!"; throw new Exception(error_message); } } //Opens file to print to. FileStream f_out = new FileStream(test_data_path, FileMode.Create, FileAccess.Write); //Creates a right with the file stream above. StreamWriter s_out = new StreamWriter(f_out); //Gives me access to the to_string function PersistedDataByPosition d = new PersistedDataByPosition(null); //Prints to a file //first line's values are counts. //(x,y), (numNodes), (numOrientations) for one run s_out.WriteLine("1,1 8 1"); for (uint i = 0; i < Constant.NUM_NODES; i++) s_out.WriteLine(d.to_string(loc, i, orientation, signal_strengths[i])); lst_orientation.SetSelected((lst_orientation.SelectedIndex + 1) % 4, true); if (lst_orientation.SelectedIndex == 0) { nud_x_coord.Value = (nud_x_coord.Value + 1); if (nud_x_coord.Value == 0) { nud_y_coord.Value = (nud_y_coord.Value + 1); } } s_out.Close(); }
public void create_empty_text_files_for_positions_not_tested(DirectoryInfo dir_info) { //j = Y value for (uint j = 0; j <= 33; j++) { //k = X value for (uint k = 0; k <= 39; k++) { Location loc = new Location(k, j); //l = orientation string collected_data_path = ""; for (uint l = 0; l < Constant.NUM_ORIENTATIONS; l++) { uint orientation = l; collected_data_path = "data/collected_data/Position_"; collected_data_path += k.ToString(); collected_data_path += "_"; collected_data_path += j.ToString(); collected_data_path += "_Orientation_"; collected_data_path += l.ToString(); collected_data_path += ".txt"; //Opens file to print to. try { FileStream f_out = new FileStream(collected_data_path, FileMode.CreateNew, FileAccess.Write); //Creates a right with the file stream above. StreamWriter s_out = new StreamWriter(f_out); //Gives me access to the to_string function PersistedDataByPosition d = new PersistedDataByPosition(null); s_out.WriteLine("1,1 8 1"); List<uint> list = new List<uint>(); for (uint m = 0; m < Constant.NUM_NODES; m++) s_out.WriteLine(d.to_string(loc, m, orientation, list)); s_out.Close(); f_out.Close(); } catch(IOException) { } } } } }