Made it so the file name will be the event name

Also deleted code no longer used + apparently broken from Submit.java
This commit is contained in:
wildercayden 2025-01-31 17:08:28 +00:00 committed by GitHub
parent a734027652
commit 4445aef630
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 101 additions and 34 deletions

View File

@ -19,6 +19,7 @@ import java.io.FileWriter;
import java.io.IOException; import java.io.IOException;
public class AutoActivity extends AppCompatActivity { public class AutoActivity extends AppCompatActivity {
private String auto = "Auto";
private int l4Scored = 0; private int l4Scored = 0;
private int l3Scored = 0; private int l3Scored = 0;
private int l2Scored = 0; private int l2Scored = 0;
@ -36,6 +37,9 @@ public class AutoActivity extends AppCompatActivity {
private TextView l1TV; private TextView l1TV;
private TextView processorTV; private TextView processorTV;
private TextView netTV; private TextView netTV;
private String eventString, matchString;
public static final String Event_Key = "EVENTCONFIRM";
public static final String Match_key = "MATCHCONFIRM";
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
@ -47,6 +51,10 @@ public class AutoActivity extends AppCompatActivity {
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom); v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
return insets; return insets;
}); });
Intent intentinput = getIntent();
eventString = intentinput.getStringExtra(MainActivity.Event_Key);
matchString = intentinput.getStringExtra(MainActivity.Match_key);
Button l4Button = (Button) findViewById(R.id.button_L4); Button l4Button = (Button) findViewById(R.id.button_L4);
Button l3Button = (Button) findViewById(R.id.button_L3); Button l3Button = (Button) findViewById(R.id.button_L3);
@ -137,7 +145,10 @@ public class AutoActivity extends AppCompatActivity {
nextButton.setOnLongClickListener((v) -> { nextButton.setOnLongClickListener((v) -> {
//submit data //submit data
CSVmake(AutoActivity.this);
Intent intent = new Intent(this, TeleActivity.class); Intent intent = new Intent(this, TeleActivity.class);
intent.putExtra(Event_Key, eventString);
intent.putExtra(Match_key, matchString);
startActivity(intent); startActivity(intent);
return true; return true;
}); });
@ -179,17 +190,21 @@ public class AutoActivity extends AppCompatActivity {
public void CSVmake(Context context) { public void CSVmake(Context context) {
//adds the strings //adds the strings
String CSVLine = String.format( String CSVLine = String.format(
"%s %s %s %s %s %s %s", "%s,%s,%s,%s,%s,%s,%s,%s,%s,%s",
auto,
l4Scored, l4Scored,
l3Scored, l3Scored,
l2Scored, l2Scored,
l1Scored, l1Scored,
processorScored,
netScored,
reefPickup, reefPickup,
canLeave, canLeave,
coralPickup coralPickup
); );
//makes the file //makes the file
File csvFile = new File(context.getFilesDir(), "match_data.csv"); File csvFile = new File(context.getFilesDir(), eventString+".csv");
Log.d("CSVFile", "File created/written at: " + csvFile.getAbsolutePath());
//writes to file //writes to file
try (FileWriter writer = new FileWriter(csvFile, true)) { try (FileWriter writer = new FileWriter(csvFile, true)) {
writer.append(CSVLine).append("\n"); writer.append(CSVLine).append("\n");

View File

@ -26,6 +26,9 @@ import java.io.File;
public class EndActivity extends AppCompatActivity { public class EndActivity extends AppCompatActivity {
private String eventString, matchString;
public static final String Event_Key = "EVENTCONFIRM";
public static final String Match_key = "MATCHCONFIRM";
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
@ -37,18 +40,22 @@ public class EndActivity extends AppCompatActivity {
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom); v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
return insets; return insets;
}); });
Intent intentinput = getIntent();
eventString = intentinput.getStringExtra(AutoActivity.Event_Key);
matchString = intentinput.getStringExtra(AutoActivity.Match_key);
Button submit = (Button) findViewById(R.id.Submit_button); Button submit = (Button) findViewById(R.id.Submit_button);
submit.setOnClickListener(new View.OnClickListener() { submit.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) { public void onClick(View view) {
String csvFileString = eventString+".csv";
Submit submit = new Submit(); Submit submit = new Submit();
//Writes data to file to make google sheet read it as a list //Writes data to file to make google sheet read it as a list
File csvFile = new File(getFilesDir(), "match_data.csv"); File csvFilefile = new File(getFilesDir(), "csvFileString");
List<List<Object>> data = submit.parseCSVToList(csvFile); List<List<Object>> data = submit.parseCSVToList(csvFilefile);
submit.parseCSVToList(csvFile); submit.parseCSVToList(csvFilefile);
//Uploads the Data to the Google sheet //Uploads the Data to the Google sheet
submit.uploadSheets(EndActivity.this); submit.uploadSheets(EndActivity.this, csvFileString);
submit.renameFile(EndActivity.this, eventString);
} }
}); });

View File

@ -7,6 +7,7 @@ import android.os.AsyncTask;
import android.os.Bundle; import android.os.Bundle;
import android.view.View; import android.view.View;
import android.widget.Button; import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView; import android.widget.TextView;
import androidx.activity.EdgeToEdge; import androidx.activity.EdgeToEdge;
@ -20,12 +21,21 @@ import org.json.JSONObject;
import java.io.IOException; import java.io.IOException;
import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.Headers; import okhttp3.Headers;
import okhttp3.OkHttpClient; import okhttp3.OkHttpClient;
import okhttp3.Request; import okhttp3.Request;
import okhttp3.Response; import okhttp3.Response;
import okhttp3.ResponseBody;
public class MainActivity extends AppCompatActivity { public class MainActivity extends AppCompatActivity {
private EditText Match_number;
private EditText Event;
private String Match_numberString;
private String EventString;
public static final String Event_Key = "EVENTCONFIRM";
public static final String Match_key = "MATCHCONFIRM";
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
@ -36,11 +46,16 @@ public class MainActivity extends AppCompatActivity {
Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars()); Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom); v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
return insets; return insets;
}); });
Match_number = (EditText) findViewById(R.id.Match);
Event = (EditText) findViewById(R.id.Event);
Button nextButton = (Button) findViewById(R.id.nextButton); Button nextButton = (Button) findViewById(R.id.nextButton);
nextButton.setOnClickListener(new View.OnClickListener() { nextButton.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
Match_numberString = Match_number.getText().toString();
EventString = Event.getText().toString();
makeIntent(); makeIntent();
} }
@ -48,7 +63,6 @@ public class MainActivity extends AppCompatActivity {
TextView TBAView = (TextView)findViewById(R.id.TBATest); TextView TBAView = (TextView)findViewById(R.id.TBATest);
} }
public final class AsynchronousGet { public final class AsynchronousGet {
private final OkHttpClient client = new OkHttpClient(); private final OkHttpClient client = new OkHttpClient();
@ -90,6 +104,8 @@ public class MainActivity extends AppCompatActivity {
private void makeIntent() private void makeIntent()
{ {
Intent intent = new Intent(this, AutoActivity.class); Intent intent = new Intent(this, AutoActivity.class);
intent.putExtra(Event_Key, EventString);
intent.putExtra(Match_key, Match_numberString);
startActivity(intent); startActivity(intent);
} }
} }

View File

@ -23,7 +23,7 @@ import java.util.List;
public class Submit { public class Submit {
void uploadSheets(Context context) { void uploadSheets(Context context, String csvFileString) {
new Thread(() -> { new Thread(() -> {
try { try {
//adds account info //adds account info
@ -37,7 +37,7 @@ public class Submit {
).setApplicationName("Scouting App").build(); ).setApplicationName("Scouting App").build();
//make sure the file is there //make sure the file is there
File csvFile = new File(context.getFilesDir(), "match_data.csv"); File csvFile = new File(context.getFilesDir(), csvFileString);
if (!csvFile.exists()) { if (!csvFile.exists()) {
Log.d("CSVError", "CSV file does not exist."); Log.d("CSVError", "CSV file does not exist.");
return; return;
@ -67,33 +67,51 @@ public class Submit {
List<List<Object>> parseCSVToList(File csvFile) { List<List<Object>> parseCSVToList(File csvFile) {
//makes A array //makes A array
List<List<Object>> data = Lists.newArrayList(); List<List<Object>> data = Lists.newArrayList();
//Reads the info from the CSV file and makes it usedable to upload to the google sheet
try (BufferedReader br = new BufferedReader(new FileReader(csvFile))) {
String line;
while ((line = br.readLine()) != null) {
List<Object> row = Arrays.asList(line.split(","));
data.add(row);
}
} catch (IOException e) {
Log.d("parseCSVToList", "Error with BufferredReader");
}
return data; return data;
} }
public void deleteCSVFile(Context context) { public void deleteCSVFile(Context context) {
//Finds the file // Get the directory containing the files
File csvFile = new File(context.getFilesDir(), "match_data.csv"); File directory = context.getFilesDir();
//Checks if the file exists // Get all files in the directory
if (csvFile.exists()) { File[] files = directory.listFiles();
//Tries to delete file
if (csvFile.delete()) { if (files != null) {
Log.d("CSVDelete", "match_data.csv deleted successfully."); // Iterate through each file in the directory
for (File file : files) {
// Deletes the file
if (file.delete()) {
Log.d("CSVDelete", file.getName() + " deleted successfully.");
} else { } else {
Log.d("CSVDelete", "Failed to delete match_data.csv."); Log.d("CSVDelete", "Failed to delete " + file.getName());
}
} }
} else { } else {
Log.d("CSVDelete", "match_data.csv does not exist."); Log.d("CSVDelete", "No files found in the directory.");
} }
} }
public void renameFile(Context context, String csvFileString){
File csvFile = new File(context.getFilesDir(), csvFileString + ".csv");
// Then perform renaming
File newFile = new File(context.getFilesDir(), csvFileString+".csv");
if (csvFile.renameTo(newFile)) {
Log.d("CSVRename", "File renamed successfully to: " + newFile.getAbsolutePath());
} else {
Log.d("CSVRenameFail", "File renaming failed.");
}
// Define the new file name
File renamedFile = new File(context.getFilesDir(), "old"+csvFileString+".csv");
// Rename the original file
if (csvFile.renameTo(newFile)) {
Log.d("CSVRename", "File renamed successfully to: " + renamedFile.getAbsolutePath());
} else {
Log.d("CSVRenameFail", "File renaming failed.");
}
}
} }

View File

@ -19,6 +19,7 @@ import java.io.FileWriter;
import java.io.IOException; import java.io.IOException;
public class TeleActivity extends AppCompatActivity { public class TeleActivity extends AppCompatActivity {
private String tele = "Teleop";
private int l4Scored = 0; private int l4Scored = 0;
private int l3Scored = 0; private int l3Scored = 0;
private int l2Scored = 0; private int l2Scored = 0;
@ -36,6 +37,9 @@ public class TeleActivity extends AppCompatActivity {
private TextView l1TV; private TextView l1TV;
private TextView processorTV; private TextView processorTV;
private TextView netTV; private TextView netTV;
private String eventString, matchString;
public static final String Event_Key = "EVENTCONFIRM";
public static final String Match_key = "MATCHCONFIRM";
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
@ -47,6 +51,9 @@ public class TeleActivity extends AppCompatActivity {
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom); v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
return insets; return insets;
}); });
Intent intentinput = getIntent();
eventString = intentinput.getStringExtra(AutoActivity.Event_Key);
matchString = intentinput.getStringExtra(AutoActivity.Match_key);
Button l4Button = (Button) findViewById(R.id.button_L4); Button l4Button = (Button) findViewById(R.id.button_L4);
Button l3Button = (Button) findViewById(R.id.button_L3); Button l3Button = (Button) findViewById(R.id.button_L3);
@ -139,6 +146,8 @@ public class TeleActivity extends AppCompatActivity {
//submit data //submit data
csvMake(); csvMake();
Intent intent = new Intent(this, EndActivity.class); Intent intent = new Intent(this, EndActivity.class);
intent.putExtra(Event_Key, eventString);
intent.putExtra(Match_key, matchString);
startActivity(intent); startActivity(intent);
return true; return true;
}); });
@ -180,7 +189,8 @@ public class TeleActivity extends AppCompatActivity {
public void csvMake() { public void csvMake() {
//adds the strings //adds the strings
String CSVLine = String.format( String CSVLine = String.format(
"%s %s %s %s %s %s %s %s %s", "%s,%s,%s,%s,%s,%s,%s,%s,%s,%s",
tele,
l4Scored, l4Scored,
l3Scored, l3Scored,
l2Scored, l2Scored,
@ -192,7 +202,8 @@ public class TeleActivity extends AppCompatActivity {
coralPickup coralPickup
); );
//makes the file //makes the file
File csvFile = new File(this.getFilesDir(), "match_data.csv"); File csvFile = new File(this.getFilesDir(), eventString+".csv");
Log.d("CSVFile", "File created/written at: " + csvFile.getAbsolutePath());
//writes to file //writes to file
try (FileWriter writer = new FileWriter(csvFile, true)) { try (FileWriter writer = new FileWriter(csvFile, true)) {
writer.append(CSVLine).append("\n"); writer.append(CSVLine).append("\n");