forked from equinor/flotilla
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInspection.cs
191 lines (166 loc) · 6.45 KB
/
Inspection.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using Api.Controllers.Models;
using Api.Services.Models;
#pragma warning disable CS8618
namespace Api.Database.Models
{
public class Inspection
{
private InspectionStatus _status;
public Inspection()
{
InspectionType = InspectionType.Image;
Status = InspectionStatus.NotStarted;
InspectionTarget = new Position();
}
public Inspection(
InspectionType inspectionType,
float? videoDuration,
Position inspectionTarget,
string? inspectionTargetName,
InspectionStatus status = InspectionStatus.NotStarted,
AnalysisType? analysisType = null
)
{
InspectionType = inspectionType;
VideoDuration = videoDuration;
InspectionTarget = inspectionTarget;
InspectionTargetName = inspectionTargetName;
AnalysisType = analysisType;
Status = status;
}
public Inspection(CustomInspectionQuery inspectionQuery)
{
InspectionType = inspectionQuery.InspectionType;
InspectionTarget = inspectionQuery.InspectionTarget;
VideoDuration = inspectionQuery.VideoDuration;
AnalysisType = inspectionQuery.AnalysisType;
Status = InspectionStatus.NotStarted;
}
// Creates a blank deepcopy of the provided inspection
public Inspection(Inspection copy, InspectionStatus? inspectionStatus = null, bool useEmptyID = false)
{
Id = useEmptyID ? "" : Guid.NewGuid().ToString();
IsarTaskId = useEmptyID ? "" : copy.IsarTaskId;
IsarInspectionId = useEmptyID ? "" : copy.IsarInspectionId;
Status = inspectionStatus ?? copy.Status;
InspectionType = copy.InspectionType;
VideoDuration = copy.VideoDuration;
AnalysisType = copy.AnalysisType;
InspectionUrl = copy.InspectionUrl;
InspectionTarget = new Position(copy.InspectionTarget);
}
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public string Id { get; set; }
[Required]
[MaxLength(200)]
// ReSharper disable once AutoPropertyCanBeMadeGetOnly.Local
public string IsarTaskId { get; set; } = Guid.NewGuid().ToString();
[Required]
[MaxLength(200)]
public string IsarInspectionId { get; set; } = Guid.NewGuid().ToString();
[Required]
public Position InspectionTarget { get; set; }
public string? InspectionTargetName { get; set; }
[Required]
public InspectionStatus Status
{
get => _status;
set
{
_status = value;
if (IsCompleted && EndTime is null)
{
EndTime = DateTime.UtcNow;
}
if (_status is InspectionStatus.InProgress && StartTime is null)
{
StartTime = DateTime.UtcNow;
}
}
}
public bool IsCompleted =>
_status
is InspectionStatus.Cancelled
or InspectionStatus.Successful
or InspectionStatus.Failed;
[Required]
public InspectionType InspectionType { get; set; }
public float? VideoDuration { get; set; }
public AnalysisType? AnalysisType { get; set; }
[MaxLength(250)]
public string? InspectionUrl { get; set; }
public DateTime? StartTime { get; private set; }
public DateTime? EndTime { get; private set; }
public List<InspectionFinding> InspectionFindings { get; set; }
public void UpdateWithIsarInfo(IsarTask isarTask)
{
UpdateStatus(isarTask.TaskStatus);
InspectionType = isarTask.TaskType switch
{
IsarTaskType.RecordAudio => InspectionType.Audio,
IsarTaskType.TakeImage => InspectionType.Image,
IsarTaskType.TakeThermalImage => InspectionType.ThermalImage,
IsarTaskType.TakeVideo => InspectionType.Video,
IsarTaskType.TakeThermalVideo => InspectionType.ThermalVideo,
_
=> throw new ArgumentException(
$"ISAR task type '{isarTask.TaskType}' not supported for inspections"
)
};
IsarTaskId = isarTask.IsarTaskId;
if (isarTask.IsarInspectionId != null) { IsarInspectionId = isarTask.IsarInspectionId; }
}
public void UpdateStatus(IsarTaskStatus isarStatus)
{
Status = isarStatus switch
{
IsarTaskStatus.NotStarted => InspectionStatus.NotStarted,
IsarTaskStatus.InProgress => InspectionStatus.InProgress,
IsarTaskStatus.Successful => InspectionStatus.Successful,
IsarTaskStatus.Cancelled => InspectionStatus.Cancelled,
IsarTaskStatus.Failed => InspectionStatus.Failed,
IsarTaskStatus.Paused => InspectionStatus.InProgress,
_
=> throw new ArgumentException(
$"ISAR task status '{isarStatus}' not supported for inspection status"
)
};
}
public bool IsSupportedInspectionType(IList<RobotCapabilitiesEnum> capabilities)
{
return InspectionType switch
{
InspectionType.Image => capabilities.Contains(RobotCapabilitiesEnum.take_image),
InspectionType.ThermalImage => capabilities.Contains(RobotCapabilitiesEnum.take_thermal_image),
InspectionType.Video => capabilities.Contains(RobotCapabilitiesEnum.take_video),
InspectionType.ThermalVideo => capabilities.Contains(RobotCapabilitiesEnum.take_thermal_video),
InspectionType.Audio => capabilities.Contains(RobotCapabilitiesEnum.record_audio),
_ => false,
};
}
}
public enum InspectionStatus
{
Successful,
InProgress,
NotStarted,
Failed,
Cancelled
}
public enum InspectionType
{
Image,
ThermalImage,
Video,
ThermalVideo,
Audio
}
public enum AnalysisType
{
CarSeal,
RtjFlange
}
}