<commit_before>package com.example.falltimeseries;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.List;

import android.app.Activity;
import android.content.Context;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.os.Bundle;
import android.os.Environment;
import android.util.Log;
import android.view.View;
import android.widget.TextView;

public class MainActivity extends Activity implements SensorEventListener {

	private SensorManager mSensorManager;
	private Sensor mOriSensor, mAccSensor;
	private TextView t_o_x, t_o_y, t_o_z;
	private TextView t_a_x, t_a_y, t_a_z;
	private List<Float> o_x, o_y, o_z;
	private List<Float> a_x, a_y, a_z;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);

		// Get handlers for GUI text
		t_o_x = (TextView)findViewById(R.id.textView1);
		t_o_y = (TextView)findViewById(R.id.textView2);
		t_o_z = (TextView)findViewById(R.id.textView3);
		t_a_x = (TextView)findViewById(R.id.textView5);
		t_a_y = (TextView)findViewById(R.id.textView6);
		t_a_z = (TextView)findViewById(R.id.textView7);
		// Initialize lists
		o_x = new ArrayList<Float>();
		o_y = new ArrayList<Float>();
		o_z = new ArrayList<Float>();
		a_x = new ArrayList<Float>();
		a_y = new ArrayList<Float>();
		a_z = new ArrayList<Float>();
		
		// Register sensor for orientation events
		mSensorManager = (SensorManager)getApplicationContext().getSystemService(Context.SENSOR_SERVICE);
		for (Sensor s : mSensorManager.getSensorList(Sensor.TYPE_ALL)) {
			if (s.getType() == Sensor.TYPE_ORIENTATION) {
				mOriSensor = s;
			}
			else if (s.getType() == Sensor.TYPE_ACCELEROMETER) {
				mAccSensor = s;
			}
		}
		
		Log.w("Ori", mOriSensor.toString());
		Log.w("Acc", mAccSensor.toString());
		// Check that we found a sensor object
		if (mOriSensor == null ||  mAccSensor == null) {
			System.out.println("Did not find all sensors!");
			cleanUp();
		}
		
		mSensorManager.registerListener(this, mOriSensor, SensorManager.SENSOR_DELAY_UI);
		mSensorManager.registerListener(this, mAccSensor, SensorManager.SENSOR_DELAY_UI);
	}

	private void cleanUp() {
		mSensorManager.unregisterListener(this);
		finish();
	}

	public void storeData(View view) {
		storeToSD("o_x.txt", o_x);
		storeToSD("o_y.txt", o_y);
		storeToSD("o_z.txt", o_z);
		storeToSD("a_x.txt", a_x);
		storeToSD("a_y.txt", a_y);
		storeToSD("a_z.txt", a_z);
		cleanUp();
	}
	
	@Override
	public void onAccuracyChanged(Sensor arg0, int arg1) {
		// We don't really care about this
		
	}

	@Override
	public void onSensorChanged(SensorEvent se) {
		if (se.sensor.getType() == Sensor.TYPE_ORIENTATION) { 
			o_x.add(se.values[0]);
			o_y.add(se.values[1]);
			o_z.add(se.values[2]);
			t_o_x.setText(String.valueOf(se.values[0]));
			t_o_y.setText(String.valueOf(se.values[1]));
			t_o_z.setText(String.valueOf(se.values[2]));
		}
		else if (se.sensor.getType() == Sensor.TYPE_ACCELEROMETER) {
			a_x.add(se.values[0]);
			a_y.add(se.values[1]);
			a_z.add(se.values[2]);
			t_a_x.setText(String.valueOf(se.values[0]));
			t_a_y.setText(String.valueOf(se.values[1]));
			t_a_z.setText(String.valueOf(se.values[2]));
		}
	}
	
	private void storeToSD(String filename, List<Float> values) {
		File path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
		File file = new File(path, filename);
		try {
			OutputStream os = new FileOutputStream(file);
			for (Float f : values) {
				os.write((String.valueOf(f)+"\n").getBytes());
			}
		} catch(IOException e) {
			Log.w("ExternalStorage", "Error writing " + file, e);
		}
	}

}
<commit_msg>CSV separated values and rounded values.<commit_after>package com.example.falltimeseries;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import android.app.Activity;
import android.content.Context;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.os.Bundle;
import android.os.Environment;
import android.util.Log;
import android.view.View;
import android.widget.TextView;

public class MainActivity extends Activity implements SensorEventListener {

