-
Notifications
You must be signed in to change notification settings - Fork 0
/
uAutoDroneDeployment.pas
115 lines (103 loc) · 4.02 KB
/
uAutoDroneDeployment.pas
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
unit uAutoDroneDeployment;
interface
uses
uLibrary, uDB_Source;
const
arrFootage : array[1..2] of string =
(
'SurvFootage1.jpg', 'SurvFootage2.jpg'
);
procedure DeployDrones;
procedure CompleteFlights;
implementation
//-------------------------------------DEPLOYS ALL DRONES IF THEY HAVE A
//-------------------------------------SCHEDULED FLIGHT
procedure DeployDrones;
var
sSQL : string;
K, iLength : byte;
arrDroneFlightIDs : TDynamicArray;
begin
//-------------------------------------GETS ALL FLIGHTS WHICH ARE MEANT
//-------------------------------------TO BE UNDERWAY
sSQL := 'Select [DroneFlightID] '
+ 'from DroneFlights '
+ 'where [Date and Time of Response] <= Now() AND [Status] ' +
'<> "Completed"';
arrDroneFlightIDs := objDB.ToArray(sSQL);
//-------------------------------------DEPART EACH DRONE
iLength := Length(arrDroneFlightIDs);
if iLength <> 0 then
begin
sSQL := 'Update DroneFlights '
+ 'Set [Status] = "Departed" '
+ 'where [Date and Time of Response] <= Now() AND [Status] ' +
'<> "Completed"';
objDB.DoSQL(sSQL);
Randomize;
for K := 0 to Length(arrDroneFlightIDs) - 1 do
begin
sSQL := 'Update SurveillanceReports '
+ 'Set [Surveillance Summary] = "Retrieving ' +
'Surveillance Footage..." '
+ 'where [DroneFlightID] = ' + arrDroneFlightIDs[K];
objDB.DoSQL(sSQL);
end;
end;
end;
//-------------------------------------CHANGE FLIGHT STATUS TO COMPLETE IF
//-------------------------------------SURVEILLANCE IS OVER
procedure CompleteFlights;
var
sSQL : string;
K, iRandom, iLength : byte;
arrDroneFlightIDs : TDynamicArray;
begin
//-------------------------------------GETS ALL FLIGHTS WHICH ARE MEANT
//-------------------------------------TO HAVE BEEN COMPLETED
sSQL := 'Select [DroneFlightID] '
+ 'from DroneFlights, Drones, Services '
+ 'where [DroneFlights.DroneID] = [Drones.DroneID] AND ' +
'[Drones.Drone Type] = [ServiceID] AND ' +
'IIF([Service Name] = "Emergency Response", DateAdd("h", 1, ' +
'[Date and Time of Response]) <= Now(), Format(Format(' +
'[Date and Time of Response], "Short Date") & " " & ' +
'Format([Surveillance End Time], "Long Time"), ' +
'"General Date") <= Now()) AND [DroneFlights.Status] ' +
'<> "Completed"';
arrDroneFlightIDs := objDB.ToArray(sSQL);
//-------------------------------------COMPLETES EACH FLIGHT
iLength := Length(arrDroneFlightIDs);
if iLength <> 0 then
begin
sSQL := 'Update DroneFlights '
+ 'Set [Status] = "Completed" '
+ 'where [DroneFlightID] IN (Select [DroneFlightID]' +
' from DroneFlights, Drones, Services where ' +
'[DroneFlights.DroneID] = [Drones.DroneID] AND ' +
'[Drones.Drone Type] = [ServiceID] AND ' +
'IIF([Service Name] = "Emergency Response", DateAdd("h", 1, ' +
'[Date and Time of Response]) <= Now(), Format(Format(' +
'[Date and Time of Response], "Short Date") & " " & ' +
'Format([Surveillance End Time], "Long Time"), ' +
'"General Date") <= Now()) AND [DroneFlights.Status] ' +
'<> "Completed")';
objDB.DoSQL(sSQL);
//-------------------------------------ASSIGNS FOOTAGE TO A FLIGHT
Randomize;
for K := 0 to iLength - 1 do
begin
iRandom := Random(Length(arrFootage)) + 1;
sSQL := 'Update SurveillanceReports '
+ 'Set [Surveillance Footage] = "' + arrFootage[iRandom] + '" '
+ 'where [DroneFlightID] = ' + arrDroneFlightIDs[K];
objDB.DoSQL(sSQL);
sSQL := 'Update SurveillanceReports '
+ 'Set [Surveillance Summary] = "Waiting for ' +
'Incident Report..." '
+ 'where [DroneFlightID] = ' + arrDroneFlightIDs[K];
objDB.DoSQL(sSQL);
end;
end;
end;
end.