Releasing LogUtils, a class for logging to a .csv file

We, team FTCunits, chose to release one of our custom classes to the public! LogUtils is a class we use in our autonomous period for logging the current state of our run to a .csv file, readable by almost all spreadsheet editors.

For starters, to start logging you call StartLogging(), with as arguments an id for referring to a specific file. To log some data, you use Log(), with as arguments a type of message, the message to log, and the id of the logging channel. To close a logging channel, you use StopLogging(), with the argument the id of the channel to close.

The class has support for custom team names and saves the data to the public file directory. Now, the code:

package org.firstinspires.ftc.teamcode;

import android.os.Environment;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Calendar;
import java.util.HashMap;

/**
* Created by guusd on 7/20/2018.
* for logging in the ftc to a .csv file
*/

public class logUtils {

/** the type of logmessage, used for sorting in a spreadsheet editor*/
public enum logType {
normal,
warning,
error
};
/**name of the FTC team, used in the file namesw */
static public String teamname = “FTCUnits”;
FileOutputStream fOUT = null;
/**the list of filewriters, can be seen as the list of logging channels */
static public HashMap filewriters;

public static void StartLogging(Integer id) throws IOException {
String FileName = teamname + Calendar.getInstance().getTime().toString() + “.csv”;
File file = new File(getPublicAlbumStorageDir(teamname),FileName );
if(filewriters == null){
filewriters = new HashMap();
}
filewriters.put(id,new FileWriter(file));
}

/**sets the FTC team name, used in the file name */
public static void setTeamname(String _teamname){
teamname = _teamname;
}

/**gets the public image folder */
public static File getPublicAlbumStorageDir(String albumName) {
// Get the directory for the user’s public pictures directory.
File file = new File(Environment.getExternalStoragePublicDirectory(
Environment.DIRECTORY_DOCUMENTS), albumName);
if (!file.mkdirs()) {

}
return file;
}

/**closes the filewriter given by the id, do this to make sure your data gets saved */
public static void StopLogging(int id) {
try {
filewriters.get(id).close();
} catch (IOException e) {
e.printStackTrace();
}
}

/** log your data to the filewriter given by the ID */
public static void Log(logType type, String message, int id) {

try {
filewriters.get(id).write(“\n”+ type.toString() + “,” + Calendar.getInstance().getTime() + “,” + message);
} catch (IOException e) {
e.printStackTrace();
}
}


}

League meet 4

We had a great day last league meet and we hope the other teams had a great day too! We learned a lot and we finished in the ninth place in the national rankings. We hope to see all the other teams at the next league meet even when they’re not competing.

League meet 2

On the 2nd of December, we went to the second league meet at the Newman College and we came in the thirteenth place out of the fifteen participants, however, the team we coach, team Panic Attack, came in the eighth place out of the fifteen participants. We have learned a lot and we are going to use that for our next league meet in January, we will continue with fixing our mistakes.

New website FTCUnits

Welcome on our new website. Don’t forget to take a peek at our social media accounts:

Twitter: @FtcUnits

Instagram: FTCUnits

Youtube: FTCUnits

For more information in dutch about our FLL and FTC programs see www.neobots.nl