use of com.cpjd.roblu.models.metrics.RGallery in project Roblu by wdavies973.
the class MetricEditor method onItemSelected.
/**
* Called when the user selects a metric type
* @param adapterView the adapter containing all the choices
* @param view the view that was tapped
* @param i the position of the view
* @param l id of the view
*/
@Override
public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
((TextView) adapterView.getChildAt(0)).setTextColor(rui.getText());
/*
* User selected a new metric, let's create it
*/
String stringOfSelected = METRIC_TYPES[i];
if (stringOfSelected.equals(METRIC_TYPES[0])) {
metric = new RBoolean(0, "Boolean", false);
} else if (stringOfSelected.equals(METRIC_TYPES[1])) {
metric = new RCounter(0, "Counter", 1, 0);
} else if (stringOfSelected.equals(METRIC_TYPES[2])) {
metric = new RSlider(0, "Slider", 0, 100, 0);
} else if (stringOfSelected.equals(METRIC_TYPES[3])) {
metric = new RChooser(0, "Chooser", null, 0);
} else if (stringOfSelected.equals(METRIC_TYPES[4])) {
metric = new RCheckbox(0, "Checkbox", null);
} else if (stringOfSelected.equals(METRIC_TYPES[5])) {
metric = new RStopwatch(0, "Stopwatch", 0);
} else if (stringOfSelected.equals(METRIC_TYPES[6])) {
metric = new RTextfield(0, "Text field", "");
} else if (stringOfSelected.equals(METRIC_TYPES[7])) {
metric = new RGallery(0, "Gallery");
} else if (stringOfSelected.equalsIgnoreCase(METRIC_TYPES[8])) {
metric = new RDivider(0, "Divider");
} else if (stringOfSelected.equals(METRIC_TYPES[9])) {
metric = new RFieldDiagram(0, R.drawable.field2018, null);
} else if (stringOfSelected.equals(METRIC_TYPES[10])) {
metric = new RCalculation(0, "Custom calculation");
} else if (stringOfSelected.equals(METRIC_TYPES[11])) {
metric = new RFieldData(0, "Match data");
}
metric.setModified(true);
addMetricPreviewToToolbar();
buildConfigLayout();
}
use of com.cpjd.roblu.models.metrics.RGallery in project Roblu by wdavies973.
the class Overview method onCreateView.
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.overview_tab, container, false);
Bundle bundle = this.getArguments();
layout = view.findViewById(R.id.overview_layout);
REvent event = (REvent) getArguments().getSerializable("event");
RTeam team = new IO(getActivity()).loadTeam(event.getID(), TeamViewer.team.getID());
rMetricToUI = new RMetricToUI(getActivity(), new IO(getActivity()).loadSettings().getRui(), true);
try {
/*
* Do statistics generation, this will generate graphs for certain metrics
*/
// Stores pie chart values, with the sub linked hash map <item,occurrences>, this will need to be processed later into a percent
LinkedHashMap<String, LinkedHashMap<String, Double>> pieValues = new LinkedHashMap<>();
// Stores line chart values, with the sub linked hash map <matchName,value>
LinkedHashMap<String, LinkedHashMap<String, Double>> lineValues = new LinkedHashMap<>();
// This isn't directly related, more of a side project
ArrayList<RGallery> galleries = new ArrayList<>();
for (RTab tab : team.getTabs()) {
// Rule out disallowed tabs
if (tab.getTitle().equalsIgnoreCase("PIT"))
continue;
// Start processing metrics
for (RMetric metric : tab.getMetrics()) {
if (metric instanceof RGallery) {
galleries.add((RGallery) metric);
}
if (!metric.isModified())
continue;
// Pie graph metrics, scan these here
if (metric instanceof RBoolean) {
LinkedHashMap<String, Double> temp = pieValues.get(metric.getTitle());
if (temp == null)
temp = new LinkedHashMap<>();
String key = ((RBoolean) metric).isValue() ? "Yes" : "No";
if (temp.get(key) == null)
temp.put(key, 1.0);
else
temp.put(key, temp.get(key) + 1);
pieValues.put(metric.getTitle(), temp);
} else if (metric instanceof RCheckbox) {
if (((RCheckbox) metric).getValues() != null) {
for (Object key : ((RCheckbox) metric).getValues().keySet()) {
LinkedHashMap<String, Double> temp = pieValues.get(metric.getTitle());
if (temp == null)
temp = new LinkedHashMap<>();
if (temp.get(key.toString()) == null)
temp.put(key.toString(), 1.0);
else
temp.put(key.toString(), temp.get(key.toString()) + 1);
pieValues.put(metric.getTitle(), temp);
}
}
} else if (metric instanceof RChooser) {
LinkedHashMap<String, Double> temp = pieValues.get(metric.getTitle());
if (temp == null)
temp = new LinkedHashMap<>();
if (temp.get(metric.toString()) == null)
temp.put(metric.toString(), 1.0);
else
temp.put(metric.toString(), temp.get(metric.toString()) + 1);
pieValues.put(metric.getTitle(), temp);
} else // Line chart metrics
if (metric instanceof RCounter || metric instanceof RSlider || metric instanceof RStopwatch || metric instanceof RCalculation) {
LinkedHashMap<String, Double> temp = lineValues.get(metric.getTitle());
if (temp == null)
temp = new LinkedHashMap<>();
temp.put(tab.getTitle(), Double.parseDouble(metric.toString()));
lineValues.put(metric.getTitle(), temp);
}
}
}
// Add the divider metrics by position, -1 if no metric after it, or at the end
ArrayList<RDivider> addedDividers = new ArrayList<>();
/*
* Add the charts!
*/
for (Object key : lineValues.keySet()) {
if (lineValues.get(key.toString()).size() >= 2) {
loop: for (RTab tab : team.getTabs()) {
for (int i = 0; i < tab.getMetrics().size(); i++) {
if (tab.getMetrics().get(i).getTitle().equals(key.toString())) {
// See if there is a RDivider hiding above this metric
for (int j = i; j >= 0; j--) {
if (tab.getMetrics().get(j) instanceof RDivider && !addedDividers.contains(tab.getMetrics().get(j))) {
layout.addView(rMetricToUI.getDivider((RDivider) tab.getMetrics().get(j)));
addedDividers.add((RDivider) tab.getMetrics().get(j));
break loop;
}
}
}
}
}
layout.addView(rMetricToUI.generateLineChart(key.toString(), lineValues.get(key.toString())));
}
}
// Process the pie charts
for (Object key : pieValues.keySet()) {
if (pieValues.get(key.toString()).size() <= 1)
continue;
int metricID = 0;
loop: for (RTab tab : team.getTabs()) {
for (int i = 0; i < tab.getMetrics().size(); i++) {
if (tab.getMetrics().get(i).getTitle().equals(key.toString())) {
metricID = tab.getMetrics().get(i).getID();
// See if there is a RDivider hiding above this metric
for (int j = i; j >= 0; j--) {
if (tab.getMetrics().get(j) instanceof RDivider && !addedDividers.contains(tab.getMetrics().get(j))) {
layout.addView(rMetricToUI.getDivider((RDivider) tab.getMetrics().get(j)));
addedDividers.add((RDivider) tab.getMetrics().get(j));
break loop;
}
}
}
}
}
for (Object key2 : pieValues.get(key.toString()).keySet()) {
if (numModified(team.getTabs(), metricID) != 0)
pieValues.get(key.toString()).put(key2.toString(), pieValues.get(key.toString()).get(key2.toString()) / (double) numModified(team.getTabs(), metricID));
}
layout.addView(rMetricToUI.generatePieChart(key.toString(), pieValues.get(key.toString())));
}
/*
* Find the image with the most entropy, and add
* it as the "featured" image
*/
galleryLoop: for (int j = galleries.size() - 1; j >= 0; j--) {
if (galleries.get(j).getImages() != null && galleries.get(j).getImages().size() > 0) {
for (int i = galleries.get(j).getImages().size() - 1; i >= 0; i--) {
try {
layout.addView(rMetricToUI.getImageView("Featured image", BitmapFactory.decodeByteArray(galleries.get(j).getImages().get(i), 0, galleries.get(j).getImages().get(i).length)));
break galleryLoop;
} catch (Exception e) {
Log.d("RBS", "Failed to load featured image: " + e.getMessage());
}
}
}
}
} catch (Exception e) {
Log.d("RBS", "Failed to generate graphs for this team profile.");
}
/*
* Attempt to download TBA info for this team
*/
if (!team.hasTBAInfo()) {
if (event.getKey() != null && event.getKey().length() >= 4)
new TBATeamInfoTask(view.getContext(), team.getNumber(), event.getKey().substring(0, 4), this);
} else {
// TBA info card
layout.addView(rMetricToUI.getInfoField("TBA.com information", TeamViewer.team.getTbaInfo(), TeamViewer.team.getWebsite(), TeamViewer.team.getNumber()), 0);
if (TeamViewer.team.getImage() != null) {
// Image view
Bitmap bitmap = BitmapFactory.decodeByteArray(TeamViewer.team.getImage(), 0, TeamViewer.team.getImage().length);
layout.addView(rMetricToUI.getImageView("Robot", bitmap));
}
}
/*
* Add UI cards to the layout
*/
// "Other" card
layout.addView(rMetricToUI.getInfoField("Other", "Last edited: " + Utils.convertTime(team.getLastEdit()) + "\nSize on disk: " + new IO(view.getContext()).getTeamSize(bundle.getInt("eventID"), team.getID()) + " KB", "", 0));
return view;
}
use of com.cpjd.roblu.models.metrics.RGallery in project Roblu by wdavies973.
the class FormRecyclerTouchHelper method onSwiped.
/**
* Called when a form card is swiped in a certain direction
* @param viewHolder the view holder containing the swiped card
* @param direction the direction the card was swiped in
*/
@Override
public void onSwiped(final RecyclerView.ViewHolder viewHolder, int direction) {
final RMetric metric = mMetricsAdapter.getMetrics().get(viewHolder.getAdapterPosition());
/*
* User wants to delete the RMetric
*/
if (direction == ItemTouchHelper.LEFT) {
/*
* Decide which delete message to display, if the user is deleting a form metric that contains scouting data somewhere else,
* we'll want to notify them a bit more
*/
if (metric.getID() <= mMetricsAdapter.getInitID()) {
new FastDialogBuilder().setTitle("Warning").setMessage("Deleting this metric will remove it and all its associated scouting data from ALL team profiles.").setPositiveButtonText("Delete").setNegativeButtonText("Cancel").setFastDialogListener(new FastDialogBuilder.FastDialogListener() {
@Override
public void accepted() {
mMetricsAdapter.getMetrics().remove(viewHolder.getAdapterPosition());
mMetricsAdapter.notifyItemRemoved(viewHolder.getAdapterPosition());
}
@Override
public void denied() {
mMetricsAdapter.reAdd(metric);
mMetricsAdapter.notifyDataSetChanged();
}
@Override
public void neutral() {
}
}).build(mMetricsAdapter.getContext());
} else {
mMetricsAdapter.getMetrics().remove(viewHolder.getAdapterPosition());
mMetricsAdapter.notifyItemRemoved(viewHolder.getAdapterPosition());
}
} else /*
* User wants to edit the RMetric, we can't actually handle that here, so pass it back tot he FormViewer activity
*/
if (direction == ItemTouchHelper.RIGHT) {
/*
* One quick thing - Intents have a payload maximum, galleries will trigger this easily
* because of their size, so if the user requested a RGallery edit, remove all picture information
* from the reference.
*/
if (metric instanceof RGallery)
((RGallery) metric).setImages(null);
mMetricsAdapter.getListener().metricEditRequested(metric);
}
}
use of com.cpjd.roblu.models.metrics.RGallery in project Roblu by wdavies973.
the class EventDepacker method run.
@Override
public void run() {
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitNetwork().build();
StrictMode.setThreadPolicy(policy);
Log.d("RBS", "Executing EventDepacker task...");
ObjectMapper mapper = new ObjectMapper().configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false);
RSettings settings = io.loadSettings();
RSyncSettings cloudSettings = io.loadCloudSettings();
cloudSettings.setTeamSyncID(0);
cloudSettings.getCheckoutSyncIDs().clear();
cloudSettings.setPurgeRequested(false);
io.saveCloudSettings(cloudSettings);
Request r = new Request(settings.getServerIP());
CloudTeamRequest ctr = new CloudTeamRequest(r, settings.getCode());
if (teamNumber != -1) {
ctr.setCode("");
ctr.setTeamNumber(teamNumber);
}
CloudCheckoutRequest ccr = new CloudCheckoutRequest(r, settings.getCode());
if (teamNumber != -1) {
ccr.setTeamCode("");
ccr.setTeamNumber(teamNumber);
}
if (teamNumber == -1 && (settings.getCode() == null || settings.getCode().equals(""))) {
if (listener != null)
listener.errorOccurred("No team code found in settings. Unable to import event.");
return;
}
// Ping
if (!r.ping()) {
if (listener != null)
listener.errorOccurred("It appears as though the server is offline. Try again later.");
return;
}
if (!ctr.isActive()) {
if (listener != null)
listener.errorOccurred("No event found on Roblu Cloud.");
return;
}
/*
* Download everything
*
*/
CloudTeam team = ctr.getTeam(-1);
REvent event;
try {
// Create a new event
event = new REvent(io.getNewEventID(), team.getActiveEventName());
event.setKey(team.getTbaKey());
// should be -1 if cloud is not enabled
event.setReadOnlyTeamNumber(teamNumber);
event.setID(io.getNewEventID());
event.setCloudEnabled(true);
io.saveEvent(event);
settings.setTeamNumber((int) team.getNumber());
settings.setRui(mapper.readValue(team.getUi(), RUI.class));
io.saveSettings(settings);
RForm form = mapper.readValue(team.getForm(), RForm.class);
io.saveForm(event.getID(), form);
} catch (Exception e) {
Log.d("RBS", "Failed to download event");
listener.errorOccurred("Failed to import Roblu Cloud event.");
return;
}
/*
* Un-package checkouts into a teams array
*/
ArrayList<RCheckout> checkouts = new ArrayList<>();
try {
CloudCheckout[] pulledCheckouts = ccr.pullCheckouts(null, true);
for (CloudCheckout s : pulledCheckouts) checkouts.add(mapper.readValue(s.getContent(), RCheckout.class));
} catch (IOException e) {
Log.d("RBS", "Failed to de-package checkouts.");
listener.errorOccurred("Failed to import Roblu Cloud event.");
return;
}
/*
* Start sorting the checkouts into teams
*/
ArrayList<RTeam> teams = new ArrayList<>();
for (RCheckout checkout : checkouts) {
// First, check if the team has already been created
boolean found = false;
for (RTeam t : teams) {
if (t.getID() == checkout.getTeam().getID()) {
// Add the checkout information to the team
t.getTabs().addAll(checkout.getTeam().getTabs());
found = true;
break;
}
t.setLastEdit(checkout.getTime());
}
// If not found, create a new team
if (!found) {
RTeam newTeam = new RTeam(checkout.getTeam().getName(), checkout.getTeam().getNumber(), checkout.getTeam().getID());
newTeam.setTabs(new ArrayList<RTab>());
newTeam.getTabs().addAll(checkout.getTeam().getTabs());
teams.add(newTeam);
}
}
Log.d("RBS", "Created " + teams.size() + " teams");
/*
* Unpack images
*/
for (RCheckout checkout : checkouts) {
for (RTab tab : checkout.getTeam().getTabs()) {
for (RMetric metric : tab.getMetrics()) {
if (metric instanceof RGallery) {
for (int i = 0; ((RGallery) metric).getImages() != null && i < ((RGallery) metric).getImages().size(); i++) {
int picID = io.savePicture(event.getID(), ((RGallery) metric).getImages().get(i));
if (picID != -1) {
((RGallery) metric).setPictureIDs(new ArrayList<Integer>());
((RGallery) metric).getPictureIDs().add(picID);
}
}
if (((RGallery) metric).getImages() != null)
((RGallery) metric).getImages().clear();
}
}
}
}
/*
* Save teams
* -Teams don't need to be verified since the form has also been pulled from the server
*/
for (RTeam t : teams) {
Collections.sort(t.getTabs());
io.saveTeam(event.getID(), t);
}
// Remove all the other synced events
REvent[] events = io.loadEvents();
for (int i = 0; events != null && i < events.length; i++) {
events[i].setCloudEnabled(events[i].getID() == event.getID());
io.saveEvent(events[i]);
}
/*
* Add default sync ids
*/
for (RCheckout checkout : checkouts) {
cloudSettings.getCheckoutSyncIDs().put(checkout.getID(), 0L);
}
io.saveCloudSettings(cloudSettings);
if (listener != null) {
listener.success(event);
}
}
use of com.cpjd.roblu.models.metrics.RGallery in project Roblu by wdavies973.
the class MetricEditor method addMetricPreviewToToolbar.
/**
* Adds the metric preview to the Toolbar
*/
private void addMetricPreviewToToolbar() {
Toolbar toolbar = findViewById(R.id.toolbar);
toolbar.setBackgroundColor(rui.getPrimaryColor());
toolbar.removeAllViews();
if (metric instanceof RBoolean)
toolbar.addView(rMetricToUI.getBoolean((RBoolean) metric));
else if (metric instanceof RCounter)
toolbar.addView(rMetricToUI.getCounter((RCounter) metric));
else if (metric instanceof RSlider)
toolbar.addView(rMetricToUI.getSlider((RSlider) metric));
else if (metric instanceof RChooser)
toolbar.addView(rMetricToUI.getChooser((RChooser) metric));
else if (metric instanceof RCheckbox)
toolbar.addView(rMetricToUI.getCheckbox((RCheckbox) metric));
else if (metric instanceof RStopwatch)
toolbar.addView(rMetricToUI.getStopwatch((RStopwatch) metric, true));
else if (metric instanceof RTextfield)
toolbar.addView(rMetricToUI.getTextfield((RTextfield) metric));
else if (metric instanceof RGallery)
toolbar.addView(rMetricToUI.getGallery(true, 0, 0, ((RGallery) metric)));
else if (metric instanceof RDivider)
toolbar.addView(rMetricToUI.getDivider((RDivider) metric));
else if (metric instanceof RFieldDiagram)
toolbar.addView(rMetricToUI.getFieldDiagram(-1, (RFieldDiagram) metric));
else if (metric instanceof RCalculation)
toolbar.addView(rMetricToUI.getCalculationMetric(null, ((RCalculation) metric)));
else if (metric instanceof RFieldData)
toolbar.addView(rMetricToUI.getFieldData((RFieldData) metric));
}
Aggregations