-
Notifications
You must be signed in to change notification settings - Fork 1
/
sample-extract-images.html
269 lines (235 loc) · 7.89 KB
/
sample-extract-images.html
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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<meta http-equiv="x-ua-compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
<title>VXG AI Image loader</title>
<!-- frameworks -->
<script src="frw/jquery.min.js"></script>
<script src="frw/jquery-ui.min.js"></script>
<script src="frw/jquery.formatDateTime.js"></script>
<script src="frw/datetimepicker.full.min.js"></script>
<link rel="stylesheet" type="text/css" href="frw/bootstrap.min.css">
<script src="frw/bootstrap.min.js"></script>
<style>
#tokenContainer {
width: 700px;
}
#showForm {
text-decoration: underline;
}
#showForm:hover {
cursor: pointer;
}
.btn {
color: white;
background-color: #a0cf4d;
}
</style>
</head>
<body onLoad="Load()">
<div class="container">
<h1>Extract Images Sample</h1>
<div class="form-inline" role="form">
<h3>Select a camera</h3>
<div class="form-group ">
<div class="input-group ">
<input id="tokenContainer" type="text" class="form-control" placeholder="Enter access token" value="">
</div>
</div>
<h3>Set interval</h3>
<div class="form-group ">
<div class="input-group ">
<input id="period" type="number" class="form-control" aria-describedby="basic-addon3"
placeholder="Period" value="60">
<div class="input-group-append">
<span class="input-group-text">in seconds</span>
</div>
</div>
</div>
</div>
<p id="showForm" style="display: hide; margin-top:10px;">Extract Images the last 1 hour</p>
<div class="time-form hidden">
<h3>Select time interval and period</h3>
<div class="form-inline" role="form">
<div class="form-group ">
<div class="input-group ">
<input id="from" type="text" class="form-control" aria-describedby="basic-addon1"
placeholder="Start time">
<div class="input-group-append">
<span class="input-group-text">Start time in UTC</span>
</div>
</div>
</div>
<div class="form-group ">
<div class="input-group ">
<input id="to" type="text" class="form-control" aria-describedby="basic-addon2"
placeholder="End time">
<div class="input-group-append">
<span class="input-group-text">End time in UTC</span>
</div>
</div>
</div>
</div>
</div>
<div style="margin-top:10px;">
<button id="startTask" class="btn btn-default">Start image extraction</button>
<button id="checkTask" class="btn btn-defaultx">Check image extraction</button>
<button id="getImages" class="btn btn-default">Show images</button>
<div id="result"></div>
</div>
</div>
<script>
////////////////////////////////////////////////////////////
//
// This section shows how to use VXG REST API.
//
////////////////////////////////////////////////////////////
var taskId;
var access_token;
$( "#startTask" ).click(function() {
access_token = $('#tokenContainer').val();
// initializes HTTP header
$.ajaxSetup({
headers: {
'Authorization': 'Acc ' + access_token
}
});
let startTime = new Date($('#from').val()).getTime();
let endTime = new Date($('#to').val()).getTime();
let period = $('#period').val();
let requestData = {
period: period,
};
// time conversion
let ts = new Date();
if (startTime != null) {
ts.setTime(startTime);
requestData.start = convertTimeToStr(ts);
}
if (endTime != null) {
ts.setTime(endTime);
requestData.end = convertTimeToStr(ts);
}
return $.ajax({
method: 'POST',
url: 'https://web.skyvr.videoexpertsgroup.com/' + 'api/v4/images/generation/tasks/',
data: JSON.stringify(requestData),
contentType: "application/json",
dataType: 'json',
}).then(function (data) {
taskId = data.id;
$( "#result" ).html('A new task created with a task ID: ' + taskId)
});
// executes HTTP POST request '/images/generation/tasks/'
});
$( "#checkTask" ).click(function() {
if(taskId){
// executes HTTP GET request '/images/generation/tasks/{TID}'
$.ajax({
method: 'GET',
url: 'https://web.skyvr.videoexpertsgroup.com/' + 'api/v4/images/generation/tasks/' + taskId + '/',
dataType: 'json'
}).then(function (data) {
$( "#result" ).html('Task is '+ data.status)
})
} else {
alert( "No task ID. Start a task first." );
}
});
$( "#getImages" ).click(function() {
if(taskId){
access_token = $('#tokenContainer').val();
// initializes HTTP header
$.ajaxSetup({
headers: {
'Authorization': 'Acc ' + access_token
}
});
let start = new Date($('#from').val());
let end = new Date($('#to').val());
let requestData = {
limit: 1000,
order_by: '-time',
};
// time conversion
let ts = new Date();
if (start != null) {
ts.setTime(start.getTime());
requestData.start = convertTimeToStr(ts);
}
if (end != null) {
ts.setTime(end.getTime());
requestData.end = convertTimeToStr(ts);
}
// executes HTTP GET request '/storage/images/'
return $.ajax({
method: 'GET',
url: 'https://web.skyvr.videoexpertsgroup.com/' + 'api/v4/storage/images/?origin=generated_from_records&origin_ids=' + taskId,
data: requestData,
dataType: 'json',
}).then(function (data) {
var count = 0;
console.log(data.objects);
var res = ''; $( "#result" ).html('')
$.each(data.objects, function(i, item){
if (item.url.indexOf("_recig_") >=0 )
{
res+='<div><a target="_blank" href='+item.url+'>'+count+' ' + item.time+' ' + item.height +'x' + item.width + ' </a></div>';
count++;
}
})
res+='<div> Total images: '+count+'</div>';
if (count == 0) res+='<div> It can take upto 30 seconds to start a task</div>'
$( "#result" ).html( res );
//alert("Images objects were loaded. Total images: " + count + '. Check the browsers console for details.');
}).fail(function () {
}).always(function () {
});
} else {
alert( "No task ID. Start a task first." );
}
});
////////////////////////////////////////////////////////////
//
// This section is handling UI and data/time conversions.
//
////////////////////////////////////////////////////////////
Date.prototype.getFromFormat = function (format) {
let yyyy = this.getUTCFullYear().toString();
format = format.replace(/yyyy/g, yyyy)
let mm = (this.getUTCMonth() + 1).toString();
format = format.replace(/mm/g, (mm[1] ? mm : "0" + mm[0]));
let dd = this.getUTCDate().toString();
format = format.replace(/dd/g, (dd[1] ? dd : "0" + dd[0]));
let hh = this.getUTCHours().toString();
format = format.replace(/hh/g, (hh[1] ? hh : "0" + hh[0]));
let ii = this.getUTCMinutes().toString();
format = format.replace(/ii/g, (ii[1] ? ii : "0" + ii[0]));
let ss = this.getUTCSeconds().toString();
format = format.replace(/ss/g, (ss[1] ? ss : "0" + ss[0]));
return format;
};
function Load() {
let f1 = new Date();
let e1 = new Date(f1.getTime() - 60 * 60 * 1000); // - 1 hour
document.getElementById('from').value = e1.getFromFormat('mm/dd/yyyy hh:ii');
document.getElementById('to').value = f1.getFromFormat('mm/dd/yyyy hh:ii');
}
function convertTimeToStr(t) {
let d = new Date();
d.setTime(t);
let str = d.getFullYear() + "-"
+ ("00" + (d.getMonth() + 1)).slice(-2) + "-"
+ ("00" + d.getDate()).slice(-2) + "T"
+ ("00" + d.getHours()).slice(-2) + ":"
+ ("00" + d.getMinutes()).slice(-2) + ":"
+ ("00" + d.getSeconds()).slice(-2);
return str;
}
$('#showForm').on('click', function () {
$('.time-form').toggleClass('hidden')
})
</script>
</body>
</html>