Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make various refactors to clean up codebase #1830

Open
wants to merge 21 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,11 @@ Python/app/__pycache__/

Python/app/handlers/__pycache__/

\.vscode/

/.vs

backend/settings/
/.vscode/
.vscode/
source/_build
source/docs/_build
# Compiled class file
*.class

Expand Down Expand Up @@ -109,7 +108,6 @@ fabric.properties

# Temporary build files
**/.gradle
**/target
**/src/main/java/META-INF
**/.settings
**/.classpath
Expand Down
9 changes: 0 additions & 9 deletions docs/.gitignore

This file was deleted.

13 changes: 0 additions & 13 deletions photon-core/.gitignore

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,19 @@
public final class DatabaseSchema {
public static final String[] migrations = {
// #1 - initial schema
"CREATE TABLE IF NOT EXISTS global (\n"
+ " filename TINYTEXT PRIMARY KEY,\n"
+ " contents mediumtext NOT NULL\n"
+ ");"
+ "CREATE TABLE IF NOT EXISTS cameras (\n"
+ " unique_name TINYTEXT PRIMARY KEY,\n"
+ " config_json text NOT NULL,\n"
+ " drivermode_json text NOT NULL,\n"
+ " pipeline_jsons mediumtext NOT NULL\n"
+ ");",
// spotless:off
"""
CREATE TABLE IF NOT EXISTS global (
filename TINYTEXT PRIMARY KEY,
contents mediumtext NOT NULL
);
CREATE TABLE IF NOT EXISTS cameras (
unique_name TINYTEXT PRIMARY KEY,
config_json text NOT NULL,
drivermode_json text NOT NULL,
pipeline_jsons mediumtext NOT NULL
);""",
// spotless:on
// #2 - add column otherpaths_json
"ALTER TABLE cameras ADD COLUMN otherpaths_json TEXT NOT NULL DEFAULT '[]';",
// add future migrations here
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,113 +19,59 @@

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

@JsonIgnoreProperties(ignoreUnknown = true)
public class HardwareConfig {
public final String deviceName;
public final String deviceLogoPath;
public final String supportURL;
public record HardwareConfig(
String deviceName,
String deviceLogoPath,
String supportURL,
// LED control

// LED control
public final ArrayList<Integer> ledPins;
public final String ledSetCommand;
public final boolean ledsCanDim;
public final ArrayList<Integer> ledBrightnessRange;
public final String ledDimCommand;
public final String ledBlinkCommand;
public final ArrayList<Integer> statusRGBPins;
ArrayList<Integer> ledPins,
String ledSetCommand,
boolean ledsCanDim,
ArrayList<Integer> ledBrightnessRange,
String ledDimCommand,
String ledBlinkCommand,
ArrayList<Integer> statusRGBPins,
// Metrics

// Metrics
public final String cpuTempCommand;
public final String cpuMemoryCommand;
public final String cpuUtilCommand;
public final String cpuThrottleReasonCmd;
public final String cpuUptimeCommand;
public final String gpuMemoryCommand;
public final String ramUtilCommand;
public final String gpuMemUsageCommand;
public final String diskUsageCommand;

// Device stuff
public final String restartHardwareCommand;
public final double vendorFOV; // -1 for unmanaged
public final List<Integer> blacklistedResIndices; // this happens before the defaults are applied
String cpuTempCommand,
String cpuMemoryCommand,
String cpuUtilCommand,
String cpuThrottleReasonCmd,
String cpuUptimeCommand,
String gpuMemoryCommand,
String ramUtilCommand,
String gpuMemUsageCommand,
String diskUsageCommand,
// Device stuff
String restartHardwareCommand,
double vendorFOV) { // -1 for unmanaged

public HardwareConfig() {
deviceName = "";
deviceLogoPath = "";
supportURL = "";
ledPins = new ArrayList<>();
ledSetCommand = "";
ledsCanDim = false;
ledBrightnessRange = new ArrayList<>();
statusRGBPins = new ArrayList<>();
ledDimCommand = "";

cpuTempCommand = "";
cpuMemoryCommand = "";
cpuUtilCommand = "";
cpuThrottleReasonCmd = "";
cpuUptimeCommand = "";
gpuMemoryCommand = "";
ramUtilCommand = "";
ledBlinkCommand = "";
gpuMemUsageCommand = "";
diskUsageCommand = "";

restartHardwareCommand = "";
vendorFOV = -1;
blacklistedResIndices = Collections.emptyList();
}

@SuppressWarnings("unused")
public HardwareConfig(
String deviceName,
String deviceLogoPath,
String supportURL,
ArrayList<Integer> ledPins,
String ledSetCommand,
boolean ledsCanDim,
ArrayList<Integer> ledBrightnessRange,
String ledDimCommand,
String ledBlinkCommand,
ArrayList<Integer> statusRGBPins,
String cpuTempCommand,
String cpuMemoryCommand,
String cpuUtilCommand,
String cpuThrottleReasonCmd,
String cpuUptimeCommand,
String gpuMemoryCommand,
String ramUtilCommand,
String gpuMemUsageCommand,
String diskUsageCommand,
String restartHardwareCommand,
double vendorFOV,
List<Integer> blacklistedResIndices) {
this.deviceName = deviceName;
this.deviceLogoPath = deviceLogoPath;
this.supportURL = supportURL;
this.ledPins = ledPins;
this.ledSetCommand = ledSetCommand;
this.ledsCanDim = ledsCanDim;
this.ledBrightnessRange = ledBrightnessRange;
this.ledDimCommand = ledDimCommand;
this.ledBlinkCommand = ledBlinkCommand;
this.statusRGBPins = statusRGBPins;
this.cpuTempCommand = cpuTempCommand;
this.cpuMemoryCommand = cpuMemoryCommand;
this.cpuUtilCommand = cpuUtilCommand;
this.cpuThrottleReasonCmd = cpuThrottleReasonCmd;
this.cpuUptimeCommand = cpuUptimeCommand;
this.gpuMemoryCommand = gpuMemoryCommand;
this.ramUtilCommand = ramUtilCommand;
this.gpuMemUsageCommand = gpuMemUsageCommand;
this.diskUsageCommand = diskUsageCommand;
this.restartHardwareCommand = restartHardwareCommand;
this.vendorFOV = vendorFOV;
this.blacklistedResIndices = blacklistedResIndices;
this(
"", // deviceName
"", // deviceLogoPath
"", // supportURL
new ArrayList<>(), // ledPins
"", // ledSetCommand
false, // ledsCanDim
new ArrayList<>(), // ledBrightnessRange
"", // ledDimCommand
"", // ledBlinkCommand
new ArrayList<>(), // statusRGBPins
"", // cpuTempCommand
"", // cpuMemoryCommand
"", // cpuUtilCommand
"", // cpuThrottleReasonCmd
"", // cpuUptimeCommand
"", // gpuMemoryCommand
"", // ramUtilCommand
"", // gpuMemUsageCommand
"", // diskUsageCommand
"", // restartHardwareCommand
-1); // vendorFOV
}

/**
Expand All @@ -150,53 +96,4 @@ public final boolean hasCommandsConfigured() {
|| gpuMemUsageCommand != ""
|| diskUsageCommand != "";
}

@Override
public String toString() {
return "HardwareConfig [deviceName="
+ deviceName
+ ", deviceLogoPath="
+ deviceLogoPath
+ ", supportURL="
+ supportURL
+ ", ledPins="
+ ledPins
+ ", ledSetCommand="
+ ledSetCommand
+ ", ledsCanDim="
+ ledsCanDim
+ ", ledBrightnessRange="
+ ledBrightnessRange
+ ", ledDimCommand="
+ ledDimCommand
+ ", ledBlinkCommand="
+ ledBlinkCommand
+ ", statusRGBPins="
+ statusRGBPins
+ ", cpuTempCommand="
+ cpuTempCommand
+ ", cpuMemoryCommand="
+ cpuMemoryCommand
+ ", cpuUtilCommand="
+ cpuUtilCommand
+ ", cpuThrottleReasonCmd="
+ cpuThrottleReasonCmd
+ ", cpuUptimeCommand="
+ cpuUptimeCommand
+ ", gpuMemoryCommand="
+ gpuMemoryCommand
+ ", ramUtilCommand="
+ ramUtilCommand
+ ", gpuMemUsageCommand="
+ gpuMemUsageCommand
+ ", diskUsageCommand="
+ diskUsageCommand
+ ", restartHardwareCommand="
+ restartHardwareCommand
+ ", vendorFOV="
+ vendorFOV
+ ", blacklistedResIndices="
+ blacklistedResIndices
+ "]";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import java.time.format.DateTimeFormatter;
import java.time.temporal.TemporalAccessor;
import java.util.*;
import java.util.stream.Collectors;
import org.photonvision.common.logging.LogGroup;
import org.photonvision.common.logging.Logger;
import org.photonvision.common.util.file.FileUtils;
Expand Down Expand Up @@ -280,9 +279,7 @@ private HashMap<String, CameraConfiguration> loadCameraConfigs() {
HashMap<String, CameraConfiguration> loadedConfigurations = new HashMap<>();
try {
var subdirectories =
Files.list(camerasFolder.toPath())
.filter(f -> f.toFile().isDirectory())
.collect(Collectors.toList());
Files.list(camerasFolder.toPath()).filter(f -> f.toFile().isDirectory()).toList();

for (var subdir : subdirectories) {
var cameraConfigPath = Path.of(subdir.toString(), "config.json");
Expand Down Expand Up @@ -348,7 +345,7 @@ private HashMap<String, CameraConfiguration> loadCameraConfigs() {
return null;
})
.filter(Objects::nonNull)
.collect(Collectors.toList())
.toList()
: Collections.emptyList();

loadedConfig.driveModeSettings = driverMode;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ private void saveCameras(Connection conn) {
}
})
.filter(Objects::nonNull)
.collect(Collectors.toList());
.toList();
statement.setString(4, JacksonUtils.serializeToString(settings));

statement.executeUpdate();
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,8 @@ public void accept(CVPipelineResult result) {
ts.cameraIntrinsicsPublisher.accept(fsp.cameraCalibration.getIntrinsicsArr());
ts.cameraDistortionPublisher.accept(fsp.cameraCalibration.getDistCoeffsArr());
} else {
ts.cameraIntrinsicsPublisher.accept(new double[] {});
ts.cameraDistortionPublisher.accept(new double[] {});
ts.cameraIntrinsicsPublisher.accept(new double[0]);
ts.cameraDistortionPublisher.accept(new double[0]);
}

ts.heartbeatPublisher.set(acceptedResult.sequenceID);
Expand Down
Loading
Loading