-
Notifications
You must be signed in to change notification settings - Fork 5
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
Fixing import for JSON #112
base: main
Are you sure you want to change the base?
Conversation
doubleUnitMap.put("angle_psi","degrees"); | ||
doubleUnitMap.put("AltAGL","ft"); | ||
doubleUnitMap.put("flip_type","unknown"); | ||
doubleUnitMap.put("GndSpd","kt"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should be able to figure out what values are present in the JSON file automatically by reading it instead of hardcoding each parameter. If the columns in the JSON file change (or other drones use a similar format but different columns) this approach will break.
|
||
Map<String, DoubleTimeSeries> doubleSeries = new HashMap<>(); | ||
Map<String, StringTimeSeries> stringSeries = new HashMap<>(); | ||
|
||
String dataType = ""; | ||
|
||
for(String column: headers) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As we discussed this should be replaced with a static immutable map, something like:
static final Map<String, String> UNIT_MAP = Map.ofEntries(
Entry("time", "milliseconds"),
Entry("battery_level", "percentage"),
...
);
Before the declaration of the processJSON
function. This will make the code in the actual function significantly more concise. The way it was before, you were defining the map in the function itself which was also bloating the code length.
DoubleTimeSeries dseries = doubleSeries.get(column); | ||
|
||
if (dseries == null) { | ||
|
||
dseries = new DoubleTimeSeries(connection, column, unit, len); | ||
dseries = new DoubleTimeSeries(connection, column, dataType, len); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This entire switch can be refactored. All of these special cases can be handled in their own break out functions.
Basically, just get all of the data into the time series and then call functions to process the data after the fact e.g.
for (ArrayList<T> line : lines) {
for (int i = 0; i < line.size(); i++) {
String column = columns.get(i);
if (doubleSeries.containsKey(column)) {
...
} else {
...
}
}
}
processAltAGL(doubleSeries.get("AltAGL"));
processGndSpd(doubleSeries.get("GndSpd"));
...
No description provided.