Skip to content

Commit

Permalink
Release 4.4.0 - Pre build
Browse files Browse the repository at this point in the history
  • Loading branch information
widavies committed Mar 12, 2018
1 parent 16edfce commit 6c79dd5
Show file tree
Hide file tree
Showing 48 changed files with 1,125 additions and 223 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ android {
applicationId "com.cpjd.roblu"
minSdkVersion 19
targetSdkVersion 27
versionCode 50
versionName "4.3.5"
versionCode 52
versionName "4.4.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

javaCompileOptions {
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/java/com/cpjd/roblu/csv/CSVActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,15 @@ public boolean onOptionsItemSelected(MenuItem item) {
CheckBox matchList = findViewById(R.id.match_list);
CheckBox matchLookup = findViewById(R.id.match_lookup);
CheckBox ourMatches = findViewById(R.id.our_matches);
CheckBox fieldData = findViewById(R.id.field_data);
ArrayList<Integer> enabledSheets = new ArrayList<>();

if(matchData.isChecked()) enabledSheets.add(ExportCSVTask.SHEETS.MATCH_DATA);
if(pitData.isChecked()) enabledSheets.add(ExportCSVTask.SHEETS.PIT_DATA);
if(matchList.isChecked()) enabledSheets.add(ExportCSVTask.SHEETS.MATCH_LIST);
if(matchLookup.isChecked()) enabledSheets.add(ExportCSVTask.SHEETS.MATCH_LOOKUP);
if(ourMatches.isChecked()) enabledSheets.add(ExportCSVTask.SHEETS.OUR_MATCHES);
if(fieldData.isChecked()) enabledSheets.add(ExportCSVTask.SHEETS.FIELD_DATA);

String fileName = ((AppCompatEditText)findViewById(R.id.file_name)).getText().toString();

Expand Down
16 changes: 9 additions & 7 deletions app/src/main/java/com/cpjd/roblu/csv/ExportCSVTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import android.util.Log;

import com.cpjd.roblu.csv.csvSheets.CSVSheet;
import com.cpjd.roblu.csv.csvSheets.FieldData;
import com.cpjd.roblu.csv.csvSheets.Lookup;
import com.cpjd.roblu.csv.csvSheets.MatchData;
import com.cpjd.roblu.csv.csvSheets.MatchList;
Expand Down Expand Up @@ -53,7 +54,7 @@ public class ExportCSVTask extends Thread {
* The order of this array should match the order of the IDs in
* @see SHEETS
*/
private CSVSheet[] CSVSheets = {new MatchData(), new PitData(), new MatchList(), new Lookup(), new OurMatches()};
private CSVSheet[] CSVSheets = {new MatchData(), new PitData(), new MatchList(), new Lookup(), new OurMatches(), new FieldData()};

/**
* Reference to the context object for file system access
Expand Down Expand Up @@ -113,6 +114,7 @@ public static class SHEETS {
static int MATCH_LIST = 2;
static int MATCH_LOOKUP = 3;
static int OUR_MATCHES = 4;
static int FIELD_DATA = 5;
}

public static class VERBOSENESS {
Expand Down Expand Up @@ -254,18 +256,18 @@ public void run() {
new Thread() {
public void run() {
if(s.isEnabled()) {
// try {
try {
s.setIo(io);
s.setVerboseness(verboseness);
s.setWorkbook(workbook);
Log.d("RBS", "ExportCSVTask: Generating sheet: "+s.getSheetName());
s.setCellStyle(BorderStyle.THIN, IndexedColors.WHITE, IndexedColors.BLACK, false); // sets the default, this may get overrided at any point in time by the user
s.generateSheet(sheets.get(s.getSheetName()), event, form, teams, checkouts);
// for(int i = 0; i < sheets.get(s.getSheetName()).getRow(0).getLastCellNum(); i++) sheets.get(s.getSheetName()).setColumnWidth(i, s.getColumnWidth());
// } catch(Exception e) {
// listener.errorOccurred("Failed to execute "+s.getSheetName()+" sheet generation.");
// Log.d("RBS", "Failed to execute "+s.getSheetName()+" sheet generation. Err: "+e.getMessage());
// }
for(int i = 0; i < sheets.get(s.getSheetName()).getRow(0).getLastCellNum(); i++) sheets.get(s.getSheetName()).setColumnWidth(i, s.getColumnWidth());
} catch(Exception e) {
listener.errorOccurred("Failed to execute "+s.getSheetName()+" sheet generation.");
Log.d("RBS", "Failed to execute "+s.getSheetName()+" sheet generation. Err: "+e.getMessage());
}
threadCompleted(s.getSheetName());
}

Expand Down
87 changes: 87 additions & 0 deletions app/src/main/java/com/cpjd/roblu/csv/csvSheets/FieldData.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package com.cpjd.roblu.csv.csvSheets;

import com.cpjd.roblu.models.RCheckout;
import com.cpjd.roblu.models.REvent;
import com.cpjd.roblu.models.RForm;
import com.cpjd.roblu.models.RTab;
import com.cpjd.roblu.models.RTeam;
import com.cpjd.roblu.models.metrics.RFieldData;
import com.cpjd.roblu.models.metrics.RMetric;

import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.xssf.usermodel.XSSFSheet;

import java.util.ArrayList;

/**
* Exports all the field data metrics
*
* @author Will Davies
* @version 1
* @since 4.4.0
*/
public class FieldData extends CSVSheet {
@Override
public void generateSheet(XSSFSheet sheet, REvent event, RForm form, RTeam[] teams, ArrayList<RCheckout> checkouts) {
Row one = createRow(sheet);
createCell(one, 0, "Team#");
createCell(one, 1, "Match#");

// Find a random RFieldData reference
RFieldData fieldData = null;
try {
mainLoop:
for(RTab tab : teams[0].getTabs()) {
if(tab.getTitle().equalsIgnoreCase("PIT") || tab.getTitle().equalsIgnoreCase("PREDICTIONS")) continue;
for(RMetric metric2 : tab.getMetrics()) {
if(metric2 instanceof RFieldData) {
fieldData = (RFieldData) metric2;
break mainLoop;
}
}
}
} catch(Exception e) {//}
}

// Copy the metrics over
int index = 2;
for(Object key : fieldData.getData().keySet()) {
createCell(one, index, key.toString());
index++;
}

// Start copying data
for(RCheckout checkout : checkouts) {
if(!checkout.getTeam().getTabs().get(0).getTitle().startsWith("Quals")) continue;

Row row = createRow(sheet);

createCell(row, 0, String.valueOf(checkout.getTeam().getNumber()));
createCell(row, 1, checkout.getTeam().getTabs().get(0).getTitle());

index = 0;
mainLoop : for(RTab tab : checkout.getTeam().getTabs()) {
for(RMetric metric2 : tab.getMetrics()) {
if(metric2 instanceof RFieldData) {
for(Object key : ((RFieldData)metric2).getData().keySet()) {
createCell(row, index + 2, ((RFieldData)metric2).getData().get(key).toString());
index++;
}
break mainLoop;
}
}
}

}
}

@Override
public String getSheetName() {
return "FieldData";
}

@Override
public int getColumnWidth() {
return 3000;
}
}
2 changes: 2 additions & 0 deletions app/src/main/java/com/cpjd/roblu/csv/csvSheets/MatchData.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.cpjd.roblu.models.REvent;
import com.cpjd.roblu.models.RForm;
import com.cpjd.roblu.models.RTeam;
import com.cpjd.roblu.models.metrics.RFieldData;
import com.cpjd.roblu.models.metrics.RMetric;
import com.cpjd.roblu.models.metrics.RStopwatch;

Expand Down Expand Up @@ -45,6 +46,7 @@ public void generateSheet(XSSFSheet sheet, REvent event, RForm form, RTeam[] tea
for(RMetric metric : checkout.getTeam().getTabs().get(0).getMetrics()) {
if(shouldWriteMetric(checkout.getTeam(), metric)) {
if(metric instanceof RStopwatch) createCell(data, index + 2, ((RStopwatch) metric).getLapsString());
else if(metric instanceof RFieldData) continue;
else createCell(data, index + 2, metric.toString());
}
else createCell(data, index + 2, "");
Expand Down
99 changes: 35 additions & 64 deletions app/src/main/java/com/cpjd/roblu/io/IO.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@

import com.cpjd.roblu.models.RBackup;
import com.cpjd.roblu.models.RCheckout;
import com.cpjd.roblu.models.RSyncSettings;
import com.cpjd.roblu.models.REvent;
import com.cpjd.roblu.models.RForm;
import com.cpjd.roblu.models.RSettings;
import com.cpjd.roblu.models.RSyncSettings;
import com.cpjd.roblu.models.RTeam;
import com.cpjd.roblu.models.RUI;
import com.cpjd.roblu.utils.Utils;
Expand Down Expand Up @@ -396,7 +396,10 @@ public RForm loadForm(int eventID) {
* @param form the form to save
*/
public void saveForm(int eventID, RForm form) {
if(eventID == -1) serializeObject(form, new File(context.getFilesDir(), PREFIX+File.separator+"master_form.ser"));
if(eventID == -1) {
serializeObject(form, new File(context.getFilesDir(), PREFIX+File.separator+"master_form.ser"));
return;
}

serializeObject(form, new File(context.getFilesDir(), PREFIX+File.separator+"events"+File.separator+eventID+File.separator+"form.ser"));
}
Expand All @@ -405,15 +408,14 @@ public void saveForm(int eventID, RForm form) {
/*
* Backup methods
*/

/**
* Saves a backup file to the cache directory. It should be saved to an external location by the user
* IMMEDIATELY, because the cache dir does not guarantee the existence of any files
* @param backup the backup file to save to a temporary file
* @return File reference to a temporary file location that can later be saved to an external location
*/
public File saveBackup(RBackup backup) {
File file = new File(context.getCacheDir(), PREFIX+File.separator+"backups"+ File.separator+"event.roblubackup");
public File saveBackup(RBackup backup, String name) {
File file = new File(context.getCacheDir(), PREFIX+File.separator+"backups"+ File.separator+name);
if(file.mkdirs()) Log.d("RBS", "Successfully created backup parent dirs");
if(file.exists()) delete(file);
serializeObject(backup, file);
Expand All @@ -426,7 +428,7 @@ public File saveBackup(RBackup backup) {
* @return RBackup object instance
*/
public RBackup convertBackupFile(Uri toCopy) {
File file = new File(context.getCacheDir(), PREFIX+ File.separator+"tempBackupImport.roblubackup");
File file = new File(context.getCacheDir(), PREFIX+ File.separator+"tempBackup.backup");
if(file.mkdirs()) Log.d("RBS", "Successfully created backup parent dirs");
if(file.exists()) {
if(!file.delete()) Log.d("RBS", "Failed to delete old cached backup file.");
Expand All @@ -444,11 +446,35 @@ public RBackup convertBackupFile(Uri toCopy) {
}
return null;
} catch(Exception e) {
Log.d("RBS", "Exception: "+e.getMessage());
return null;
} finally {
if(file.delete()) Log.d("RBS", "Cached backup file successfully deleted.");
}
}

public RForm convertFormFile(Uri toCopy) {
File file = new File(context.getFilesDir(), PREFIX+ File.separator+"master_form.ser");
if(file.mkdirs()) Log.d("RBS", "Successfully created form backup parent dirs");
if(file.exists()) {
if(!file.delete()) Log.d("RBS", "Failed to delete old cached backup file.");
}
try {
InputStream is = context.getContentResolver().openInputStream(toCopy);
FileOutputStream out = new FileOutputStream(file);
if(is != null) {
IOUtils.copy(is, out);
RForm backup = (RForm) deserializeObject(file);
is.close();
out.flush();
out.close();
}
return (RForm) deserializeObject(file);
} catch(Exception e) {
Log.d("RBS", "Exception: "+e.getMessage());
return null;
}
}
// End backup methods

/*
Expand All @@ -472,61 +498,6 @@ public File getNewCSVExportFile(String name) {
return f;
}
// End CSV Methods

/*
* CHECKOUTS Methods
*/
/**
* Saves a checkout to the /checkouts/ directory, presumably because an import has occured
* @param checkout the RCheckout object instance to save
*/
public void saveCheckout(RCheckout checkout) {
serializeObject(checkout, new File(context.getFilesDir(), PREFIX+File.separator+"checkouts"+File.separator+checkout.getID()+".ser"));
}

/**
* Loads the RCheckout with the specified ID
* @param checkoutID the checkout ID to laod
* @return RCheckout object instance
*/
private RCheckout loadCheckout(int checkoutID) {
RCheckout checkout = (RCheckout) deserializeObject(new File(context.getFilesDir(), PREFIX+File.separator+"checkouts"+File.separator+checkoutID+".ser"));
if(checkout != null) checkout.setID(checkoutID);
return checkout;
}

/**
* Loads all checkouts in the file system
* @return Array of RCheckout object instances
*/
public RCheckout[] loadCheckouts() {
File[] files = getChildFiles(new File(context.getFilesDir(), PREFIX+File.separator+"checkouts"+File.separator));
if(files == null || files.length == 0) return null;
RCheckout[] checkouts = new RCheckout[files.length];
for(int i = 0; i < checkouts.length; i++) {
checkouts[i] = loadCheckout(Integer.parseInt(files[i].getName().replace(".ser", "")));
}
return checkouts;
}

/**
* Returns an unused, new event ID that a new team can be saved under.
* This method will take the HIGHEST ID it finds, and add one to it. It will
* not just find the closest unused ID to 0.
* @return unused ID to save this team's info to
*/
public int getNewCheckoutID() {
File[] files = getChildFiles(new File(context.getFilesDir(), PREFIX+ File.separator+"checkouts"+File.separator));
if(files == null || files.length == 0) return 0;
int topID = 0;
for(File f : files) {
int newID = Integer.parseInt(f.getName().replaceAll(".ser", ""));
if(newID > topID) topID = newID;
}
return topID + 1;
}
// End checkouts methods

/*
* PENDING methods
*/
Expand All @@ -535,13 +506,13 @@ public int getNewCheckoutID() {
* Saves a checkout to the /pending/ directory, presumably because an import has occurred
* @param checkout the RCheckout instance to save
*/
public void savePendingObject(RCheckout checkout) {
public void savePendingCheckout(RCheckout checkout) {
serializeObject(checkout, new File(context.getFilesDir(), PREFIX+File.separator+"pending"+File.separator+checkout.getID()+".ser"));
}

/**
* Loads the RCheckout with the specified ID
* @param checkoutID the checkout ID to laod
* @param checkoutID the checkout ID to load
* @return RCheckout object instance
*/
public RCheckout loadPendingCheckout(int checkoutID) {
Expand All @@ -559,7 +530,7 @@ public RCheckout[] loadPendingCheckouts() {
if(files == null || files.length == 0) return null;
RCheckout[] checkouts = new RCheckout[files.length];
for(int i = 0; i < checkouts.length; i++) {
checkouts[i] = loadCheckout(Integer.parseInt(files[i].getName().replace(".ser", "")));
checkouts[i] = loadPendingCheckout(Integer.parseInt(files[i].getName().replace(".ser", "")));
}
return checkouts;
}
Expand Down
3 changes: 1 addition & 2 deletions app/src/main/java/com/cpjd/roblu/models/RTeam.java
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,7 @@ public void verify(RForm form) {
}
}
}

// Update default values for non-modified values, also check for some weird scenarios
// Update default values for non-modified values, also check for some weird scenario
temp = form.getPit();
for(int i = 0; i < tabs.size(); i++) {
if(!tabs.get(i).getTitle().equalsIgnoreCase("PIT")) temp = form.getMatch();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ else if(metric instanceof RCalculation) {

// Process
lastValue = Utils.round(new DoubleEvaluator().evaluate(equation), 2);
return String.valueOf(Utils.round(new DoubleEvaluator().evaluate(equation), 2));
return String.valueOf(lastValue);
} catch(Exception e) {
Log.d("RBS", "bad equation: ", e);
return "Bad equation";
Expand Down
Loading

0 comments on commit 6c79dd5

Please sign in to comment.