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

Filter sensor types by distinct values #1015

Merged
merged 2 commits into from
Oct 4, 2023
Merged
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
22 changes: 22 additions & 0 deletions backend/api/Controllers/Models/EchoInspection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,26 @@ private static InspectionType InspectionTypeFromEchoSensorType(string sensorType
};
}
}

public class EchoInspectionComparer : IEqualityComparer<EchoInspection>
{
public bool Equals(EchoInspection? e1, EchoInspection? e2)
{
if (ReferenceEquals(e1, e2))
return true;

if (e2 is null || e1 is null)
return false;

return e1.InspectionType == e2.InspectionType
&& e1.TimeInSeconds == e2.TimeInSeconds;
}

public int GetHashCode(EchoInspection e)
{
// We cannot incorporate TimeInSeconds here are SQL queries do not handle
// nullables even with short circuiting logic
return (int)e.InspectionType;
}
}
}
3 changes: 1 addition & 2 deletions backend/api/Services/EchoService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,7 @@ private List<EchoTag> ProcessPlanItems(List<PlanItem> planItems, string installa
$"https://stid.equinor.com/{installationCode}/tag?tagNo={planItem.Tag}"
),
Inspections = planItem.SensorTypes
.Select(sensor => new EchoInspection(sensor))
.ToList()
.Select(sensor => new EchoInspection(sensor)).Distinct(new EchoInspectionComparer()).ToList()
};

if (tag.Inspections.IsNullOrEmpty())
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/language/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -174,5 +174,6 @@
"Custom": "Custom",
"Hours between inspections": "Hours between inspections",
"Days between inspections": "Days between inspections",
"Confirm plant": "Confirm plant"
"Confirm plant": "Confirm plant",
"N": "N"
}
3 changes: 2 additions & 1 deletion frontend/src/language/no.json
Original file line number Diff line number Diff line change
Expand Up @@ -174,5 +174,6 @@
"No planned inspection": "Ingen inspeksjon planlagt",
"Hours between inspections": "Timer mellom inspeksjoner",
"Days between inspections": "Dager mellom inspeksjoner",
"Confirm plant": "Bekreft anlegg"
"Confirm plant": "Bekreft anlegg",
"N": "N"
}
Loading