SensorModelDataCollector/src/com/clarkson/sensormodeldatacollector/WiFiScanActivity.java
/*
    Writes access point collected data to CSV files
     */
Writes access point collected data to CSV files
Writes access point collected data to CSV files
@SuppressLint("SdCardPath")
	boolean writeAPDataToCSVFile()
	{
		boolean file_written_successfully = false;
		WiFiScanResult selected_AP_scan_result_data = ( WiFiScanResult ) mScanResultsArrayList.get(mCurrentlySelectedItemIndex);
		if(mWriteToCSVFile == true && Environment.getExternalStorageState() != Environment.MEDIA_MOUNTED_READ_ONLY)        
		{
			try
            {
				String column_header_string="SSID,Channel,Frequency,MAC,RSS,Timestamp,Local Time\n";
				Log.d(getLocalClassName(), "Step 11A: Logging to CSV file");
                File new_file = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS) + File.separator + "SensorModelDataCollector");
                boolean folder_success = true;
				if (!new_file.exists())
                {
                    folder_success |= new_file.mkdir();
				}
				if(folder_success == true)
				{
					String output_filename = selected_AP_scan_result_data.mSSID+"_"+selected_AP_scan_result_data.getLatestTimestampedRSS().mTimestamp+"_"+ getCurrentDateString() + ".csv";
                    File output_file = new File(new_file, output_filename);
					if (output_file.exists() == false)
					{
						output_file.createNewFile();
					}
					if(output_file.canWrite() == true)
					{
						FileWriter output_file_writer = new FileWriter(output_file);
                        output_file_writer.append(column_header_string);
						String data_row_output_string = selected_AP_scan_result_data.mSSID + ",";
                        data_row_output_string += selected_AP_scan_result_data.channel + ",";
                        data_row_output_string += selected_AP_scan_result_data.frequency_MHz + ",";
                        data_row_output_string += selected_AP_scan_result_data.getMac_address() + ",";
						Queue<TimestampedRSS> all_rss_values = selected_AP_scan_result_data.getAllRSS();
						String rss_string = "";
						Iterator<TimestampedRSS> rss_iterator = all_rss_values.iterator();
						while (rss_iterator.hasNext() == true)
						{
							Log.d(getLocalClassName(), "Step 10A: RSS Strings Assembled");
							rss_string = rss_iterator.next().rssTimestampPair();
							output_file_writer.append(data_row_output_string + rss_string + "\n");
						}
						output_file_writer.flush();
						output_file_writer.close();
						file_written_successfully = true;
					}
					else
					{
						Log.d(getLocalClassName(), "Step 10C: No file write access permission");
					}
				}
			}
			catch (IOException ioe) 
			{ioe.printStackTrace();}
		}
		else
		{
			Log.d(getLocalClassName(), "Step 11B: mWriteToCSVFile set to false or media not mounted for write");
		}
		return file_written_successfully;
	}
@ SuppressLint ( "SdCardPath" ) boolean writeAPDataToCSVFile ( ) { boolean file_written_successfully = false ; WiFiScanResult selected_AP_scan_result_data = ( WiFiScanResult ) mScanResultsArrayList . get ( mCurrentlySelectedItemIndex ) ; if ( mWriteToCSVFile == true && Environment . getExternalStorageState ( ) != Environment . MEDIA_MOUNTED_READ_ONLY ) { try { String column_header_string = "SSID,Channel,Frequency,MAC,RSS,Timestamp,Local Time\n" ; Log . d ( getLocalClassName ( ) , "Step 11A: Logging to CSV file" ) ; File new_file = new File ( Environment . getExternalStoragePublicDirectory ( Environment . DIRECTORY_DOWNLOADS ) + File . separator + "SensorModelDataCollector" ) ; boolean folder_success = true ; if ( ! new_file . exists ( ) ) { folder_success |= new_file . mkdir ( ) ; } if ( folder_success == true ) { String output_filename = selected_AP_scan_result_data . mSSID + "_" + selected_AP_scan_result_data . getLatestTimestampedRSS ( ) . mTimestamp + "_" + getCurrentDateString ( ) + ".csv" ; File output_file = new File ( new_file , output_filename ) ; if ( output_file . exists ( ) == false ) { output_file . createNewFile ( ) ; } if ( output_file . canWrite ( ) == true ) { FileWriter output_file_writer = new FileWriter ( output_file ) ; output_file_writer . append ( column_header_string ) ; String data_row_output_string = selected_AP_scan_result_data . mSSID + "," ; data_row_output_string += selected_AP_scan_result_data . channel + "," ; data_row_output_string += selected_AP_scan_result_data . frequency_MHz + "," ; data_row_output_string += selected_AP_scan_result_data . getMac_address ( ) + "," ; Queue < TimestampedRSS > all_rss_values = selected_AP_scan_result_data . getAllRSS ( ) ; String rss_string = "" ; Iterator < TimestampedRSS > rss_iterator = all_rss_values . iterator ( ) ; while ( rss_iterator . hasNext ( ) == true ) { Log . d ( getLocalClassName ( ) , "Step 10A: RSS Strings Assembled" ) ; rss_string = rss_iterator . next ( ) . rssTimestampPair ( ) ; output_file_writer . append ( data_row_output_string + rss_string + "\n" ) ; } output_file_writer . flush ( ) ; output_file_writer . close ( ) ; file_written_successfully = true ; } else { Log . d ( getLocalClassName ( ) , "Step 10C: No file write access permission" ) ; } } } catch ( IOException ioe ) { ioe . printStackTrace ( ) ; } } else { Log . d ( getLocalClassName ( ) , "Step 11B: mWriteToCSVFile set to false or media not mounted for write" ) ; } return file_written_successfully ; }
Writes access point collected data to CSV files
Writes access point collected data to CSV files
//File output_folder = new File(Environment.getExternalStorageDirectory() + File.separator + "SensorModelDataCollector");
 //File new_file = new File(getFilesDir() + File.separator + "SensorModelDataCollector");
 //folder_success = output_folder.mkdir();
 //if
 //File output_file = new File(output_folder, output_filename);
 //output_file2.createNewFile();
 //if - file doesn't exist, create it
 //while
 //if
 //else
 //if
 //try
 //if
 //else
 //writeAccelerometerDataToFile();
