Skip to content

Commit

Permalink
Add picklist exporting
Browse files Browse the repository at this point in the history
  • Loading branch information
spencerng committed Feb 19, 2018
1 parent a750e5d commit eb907ad
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 3 deletions.
Binary file modified .gradle/2.13/taskArtifacts/cache.properties.lock
Binary file not shown.
Binary file modified .gradle/2.13/taskArtifacts/fileHashes.bin
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map.Entry;

import org.usfirst.frc.team25.scouting.client.models.Autonomous;
Expand Down Expand Up @@ -318,6 +323,82 @@ public void generateTeamReportJson(File outputDirectory){
}
}

public void generatePicklists(File outputDirectory){
HashMap<Integer, Integer> compareList = new HashMap<>();
HashMap<Integer, Integer> pickNumList = new HashMap<>();

for(ScoutEntry entry : scoutEntries){
Integer teamNum = entry.getPreMatch().getTeamNum();

if(!compareList.containsKey(teamNum)){
compareList.put(teamNum, 0);
pickNumList.put(teamNum, 0);
}

pickNumList.put(teamNum, pickNumList.get(teamNum)+entry.getPostMatch().getPickNumber());
String comparisonChar = entry.getPostMatch().getComparison();
Integer t1 = entry.getPostMatch().getTeamOneCompare(), t2 = entry.getPostMatch().getTeamTwoCompare();
if(comparisonChar.equals("<")){
compareList.put(t1, compareList.get(t1)-1);
compareList.put(t2, compareList.get(t2)+1);
}
else if(comparisonChar.equals(">")){
compareList.put(t1, compareList.get(t1)+1);
compareList.put(t2, compareList.get(t2)-1);
}
}

compareList = sortByComparator(compareList, false);
pickNumList = sortByComparator(pickNumList, false);

String compareListOut = "", pickNumListOut = "";

int rankNum = 1;
for (Entry<Integer, Integer> entry : compareList.entrySet()){
compareListOut += rankNum++ + ". " + entry.getKey() + " - " + entry.getValue() + " pts\n";
}
rankNum = 1;
for (Entry<Integer, Integer> entry : pickNumList.entrySet()){
pickNumListOut += rankNum++ + ". " + entry.getKey() + " - " + entry.getValue() + " pts\n";
}

FileManager.outputFile(new File(outputDirectory.getAbsolutePath() + "\\compare_list.txt"), compareListOut);
FileManager.outputFile(new File(outputDirectory.getAbsolutePath() + "\\picknum_list.txt"), pickNumListOut);

}

// true is ascending, false is descending
private HashMap<Integer, Integer> sortByComparator(HashMap<Integer, Integer> unsortMap, final boolean order)
{

List<Entry<Integer, Integer>> list = new LinkedList<Entry<Integer, Integer>>(unsortMap.entrySet());

// Sorting the list based on values
Collections.sort(list, new Comparator<Entry<Integer, Integer>>()
{
public int compare(Entry<Integer, Integer> o1,
Entry<Integer, Integer> o2)
{
if (order)
{
return o1.getValue().compareTo(o2.getValue());
}
else
{
return o2.getValue().compareTo(o1.getValue());

}
}
});

// Maintaining insertion order with the help of LinkedList
HashMap<Integer, Integer> sortedMap = new LinkedHashMap<Integer, Integer>();
for (Entry<Integer, Integer> entry : list)
sortedMap.put(entry.getKey(), entry.getValue());

return sortedMap;
}

public TeamReport getTeamReport(int teamNum){
return teamReports.get(teamNum);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,9 @@ public static void processData(JFrame frame){
if(!file.getName().contains("All"))
file.delete();

report.generateTeamReportJson(dataDirectory);
report.generateTeamReportSpreadsheet(dataDirectory);
//report.generateTeamReportJson(dataDirectory);
//report.generateTeamReportSpreadsheet(dataDirectory);
report.generatePicklists(dataDirectory);

introText.setText("<html><h1>Processing data</h1><br>Done!</html>");

Expand Down Expand Up @@ -269,7 +270,10 @@ public void actionPerformed(ActionEvent e){
public void actionPerformed(ActionEvent e){
JFrame eventCodePrompt = addIcon(new JFrame()), apiKeyPrompt= addIcon(new JFrame());

String apiKey = JOptionPane.showInputDialog(apiKeyPrompt,
String apiKey = FileManager.getFileString(new File("apikey.txt"));
System.out.println(apiKey);
if(apiKey==null)
apiKey = JOptionPane.showInputDialog(apiKeyPrompt,
"Enter The Blue Alliance API key", "Enter API key",JOptionPane.PLAIN_MESSAGE);
//test if API key is valid
tba = new TBA(apiKey);
Expand Down

0 comments on commit eb907ad

Please # to comment.