= Benchmark subsystem formatting update

This commit is contained in:
Matthew Cech
2019-06-19 20:03:16 -07:00
parent 2a2b46a507
commit 51e40610a2
61 changed files with 172 additions and 172 deletions
+1 -1
View File
@@ -6,5 +6,5 @@ public abstract class BenchmarkCommand
{ }
// OVERRIDE ME
public abstract BenchmarkFormattable OnRun(BenchmarkManager manager, BenchmarkInput input);
public abstract BenchmarkFormattable onRun(BenchmarkManager manager, BenchmarkInput input);
}
+3 -3
View File
@@ -30,11 +30,11 @@ public class BenchmarkFormattable
this.resString = null;
}
public void Call(Response res)
public void call(Response res)
{
if(resEmbed == null)
res.Call(resString);
res.call(resString);
else
res.CallEmbed(resEmbed);
res.callEmbed(resEmbed);
}
}
+12 -12
View File
@@ -16,43 +16,43 @@ public class BenchmarkFramework
this.benchmarkManager = new BenchmarkManager();
this.benchmarkCommand = new HashMap<String, BenchmarkCommand>();
RegisterCommand("find", new BenchmarkCommandFind());
RegisterCommand("compare", new BenchmarkCommandCompare());
RegisterCommand("info", new BenchmarkCommandInfo());
registerCommand("find", new BenchmarkCommandFind());
registerCommand("compare", new BenchmarkCommandCompare());
registerCommand("info", new BenchmarkCommandInfo());
}
// Runs a command if possible.
public BenchmarkFormattable Run(String args)
public BenchmarkFormattable run(String args)
{
BenchmarkInput input = new BenchmarkInput(args);
return ExecuteCommand(input.key, input);
return executeCommand(input.key, input);
}
public void Update()
public void update()
{
synchronized(benchmarkManager)
{
benchmarkManager.Update();
benchmarkManager.update();
}
}
// Registers a command
private void RegisterCommand(String commandName, BenchmarkCommand command)
private void registerCommand(String commandName, BenchmarkCommand command)
{
commandName = commandName.toLowerCase();
if(benchmarkCommand.put(commandName, command) != null)
BenchmarkLog.Log("Multiple registration of a command with name '" + commandName + "'!");
BenchmarkLog.log("Multiple registration of a command with name '" + commandName + "'!");
BenchmarkLog.Log("Registered " + commandName);
BenchmarkLog.log("Registered " + commandName);
}
// Executes a command with the specified name, and provides it with some extra input data.
private BenchmarkFormattable ExecuteCommand(String name, BenchmarkInput input)
private BenchmarkFormattable executeCommand(String name, BenchmarkInput input)
{
BenchmarkCommand command = benchmarkCommand.get(name.toLowerCase());
if(command != null && benchmarkManager != null)
return command.OnRun(benchmarkManager, input);
return command.onRun(benchmarkManager, input);
return null;
}
+3 -3
View File
@@ -5,7 +5,7 @@ import utils.GlobalLog;
//Logging shim
public class BenchmarkLog
{
public static void Log(String str) { GlobalLog.Log("[Benchmark] " + str); }
public static void Warn(String str) { GlobalLog.Warn("[Benchmark] " + str); }
public static void Error(String str) { GlobalLog.Error(" [Benchmark] " + str); }
public static void log(String str) { GlobalLog.Log("[Benchmark] " + str); }
public static void warn(String str) { GlobalLog.Warn("[Benchmark] " + str); }
public static void error(String str) { GlobalLog.Error(" [Benchmark] " + str); }
}
+18 -18
View File
@@ -33,13 +33,13 @@ public class BenchmarkManager
directoryMonitor = new DirectoryMonitor(directory);
needsUpdate = false;
RebuildLookup();
rebuildLookup();
BenchmarkLog.Log("Took " + (Instant.now().toEpochMilli() - start) + " ms to load " + raw.size() + " entries from " + directoryMonitor.GetCurrentFiles().size() + " file" + (raw.size() > 1 ? "s" : ""));
BenchmarkLog.log("Took " + (Instant.now().toEpochMilli() - start) + " ms to load " + raw.size() + " entries from " + directoryMonitor.GetCurrentFiles().size() + " file" + (raw.size() > 1 ? "s" : ""));
}
// Rebuilds the files being monitored
public void RebuildLookup()
public void rebuildLookup()
{
long start = Instant.now().toEpochMilli();
@@ -66,17 +66,17 @@ public class BenchmarkManager
}
else
{
BenchmarkLog.Warn("No " + extension + " files where found in " + directory);
BenchmarkLog.warn("No " + extension + " files where found in " + directory);
}
}
long end = Instant.now().toEpochMilli();
BenchmarkLog.Log("Rebuilt data in " + (end - start) + "ms");
BenchmarkLog.log("Rebuilt data in " + (end - start) + "ms");
}
// Re-evaluates and re-orders the input list based on the Levenshtein distance of the
// original search and the contents of the provided list of benchmark entries.
public List<BenchmarkEntry> EvaluateLevenshteinDistance(List<BenchmarkEntry> entries, String search)
public List<BenchmarkEntry> evaluateLevenshteinDistance(List<BenchmarkEntry> entries, String search)
{
// Populate cost list with heuristic results
List<Pair<BenchmarkEntry, Integer>> cost = new ArrayList<Pair<BenchmarkEntry, Integer>>();
@@ -86,7 +86,7 @@ public class BenchmarkManager
BenchmarkEntry entry = entries.get(i);
String entryString = entry.brand + " " + entry.model;
int heuristic = LevenshteinHeuristic(entryString, search, bestSoFar);
int heuristic = levenshteinHeuristic(entryString, search, bestSoFar);
if(heuristic < bestSoFar)
bestSoFar = heuristic;
@@ -120,7 +120,7 @@ public class BenchmarkManager
// Returns cost based on distance of characters from string. This is a kinda sloppy way
// to do it, but because I keep tabs on the best result so far, it could be much worse.
// Still chucks a lot - a non-recursive result w/ memoization would be best but this will do.
private int LevenshteinHeuristic(String str1, String str2, int bestSoFar)
private int levenshteinHeuristic(String str1, String str2, int bestSoFar)
{
int cost;
@@ -139,15 +139,15 @@ public class BenchmarkManager
if(distance > bestSoFar)
return distance;
int s1 = LevenshteinHeuristic(str1.substring(1), str2, bestSoFar) + 1;
int s2 = LevenshteinHeuristic(str1, str2.substring(1), bestSoFar) + 1;
int s3 = LevenshteinHeuristic(str1.substring(1), str2.substring(1), bestSoFar) + cost;
int s1 = levenshteinHeuristic(str1.substring(1), str2, bestSoFar) + 1;
int s2 = levenshteinHeuristic(str1, str2.substring(1), bestSoFar) + 1;
int s3 = levenshteinHeuristic(str1.substring(1), str2.substring(1), bestSoFar) + cost;
return min(new int[] {s1, s2, s3 });
}
// Search for a substring in the model name
public List<BenchmarkEntry> FindModel(String modelSubstr)
public List<BenchmarkEntry> findModel(String modelSubstr)
{
long start = Instant.now().toEpochMilli();
List<BenchmarkEntry> matching = new ArrayList<BenchmarkEntry>();
@@ -161,27 +161,27 @@ public class BenchmarkManager
matching.add(e);
}
BenchmarkLog.Log("Searched for '" + searchSubstr + "' for "+ (Instant.now().toEpochMilli() - start) + "ms and found " + matching.size() + " entries.");
BenchmarkLog.log("Searched for '" + searchSubstr + "' for "+ (Instant.now().toEpochMilli() - start) + "ms and found " + matching.size() + " entries.");
return matching;
}
// Keeps tabs on any changes of the files.
public void Update()
public void update()
{
needsUpdate = false;
directoryMonitor.Update(this::OnRescan, this::OnRescan, this::OnRescan);
directoryMonitor.Update(this::onRescan, this::onRescan, this::onRescan);
if(needsUpdate)
RebuildLookup();
rebuildLookup();
}
// When a file is changed, handle it.
private void OnRescan(MonitoredFile file)
private void onRescan(MonitoredFile file)
{
// For now, all we need is to note that something was adjusted.
if(file.path.toString().contains(extension))
{
BenchmarkLog.Log("File status changed: " + file.path);
BenchmarkLog.log("File status changed: " + file.path);
needsUpdate = true;
}
}