Work on report menu

This commit is contained in:
astatin3
2024-09-22 11:06:40 -06:00
parent 07c6e9a2aa
commit b62d04dac5
11 changed files with 307 additions and 185 deletions
@@ -71,7 +71,7 @@ public class DataFragment extends Fragment {
});
binding.reportButton.setOnClickListener(v -> {
findNavController(this).navigate(R.id.action_navigation_data_to_navigation_data_report);
findNavController(this).navigate(R.id.action_navigation_data_to_navigation_data_report_selector);
});
return root;
@@ -1,9 +1,6 @@
package com.ridgebotics.ridgescout.ui.data;
import static com.ridgebotics.ridgescout.utility.DataManager.evcode;
import static com.ridgebotics.ridgescout.utility.DataManager.event;
import static com.ridgebotics.ridgescout.utility.DataManager.match_latest_values;
import static com.ridgebotics.ridgescout.utility.DataManager.pit_latest_values;
import android.os.Bundle;
import android.view.LayoutInflater;
@@ -17,110 +14,57 @@ import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import com.ridgebotics.ridgescout.databinding.FragmentDataReportBinding;
import com.ridgebotics.ridgescout.scoutingData.ScoutingDataWriter;
import com.ridgebotics.ridgescout.types.data.dataType;
import com.ridgebotics.ridgescout.types.frcMatch;
import com.ridgebotics.ridgescout.types.input.dropdownType;
import com.ridgebotics.ridgescout.types.input.inputType;
import com.ridgebotics.ridgescout.types.input.sliderType;
import com.ridgebotics.ridgescout.utility.DataManager;
import com.ridgebotics.ridgescout.utility.fileEditor;
import com.ridgebotics.ridgescout.utility.ollama.OllamaClient;
import com.ridgebotics.ridgescout.utility.ollama.PromptCreator;
import com.ridgebotics.ridgescout.utility.settingsManager;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.IntStream;
public class ReportFragment extends Fragment {
FragmentDataReportBinding binding;
private static frcMatch match;
public static void setMatch(frcMatch m){
match = m;
}
private final int ourTeamNum = settingsManager.getTeamNum();
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
@Nullable Bundle savedInstanceState) {
binding = FragmentDataReportBinding.inflate(inflater, container, false);
binding.teamNumber.setText(String.valueOf(ourTeamNum));
binding.AyEyeBox.setVisibility(View.GONE);
DataManager.reload_event();
DataManager.reload_pit_fields();
DataManager.reload_match_fields();
getReportMatches();
AIDataOverview();
binding.AyEyeButton.setText("Create Prompt");
binding.AyEyeButton.setOnClickListener(a ->{
getPrompt();
binding.AyEyeButton.setText("Generate Overview");
binding.AyEyeButton.setOnClickListener(b ->{
AIDataOverview();
binding.AyEyeButton.setVisibility(View.GONE);
});
});
return binding.getRoot();
}
//
// public frcMatch[] getTeamMatches(int teamNum){
// List<frcMatch> teamMatches = new ArrayList<>();
// for(int i = 0; i < event.matches.size(); i++){
// frcMatch match = event.matches.get(i);
// boolean isTeamMatch = false;
// isTeamMatch = IntStream.of(match.redAlliance).anyMatch(x -> x == teamNum);
// isTeamMatch = isTeamMatch || IntStream.of(match.blueAlliance).anyMatch(x -> x == teamNum);
// if(isTeamMatch)
// teamMatches.add(match);
// }
// return teamMatches.toArray(new frcMatch[0]);
// }
public void getReportMatches(){
// String out = "";
int ourTeamNum = settingsManager.getTeamNum();
frcMatch[] teamMatches = event.getTeamMatches(ourTeamNum);
TableRow tr = new TableRow(getContext());
TextView tv = new TextView(getContext());
tv.setText("Team match");
tr.addView(tv);
tv = new TextView(getContext());
tv.setText("Most informed match");
tr.addView(tv);
binding.teamMatchesTable.addView(tr);
binding.teamMatchesTable.setStretchAllColumns(true);
for(int i = 0; i < teamMatches.length; i++){
tr = new TableRow(getContext());
tv = new TextView(getContext());
tv.setText(String.valueOf(teamMatches[i].matchIndex));
tr.addView(tv);
int maxMatch = -1;
for(int a = 0; a < 6; a++){
int teamNum = 0;
if(a < 3)
teamNum = teamMatches[i].redAlliance[a];
else
teamNum = teamMatches[i].blueAlliance[a-3];
if(teamNum == ourTeamNum)
continue;
int matchNum = event.getMostRecentTeamMatch(teamNum, teamMatches[i].matchIndex);
if(maxMatch < matchNum)
maxMatch = matchNum;
}
tv = new TextView(getContext());
tv.setText(String.valueOf(maxMatch));
tr.addView(tv);
binding.teamMatchesTable.addView(tr);
}
// AlertManager.error(out);
private void getPrompt(){
binding.AyEyeBox.setVisibility(View.VISIBLE);
String prompt = PromptCreator.genMatchPrompt(0);
binding.AyEyeBox.setText(prompt);
}
private void AIDataOverview(){
String prompt = PromptCreator.genMatchPrompt(0);
// System.out.println(prompt);
String prompt = binding.AyEyeBox.getText().toString();
binding.AyEyeBox.setText("");
OllamaClient.run(prompt, new OllamaClient.ollamaListener() {
@Override
public void onResponse(String response) {
@@ -0,0 +1,82 @@
package com.ridgebotics.ridgescout.ui.data;
import static androidx.navigation.fragment.FragmentKt.findNavController;
import static com.ridgebotics.ridgescout.utility.DataManager.evcode;
import static com.ridgebotics.ridgescout.utility.DataManager.event;
import android.annotation.SuppressLint;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import com.ridgebotics.ridgescout.R;
import com.ridgebotics.ridgescout.databinding.FragmentDataReportSelectorBinding;
import com.ridgebotics.ridgescout.types.frcMatch;
import com.ridgebotics.ridgescout.utility.AlertManager;
import com.ridgebotics.ridgescout.utility.DataManager;
import com.ridgebotics.ridgescout.utility.settingsManager;
public class ReportSelectorFragment extends Fragment {
FragmentDataReportSelectorBinding binding;
private final int teamNum = settingsManager.getTeamNum();
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
@Nullable Bundle savedInstanceState) {
binding = FragmentDataReportSelectorBinding.inflate(inflater, container, false);
binding.matchTable.setStretchAllColumns(true);
DataManager.reload_event();
frcMatch[] teamMatches = event.getTeamMatches(teamNum);
if(teamMatches.length == 0){
AlertManager.error("Team number " + teamNum + " could not be found in event " + evcode);
findNavController(this).navigate(R.id.action_navigation_data_report_selector_to_navigation_data);
}
for(int i = 0; i < teamMatches.length; i++){
addTableRow(teamMatches[i]);
}
return binding.getRoot();
}
@SuppressLint("SetTextI18n")
private void addTableRow(frcMatch match){
TableRow tr = new TableRow(getContext());
TableLayout.LayoutParams rowParams = new TableLayout.LayoutParams(
FrameLayout.LayoutParams.WRAP_CONTENT,
FrameLayout.LayoutParams.WRAP_CONTENT
);
rowParams.setMargins(20,20,20,20);
tr.setLayoutParams(rowParams);
tr.setPadding(20,20,20,20);
tr.setBackgroundColor(0x5000ff00);
binding.matchTable.addView(tr);
TextView tv = new TextView(getContext());
tv.setText("Match " + match.matchIndex);
tv.setTextAlignment(View.TEXT_ALIGNMENT_CENTER);
tr.addView(tv);
tv = new TextView(getContext());
tv.setText("Pos " + match.getTeamAlliance(teamNum));
tv.setTextAlignment(View.TEXT_ALIGNMENT_CENTER);
tr.addView(tv);
tr.setOnClickListener(v -> {
ReportFragment.setMatch(match);
findNavController(this).navigate(R.id.action_navigation_data_report_selector_to_navigation_data_report);
});
}
}