	private SensorManager mSensorManager;
	private Sensor mOriSensor, mAccSensor;
//	private TextView t_o_x, t_o_y, t_o_z;
	private TextView t_a_x, t_a_y, t_a_z;
//	private List<Float> o_x, o_y, o_z;
	private List<Object> a_x, a_y, a_z;
	private List<Object> csv;
	private Date start;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);

		// Get handlers for GUI text
//		t_o_x = (TextView)findViewById(R.id.textView1);
//		t_o_y = (TextView)findViewById(R.id.textView2);
//		t_o_z = (TextView)findViewById(R.id.textView3);
		t_a_x = (TextView)findViewById(R.id.textView5);
		t_a_y = (TextView)findViewById(R.id.textView6);
		t_a_z = (TextView)findViewById(R.id.textView7);
		// Initialize lists
//		o_x = new ArrayList<Float>();
//		o_y = new ArrayList<Float>();
//		o_z = new ArrayList<Float>();
		a_x = new ArrayList<Object>();
		a_y = new ArrayList<Object>();
		a_z = new ArrayList<Object>();
		csv = new ArrayList<Object>();
		
		// Register sensor for orientation events
		mSensorManager = (SensorManager)getApplicationContext().getSystemService(Context.SENSOR_SERVICE);
		for (Sensor s : mSensorManager.getSensorList(Sensor.TYPE_ALL)) {
			if (s.getType() == Sensor.TYPE_ORIENTATION) {
				mOriSensor = s;
			}
			else if (s.getType() == Sensor.TYPE_ACCELEROMETER) {
				mAccSensor = s;
			}
		}
		
//		Log.w("Ori", mOriSensor.toString());
		Log.w("Acc", mAccSensor.toString());
		// Check that we found a sensor object
		if (mOriSensor == null ||  mAccSensor == null) {
			System.out.println("Did not find all sensors!");
			cleanUp();
		}
		
//		mSensorManager.registerListener(this, mOriSensor, SensorManager.SENSOR_DELAY_UI);
		mSensorManager.registerListener(this, mAccSensor, SensorManager.SENSOR_DELAY_GAME);
	}

	private void cleanUp() {
		mSensorManager.unregisterListener(this);
		finish();
	}

	public void storeData(View view) {
//		storeToSD("o_x.txt", o_x);
//		storeToSD("o_y.txt", o_y);
//		storeToSD("o_z.txt", o_z);
		storeToSD("a_x.txt", a_x);
		storeToSD("a_y.txt", a_y);
		storeToSD("a_z.txt", a_z);
		storeToSD("csvdata.txt", csv);
		cleanUp();
	}
	
	@Override
	public void onAccuracyChanged(Sensor arg0, int arg1) {
		// We don't really care about this
		
	}

	@Override
	public void onSensorChanged(SensorEvent se) {
		if (se.sensor.getType() == Sensor.TYPE_ACCELEROMETER) {
			if(start == null){
				start = new Date();
				csv.add("#START#" + (start.getTime() / 1000));
			}
			else if(((new Date()).getTime() - start.getTime()) > 10000){
				csv.add("#END#" + ((new Date()).getTime() / 1000));
				start = new Date();
				csv.add("#START#" + (start.getTime() / 1000));
			}
			a_x.add(se.values[0]);
			a_y.add(se.values[1]);
			a_z.add(se.values[2]);
			t_a_x.setText(String.valueOf(se.values[0]));
			t_a_y.setText(String.valueOf(se.values[1]));
			t_a_z.setText(String.valueOf(se.values[2]));
			DecimalFormat df = new DecimalFormat("#.##");
			//df.setRoundingMode(java.math.RoundingMode.HALF_UP); //requires min api 9...
			csv.add(df.format(se.values[0]) + ";" + df.format(se.values[1]) + ";" + df.format(se.values[2]));
		}
	}
	
	private void storeToSD(String filename, List<Object> values) {
		File path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
		File file = new File(path, filename);
		try {
			OutputStream os = new FileOutputStream(file);
			for (Object f : values) {
				os.write((String.valueOf(f)+"\n").getBytes());
			}
		} catch(IOException e) {
			Log.w("ExternalStorage", "Error writing " + file, e);
		}
	}

}

{'fraction_non_alphanumeric': 0.14693330081697353, 'fraction_numerical': 0.00670649920741373, 'mean_word_length': 4.575798776342624, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 24, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7248810', 'n_tokens_mistral': 3210, 'n_tokens_neox': 2981, 'n_words': 553}