+ Added command functionality base and modified command stub
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
package core.benchmark;
|
||||
|
||||
public class BenchmarkEntry
|
||||
{
|
||||
public final BenchmarkType type;
|
||||
public final String partNumber;
|
||||
public final String brand;
|
||||
public final String model;
|
||||
public final int rank;
|
||||
public final float benchmark;
|
||||
public final int samples;
|
||||
public final String url;
|
||||
|
||||
BenchmarkEntry(String input)
|
||||
{
|
||||
String[] row = input.split(",");
|
||||
|
||||
type = BenchmarkType.valueOf(row[0]);
|
||||
partNumber = row[1];
|
||||
brand = row[2];
|
||||
model = row[3];
|
||||
rank = Integer.parseInt(row[4]);
|
||||
benchmark = Float.parseFloat(row[5]);
|
||||
samples = Integer.parseInt(row[6]);
|
||||
url = row[7];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package core.benchmark;
|
||||
|
||||
import utils.GlobalLog;
|
||||
|
||||
public class BenchmarkLog
|
||||
{
|
||||
// Logging
|
||||
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); }
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
package core.benchmark;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import utils.FileUtils;
|
||||
import utils.directoryMonitor.DirectoryMonitor;
|
||||
import utils.directoryMonitor.MonitoredFile;
|
||||
|
||||
// All things considered, this doesn't need to be particularly efficient since anything
|
||||
// less than 10ms of search time won't be noticable to an end user really, not for
|
||||
// a networked application that's not performance bound.
|
||||
public class BenchmarkManager
|
||||
{
|
||||
// Variables
|
||||
public final String directory = "assets/userbench/";
|
||||
public final String extension = ".csv";
|
||||
public final String lineDelimiter = "\n";
|
||||
|
||||
private List<BenchmarkEntry> raw;
|
||||
private DirectoryMonitor directoryMonitor;
|
||||
private boolean needsUpdate;
|
||||
|
||||
// Read in all extensions
|
||||
public BenchmarkManager()
|
||||
{
|
||||
long start = Instant.now().toEpochMilli();
|
||||
|
||||
raw = new ArrayList<BenchmarkEntry>();
|
||||
directoryMonitor = new DirectoryMonitor(directory);
|
||||
needsUpdate = false;
|
||||
|
||||
RebuildLookup();
|
||||
|
||||
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()
|
||||
{
|
||||
synchronized(raw)
|
||||
{
|
||||
raw.clear();
|
||||
List<MonitoredFile> files;
|
||||
|
||||
synchronized(directoryMonitor)
|
||||
{
|
||||
files = directoryMonitor.GetCurrentFiles();
|
||||
}
|
||||
|
||||
if(files != null)
|
||||
{
|
||||
for(MonitoredFile mf : files)
|
||||
{
|
||||
String contents = FileUtils.ReadContent(mf.path);
|
||||
String[] lines = contents.split(lineDelimiter);
|
||||
|
||||
for(int i = 1; i < lines.length; ++i)
|
||||
raw.add(new BenchmarkEntry(lines[i]));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
BenchmarkLog.Warn("No " + extension + " files where found in " + directory);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Search for a substring in the model name
|
||||
public List<BenchmarkEntry> FindModel(String modelSubstr)
|
||||
{
|
||||
long start = Instant.now().toEpochMilli();
|
||||
List<BenchmarkEntry> matching = new ArrayList<BenchmarkEntry>();
|
||||
String searchSubstr = modelSubstr.toLowerCase();
|
||||
|
||||
for(BenchmarkEntry e : raw)
|
||||
{
|
||||
String model = e.model.toLowerCase().trim();
|
||||
|
||||
if(model.contains(searchSubstr))
|
||||
matching.add(e);
|
||||
}
|
||||
|
||||
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()
|
||||
{
|
||||
needsUpdate = false;
|
||||
directoryMonitor.Update(this::OnRescan, this::OnRescan, this::OnRescan);
|
||||
|
||||
if(needsUpdate)
|
||||
RebuildLookup();
|
||||
}
|
||||
|
||||
// When a file is changed, handle it.
|
||||
private void OnRescan(MonitoredFile file)
|
||||
{
|
||||
// For now, all we need is to note that something was adjusted.
|
||||
if(file.path.endsWith(extension))
|
||||
needsUpdate = true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package core.benchmark;
|
||||
|
||||
public enum BenchmarkType
|
||||
{
|
||||
CPU(0), GPU(1), SSD(2), HDD(4), RAM(8), USB(16);
|
||||
|
||||
private final int value;
|
||||
private BenchmarkType(int value)
|
||||
{
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public int getValue()
|
||||
{
|
||||
return value;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user