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

Fixing import for JSON #112

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open

Conversation

KanishaAgrawal
Copy link
Collaborator

No description provided.

@KanishaAgrawal KanishaAgrawal marked this pull request as ready for review July 21, 2023 14:09
doubleUnitMap.put("angle_psi","degrees");
doubleUnitMap.put("AltAGL","ft");
doubleUnitMap.put("flip_type","unknown");
doubleUnitMap.put("GndSpd","kt");
Copy link
Owner

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) {
Copy link
Collaborator

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);
Copy link
Collaborator

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"));
    ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants