Commit 27cceb14e1465c5b1cdbbf28d16ffb175167ad62
1 parent
6aa1ed7c
Optimized query for getting data on the basis of body sytem
Showing
14 changed files
with
2907 additions
and
27 deletions
400-SOURCECODE/AIAHTML5.API/Models/PixelLocator.cs
... | ... | @@ -9,31 +9,26 @@ namespace AIAHTML5.API.Models |
9 | 9 | { |
10 | 10 | public class PixelLocator |
11 | 11 | { |
12 | - | |
13 | - internal static dynamic GetBodyRegionsPixelData(string layerNumber, string bodyViewIndex, string systemNumber, string zoom) | |
14 | - { | |
15 | - try | |
12 | + | |
13 | + internal static dynamic GetBodyRegionsPixelData(string layerNumber, string bodyViewIndex, string systemNumber, string zoom) | |
16 | 14 | { |
17 | - var client = new MongoClient("localhost:27017"); | |
18 | - var db = client.GetDatabase("AIAHTML5"); | |
15 | + var client = new MongoClient("mongodb://192.168.90.43:27017"); | |
16 | + var db = client.GetDatabase("aia"); | |
19 | 17 | |
20 | 18 | var col = db.GetCollection<BsonDocument>("DAImages"); |
21 | 19 | |
22 | - var pipeline = new BsonDocument[] | |
23 | - { | |
24 | - new BsonDocument{ {"$match", new BsonDocument("terms.SystemNumbers", Convert.ToInt32(systemNumber)) }}, | |
25 | - new BsonDocument{{"$unwind", "$terms"}}, | |
26 | - new BsonDocument{ { "$match", new BsonDocument("terms.SystemNumbers", Convert.ToInt32(systemNumber)) }}, | |
27 | - new BsonDocument{ { "$match", new BsonDocument("bodyViewIndex", Convert.ToInt32(bodyViewIndex)) }}, | |
28 | - new BsonDocument{ { "$match", new BsonDocument("layerNumber", Convert.ToInt32(layerNumber)) }}, | |
29 | - new BsonDocument{ { "$match", new BsonDocument("zoom", Convert.ToInt32(zoom)) }}, | |
30 | - | |
31 | - new BsonDocument { {"$project", new BsonDocument() | |
32 | - .Add("_id", 0) | |
33 | - .Add("terms", 1) | |
34 | - .Add("bodyRegionId", 1) | |
35 | - .Add("layerNumber", 1) | |
36 | - .Add("bodyViewIndex", 1) | |
20 | + var pipeline = new BsonDocument[] | |
21 | + { | |
22 | + new BsonDocument{{"$unwind", "$terms"}}, | |
23 | + new BsonDocument{ { "$match", new BsonDocument("terms.SystemNumbers", | |
24 | + Convert.ToInt32(systemNumber)).Add("bodyViewIndex", | |
25 | + Convert.ToInt32(bodyViewIndex)).Add("layerNumber", | |
26 | + Convert.ToInt32(layerNumber)).Add("zoom", | |
27 | + Convert.ToInt32(zoom)) }}, | |
28 | + new BsonDocument { {"$project", new BsonDocument() | |
29 | + .Add("_id", 0) | |
30 | + .Add("terms", 1) | |
31 | + .Add("bodyRegionId", 1) | |
37 | 32 | } } |
38 | 33 | }; |
39 | 34 | |
... | ... | @@ -42,10 +37,5 @@ namespace AIAHTML5.API.Models |
42 | 37 | |
43 | 38 | return pixelData.ToJson(); |
44 | 39 | } |
45 | - catch (Exception e) | |
46 | - { | |
47 | - return "error"; | |
48 | - } | |
49 | - } | |
50 | -} | |
40 | +} | |
51 | 41 | } | ... | ... |
600-POC/fileSave.rar
0 → 100644
No preview for this file type
600-POC/fileSave/DBSAVe/Program.cs
0 → 100644
1 | +using System; | |
2 | +using System.Collections.Generic; | |
3 | +using System.Linq; | |
4 | +using System.Text; | |
5 | +using System.Threading; | |
6 | +using System.Threading.Tasks; | |
7 | +//using log4net; | |
8 | +using MongoDB.Driver; | |
9 | +using System.IO; | |
10 | +using Newtonsoft.Json.Linq; | |
11 | +using MongoDB.Bson.Serialization.Attributes; | |
12 | +using MongoDB.Bson; | |
13 | + | |
14 | +namespace AIAHighlight.DBSave | |
15 | +{ | |
16 | + [BsonIgnoreExtraElements] | |
17 | + public class BodyRegionImage | |
18 | + { | |
19 | + public ObjectId _id { get; set; } | |
20 | + public string imageName; | |
21 | + public int bodyViewIndex; | |
22 | + public int layerNumber; | |
23 | + public int bodyRegionId; | |
24 | + public int zoom; | |
25 | + public List<Term> terms; | |
26 | + | |
27 | + public BodyRegionImage() | |
28 | + { | |
29 | + this.terms = new List<Term>(); | |
30 | + } | |
31 | + } | |
32 | + | |
33 | + public class Term | |
34 | + { | |
35 | + public int TermNumber; | |
36 | + public List<int> SystemNumbers; | |
37 | + public List<int> PixelLocations; | |
38 | + public int ActualTermNumber; | |
39 | + | |
40 | + public Term(int termNumber, int systemNumber, int pixelLocation) | |
41 | + { | |
42 | + this.SystemNumbers = new List<int>(); | |
43 | + this.PixelLocations = new List<int>(); | |
44 | + this.TermNumber = termNumber; | |
45 | + this.SystemNumbers.Add(systemNumber); | |
46 | + this.PixelLocations.Add(pixelLocation); | |
47 | + } | |
48 | + } | |
49 | + | |
50 | + | |
51 | + | |
52 | + | |
53 | + public class Program | |
54 | + { | |
55 | + //public JObject data { get; set; } | |
56 | + // public Dictionary<int, Term> termList; | |
57 | + | |
58 | + internal void saveImageData(JObject data, int bodyviewId) | |
59 | + { | |
60 | + // DateTime datetime = new DateTime(); | |
61 | + Console.WriteLine("AT "+ DateTime.Now.ToString("yyyy-MM-ddThh:mm:sszzz")+"..In saveImageData. for imageName: "+ data["imageName"].ToString()+ ",bodyViewIndex= "+ data["bodyViewIndex"]+ ",layerNumber: "+ | |
62 | + data["layerNumber"]+ ",bodyRegionId= "+ data["bodyRegion"]); | |
63 | + try | |
64 | + { | |
65 | + BodyRegionImage bodyRegionImage = new BodyRegionImage(); | |
66 | + | |
67 | + var client = new MongoClient(); | |
68 | + | |
69 | + //var db = client.GetDatabase("AIADB_bodyviewId"+bodyviewId.ToString()); | |
70 | + var db = client.GetDatabase("aia"); | |
71 | + | |
72 | + var col = db.GetCollection<BodyRegionImage>("DAImages"); | |
73 | + | |
74 | + JObject imageData = data; | |
75 | + | |
76 | + | |
77 | + | |
78 | + string bodyViewIndex = data["bodyViewIndex"].ToString(); | |
79 | + | |
80 | + string termFilePath = @"C:\ADAM-AWS-FTP\ADAM-AWS\AIAHTML5\bodyViewsData\body-views\" + bodyViewIndex + "\\da_dat_body_system_term_" + bodyViewIndex + ".json"; | |
81 | + //string termFilePath = @"D:\100-PROJECTS\008-AIAHighlight.FileSave\dist\assets\data\json\da\body-views\" + bodyViewIndex + "\\da_dat_body_system_term_" + bodyViewIndex + ".json"; | |
82 | + | |
83 | + string systemTermMapping; | |
84 | + using (StreamReader reader = new StreamReader(termFilePath)) | |
85 | + | |
86 | + // using (StreamReader reader = new StreamReader(path+fileName)) | |
87 | + { | |
88 | + systemTermMapping = reader.ReadToEnd(); | |
89 | + } | |
90 | + | |
91 | + JObject systemTermMappingObject = JObject.Parse(systemTermMapping); | |
92 | + | |
93 | + //Console.WriteLine("AT " + DateTime.Now.ToString("yyyy-MM-ddThh:mm:sszzz") + ".systemTermMappingObject created."); | |
94 | + | |
95 | + dynamic systemTerms = systemTermMappingObject["BodySystem"]["BodySystemTerm"]; | |
96 | + | |
97 | + dynamic imageDataArray = data["data"]; | |
98 | + | |
99 | + Dictionary<int,Term> termList = new Dictionary<int, Term>(); | |
100 | + | |
101 | + Console.WriteLine("AT " + DateTime.Now.ToString("yyyy-MM-ddThh:mm:sszzz") + "..before itrating imageDataArray. for imageName: " + data["imageName"].ToString() + ",bodyViewIndex= " + data["bodyViewIndex"] + ",layerNumber: " + | |
102 | + data["layerNumber"] + ",bodyRegionId= " + data["bodyRegion"]); | |
103 | + | |
104 | + for (int i = 0; i < imageDataArray.Count; i += 4) | |
105 | + { | |
106 | + if(imageDataArray[i] == 0 && imageDataArray[i+1] == 0 && imageDataArray[i+2] == 0) | |
107 | + { | |
108 | + continue; | |
109 | + } | |
110 | + var RED = Convert.ToInt32(imageDataArray[i]) - 9; | |
111 | + var GREEN = Convert.ToInt32(imageDataArray[i + 1]) - 9; | |
112 | + var BLUE = Convert.ToInt32(imageDataArray[i + 2]) - 9; | |
113 | + | |
114 | + if (RED == -9 && GREEN == -9 && BLUE == -9) | |
115 | + continue; | |
116 | + | |
117 | + var Red = ""; | |
118 | + var Green = ""; | |
119 | + var Blue = ""; | |
120 | + string zero = "0"; | |
121 | + | |
122 | + if ((RED).ToString().Length != 2) | |
123 | + { | |
124 | + Red = zero + RED.ToString(); | |
125 | + } | |
126 | + else | |
127 | + { | |
128 | + Red = RED.ToString(); | |
129 | + } | |
130 | + if ((GREEN).ToString().Length != 2) | |
131 | + { | |
132 | + Green = zero + GREEN.ToString(); | |
133 | + } | |
134 | + else | |
135 | + { | |
136 | + Green = GREEN.ToString(); | |
137 | + } | |
138 | + if ((BLUE).ToString().Length != 2) | |
139 | + { | |
140 | + Blue = zero + BLUE.ToString(); | |
141 | + } | |
142 | + else | |
143 | + { | |
144 | + Blue = BLUE.ToString(); | |
145 | + } | |
146 | + | |
147 | + string Icolor = (Red + Green + Blue); | |
148 | + | |
149 | + | |
150 | + | |
151 | + foreach (dynamic systemTerm in systemTerms) | |
152 | + { | |
153 | + | |
154 | + int iColor = Convert.ToInt32(Icolor); | |
155 | + int termNumber = Convert.ToInt32(systemTerm._TermNumber.ToString()); | |
156 | + int systemNumber = Convert.ToInt32(systemTerm._SystemNumber.ToString()); | |
157 | + | |
158 | + if (systemTerm._TermNumber.ToString() == Icolor) | |
159 | + { | |
160 | + this.AddToTermList(termNumber, systemNumber, i, termList); | |
161 | + //this.AddToTermList(termNumber, systemNumber, i, termList); | |
162 | + this.AddToTermList(termNumber, systemNumber, i + 1, termList); | |
163 | + this.AddToTermList(termNumber, systemNumber, i + 2, termList); | |
164 | + break; | |
165 | + } | |
166 | + } | |
167 | + } | |
168 | + | |
169 | + Console.WriteLine("AT " + DateTime.Now.ToString("yyyy-MM-ddThh:mm:sszzz") + "..after craeting termList.. for imageName: " + data["imageName"].ToString() + ",bodyViewIndex= " + data["bodyViewIndex"] + ",layerNumber: " + | |
170 | + data["layerNumber"] + ",bodyRegionId= " + data["bodyRegion"]); | |
171 | + | |
172 | + bodyRegionImage.imageName = data["imageName"].ToString(); | |
173 | + bodyRegionImage.bodyViewIndex = Convert.ToInt32(data["bodyViewIndex"]); | |
174 | + bodyRegionImage.layerNumber = Convert.ToInt32(data["layerNumber"]); | |
175 | + bodyRegionImage.bodyRegionId = Convert.ToInt32(data["bodyRegion"]); | |
176 | + bodyRegionImage.zoom = Convert.ToInt32(data["zoom"]); | |
177 | + | |
178 | + foreach (int key in termList.Keys) | |
179 | + { | |
180 | + bodyRegionImage.terms.Add(termList[key]); | |
181 | + } | |
182 | + | |
183 | + Console.WriteLine("AT " + DateTime.Now.ToString("yyyy-MM-ddThh:mm:sszzz") + "...inserting for imageName: " + data["imageName"].ToString() + ",bodyViewIndex= " + data["bodyViewIndex"] + ",layerNumber: " + | |
184 | + data["layerNumber"] + ",bodyRegionId= " + data["bodyRegion"]); | |
185 | + | |
186 | + col.InsertOne(bodyRegionImage); | |
187 | + | |
188 | + Console.WriteLine("AT " + DateTime.Now.ToString("yyyy-MM-ddThh:mm:sszzz") + "..inserted for imageName: " + data["imageName"].ToString() + ",bodyViewIndex= " + data["bodyViewIndex"] + ",layerNumber: " + | |
189 | + data["layerNumber"] + ",bodyRegionId= " + data["bodyRegion"]); | |
190 | + | |
191 | + var logCol = db.GetCollection<BodyRegionImage>("DAImageLogs"); | |
192 | + | |
193 | + BodyRegionImage bodyRegionImageTolog = new BodyRegionImage(); | |
194 | + bodyRegionImageTolog.bodyViewIndex = Convert.ToInt32(data["bodyViewIndex"]); | |
195 | + bodyRegionImageTolog.layerNumber = Convert.ToInt32(data["layerNumber"]); | |
196 | + bodyRegionImageTolog.bodyRegionId = Convert.ToInt32(data["bodyRegion"]); | |
197 | + bodyRegionImageTolog.zoom = Convert.ToInt32(data["zoom"]); | |
198 | + | |
199 | + logCol.InsertOne(bodyRegionImageTolog); | |
200 | + | |
201 | + bodyRegionImageTolog = null; | |
202 | + | |
203 | + data = null; | |
204 | + termList = null; | |
205 | + systemTermMappingObject = null; | |
206 | + systemTerms = null; | |
207 | + } | |
208 | + catch(Exception ex) | |
209 | + { | |
210 | + Console.WriteLine("AT " + DateTime.Now.ToString("yyyy-MM-ddThh:mm:sszzz") + "..Exception occured for imageName: " + data["imageName"].ToString() + ",bodyViewIndex= " + data["bodyViewIndex"] + ",layerNumber: " + | |
211 | + data["layerNumber"] + ",bodyRegionId= " + data["bodyRegion"]+"... EXCEPTION= "+ex.Message+".. STACKTRACE= "+ex.StackTrace); | |
212 | + | |
213 | + } | |
214 | + | |
215 | + | |
216 | + } | |
217 | + | |
218 | + public void AddToTermList(int termNumber, int systemNumber, int pixelLocation,Dictionary<int, Term> termList) | |
219 | + { | |
220 | + if (!termList.ContainsKey(termNumber)) | |
221 | + { | |
222 | + termList.Add(termNumber, new Term(termNumber, systemNumber, pixelLocation)); | |
223 | + } | |
224 | + else | |
225 | + { | |
226 | + bool isSystemNumberExisting = false; | |
227 | + foreach (int sn in termList[termNumber].SystemNumbers) | |
228 | + { | |
229 | + if (systemNumber == sn) | |
230 | + { | |
231 | + isSystemNumberExisting = true; | |
232 | + break; | |
233 | + } | |
234 | + | |
235 | + } | |
236 | + if (!isSystemNumberExisting) | |
237 | + termList[termNumber].SystemNumbers.Add(systemNumber); | |
238 | + | |
239 | + bool isPixelLocationExisting = false; | |
240 | + foreach (int pl in termList[termNumber].PixelLocations) | |
241 | + { | |
242 | + if (pixelLocation == pl) | |
243 | + { | |
244 | + isPixelLocationExisting = true; | |
245 | + break; | |
246 | + } | |
247 | + | |
248 | + } | |
249 | + if (!isPixelLocationExisting) | |
250 | + termList[termNumber].PixelLocations.Add(pixelLocation); | |
251 | + | |
252 | + } | |
253 | + } | |
254 | + | |
255 | + | |
256 | + | |
257 | + | |
258 | + static void Main(string[] args) | |
259 | + { | |
260 | + | |
261 | + Console.WriteLine("Enter BodyViewId"); | |
262 | + int BodyViewIndex = Convert.ToInt32(Console.ReadLine()); | |
263 | + | |
264 | + Program program = new Program(); | |
265 | + program.getAlreadyInsertedLayer(BodyViewIndex.ToString()); | |
266 | + program = null; | |
267 | + | |
268 | + } | |
269 | + | |
270 | + internal void getAlreadyInsertedLayer(string bodyviewId) | |
271 | + { | |
272 | + Console.WriteLine("AT " + DateTime.Now.ToString("yyyy-MM-ddThh:mm:sszzz") + "inside getAlreadyInsertedLayer"); | |
273 | + int totalLayers = 0; | |
274 | + int [] totalBodyReigons =null; | |
275 | + List<int> bodyRegions = new List<int>(); | |
276 | + | |
277 | + switch (Convert.ToInt32(bodyviewId)) | |
278 | + { | |
279 | + case 1: | |
280 | + totalLayers = 330; | |
281 | + totalBodyReigons = new int[6] {1,2,3,4,5,6}; | |
282 | + bodyRegions.Add(1); | |
283 | + bodyRegions.Add(2); | |
284 | + bodyRegions.Add(3); | |
285 | + bodyRegions.Add(4); | |
286 | + bodyRegions.Add(5); | |
287 | + bodyRegions.Add(6); | |
288 | + break; | |
289 | + case 2: | |
290 | + totalLayers = 288; | |
291 | + bodyRegions.Add(1); | |
292 | + bodyRegions.Add(2); | |
293 | + bodyRegions.Add(3); | |
294 | + bodyRegions.Add(4); | |
295 | + bodyRegions.Add(5); | |
296 | + break; | |
297 | + case 3: | |
298 | + totalLayers = 127; | |
299 | + bodyRegions.Add(1); | |
300 | + bodyRegions.Add(2); | |
301 | + bodyRegions.Add(3); | |
302 | + bodyRegions.Add(4); | |
303 | + bodyRegions.Add(5); | |
304 | + break; | |
305 | + case 4: | |
306 | + totalLayers = 186; | |
307 | + bodyRegions.Add(1); | |
308 | + bodyRegions.Add(2); | |
309 | + bodyRegions.Add(3); | |
310 | + bodyRegions.Add(4); | |
311 | + bodyRegions.Add(5); | |
312 | + bodyRegions.Add(6); | |
313 | + break; | |
314 | + case 5: | |
315 | + totalLayers = 229; | |
316 | + bodyRegions.Add(1); | |
317 | + bodyRegions.Add(2); | |
318 | + bodyRegions.Add(3); | |
319 | + bodyRegions.Add(4); | |
320 | + bodyRegions.Add(5); | |
321 | + bodyRegions.Add(6); | |
322 | + break; | |
323 | + case 6: | |
324 | + totalLayers = 289; | |
325 | + bodyRegions.Add(1); | |
326 | + bodyRegions.Add(2); | |
327 | + bodyRegions.Add(3); | |
328 | + bodyRegions.Add(4); | |
329 | + bodyRegions.Add(5); | |
330 | + | |
331 | + break; | |
332 | + case 7: | |
333 | + totalLayers = 130; | |
334 | + | |
335 | + bodyRegions.Add(1); | |
336 | + bodyRegions.Add(2); | |
337 | + bodyRegions.Add(3); | |
338 | + bodyRegions.Add(4); | |
339 | + bodyRegions.Add(5); | |
340 | + | |
341 | + break; | |
342 | + case 8: | |
343 | + totalLayers = 186; | |
344 | + | |
345 | + bodyRegions.Add(1); | |
346 | + bodyRegions.Add(2); | |
347 | + bodyRegions.Add(3); | |
348 | + bodyRegions.Add(4); | |
349 | + bodyRegions.Add(5); | |
350 | + bodyRegions.Add(6); | |
351 | + break; | |
352 | + case 9: | |
353 | + totalLayers = 64; | |
354 | + bodyRegions.Add(6); | |
355 | + break; | |
356 | + case 10: | |
357 | + totalLayers = 72; | |
358 | + bodyRegions.Add(6); | |
359 | + break; | |
360 | + case 11: | |
361 | + totalLayers = 64; | |
362 | + bodyRegions.Add(6); | |
363 | + break; | |
364 | + case 12: | |
365 | + totalLayers = 72; | |
366 | + bodyRegions.Add(6); | |
367 | + break; | |
368 | + } | |
369 | + | |
370 | + var client = new MongoClient(); | |
371 | + // var db = client.GetDatabase("AIADB_bodyviewId" + bodyviewId.ToString()); | |
372 | + var db = client.GetDatabase("aia"); | |
373 | + | |
374 | + var col = db.GetCollection<BodyRegionImage>("DAImages"); | |
375 | + //var col = db.GetCollection<BodyRegionImage>("DAImages"); | |
376 | + | |
377 | + | |
378 | + FilterDefinition<BodyRegionImage>[] filterCondition = { | |
379 | + Builders<BodyRegionImage>.Filter.Eq("bodyViewIndex", Convert.ToInt32(bodyviewId))}; | |
380 | + | |
381 | + dynamic list = col.Find(Builders<BodyRegionImage>.Filter.And(filterCondition)).Project(Builders<BodyRegionImage>.Projection.Include("layerNumber").Include("bodyRegionId")).ToList(); | |
382 | + Console.WriteLine("already inserted record count: " + list.Count); | |
383 | + | |
384 | + Dictionary<int, List<int>> layersToProcess = new Dictionary<int, List<int>>(); | |
385 | + | |
386 | + for (int i = 1; i <= totalLayers; i++) | |
387 | + { | |
388 | + List<int> bodyRegionForThisLayer = new List<int>(); | |
389 | + switch (Convert.ToInt32(bodyviewId)) | |
390 | + { | |
391 | + case 1: | |
392 | + bodyRegionForThisLayer.Add(1); | |
393 | + bodyRegionForThisLayer.Add(2); | |
394 | + bodyRegionForThisLayer.Add(3); | |
395 | + bodyRegionForThisLayer.Add(4); | |
396 | + bodyRegionForThisLayer.Add(5); | |
397 | + bodyRegionForThisLayer.Add(6); | |
398 | + break; | |
399 | + case 2: | |
400 | + bodyRegionForThisLayer.Add(1); | |
401 | + bodyRegionForThisLayer.Add(2); | |
402 | + bodyRegionForThisLayer.Add(3); | |
403 | + bodyRegionForThisLayer.Add(4); | |
404 | + bodyRegionForThisLayer.Add(5); | |
405 | + break; | |
406 | + case 3: | |
407 | + bodyRegionForThisLayer.Add(1); | |
408 | + bodyRegionForThisLayer.Add(2); | |
409 | + bodyRegionForThisLayer.Add(3); | |
410 | + bodyRegionForThisLayer.Add(4); | |
411 | + bodyRegionForThisLayer.Add(5); | |
412 | + break; | |
413 | + case 4: | |
414 | + bodyRegionForThisLayer.Add(1); | |
415 | + bodyRegionForThisLayer.Add(2); | |
416 | + bodyRegionForThisLayer.Add(3); | |
417 | + bodyRegionForThisLayer.Add(4); | |
418 | + bodyRegionForThisLayer.Add(5); | |
419 | + bodyRegionForThisLayer.Add(6); | |
420 | + break; | |
421 | + case 5: | |
422 | + bodyRegionForThisLayer.Add(1); | |
423 | + bodyRegionForThisLayer.Add(2); | |
424 | + bodyRegionForThisLayer.Add(3); | |
425 | + bodyRegionForThisLayer.Add(4); | |
426 | + bodyRegionForThisLayer.Add(5); | |
427 | + bodyRegionForThisLayer.Add(6); | |
428 | + break; | |
429 | + case 6: | |
430 | + bodyRegionForThisLayer.Add(1); | |
431 | + bodyRegionForThisLayer.Add(2); | |
432 | + bodyRegionForThisLayer.Add(3); | |
433 | + bodyRegionForThisLayer.Add(4); | |
434 | + bodyRegionForThisLayer.Add(5); | |
435 | + | |
436 | + break; | |
437 | + case 7: | |
438 | + bodyRegionForThisLayer.Add(1); | |
439 | + bodyRegionForThisLayer.Add(2); | |
440 | + bodyRegionForThisLayer.Add(3); | |
441 | + bodyRegionForThisLayer.Add(4); | |
442 | + bodyRegionForThisLayer.Add(5); | |
443 | + | |
444 | + break; | |
445 | + case 8: | |
446 | + bodyRegionForThisLayer.Add(1); | |
447 | + bodyRegionForThisLayer.Add(2); | |
448 | + bodyRegionForThisLayer.Add(3); | |
449 | + bodyRegionForThisLayer.Add(4); | |
450 | + bodyRegionForThisLayer.Add(5); | |
451 | + bodyRegionForThisLayer.Add(6); | |
452 | + break; | |
453 | + } | |
454 | + | |
455 | + int previousLayerNumber = 0; | |
456 | + int existingLayerNumber = 0; | |
457 | + bool isLayerMatched = false; | |
458 | + | |
459 | + foreach (dynamic lNumber in list) | |
460 | + { | |
461 | + existingLayerNumber = Convert.ToInt32((lNumber.GetValue("layerNumber")).ToString()); | |
462 | + | |
463 | + if (existingLayerNumber == i) | |
464 | + { | |
465 | + isLayerMatched = true; | |
466 | + int existingBodyRegionId = Convert.ToInt32((lNumber.GetValue("bodyRegionId")).ToString()); | |
467 | + | |
468 | + | |
469 | + if (bodyRegionForThisLayer.Contains(existingBodyRegionId)) { | |
470 | + //remove from bodyRegions list as this is already present | |
471 | + bodyRegionForThisLayer.Remove(existingBodyRegionId); | |
472 | + } | |
473 | + previousLayerNumber = existingLayerNumber; | |
474 | + | |
475 | + } | |
476 | + | |
477 | + else | |
478 | + { | |
479 | + | |
480 | + } | |
481 | + | |
482 | + } | |
483 | + if(isLayerMatched) | |
484 | + layersToProcess.Add(previousLayerNumber, bodyRegionForThisLayer); | |
485 | + else | |
486 | + layersToProcess.Add(i, bodyRegionForThisLayer); | |
487 | + } | |
488 | + Console.WriteLine("AT " + DateTime.Now.ToString("yyyy-MM-ddThh:mm:sszzz") + "after preparing list to process files To Process count: "+ layersToProcess.Count); | |
489 | + | |
490 | + makeFileNameAndProcess(layersToProcess,Convert.ToInt32(bodyviewId)); | |
491 | + } | |
492 | + | |
493 | + | |
494 | + internal void makeFileNameAndProcess(Dictionary<int, List<int>> filesToProcess, int BodyViewIndex) | |
495 | + { | |
496 | + Console.WriteLine("AT " + DateTime.Now.ToString("yyyy-MM-ddThh:mm:sszzz") + "in makeFileNameAndProcess"); | |
497 | + | |
498 | + foreach (KeyValuePair<int, List<int>> pair in filesToProcess) | |
499 | + { | |
500 | + | |
501 | + | |
502 | + foreach (int item in pair.Value) | |
503 | + { | |
504 | + string fileName = "BodyView" + BodyViewIndex + "_layer" + pair.Key + "_bodyRegionId" + item+".json"; | |
505 | + | |
506 | + //string filePath = @"D:\100-PROJECTS\008-AIAHighlight.FileSave\AIAHighlight\AIAHighlight\data\" + fileName; | |
507 | + string filePath = @"C:\ADAM-AWS-FTP\ADAM-AWS\AIAHTML5\data\" + fileName; | |
508 | + getDataFromFileAndSaveInDB(filePath, BodyViewIndex); | |
509 | + } | |
510 | + | |
511 | + } | |
512 | + } | |
513 | + | |
514 | + internal void processFiles(string[] files,int bodyviewId) | |
515 | + { | |
516 | + | |
517 | + //without multithreading | |
518 | + foreach(string filename in files) | |
519 | + { | |
520 | + Console.WriteLine("AT " + DateTime.Now.ToString("yyyy-MM-ddThh:mm:sszzz") + "in processFiles for filename"); | |
521 | + getDataFromFileAndSaveInDB(filename, bodyviewId); | |
522 | + } | |
523 | + | |
524 | + } | |
525 | + | |
526 | + | |
527 | + | |
528 | + internal void getDataFromFileAndSaveInDB(string filePath,int bodyViewId) | |
529 | + { | |
530 | + if (File.Exists(filePath)) | |
531 | + { | |
532 | + string fileData; | |
533 | + using (StreamReader reader = new StreamReader(filePath)) | |
534 | + { | |
535 | + fileData = reader.ReadToEnd(); | |
536 | + | |
537 | + JObject data = JObject.Parse(fileData); | |
538 | + this.saveImageData(data, bodyViewId); | |
539 | + } | |
540 | + | |
541 | + | |
542 | + } | |
543 | + else | |
544 | + { | |
545 | + Console.WriteLine("FILE.NOT.FOUND AT" + | |
546 | + ": " + filePath); | |
547 | + | |
548 | + } | |
549 | + } | |
550 | + } | |
551 | +} | ... | ... |
600-POC/fileSave/DBSAVe/Program_20Threadsfor25Zoom.cs
0 → 100644
1 | +using System; | |
2 | +using System.Collections.Generic; | |
3 | +using System.Linq; | |
4 | +using System.Text; | |
5 | +using System.Threading; | |
6 | +using System.Threading.Tasks; | |
7 | +//using log4net; | |
8 | +using MongoDB.Driver; | |
9 | +using System.IO; | |
10 | +using Newtonsoft.Json.Linq; | |
11 | +using MongoDB.Bson.Serialization.Attributes; | |
12 | +using MongoDB.Bson; | |
13 | + | |
14 | +namespace AIAHighlight.DBSave | |
15 | +{ | |
16 | + [BsonIgnoreExtraElements] | |
17 | + public class BodyRegionImage | |
18 | + { | |
19 | + public ObjectId _id { get; set; } | |
20 | + public string imageName; | |
21 | + public int bodyViewIndex; | |
22 | + public int layerNumber; | |
23 | + public int bodyRegionId; | |
24 | + public int zoom; | |
25 | + public List<Term> terms; | |
26 | + | |
27 | + public BodyRegionImage() | |
28 | + { | |
29 | + this.terms = new List<Term>(); | |
30 | + } | |
31 | + } | |
32 | + | |
33 | + public class Term | |
34 | + { | |
35 | + public int TermNumber; | |
36 | + public List<int> SystemNumbers; | |
37 | + public List<int> PixelLocations; | |
38 | + public int ActualTermNumber; | |
39 | + | |
40 | + public Term(int termNumber, int systemNumber, int pixelLocation) | |
41 | + { | |
42 | + this.SystemNumbers = new List<int>(); | |
43 | + this.PixelLocations = new List<int>(); | |
44 | + this.TermNumber = termNumber; | |
45 | + this.SystemNumbers.Add(systemNumber); | |
46 | + this.PixelLocations.Add(pixelLocation); | |
47 | + } | |
48 | + } | |
49 | + | |
50 | + | |
51 | + | |
52 | + | |
53 | + public class Program | |
54 | + { | |
55 | + //public JObject data { get; set; } | |
56 | + // public Dictionary<int, Term> termList; | |
57 | + | |
58 | + internal void saveImageData(JObject data) | |
59 | + { | |
60 | + // DateTime datetime = new DateTime(); | |
61 | + Console.WriteLine("AT "+ DateTime.Now.ToString("yyyy-MM-ddThh:mm:sszzz")+"..In saveImageData. for imageName: "+ data["imageName"].ToString()+ ",bodyViewIndex= "+ data["bodyViewIndex"]+ ",layerNumber: "+ | |
62 | + data["layerNumber"]+ ",bodyRegionId= "+ data["bodyRegion"]); | |
63 | + try | |
64 | + { | |
65 | + BodyRegionImage bodyRegionImage = new BodyRegionImage(); | |
66 | + | |
67 | + var client = new MongoClient(); | |
68 | + | |
69 | + var db = client.GetDatabase("AIAImageData_25"); | |
70 | + | |
71 | + var col = db.GetCollection<BodyRegionImage>("DAImages"); | |
72 | + | |
73 | + JObject imageData = data; | |
74 | + | |
75 | + | |
76 | + | |
77 | + string bodyViewIndex = data["bodyViewIndex"].ToString(); | |
78 | + | |
79 | + string termFilePath = @"C:\ADAM-AWS-FTP\ADAM-AWS\AIAHTML5\bodyViewsData\body-views\" + bodyViewIndex + "\\da_dat_body_system_term_" + bodyViewIndex + ".json"; | |
80 | + //string termFilePath = @"D:\100-PROJECTS\008-AIAHighlight.FileSave\dist\assets\data\json\da\body-views\" + bodyViewIndex + "\\da_dat_body_system_term_" + bodyViewIndex + ".json"; | |
81 | + | |
82 | + string systemTermMapping; | |
83 | + using (StreamReader reader = new StreamReader(termFilePath)) | |
84 | + | |
85 | + // using (StreamReader reader = new StreamReader(path+fileName)) | |
86 | + { | |
87 | + systemTermMapping = reader.ReadToEnd(); | |
88 | + } | |
89 | + | |
90 | + JObject systemTermMappingObject = JObject.Parse(systemTermMapping); | |
91 | + | |
92 | + //Console.WriteLine("AT " + DateTime.Now.ToString("yyyy-MM-ddThh:mm:sszzz") + ".systemTermMappingObject created."); | |
93 | + | |
94 | + dynamic systemTerms = systemTermMappingObject["BodySystem"]["BodySystemTerm"]; | |
95 | + | |
96 | + dynamic imageDataArray = data["data"]; | |
97 | + | |
98 | + Dictionary<int,Term> termList = new Dictionary<int, Term>(); | |
99 | + | |
100 | + Console.WriteLine("AT " + DateTime.Now.ToString("yyyy-MM-ddThh:mm:sszzz") + "..before itrating imageDataArray. for imageName: " + data["imageName"].ToString() + ",bodyViewIndex= " + data["bodyViewIndex"] + ",layerNumber: " + | |
101 | + data["layerNumber"] + ",bodyRegionId= " + data["bodyRegion"]); | |
102 | + | |
103 | + for (int i = 0; i < imageDataArray.Count; i += 4) | |
104 | + { | |
105 | + if(imageDataArray[i] == 0 && imageDataArray[i+1] == 0 && imageDataArray[i+2] == 0) | |
106 | + { | |
107 | + continue; | |
108 | + } | |
109 | + var RED = Convert.ToInt32(imageDataArray[i]) - 9; | |
110 | + var GREEN = Convert.ToInt32(imageDataArray[i + 1]) - 9; | |
111 | + var BLUE = Convert.ToInt32(imageDataArray[i + 2]) - 9; | |
112 | + | |
113 | + if (RED == -9 && GREEN == -9 && BLUE == -9) | |
114 | + continue; | |
115 | + | |
116 | + var Red = ""; | |
117 | + var Green = ""; | |
118 | + var Blue = ""; | |
119 | + string zero = "0"; | |
120 | + | |
121 | + if ((RED).ToString().Length != 2) | |
122 | + { | |
123 | + Red = zero + RED.ToString(); | |
124 | + } | |
125 | + else | |
126 | + { | |
127 | + Red = RED.ToString(); | |
128 | + } | |
129 | + if ((GREEN).ToString().Length != 2) | |
130 | + { | |
131 | + Green = zero + GREEN.ToString(); | |
132 | + } | |
133 | + else | |
134 | + { | |
135 | + Green = GREEN.ToString(); | |
136 | + } | |
137 | + if ((BLUE).ToString().Length != 2) | |
138 | + { | |
139 | + Blue = zero + BLUE.ToString(); | |
140 | + } | |
141 | + else | |
142 | + { | |
143 | + Blue = BLUE.ToString(); | |
144 | + } | |
145 | + | |
146 | + string Icolor = (Red + Green + Blue); | |
147 | + | |
148 | + | |
149 | + | |
150 | + foreach (dynamic systemTerm in systemTerms) | |
151 | + { | |
152 | + | |
153 | + int iColor = Convert.ToInt32(Icolor); | |
154 | + int termNumber = Convert.ToInt32(systemTerm._TermNumber.ToString()); | |
155 | + int systemNumber = Convert.ToInt32(systemTerm._SystemNumber.ToString()); | |
156 | + | |
157 | + if (systemTerm._TermNumber.ToString() == Icolor) | |
158 | + { | |
159 | + this.AddToTermList(termNumber, systemNumber, i, termList); | |
160 | + //this.AddToTermList(termNumber, systemNumber, i, termList); | |
161 | + this.AddToTermList(termNumber, systemNumber, i + 1, termList); | |
162 | + this.AddToTermList(termNumber, systemNumber, i + 2, termList); | |
163 | + break; | |
164 | + } | |
165 | + } | |
166 | + } | |
167 | + | |
168 | + Console.WriteLine("AT " + DateTime.Now.ToString("yyyy-MM-ddThh:mm:sszzz") + "..after craeting termList.. for imageName: " + data["imageName"].ToString() + ",bodyViewIndex= " + data["bodyViewIndex"] + ",layerNumber: " + | |
169 | + data["layerNumber"] + ",bodyRegionId= " + data["bodyRegion"]); | |
170 | + | |
171 | + bodyRegionImage.imageName = data["imageName"].ToString(); | |
172 | + bodyRegionImage.bodyViewIndex = Convert.ToInt32(data["bodyViewIndex"]); | |
173 | + bodyRegionImage.layerNumber = Convert.ToInt32(data["layerNumber"]); | |
174 | + bodyRegionImage.bodyRegionId = Convert.ToInt32(data["bodyRegion"]); | |
175 | + bodyRegionImage.zoom = Convert.ToInt32(data["zoom"]); | |
176 | + | |
177 | + foreach (int key in termList.Keys) | |
178 | + { | |
179 | + bodyRegionImage.terms.Add(termList[key]); | |
180 | + } | |
181 | + | |
182 | + Console.WriteLine("AT " + DateTime.Now.ToString("yyyy-MM-ddThh:mm:sszzz") + "...inserting for imageName: " + data["imageName"].ToString() + ",bodyViewIndex= " + data["bodyViewIndex"] + ",layerNumber: " + | |
183 | + data["layerNumber"] + ",bodyRegionId= " + data["bodyRegion"]); | |
184 | + | |
185 | + col.InsertOne(bodyRegionImage); | |
186 | + | |
187 | + Console.WriteLine("AT " + DateTime.Now.ToString("yyyy-MM-ddThh:mm:sszzz") + "..inserted for imageName: " + data["imageName"].ToString() + ",bodyViewIndex= " + data["bodyViewIndex"] + ",layerNumber: " + | |
188 | + data["layerNumber"] + ",bodyRegionId= " + data["bodyRegion"]); | |
189 | + | |
190 | + var logCol = db.GetCollection<BodyRegionImage>("DAImageLogs"); | |
191 | + | |
192 | + BodyRegionImage bodyRegionImageTolog = new BodyRegionImage(); | |
193 | + bodyRegionImageTolog.bodyViewIndex = Convert.ToInt32(data["bodyViewIndex"]); | |
194 | + bodyRegionImageTolog.layerNumber = Convert.ToInt32(data["layerNumber"]); | |
195 | + bodyRegionImageTolog.bodyRegionId = Convert.ToInt32(data["bodyRegion"]); | |
196 | + bodyRegionImageTolog.zoom = Convert.ToInt32(data["zoom"]); | |
197 | + | |
198 | + logCol.InsertOne(bodyRegionImageTolog); | |
199 | + | |
200 | + bodyRegionImageTolog = null; | |
201 | + | |
202 | + data = null; | |
203 | + termList = null; | |
204 | + systemTermMappingObject = null; | |
205 | + systemTerms = null; | |
206 | + } | |
207 | + catch(Exception ex) | |
208 | + { | |
209 | + Console.WriteLine("AT " + DateTime.Now.ToString("yyyy-MM-ddThh:mm:sszzz") + "..Exception occured for imageName: " + data["imageName"].ToString() + ",bodyViewIndex= " + data["bodyViewIndex"] + ",layerNumber: " + | |
210 | + data["layerNumber"] + ",bodyRegionId= " + data["bodyRegion"]+"... EXCEPTION= "+ex.Message+".. STACKTRACE= "+ex.StackTrace); | |
211 | + | |
212 | + } | |
213 | + | |
214 | + | |
215 | + } | |
216 | + | |
217 | + public void AddToTermList(int termNumber, int systemNumber, int pixelLocation,Dictionary<int, Term> termList) | |
218 | + { | |
219 | + if (!termList.ContainsKey(termNumber)) | |
220 | + { | |
221 | + termList.Add(termNumber, new Term(termNumber, systemNumber, pixelLocation)); | |
222 | + } | |
223 | + else | |
224 | + { | |
225 | + bool isSystemNumberExisting = false; | |
226 | + foreach (int sn in termList[termNumber].SystemNumbers) | |
227 | + { | |
228 | + if (systemNumber == sn) | |
229 | + { | |
230 | + isSystemNumberExisting = true; | |
231 | + break; | |
232 | + } | |
233 | + | |
234 | + } | |
235 | + if (!isSystemNumberExisting) | |
236 | + termList[termNumber].SystemNumbers.Add(systemNumber); | |
237 | + | |
238 | + bool isPixelLocationExisting = false; | |
239 | + foreach (int pl in termList[termNumber].PixelLocations) | |
240 | + { | |
241 | + if (pixelLocation == pl) | |
242 | + { | |
243 | + isPixelLocationExisting = true; | |
244 | + break; | |
245 | + } | |
246 | + | |
247 | + } | |
248 | + if (!isPixelLocationExisting) | |
249 | + termList[termNumber].PixelLocations.Add(pixelLocation); | |
250 | + | |
251 | + } | |
252 | + } | |
253 | + | |
254 | + | |
255 | + | |
256 | + | |
257 | + static void Main(string[] args) | |
258 | + { | |
259 | + | |
260 | + | |
261 | + //string[] files = Directory.GetFiles("D:\\100-PROJECTS\\008-AIAHighlight.FileSave\\AIAHighlight\\AIAHighlight\\data", "*.json"); | |
262 | + | |
263 | + string[] files = Directory.GetFiles(@"C:\ADAM-AWS-FTP\ADAM-AWS\AIAHTML5\data\25", "*.json"); | |
264 | + //string[] files = Directory.GetFiles(@"C:\ADAM-AWS-FTP\ADAM-AWS\AIAHTML5\data\BodyView4", "*.json"); | |
265 | + Program program = new Program(); | |
266 | + program.processFiles(files, 0, 19); | |
267 | + program = null; | |
268 | + | |
269 | + } | |
270 | + | |
271 | + internal void processFiles(string[] files, int startIndex, int endIndex) | |
272 | + { | |
273 | + | |
274 | + prepareArrayOfFiles(files, startIndex, endIndex); | |
275 | + | |
276 | + } | |
277 | + | |
278 | + internal void prepareArrayOfFiles(string[] files, int startIndex, int endIndex) | |
279 | + { | |
280 | + string[] filesToProcess = new string[20]; | |
281 | + int processedFiles = 0; | |
282 | + int j = 0; | |
283 | + for (int i = startIndex; i <= endIndex; i++) | |
284 | + { | |
285 | + | |
286 | + filesToProcess[j] = files[i]; | |
287 | + j++; | |
288 | + | |
289 | + } | |
290 | + | |
291 | + Parallel.ForEach(filesToProcess, (currentFile) => | |
292 | + { | |
293 | + if (currentFile != null) | |
294 | + { | |
295 | + Console.WriteLine("currentFile = " + currentFile); | |
296 | + using (StreamReader reader = new StreamReader(currentFile)) | |
297 | + { | |
298 | + getDataFromFileAndSaveInDB(currentFile); | |
299 | + processedFiles++; | |
300 | + | |
301 | + } | |
302 | + | |
303 | + if (processedFiles == 20) | |
304 | + { | |
305 | + startIndex = endIndex + 1; | |
306 | + endIndex = startIndex + 19; | |
307 | + filesToProcess = null; | |
308 | + | |
309 | + //in case after adding 20, the endIndex reaches more than length of files array(total files) | |
310 | + if (endIndex > files.Length - 1) | |
311 | + { | |
312 | + // int remainingFiles = endIndex - files.Length; | |
313 | + endIndex = files.Length - 1; | |
314 | + } | |
315 | + if (endIndex < files.Length) | |
316 | + { | |
317 | + processFiles(files, startIndex, endIndex); | |
318 | + } | |
319 | + //} | |
320 | + } | |
321 | + } | |
322 | + } | |
323 | + ); | |
324 | + | |
325 | + } | |
326 | + | |
327 | + | |
328 | + internal void getDataFromFileAndSaveInDB(string filePath) | |
329 | + { | |
330 | + if (File.Exists(filePath)) | |
331 | + { | |
332 | + string fileData; | |
333 | + using (StreamReader reader = new StreamReader(filePath)) | |
334 | + { | |
335 | + fileData = reader.ReadToEnd(); | |
336 | + | |
337 | + JObject data = JObject.Parse(fileData); | |
338 | + this.saveImageData(data); | |
339 | + } | |
340 | + | |
341 | + | |
342 | + } | |
343 | + else | |
344 | + { | |
345 | + Console.WriteLine("FILE.NOT.FOUND AT" + | |
346 | + ": " + filePath); | |
347 | + | |
348 | + } | |
349 | + } | |
350 | + //internal void getAlreadyInsertedLayer(string bodyviewId) | |
351 | + //{ | |
352 | + // Console.WriteLine("AT " + DateTime.Now.ToString("yyyy-MM-ddThh:mm:sszzz") + "inside getAlreadyInsertedLayer"); | |
353 | + // int totalLayers = 0; | |
354 | + // int [] totalBodyReigons =null; | |
355 | + // List<int> bodyRegions = new List<int>(); | |
356 | + | |
357 | + // switch (Convert.ToInt32(bodyviewId)) | |
358 | + // { | |
359 | + // case 1: | |
360 | + // totalLayers = 330; | |
361 | + // totalBodyReigons = new int[6] {1,2,3,4,5,6}; | |
362 | + // bodyRegions.Add(1); | |
363 | + // bodyRegions.Add(2); | |
364 | + // bodyRegions.Add(3); | |
365 | + // bodyRegions.Add(4); | |
366 | + // bodyRegions.Add(5); | |
367 | + // bodyRegions.Add(6); | |
368 | + // break; | |
369 | + // case 2: | |
370 | + // totalLayers = 288; | |
371 | + // // totalBodyReigons = 6; | |
372 | + // break; | |
373 | + // case 3: | |
374 | + // totalLayers = 127; | |
375 | + // // totalBodyReigons = 6; | |
376 | + // break; | |
377 | + // case 4: | |
378 | + // totalLayers = 186; | |
379 | + // // totalBodyReigons = 6; | |
380 | + // break; | |
381 | + // case 5: | |
382 | + // totalLayers = 229; | |
383 | + // // totalBodyReigons = 6; | |
384 | + // break; | |
385 | + // case 6: | |
386 | + // totalLayers = 289; | |
387 | + // // totalBodyReigons = 6; | |
388 | + // break; | |
389 | + // case 7: | |
390 | + // totalLayers = 130; | |
391 | + // // totalBodyReigons = 6; | |
392 | + // break; | |
393 | + // case 8: | |
394 | + // totalLayers = 186; | |
395 | + // // totalBodyReigons = 6; | |
396 | + // break; | |
397 | + // case 9: | |
398 | + // totalLayers = 64; | |
399 | + // // totalBodyReigons = 6; | |
400 | + // break; | |
401 | + // case 10: | |
402 | + // totalLayers = 72; | |
403 | + // // totalBodyReigons = 6; | |
404 | + // break; | |
405 | + // case 11: | |
406 | + // totalLayers = 64; | |
407 | + // // totalBodyReigons = 6; | |
408 | + // break; | |
409 | + // case 12: | |
410 | + // totalLayers = 72; | |
411 | + // // totalBodyReigons = 6; | |
412 | + // break; | |
413 | + // } | |
414 | + | |
415 | + // var client = new MongoClient(); | |
416 | + // var db = client.GetDatabase("AIADB_bodyviewId" + bodyviewId.ToString()); | |
417 | + // //var db = client.GetDatabase("AIAImageDB"); | |
418 | + | |
419 | + // var col = db.GetCollection<BodyRegionImage>("DAImagesLogs"); | |
420 | + // //var col = db.GetCollection<BodyRegionImage>("DAImages"); | |
421 | + | |
422 | + | |
423 | + // FilterDefinition<BodyRegionImage>[] filterCondition = { | |
424 | + // Builders<BodyRegionImage>.Filter.Eq("bodyViewIndex", Convert.ToInt32(bodyviewId))}; | |
425 | + | |
426 | + // dynamic list = col.Find(Builders<BodyRegionImage>.Filter.And(filterCondition)).Project(Builders<BodyRegionImage>.Projection.Include("layerNumber").Include("bodyRegionId")).ToList(); | |
427 | + // //collection.Find(new BsonDocument()).Project(Builders<BsonDocument>.Projection.Include("Price").Exclude("_id")).ToListAsync(); | |
428 | + // // return list; | |
429 | + // Dictionary<int, List<int>> layersToProcess = new Dictionary<int, List<int>>(); | |
430 | + | |
431 | + // for (int i = 1; i <= totalLayers; i++) | |
432 | + // { | |
433 | + // List<int> bodyRegionForThisLayer = new List<int>(); | |
434 | + // bodyRegionForThisLayer.Add(1); | |
435 | + // bodyRegionForThisLayer.Add(2); | |
436 | + // bodyRegionForThisLayer.Add(3); | |
437 | + // bodyRegionForThisLayer.Add(4); | |
438 | + // bodyRegionForThisLayer.Add(5); | |
439 | + // bodyRegionForThisLayer.Add(6); | |
440 | + | |
441 | + // int previousLayerNumber = 0; | |
442 | + // int existingLayerNumber = 0; | |
443 | + // bool isLayerMatched = false; | |
444 | + | |
445 | + // foreach (dynamic lNumber in list) | |
446 | + // { | |
447 | + // existingLayerNumber = Convert.ToInt32((lNumber.GetValue("layerNumber")).ToString()); | |
448 | + | |
449 | + // if (existingLayerNumber == i) | |
450 | + // { | |
451 | + // isLayerMatched = true; | |
452 | + // int existingBodyRegionId = Convert.ToInt32((lNumber.GetValue("bodyRegionId")).ToString()); | |
453 | + | |
454 | + | |
455 | + // if (bodyRegionForThisLayer.Contains(existingBodyRegionId)) { | |
456 | + // //remove from bodyRegions list as this is already present | |
457 | + // bodyRegionForThisLayer.Remove(existingBodyRegionId); | |
458 | + // } | |
459 | + // previousLayerNumber = existingLayerNumber; | |
460 | + | |
461 | + // } | |
462 | + | |
463 | + // else | |
464 | + // { | |
465 | + | |
466 | + // } | |
467 | + | |
468 | + // } | |
469 | + // if(isLayerMatched) | |
470 | + // layersToProcess.Add(previousLayerNumber, bodyRegionForThisLayer); | |
471 | + // else | |
472 | + // layersToProcess.Add(i, bodyRegionForThisLayer); | |
473 | + // } | |
474 | + // Console.WriteLine("AT " + DateTime.Now.ToString("yyyy-MM-ddThh:mm:sszzz") + "after preparing list to process"); | |
475 | + | |
476 | + // makeFileNameAndProcess(layersToProcess,Convert.ToInt32(bodyviewId)); | |
477 | + //} | |
478 | + | |
479 | + | |
480 | + //internal void makeFileNameAndProcess(Dictionary<int, List<int>> filesToProcess, int BodyViewIndex) | |
481 | + //{ | |
482 | + // Console.WriteLine("AT " + DateTime.Now.ToString("yyyy-MM-ddThh:mm:sszzz") + "in makeFileNameAndProcess"); | |
483 | + | |
484 | + // foreach (KeyValuePair<int, List<int>> pair in filesToProcess) | |
485 | + // { | |
486 | + | |
487 | + | |
488 | + // foreach (int item in pair.Value) | |
489 | + // { | |
490 | + // string fileName = "BodyView" + BodyViewIndex + "_layer" + pair.Key + "_bodyRegionId" + item+".json"; | |
491 | + | |
492 | + // //string filePath = @"D:\100-PROJECTS\008-AIAHighlight.FileSave\AIAHighlight\AIAHighlight\data\" + fileName; | |
493 | + // string filePath = @"C:\ADAM-AWS-FTP\ADAM-AWS\AIAHTML5\data\" + fileName; | |
494 | + // getDataFromFileAndSaveInDB(filePath, BodyViewIndex); | |
495 | + // } | |
496 | + | |
497 | + // } | |
498 | + //} | |
499 | + | |
500 | + //internal void processFiles(string[] files,int bodyviewId) | |
501 | + //{ | |
502 | + | |
503 | + // //without multithreading | |
504 | + // foreach(string filename in files) | |
505 | + // { | |
506 | + // Console.WriteLine("AT " + DateTime.Now.ToString("yyyy-MM-ddThh:mm:sszzz") + "in processFiles for filename"); | |
507 | + // getDataFromFileAndSaveInDB(filename, bodyviewId); | |
508 | + // } | |
509 | + | |
510 | + //} | |
511 | + | |
512 | + | |
513 | + | |
514 | + //internal void getDataFromFileAndSaveInDB(string filePath,int bodyViewId) | |
515 | + //{ | |
516 | + // if (File.Exists(filePath)) | |
517 | + // { | |
518 | + // string fileData; | |
519 | + // using (StreamReader reader = new StreamReader(filePath)) | |
520 | + // { | |
521 | + // fileData = reader.ReadToEnd(); | |
522 | + | |
523 | + // JObject data = JObject.Parse(fileData); | |
524 | + // this.saveImageData(data, bodyViewId); | |
525 | + // } | |
526 | + | |
527 | + | |
528 | + // } | |
529 | + // else | |
530 | + // { | |
531 | + // Console.WriteLine("FILE.NOT.FOUND AT" + | |
532 | + // ": " + filePath); | |
533 | + | |
534 | + // } | |
535 | + //} | |
536 | + } | |
537 | +} | ... | ... |
600-POC/fileSave/DBSAVe/Program_NOMultiThreading.cs
0 → 100644
1 | +using System; | |
2 | +using System.Collections.Generic; | |
3 | +using System.Linq; | |
4 | +using System.Text; | |
5 | +using System.Threading; | |
6 | +using System.Threading.Tasks; | |
7 | +//using log4net; | |
8 | +using MongoDB.Driver; | |
9 | +using System.IO; | |
10 | +using Newtonsoft.Json.Linq; | |
11 | +using MongoDB.Bson.Serialization.Attributes; | |
12 | +using MongoDB.Bson; | |
13 | + | |
14 | +namespace AIAHighlight.DBSave | |
15 | +{ | |
16 | + [BsonIgnoreExtraElements] | |
17 | + public class BodyRegionImage | |
18 | + { | |
19 | + public ObjectId _id { get; set; } | |
20 | + public string imageName; | |
21 | + public int bodyViewIndex; | |
22 | + public int layerNumber; | |
23 | + public int bodyRegionId; | |
24 | + public int zoom; | |
25 | + public List<Term> terms; | |
26 | + | |
27 | + public BodyRegionImage() | |
28 | + { | |
29 | + this.terms = new List<Term>(); | |
30 | + } | |
31 | + } | |
32 | + | |
33 | + public class Term | |
34 | + { | |
35 | + public int TermNumber; | |
36 | + public List<int> SystemNumbers; | |
37 | + public List<int> PixelLocations; | |
38 | + public int ActualTermNumber; | |
39 | + | |
40 | + public Term(int termNumber, int systemNumber, int pixelLocation) | |
41 | + { | |
42 | + this.SystemNumbers = new List<int>(); | |
43 | + this.PixelLocations = new List<int>(); | |
44 | + this.TermNumber = termNumber; | |
45 | + this.SystemNumbers.Add(systemNumber); | |
46 | + this.PixelLocations.Add(pixelLocation); | |
47 | + } | |
48 | + } | |
49 | + | |
50 | + | |
51 | + | |
52 | + | |
53 | + public class Program | |
54 | + { | |
55 | + //public JObject data { get; set; } | |
56 | + public Dictionary<int, Term> termList; | |
57 | + | |
58 | + internal void saveImageData(JObject data) | |
59 | + { | |
60 | + // DateTime datetime = new DateTime(); | |
61 | + Console.WriteLine("AT "+ DateTime.Now.ToString("yyyy-MM-ddThh:mm:sszzz")+"..In saveImageData. for imageName: "+ data["imageName"].ToString()+ ",bodyViewIndex= "+ data["bodyViewIndex"]+ ",layerNumber: "+ | |
62 | + data["layerNumber"]+ ",bodyRegionId= "+ data["bodyRegion"]); | |
63 | + try | |
64 | + { | |
65 | + BodyRegionImage bodyRegionImage = new BodyRegionImage(); | |
66 | + // var client = new MongoClient("mongodb://192.168.90.43:27017"); | |
67 | + var client = new MongoClient("mongodb://192.168.90.43:27017"); | |
68 | + | |
69 | + var db = client.GetDatabase("aia"); | |
70 | + | |
71 | + var col = db.GetCollection<BodyRegionImage>("DAImages"); | |
72 | + | |
73 | + // var list = col.Find(Builders<BodyRegionImage>.Filter.Eq("imageName", image["imageName"].ToString())).ToList(); | |
74 | + JObject imageData = data; | |
75 | + | |
76 | + | |
77 | + var projection = Builders<BodyRegionImage>.Projection.Include("_id"); | |
78 | + | |
79 | + FilterDefinition<BodyRegionImage>[] filterCondition = { Builders<BodyRegionImage>.Filter.Eq("imageName", data["imageName"].ToString()), | |
80 | + Builders<BodyRegionImage>.Filter.Eq("bodyViewIndex", Convert.ToInt32(data["bodyViewIndex"])), | |
81 | + Builders<BodyRegionImage>.Filter.Eq("layerNumber", Convert.ToInt32(data["layerNumber"])), | |
82 | + Builders<BodyRegionImage>.Filter.Eq("bodyRegionId", Convert.ToInt32(data["bodyRegion"])), | |
83 | + Builders<BodyRegionImage>.Filter.Eq("zoom", Convert.ToInt32(data["zoom"]))}; | |
84 | + var list = col.Find(Builders<BodyRegionImage>.Filter.And(filterCondition)).Project<BodyRegionImage>(projection).ToList(); | |
85 | + | |
86 | + //FilterDefinition<BodyRegionImage>[] filterCondition = { Builders<BodyRegionImage>.Filter.Eq("imageName", data["imageName"].ToString()), | |
87 | + // Builders<BodyRegionImage>.Filter.Eq("bodyViewIndex", Convert.ToInt32(data["bodyViewIndex"])), | |
88 | + // Builders<BodyRegionImage>.Filter.Eq("layerNumber", Convert.ToInt32(data["layerNumber"])), | |
89 | + // Builders<BodyRegionImage>.Filter.Eq("bodyRegionId", Convert.ToInt32(data["bodyRegion"])), | |
90 | + // Builders<BodyRegionImage>.Filter.Eq("zoom", Convert.ToInt32(data["zoom"]))}; | |
91 | + //var list = col.Find(Builders<BodyRegionImage>.Filter.And(filterCondition)).ToList(); | |
92 | + | |
93 | + if (list.Count > 0) | |
94 | + return; | |
95 | + | |
96 | + Console.WriteLine("AT " + DateTime.Now.ToString("yyyy-MM-ddThh:mm:sszzz") + "..record not found."); | |
97 | + | |
98 | + string bodyViewIndex = data["bodyViewIndex"].ToString(); | |
99 | + // string termFilePath = "D:\\100-PROJECTS\\008-AIAHighlight.FileSave\\dist\\assets\\data\\json\\da\\body-views\\" + bodyViewIndex + "\\da_dat_body_system_term_" + bodyViewIndex + ".json"; | |
100 | + // string termFilePath = " D:\\ADAM\\100-Projects\\001-AIAHighlight.FileSave\\AIAHighlight\\dist\\assets\\data\\json\\da\\body-views\\" + bodyViewIndex + "\\da_dat_body_system_term_" + bodyViewIndex + ".json"; | |
101 | + string path = @"\\ADAMSRVR\dist\assets\data\json\da\body-views\" + bodyViewIndex+"\\"; | |
102 | + string fileName = "da_dat_body_system_term_" + bodyViewIndex + ".json"; | |
103 | + string termFilePath = " D:\\ADAM\\100-Projects\\001-AIAHighlight.FileSave\\AIAHighlight\\dist\\assets\\data\\json\\da\\body-views\\" + bodyViewIndex + "\\da_dat_body_system_term_" + bodyViewIndex + ".json"; | |
104 | + string systemTermMapping; | |
105 | + // using (StreamReader reader = new StreamReader(termFilePath)) | |
106 | + | |
107 | + using (StreamReader reader = new StreamReader(path+fileName)) | |
108 | + { | |
109 | + systemTermMapping = reader.ReadToEnd(); | |
110 | + } | |
111 | + | |
112 | + JObject systemTermMappingObject = JObject.Parse(systemTermMapping); | |
113 | + | |
114 | + Console.WriteLine("AT " + DateTime.Now.ToString("yyyy-MM-ddThh:mm:sszzz") + ".systemTermMappingObject craeted."); | |
115 | + | |
116 | + dynamic systemTerms = systemTermMappingObject["BodySystem"]["BodySystemTerm"]; | |
117 | + | |
118 | + dynamic imageDataArray = data["data"]; | |
119 | + | |
120 | + Dictionary<int,Term> termList = new Dictionary<int, Term>(); | |
121 | + | |
122 | + Console.WriteLine("AT " + DateTime.Now.ToString("yyyy-MM-ddThh:mm:sszzz") + "..before itrating imageDataArray"); | |
123 | + | |
124 | + for (int i = 0; i < imageDataArray.Count; i += 4) | |
125 | + { | |
126 | + var RED = Convert.ToInt32(imageDataArray[i]) - 9; | |
127 | + var GREEN = Convert.ToInt32(imageDataArray[i + 1]) - 9; | |
128 | + var BLUE = Convert.ToInt32(imageDataArray[i + 2]) - 9; | |
129 | + | |
130 | + if (RED == -9 && GREEN == -9 && BLUE == -9) | |
131 | + continue; | |
132 | + | |
133 | + var Red = ""; | |
134 | + var Green = ""; | |
135 | + var Blue = ""; | |
136 | + string zero = "0"; | |
137 | + | |
138 | + if ((RED).ToString().Length != 2) | |
139 | + { | |
140 | + Red = zero + RED.ToString(); | |
141 | + } | |
142 | + else | |
143 | + { | |
144 | + Red = RED.ToString(); | |
145 | + } | |
146 | + if ((GREEN).ToString().Length != 2) | |
147 | + { | |
148 | + Green = zero + GREEN.ToString(); | |
149 | + } | |
150 | + else | |
151 | + { | |
152 | + Green = GREEN.ToString(); | |
153 | + } | |
154 | + if ((BLUE).ToString().Length != 2) | |
155 | + { | |
156 | + Blue = zero + BLUE.ToString(); | |
157 | + } | |
158 | + else | |
159 | + { | |
160 | + Blue = BLUE.ToString(); | |
161 | + } | |
162 | + | |
163 | + string Icolor = (Red + Green + Blue); | |
164 | + // alert('Icolor: ' + Icolor) | |
165 | + | |
166 | + foreach (dynamic systemTerm in systemTerms) | |
167 | + { | |
168 | + int iColor = Convert.ToInt32(Icolor); | |
169 | + int termNumber = Convert.ToInt32(systemTerm._TermNumber.ToString()); | |
170 | + int systemNumber = Convert.ToInt32(systemTerm._SystemNumber.ToString()); | |
171 | + | |
172 | + if (systemTerm._TermNumber.ToString() == Icolor) | |
173 | + { | |
174 | + this.AddToTermList(termNumber, systemNumber, i, termList); | |
175 | + //new Program().AddToTermList(termNumber, systemNumber, i,termList); | |
176 | + //new Program().AddToTermList(termNumber, systemNumber, i + 1, termList); | |
177 | + //new Program().AddToTermList(termNumber, systemNumber, i + 2, termList); | |
178 | + this.AddToTermList(termNumber, systemNumber, i, termList); | |
179 | + this.AddToTermList(termNumber, systemNumber, i + 1, termList); | |
180 | + this.AddToTermList(termNumber, systemNumber, i + 2, termList); | |
181 | + } | |
182 | + } | |
183 | + } | |
184 | + | |
185 | + Console.WriteLine("AT " + DateTime.Now.ToString("yyyy-MM-ddThh:mm:sszzz") + "..after craeting termList."); | |
186 | + | |
187 | + bodyRegionImage.imageName = data["imageName"].ToString(); | |
188 | + bodyRegionImage.bodyViewIndex = Convert.ToInt32(data["bodyViewIndex"]); | |
189 | + bodyRegionImage.layerNumber = Convert.ToInt32(data["layerNumber"]); | |
190 | + bodyRegionImage.bodyRegionId = Convert.ToInt32(data["bodyRegion"]); | |
191 | + bodyRegionImage.zoom = Convert.ToInt32(data["zoom"]); | |
192 | + | |
193 | + foreach (int key in termList.Keys) | |
194 | + { | |
195 | + bodyRegionImage.terms.Add(termList[key]); | |
196 | + } | |
197 | + | |
198 | + Console.WriteLine("AT " + DateTime.Now.ToString("yyyy-MM-ddThh:mm:sszzz") + "...inserting for imageName: " + data["imageName"].ToString() + ",bodyViewIndex= " + data["bodyViewIndex"] + ",layerNumber: " + | |
199 | + data["layerNumber"] + ",bodyRegionId= " + data["bodyRegion"]); | |
200 | + | |
201 | + col.InsertOne(bodyRegionImage); | |
202 | + | |
203 | + Console.WriteLine("AT " + DateTime.Now.ToString("yyyy-MM-ddThh:mm:sszzz") + "..inserted for imageName: " + data["imageName"].ToString() + ",bodyViewIndex= " + data["bodyViewIndex"] + ",layerNumber: " + | |
204 | + data["layerNumber"] + ",bodyRegionId= " + data["bodyRegion"]); | |
205 | + | |
206 | + data = null; | |
207 | + termList = null; | |
208 | + systemTermMappingObject = null; | |
209 | + systemTerms = null; | |
210 | + } | |
211 | + catch(Exception ex) | |
212 | + { | |
213 | + Console.WriteLine("AT " + DateTime.Now.ToString("yyyy-MM-ddThh:mm:sszzz") + "..Exception occured for imageName: " + data["imageName"].ToString() + ",bodyViewIndex= " + data["bodyViewIndex"] + ",layerNumber: " + | |
214 | + data["layerNumber"] + ",bodyRegionId= " + data["bodyRegion"]+"... EXCEPTION= "+ex.Message+".. STACKTRACE= "+ex.StackTrace); | |
215 | + | |
216 | + } | |
217 | + | |
218 | + | |
219 | + } | |
220 | + | |
221 | + public void AddToTermList(int termNumber, int systemNumber, int pixelLocation,Dictionary<int, Term> termList) | |
222 | + { | |
223 | + if (!termList.ContainsKey(termNumber)) | |
224 | + { | |
225 | + termList.Add(termNumber, new Term(termNumber, systemNumber, pixelLocation)); | |
226 | + } | |
227 | + else | |
228 | + { | |
229 | + bool isSystemNumberExisting = false; | |
230 | + foreach (int sn in termList[termNumber].SystemNumbers) | |
231 | + { | |
232 | + if (systemNumber == sn) | |
233 | + { | |
234 | + isSystemNumberExisting = true; | |
235 | + break; | |
236 | + } | |
237 | + | |
238 | + } | |
239 | + if (!isSystemNumberExisting) | |
240 | + termList[termNumber].SystemNumbers.Add(systemNumber); | |
241 | + | |
242 | + bool isPixelLocationExisting = false; | |
243 | + foreach (int pl in termList[termNumber].PixelLocations) | |
244 | + { | |
245 | + if (pixelLocation == pl) | |
246 | + { | |
247 | + isPixelLocationExisting = true; | |
248 | + break; | |
249 | + } | |
250 | + | |
251 | + } | |
252 | + if (!isPixelLocationExisting) | |
253 | + termList[termNumber].PixelLocations.Add(pixelLocation); | |
254 | + | |
255 | + } | |
256 | + } | |
257 | + //static void saveImageData() | |
258 | + //{ | |
259 | + | |
260 | + //} | |
261 | + | |
262 | + static void Main(string[] args) | |
263 | + { | |
264 | + Console.WriteLine("Enter BodyViewIndex"); | |
265 | + string bodyViewId = Console.ReadLine(); | |
266 | + string searchPattern = "BodyView" + bodyViewId+"_layer*"; | |
267 | + // string[] files = Directory.GetFiles("D:\\100-PROJECTS\\008-AIAHighlight.FileSave\\AIAHighlight\\AIAHighlight\\data"); | |
268 | + // string[] files = Directory.GetFiles("D:\\ADAM\\100-Projects\\001-AIAHighlight.FileSave\\AIAHighlight.Serevr\\AIAHighlight\\data", "*.json"); | |
269 | + // string[] files = Directory.GetFiles("D:\\100-PROJECTS\\008-AIAHighlight.FileSave\\AIAHighlight\\AIAHighlight\\data",searchPattern); | |
270 | + | |
271 | + string[] files = Directory.GetFiles(@"\\ADAMSRVR\data", searchPattern); | |
272 | + Program program; | |
273 | + foreach (string filePath in files) | |
274 | + { | |
275 | + program = new Program(); | |
276 | + program.getDataFromFileAndSaveInDB(filePath); | |
277 | + program = null; | |
278 | + } | |
279 | + | |
280 | + } | |
281 | + | |
282 | + internal void getDataFromFileAndSaveInDB(string filePath) | |
283 | + { | |
284 | + if (File.Exists(filePath)) | |
285 | + { | |
286 | + string fileData; | |
287 | + using (StreamReader reader = new StreamReader(filePath)) | |
288 | + { | |
289 | + fileData = reader.ReadToEnd(); | |
290 | + | |
291 | + JObject data = JObject.Parse(fileData); | |
292 | + this.saveImageData(data); | |
293 | + } | |
294 | + | |
295 | + | |
296 | + } | |
297 | + } | |
298 | + } | |
299 | +} | ... | ... |
600-POC/fileSave/DBSAVe/Program_UserInput_DifferentDB.cs
0 → 100644
1 | +using System; | |
2 | +using System.Collections.Generic; | |
3 | +using System.Linq; | |
4 | +using System.Text; | |
5 | +using System.Threading; | |
6 | +using System.Threading.Tasks; | |
7 | +//using log4net; | |
8 | +using MongoDB.Driver; | |
9 | +using System.IO; | |
10 | +using Newtonsoft.Json.Linq; | |
11 | +using MongoDB.Bson.Serialization.Attributes; | |
12 | +using MongoDB.Bson; | |
13 | + | |
14 | +namespace AIAHighlight.DBSave | |
15 | +{ | |
16 | + [BsonIgnoreExtraElements] | |
17 | + public class BodyRegionImage | |
18 | + { | |
19 | + public ObjectId _id { get; set; } | |
20 | + public string imageName; | |
21 | + public int bodyViewIndex; | |
22 | + public int layerNumber; | |
23 | + public int bodyRegionId; | |
24 | + public int zoom; | |
25 | + public List<Term> terms; | |
26 | + | |
27 | + public BodyRegionImage() | |
28 | + { | |
29 | + this.terms = new List<Term>(); | |
30 | + } | |
31 | + } | |
32 | + | |
33 | + public class Term | |
34 | + { | |
35 | + public int TermNumber; | |
36 | + public List<int> SystemNumbers; | |
37 | + public List<int> PixelLocations; | |
38 | + public int ActualTermNumber; | |
39 | + | |
40 | + public Term(int termNumber, int systemNumber, int pixelLocation) | |
41 | + { | |
42 | + this.SystemNumbers = new List<int>(); | |
43 | + this.PixelLocations = new List<int>(); | |
44 | + this.TermNumber = termNumber; | |
45 | + this.SystemNumbers.Add(systemNumber); | |
46 | + this.PixelLocations.Add(pixelLocation); | |
47 | + } | |
48 | + } | |
49 | + | |
50 | + | |
51 | + | |
52 | + | |
53 | + public class Program | |
54 | + { | |
55 | + //public JObject data { get; set; } | |
56 | + // public Dictionary<int, Term> termList; | |
57 | + | |
58 | + internal void saveImageData(JObject data, int bodyviewId) | |
59 | + { | |
60 | + // DateTime datetime = new DateTime(); | |
61 | + Console.WriteLine("AT "+ DateTime.Now.ToString("yyyy-MM-ddThh:mm:sszzz")+"..In saveImageData. for imageName: "+ data["imageName"].ToString()+ ",bodyViewIndex= "+ data["bodyViewIndex"]+ ",layerNumber: "+ | |
62 | + data["layerNumber"]+ ",bodyRegionId= "+ data["bodyRegion"]); | |
63 | + try | |
64 | + { | |
65 | + BodyRegionImage bodyRegionImage = new BodyRegionImage(); | |
66 | + // var client = new MongoClient("mongodb://192.168.90.43:27017"); | |
67 | + var client = new MongoClient(); | |
68 | + | |
69 | + var db = client.GetDatabase("AIADB_bodyviewId"+bodyviewId.ToString()); | |
70 | + | |
71 | + var col = db.GetCollection<BodyRegionImage>("DAImages"); | |
72 | + | |
73 | + // var list = col.Find(Builders<BodyRegionImage>.Filter.Eq("imageName", image["imageName"].ToString())).ToList(); | |
74 | + JObject imageData = data; | |
75 | + | |
76 | + | |
77 | + //var projection = Builders<BodyRegionImage>.Projection.Include("_id"); | |
78 | + | |
79 | + //FilterDefinition<BodyRegionImage>[] filterCondition = { Builders<BodyRegionImage>.Filter.Eq("imageName", data["imageName"].ToString()), | |
80 | + // Builders<BodyRegionImage>.Filter.Eq("bodyViewIndex", Convert.ToInt32(data["bodyViewIndex"])), | |
81 | + // Builders<BodyRegionImage>.Filter.Eq("layerNumber", Convert.ToInt32(data["layerNumber"])), | |
82 | + // Builders<BodyRegionImage>.Filter.Eq("bodyRegionId", Convert.ToInt32(data["bodyRegion"])), | |
83 | + // Builders<BodyRegionImage>.Filter.Eq("zoom", Convert.ToInt32(data["zoom"]))}; | |
84 | + //var list = col.Find(Builders<BodyRegionImage>.Filter.And(filterCondition)).Project<BodyRegionImage>(projection).ToList(); | |
85 | + | |
86 | + | |
87 | + //if (list.Count > 0) | |
88 | + // return; | |
89 | + | |
90 | + //Console.WriteLine("AT " + DateTime.Now.ToString("yyyy-MM-ddThh:mm:sszzz") + "..record not found."); | |
91 | + | |
92 | + string bodyViewIndex = data["bodyViewIndex"].ToString(); | |
93 | + | |
94 | + //string termFilePath = @"C:\ADAM-AWS-FTP\ADAM-AWS\AIAHTML5\bodyViewsData\body-views\" + bodyViewIndex + "\\da_dat_body_system_term_" + bodyViewIndex + ".json"; | |
95 | + string termFilePath = @"D:\100-PROJECTS\008-AIAHighlight.FileSave\dist\assets\data\json\da\body-views\" + bodyViewIndex + "\\da_dat_body_system_term_" + bodyViewIndex + ".json"; | |
96 | + //string path = @"\\ADAMSRVR\dist\assets\data\json\da\body-views\" + bodyViewIndex+"\\"; | |
97 | + //string fileName = "da_dat_body_system_term_" + bodyViewIndex + ".json"; | |
98 | + | |
99 | + string systemTermMapping; | |
100 | + using (StreamReader reader = new StreamReader(termFilePath)) | |
101 | + | |
102 | + // using (StreamReader reader = new StreamReader(path+fileName)) | |
103 | + { | |
104 | + systemTermMapping = reader.ReadToEnd(); | |
105 | + } | |
106 | + | |
107 | + JObject systemTermMappingObject = JObject.Parse(systemTermMapping); | |
108 | + | |
109 | + //Console.WriteLine("AT " + DateTime.Now.ToString("yyyy-MM-ddThh:mm:sszzz") + ".systemTermMappingObject created."); | |
110 | + | |
111 | + dynamic systemTerms = systemTermMappingObject["BodySystem"]["BodySystemTerm"]; | |
112 | + | |
113 | + dynamic imageDataArray = data["data"]; | |
114 | + //int[] imageDataIntArray = (int[])imageDataArray; | |
115 | + //int numToRemove = 0; | |
116 | + //dynamic imageDataWithoutZero = imageDataIntArray.Where(val => val != numToRemove).ToArray(); | |
117 | + | |
118 | + Dictionary<int,Term> termList = new Dictionary<int, Term>(); | |
119 | + | |
120 | + Console.WriteLine("AT " + DateTime.Now.ToString("yyyy-MM-ddThh:mm:sszzz") + "..before itrating imageDataArray. for imageName: " + data["imageName"].ToString() + ",bodyViewIndex= " + data["bodyViewIndex"] + ",layerNumber: " + | |
121 | + data["layerNumber"] + ",bodyRegionId= " + data["bodyRegion"]); | |
122 | + | |
123 | + for (int i = 0; i < imageDataArray.Count; i += 4) | |
124 | + { | |
125 | + var RED = Convert.ToInt32(imageDataArray[i]) - 9; | |
126 | + var GREEN = Convert.ToInt32(imageDataArray[i + 1]) - 9; | |
127 | + var BLUE = Convert.ToInt32(imageDataArray[i + 2]) - 9; | |
128 | + | |
129 | + if (RED == -9 && GREEN == -9 && BLUE == -9) | |
130 | + continue; | |
131 | + | |
132 | + var Red = ""; | |
133 | + var Green = ""; | |
134 | + var Blue = ""; | |
135 | + string zero = "0"; | |
136 | + | |
137 | + if ((RED).ToString().Length != 2) | |
138 | + { | |
139 | + Red = zero + RED.ToString(); | |
140 | + } | |
141 | + else | |
142 | + { | |
143 | + Red = RED.ToString(); | |
144 | + } | |
145 | + if ((GREEN).ToString().Length != 2) | |
146 | + { | |
147 | + Green = zero + GREEN.ToString(); | |
148 | + } | |
149 | + else | |
150 | + { | |
151 | + Green = GREEN.ToString(); | |
152 | + } | |
153 | + if ((BLUE).ToString().Length != 2) | |
154 | + { | |
155 | + Blue = zero + BLUE.ToString(); | |
156 | + } | |
157 | + else | |
158 | + { | |
159 | + Blue = BLUE.ToString(); | |
160 | + } | |
161 | + | |
162 | + string Icolor = (Red + Green + Blue); | |
163 | + // alert('Icolor: ' + Icolor) | |
164 | + if(Icolor=="000000") | |
165 | + foreach (dynamic systemTerm in systemTerms) | |
166 | + { | |
167 | + int iColor = Convert.ToInt32(Icolor); | |
168 | + int termNumber = Convert.ToInt32(systemTerm._TermNumber.ToString()); | |
169 | + int systemNumber = Convert.ToInt32(systemTerm._SystemNumber.ToString()); | |
170 | + | |
171 | + if (systemTerm._TermNumber.ToString() == Icolor) | |
172 | + { | |
173 | + this.AddToTermList(termNumber, systemNumber, i, termList); | |
174 | + this.AddToTermList(termNumber, systemNumber, i, termList); | |
175 | + this.AddToTermList(termNumber, systemNumber, i + 1, termList); | |
176 | + this.AddToTermList(termNumber, systemNumber, i + 2, termList); | |
177 | + break; | |
178 | + } | |
179 | + } | |
180 | + } | |
181 | + | |
182 | + Console.WriteLine("AT " + DateTime.Now.ToString("yyyy-MM-ddThh:mm:sszzz") + "..after craeting termList.. for imageName: " + data["imageName"].ToString() + ",bodyViewIndex= " + data["bodyViewIndex"] + ",layerNumber: " + | |
183 | + data["layerNumber"] + ",bodyRegionId= " + data["bodyRegion"]); | |
184 | + | |
185 | + bodyRegionImage.imageName = data["imageName"].ToString(); | |
186 | + bodyRegionImage.bodyViewIndex = Convert.ToInt32(data["bodyViewIndex"]); | |
187 | + bodyRegionImage.layerNumber = Convert.ToInt32(data["layerNumber"]); | |
188 | + bodyRegionImage.bodyRegionId = Convert.ToInt32(data["bodyRegion"]); | |
189 | + bodyRegionImage.zoom = Convert.ToInt32(data["zoom"]); | |
190 | + | |
191 | + foreach (int key in termList.Keys) | |
192 | + { | |
193 | + bodyRegionImage.terms.Add(termList[key]); | |
194 | + } | |
195 | + | |
196 | + Console.WriteLine("AT " + DateTime.Now.ToString("yyyy-MM-ddThh:mm:sszzz") + "...inserting for imageName: " + data["imageName"].ToString() + ",bodyViewIndex= " + data["bodyViewIndex"] + ",layerNumber: " + | |
197 | + data["layerNumber"] + ",bodyRegionId= " + data["bodyRegion"]); | |
198 | + | |
199 | + col.InsertOne(bodyRegionImage); | |
200 | + | |
201 | + Console.WriteLine("AT " + DateTime.Now.ToString("yyyy-MM-ddThh:mm:sszzz") + "..inserted for imageName: " + data["imageName"].ToString() + ",bodyViewIndex= " + data["bodyViewIndex"] + ",layerNumber: " + | |
202 | + data["layerNumber"] + ",bodyRegionId= " + data["bodyRegion"]); | |
203 | + | |
204 | + var logCol = db.GetCollection<BodyRegionImage>("DAImageLogs"); | |
205 | + | |
206 | + BodyRegionImage bodyRegionImageTolog = new BodyRegionImage(); | |
207 | + bodyRegionImageTolog.bodyViewIndex = Convert.ToInt32(data["bodyViewIndex"]); | |
208 | + bodyRegionImageTolog.layerNumber = Convert.ToInt32(data["layerNumber"]); | |
209 | + bodyRegionImageTolog.bodyRegionId = Convert.ToInt32(data["bodyRegion"]); | |
210 | + bodyRegionImageTolog.zoom = Convert.ToInt32(data["zoom"]); | |
211 | + | |
212 | + logCol.InsertOne(bodyRegionImageTolog); | |
213 | + | |
214 | + bodyRegionImageTolog = null; | |
215 | + | |
216 | + data = null; | |
217 | + termList = null; | |
218 | + systemTermMappingObject = null; | |
219 | + systemTerms = null; | |
220 | + } | |
221 | + catch(Exception ex) | |
222 | + { | |
223 | + Console.WriteLine("AT " + DateTime.Now.ToString("yyyy-MM-ddThh:mm:sszzz") + "..Exception occured for imageName: " + data["imageName"].ToString() + ",bodyViewIndex= " + data["bodyViewIndex"] + ",layerNumber: " + | |
224 | + data["layerNumber"] + ",bodyRegionId= " + data["bodyRegion"]+"... EXCEPTION= "+ex.Message+".. STACKTRACE= "+ex.StackTrace); | |
225 | + | |
226 | + } | |
227 | + | |
228 | + | |
229 | + } | |
230 | + | |
231 | + public void AddToTermList(int termNumber, int systemNumber, int pixelLocation,Dictionary<int, Term> termList) | |
232 | + { | |
233 | + if (!termList.ContainsKey(termNumber)) | |
234 | + { | |
235 | + termList.Add(termNumber, new Term(termNumber, systemNumber, pixelLocation)); | |
236 | + } | |
237 | + else | |
238 | + { | |
239 | + bool isSystemNumberExisting = false; | |
240 | + foreach (int sn in termList[termNumber].SystemNumbers) | |
241 | + { | |
242 | + if (systemNumber == sn) | |
243 | + { | |
244 | + isSystemNumberExisting = true; | |
245 | + break; | |
246 | + } | |
247 | + | |
248 | + } | |
249 | + if (!isSystemNumberExisting) | |
250 | + termList[termNumber].SystemNumbers.Add(systemNumber); | |
251 | + | |
252 | + bool isPixelLocationExisting = false; | |
253 | + foreach (int pl in termList[termNumber].PixelLocations) | |
254 | + { | |
255 | + if (pixelLocation == pl) | |
256 | + { | |
257 | + isPixelLocationExisting = true; | |
258 | + break; | |
259 | + } | |
260 | + | |
261 | + } | |
262 | + if (!isPixelLocationExisting) | |
263 | + termList[termNumber].PixelLocations.Add(pixelLocation); | |
264 | + | |
265 | + } | |
266 | + } | |
267 | + | |
268 | + | |
269 | + //static void Main(string[] args) | |
270 | + //{ | |
271 | + // Console.WriteLine("Enter BodyViewIndex"); | |
272 | + // string bodyViewId = Console.ReadLine(); | |
273 | + // string searchPattern = "BodyView" + bodyViewId+"_layer*"; | |
274 | + | |
275 | + // string[] files = Directory.GetFiles(@"\\ADAMSRVR\data", searchPattern); | |
276 | + // Program program; | |
277 | + // foreach (string filePath in files) | |
278 | + // { | |
279 | + // program = new Program(); | |
280 | + // program.getDataFromFileAndSaveInDB(filePath); | |
281 | + // program = null; | |
282 | + // } | |
283 | + | |
284 | + //} | |
285 | + | |
286 | + static void Main(string[] args) | |
287 | + { | |
288 | + | |
289 | + | |
290 | + //string[] files = Directory.GetFiles("D:\\100-PROJECTS\\008-AIAHighlight.FileSave\\AIAHighlight\\AIAHighlight\\data", "*.json"); | |
291 | + | |
292 | + //string[] files = Directory.GetFiles(@"C:\ADAM-AWS-FTP\ADAM-AWS\AIAHTML5\data", "*.json"); | |
293 | + Console.WriteLine("Enter BodyViewId"); | |
294 | + int BodyViewIndex = Convert.ToInt32(Console.ReadLine()); | |
295 | + | |
296 | + Console.WriteLine("Enter LayerNumber"); | |
297 | + string layerNumber = Console.ReadLine(); | |
298 | + int totalLayers = 0; | |
299 | + | |
300 | + switch (BodyViewIndex) | |
301 | + { | |
302 | + case 1: | |
303 | + totalLayers = 330; | |
304 | + break; | |
305 | + case 2: | |
306 | + totalLayers = 288; | |
307 | + break; | |
308 | + case 3: | |
309 | + totalLayers = 127; | |
310 | + break; | |
311 | + case 4: | |
312 | + totalLayers = 186; | |
313 | + break; | |
314 | + case 5: | |
315 | + totalLayers = 229; | |
316 | + break; | |
317 | + case 6: | |
318 | + totalLayers = 289; | |
319 | + break; | |
320 | + case 7: | |
321 | + totalLayers = 130; | |
322 | + break; | |
323 | + case 8: | |
324 | + totalLayers = 186; | |
325 | + break; | |
326 | + case 9: | |
327 | + totalLayers = 64; | |
328 | + break; | |
329 | + case 10: | |
330 | + totalLayers = 72; | |
331 | + break; | |
332 | + case 11: | |
333 | + totalLayers = 64; | |
334 | + break; | |
335 | + case 12: | |
336 | + totalLayers = 72; | |
337 | + break; | |
338 | + } | |
339 | + | |
340 | + for (int i = Convert.ToInt32(layerNumber); i <= totalLayers; i++) | |
341 | + { | |
342 | + string searchPattern = "BodyView" + BodyViewIndex + "_layer" + i + "*"; | |
343 | + // string searchPattern = "BodyView" + bodyViewId + "_layer*"; | |
344 | + | |
345 | + string[] files = Directory.GetFiles(@"D:\100-PROJECTS\008-AIAHighlight.FileSave\data", searchPattern); | |
346 | + // string[] files = Directory.GetFiles(@"C:\ADAM-AWS-FTP\ADAM-AWS\AIAHTML5\data\", searchPattern); | |
347 | + Program program = new Program(); | |
348 | + program.processFiles(files, BodyViewIndex); | |
349 | + program = null; | |
350 | + } | |
351 | + } | |
352 | + | |
353 | + internal void processFiles(string[] files,int bodyviewId) | |
354 | + { | |
355 | + //with multithreading | |
356 | + // prepareArrayOfFiles(files, startIndex, endIndex); | |
357 | + | |
358 | + //without multithreading | |
359 | + foreach(string filename in files) | |
360 | + { | |
361 | + getDataFromFileAndSaveInDB(filename, bodyviewId); | |
362 | + } | |
363 | + | |
364 | + } | |
365 | + | |
366 | + //internal void prepareArrayOfFiles(string[] files,int startIndex, int endIndex) | |
367 | + //{ | |
368 | + // string[] filesToProcess = new string[20]; | |
369 | + // int processedFiles = 1; | |
370 | + // int j = 0; | |
371 | + // for (int i = startIndex; i <= endIndex; i++) | |
372 | + // { | |
373 | + | |
374 | + // filesToProcess[j] = files[i]; | |
375 | + // j++; | |
376 | + | |
377 | + // } | |
378 | + | |
379 | + // Parallel.ForEach(filesToProcess, (currentFile) => | |
380 | + // { | |
381 | + // if (currentFile != null) | |
382 | + // { | |
383 | + // using (StreamReader reader = new StreamReader(currentFile)) | |
384 | + // { | |
385 | + // getDataFromFileAndSaveInDB(currentFile); | |
386 | + // processedFiles++; | |
387 | + | |
388 | + // } | |
389 | + | |
390 | + // if (processedFiles == 20) | |
391 | + // { | |
392 | + // startIndex = endIndex + 1; | |
393 | + // endIndex = startIndex + 19; | |
394 | + // filesToProcess = null; | |
395 | + | |
396 | + // //in case after adding 20, the endIndex reaches more than length of files array(total files) | |
397 | + // if (endIndex > files.Length - 1) | |
398 | + // { | |
399 | + // // int remainingFiles = endIndex - files.Length; | |
400 | + // endIndex = files.Length - 1; | |
401 | + // } | |
402 | + // if (endIndex < files.Length) | |
403 | + // { | |
404 | + // processFiles(files, startIndex, endIndex); | |
405 | + // } | |
406 | + // //} | |
407 | + // } | |
408 | + // } | |
409 | + // } | |
410 | + // ); | |
411 | + | |
412 | + //} | |
413 | + | |
414 | + | |
415 | + internal void getDataFromFileAndSaveInDB(string filePath,int bodyViewId) | |
416 | + { | |
417 | + if (File.Exists(filePath)) | |
418 | + { | |
419 | + string fileData; | |
420 | + using (StreamReader reader = new StreamReader(filePath)) | |
421 | + { | |
422 | + fileData = reader.ReadToEnd(); | |
423 | + | |
424 | + JObject data = JObject.Parse(fileData); | |
425 | + this.saveImageData(data, bodyViewId); | |
426 | + } | |
427 | + | |
428 | + | |
429 | + } | |
430 | + else | |
431 | + { | |
432 | + Console.WriteLine("FILE.NOT.FOUND AT" + | |
433 | + ": " + filePath); | |
434 | + | |
435 | + } | |
436 | + } | |
437 | + } | |
438 | +} | ... | ... |
600-POC/fileSave/DBSAVe/Program_WithoutMultithreading_withDBSearchBeforeExeutiom.cs
0 → 100644
1 | +using System; | |
2 | +using System.Collections.Generic; | |
3 | +using System.Linq; | |
4 | +using System.Text; | |
5 | +using System.Threading; | |
6 | +using System.Threading.Tasks; | |
7 | +//using log4net; | |
8 | +using MongoDB.Driver; | |
9 | +using System.IO; | |
10 | +using Newtonsoft.Json.Linq; | |
11 | +using MongoDB.Bson.Serialization.Attributes; | |
12 | +using MongoDB.Bson; | |
13 | + | |
14 | +namespace AIAHighlight.DBSave | |
15 | +{ | |
16 | + [BsonIgnoreExtraElements] | |
17 | + public class BodyRegionImage | |
18 | + { | |
19 | + public ObjectId _id { get; set; } | |
20 | + public string imageName; | |
21 | + public int bodyViewIndex; | |
22 | + public int layerNumber; | |
23 | + public int bodyRegionId; | |
24 | + public int zoom; | |
25 | + public List<Term> terms; | |
26 | + | |
27 | + public BodyRegionImage() | |
28 | + { | |
29 | + this.terms = new List<Term>(); | |
30 | + } | |
31 | + } | |
32 | + | |
33 | + public class Term | |
34 | + { | |
35 | + public int TermNumber; | |
36 | + public List<int> SystemNumbers; | |
37 | + public List<int> PixelLocations; | |
38 | + public int ActualTermNumber; | |
39 | + | |
40 | + public Term(int termNumber, int systemNumber, int pixelLocation) | |
41 | + { | |
42 | + this.SystemNumbers = new List<int>(); | |
43 | + this.PixelLocations = new List<int>(); | |
44 | + this.TermNumber = termNumber; | |
45 | + this.SystemNumbers.Add(systemNumber); | |
46 | + this.PixelLocations.Add(pixelLocation); | |
47 | + } | |
48 | + } | |
49 | + | |
50 | + | |
51 | + | |
52 | + | |
53 | + public class Program | |
54 | + { | |
55 | + //public JObject data { get; set; } | |
56 | + // public Dictionary<int, Term> termList; | |
57 | + | |
58 | + internal void saveImageData(JObject data, int bodyviewId) | |
59 | + { | |
60 | + // DateTime datetime = new DateTime(); | |
61 | + Console.WriteLine("AT "+ DateTime.Now.ToString("yyyy-MM-ddThh:mm:sszzz")+"..In saveImageData. for imageName: "+ data["imageName"].ToString()+ ",bodyViewIndex= "+ data["bodyViewIndex"]+ ",layerNumber: "+ | |
62 | + data["layerNumber"]+ ",bodyRegionId= "+ data["bodyRegion"]); | |
63 | + try | |
64 | + { | |
65 | + BodyRegionImage bodyRegionImage = new BodyRegionImage(); | |
66 | + | |
67 | + var client = new MongoClient(); | |
68 | + | |
69 | + var db = client.GetDatabase("AIADB_bodyviewId"+bodyviewId.ToString()); | |
70 | + | |
71 | + var col = db.GetCollection<BodyRegionImage>("DAImages"); | |
72 | + | |
73 | + JObject imageData = data; | |
74 | + | |
75 | + | |
76 | + | |
77 | + string bodyViewIndex = data["bodyViewIndex"].ToString(); | |
78 | + | |
79 | + string termFilePath = @"C:\ADAM-AWS-FTP\ADAM-AWS\AIAHTML5\bodyViewsData\body-views\" + bodyViewIndex + "\\da_dat_body_system_term_" + bodyViewIndex + ".json"; | |
80 | + //string termFilePath = @"D:\100-PROJECTS\008-AIAHighlight.FileSave\dist\assets\data\json\da\body-views\" + bodyViewIndex + "\\da_dat_body_system_term_" + bodyViewIndex + ".json"; | |
81 | + | |
82 | + string systemTermMapping; | |
83 | + using (StreamReader reader = new StreamReader(termFilePath)) | |
84 | + | |
85 | + // using (StreamReader reader = new StreamReader(path+fileName)) | |
86 | + { | |
87 | + systemTermMapping = reader.ReadToEnd(); | |
88 | + } | |
89 | + | |
90 | + JObject systemTermMappingObject = JObject.Parse(systemTermMapping); | |
91 | + | |
92 | + //Console.WriteLine("AT " + DateTime.Now.ToString("yyyy-MM-ddThh:mm:sszzz") + ".systemTermMappingObject created."); | |
93 | + | |
94 | + dynamic systemTerms = systemTermMappingObject["BodySystem"]["BodySystemTerm"]; | |
95 | + | |
96 | + JObject sysT = JObject.Parse(systemTerms); | |
97 | + | |
98 | + dynamic imageDataArray = data["data"]; | |
99 | + | |
100 | + Dictionary<int,Term> termList = new Dictionary<int, Term>(); | |
101 | + | |
102 | + Console.WriteLine("AT " + DateTime.Now.ToString("yyyy-MM-ddThh:mm:sszzz") + "..before itrating imageDataArray. for imageName: " + data["imageName"].ToString() + ",bodyViewIndex= " + data["bodyViewIndex"] + ",layerNumber: " + | |
103 | + data["layerNumber"] + ",bodyRegionId= " + data["bodyRegion"]); | |
104 | + | |
105 | + for (int i = 0; i < imageDataArray.Count; i += 4) | |
106 | + { | |
107 | + if(imageDataArray[i] == 0 && imageDataArray[i+1] == 0 && imageDataArray[i+2] == 0) | |
108 | + { | |
109 | + continue; | |
110 | + } | |
111 | + var RED = Convert.ToInt32(imageDataArray[i]) - 9; | |
112 | + var GREEN = Convert.ToInt32(imageDataArray[i + 1]) - 9; | |
113 | + var BLUE = Convert.ToInt32(imageDataArray[i + 2]) - 9; | |
114 | + | |
115 | + if (RED == -9 && GREEN == -9 && BLUE == -9) | |
116 | + continue; | |
117 | + | |
118 | + var Red = ""; | |
119 | + var Green = ""; | |
120 | + var Blue = ""; | |
121 | + string zero = "0"; | |
122 | + | |
123 | + if ((RED).ToString().Length != 2) | |
124 | + { | |
125 | + Red = zero + RED.ToString(); | |
126 | + } | |
127 | + else | |
128 | + { | |
129 | + Red = RED.ToString(); | |
130 | + } | |
131 | + if ((GREEN).ToString().Length != 2) | |
132 | + { | |
133 | + Green = zero + GREEN.ToString(); | |
134 | + } | |
135 | + else | |
136 | + { | |
137 | + Green = GREEN.ToString(); | |
138 | + } | |
139 | + if ((BLUE).ToString().Length != 2) | |
140 | + { | |
141 | + Blue = zero + BLUE.ToString(); | |
142 | + } | |
143 | + else | |
144 | + { | |
145 | + Blue = BLUE.ToString(); | |
146 | + } | |
147 | + | |
148 | + string Icolor = (Red + Green + Blue); | |
149 | + | |
150 | + | |
151 | + | |
152 | + foreach (dynamic systemTerm in systemTerms) | |
153 | + { | |
154 | + | |
155 | + int iColor = Convert.ToInt32(Icolor); | |
156 | + int termNumber = Convert.ToInt32(systemTerm._TermNumber.ToString()); | |
157 | + int systemNumber = Convert.ToInt32(systemTerm._SystemNumber.ToString()); | |
158 | + | |
159 | + if (systemTerm._TermNumber.ToString() == Icolor) | |
160 | + { | |
161 | + this.AddToTermList(termNumber, systemNumber, i, termList); | |
162 | + //this.AddToTermList(termNumber, systemNumber, i, termList); | |
163 | + this.AddToTermList(termNumber, systemNumber, i + 1, termList); | |
164 | + this.AddToTermList(termNumber, systemNumber, i + 2, termList); | |
165 | + break; | |
166 | + } | |
167 | + } | |
168 | + } | |
169 | + | |
170 | + Console.WriteLine("AT " + DateTime.Now.ToString("yyyy-MM-ddThh:mm:sszzz") + "..after craeting termList.. for imageName: " + data["imageName"].ToString() + ",bodyViewIndex= " + data["bodyViewIndex"] + ",layerNumber: " + | |
171 | + data["layerNumber"] + ",bodyRegionId= " + data["bodyRegion"]); | |
172 | + | |
173 | + bodyRegionImage.imageName = data["imageName"].ToString(); | |
174 | + bodyRegionImage.bodyViewIndex = Convert.ToInt32(data["bodyViewIndex"]); | |
175 | + bodyRegionImage.layerNumber = Convert.ToInt32(data["layerNumber"]); | |
176 | + bodyRegionImage.bodyRegionId = Convert.ToInt32(data["bodyRegion"]); | |
177 | + bodyRegionImage.zoom = Convert.ToInt32(data["zoom"]); | |
178 | + | |
179 | + foreach (int key in termList.Keys) | |
180 | + { | |
181 | + bodyRegionImage.terms.Add(termList[key]); | |
182 | + } | |
183 | + | |
184 | + Console.WriteLine("AT " + DateTime.Now.ToString("yyyy-MM-ddThh:mm:sszzz") + "...inserting for imageName: " + data["imageName"].ToString() + ",bodyViewIndex= " + data["bodyViewIndex"] + ",layerNumber: " + | |
185 | + data["layerNumber"] + ",bodyRegionId= " + data["bodyRegion"]); | |
186 | + | |
187 | + col.InsertOne(bodyRegionImage); | |
188 | + | |
189 | + Console.WriteLine("AT " + DateTime.Now.ToString("yyyy-MM-ddThh:mm:sszzz") + "..inserted for imageName: " + data["imageName"].ToString() + ",bodyViewIndex= " + data["bodyViewIndex"] + ",layerNumber: " + | |
190 | + data["layerNumber"] + ",bodyRegionId= " + data["bodyRegion"]); | |
191 | + | |
192 | + var logCol = db.GetCollection<BodyRegionImage>("DAImageLogs"); | |
193 | + | |
194 | + BodyRegionImage bodyRegionImageTolog = new BodyRegionImage(); | |
195 | + bodyRegionImageTolog.bodyViewIndex = Convert.ToInt32(data["bodyViewIndex"]); | |
196 | + bodyRegionImageTolog.layerNumber = Convert.ToInt32(data["layerNumber"]); | |
197 | + bodyRegionImageTolog.bodyRegionId = Convert.ToInt32(data["bodyRegion"]); | |
198 | + bodyRegionImageTolog.zoom = Convert.ToInt32(data["zoom"]); | |
199 | + | |
200 | + logCol.InsertOne(bodyRegionImageTolog); | |
201 | + | |
202 | + bodyRegionImageTolog = null; | |
203 | + | |
204 | + data = null; | |
205 | + termList = null; | |
206 | + systemTermMappingObject = null; | |
207 | + systemTerms = null; | |
208 | + } | |
209 | + catch(Exception ex) | |
210 | + { | |
211 | + Console.WriteLine("AT " + DateTime.Now.ToString("yyyy-MM-ddThh:mm:sszzz") + "..Exception occured for imageName: " + data["imageName"].ToString() + ",bodyViewIndex= " + data["bodyViewIndex"] + ",layerNumber: " + | |
212 | + data["layerNumber"] + ",bodyRegionId= " + data["bodyRegion"]+"... EXCEPTION= "+ex.Message+".. STACKTRACE= "+ex.StackTrace); | |
213 | + | |
214 | + } | |
215 | + | |
216 | + | |
217 | + } | |
218 | + | |
219 | + public void AddToTermList(int termNumber, int systemNumber, int pixelLocation,Dictionary<int, Term> termList) | |
220 | + { | |
221 | + if (!termList.ContainsKey(termNumber)) | |
222 | + { | |
223 | + termList.Add(termNumber, new Term(termNumber, systemNumber, pixelLocation)); | |
224 | + } | |
225 | + else | |
226 | + { | |
227 | + bool isSystemNumberExisting = false; | |
228 | + foreach (int sn in termList[termNumber].SystemNumbers) | |
229 | + { | |
230 | + if (systemNumber == sn) | |
231 | + { | |
232 | + isSystemNumberExisting = true; | |
233 | + break; | |
234 | + } | |
235 | + | |
236 | + } | |
237 | + if (!isSystemNumberExisting) | |
238 | + termList[termNumber].SystemNumbers.Add(systemNumber); | |
239 | + | |
240 | + bool isPixelLocationExisting = false; | |
241 | + foreach (int pl in termList[termNumber].PixelLocations) | |
242 | + { | |
243 | + if (pixelLocation == pl) | |
244 | + { | |
245 | + isPixelLocationExisting = true; | |
246 | + break; | |
247 | + } | |
248 | + | |
249 | + } | |
250 | + if (!isPixelLocationExisting) | |
251 | + termList[termNumber].PixelLocations.Add(pixelLocation); | |
252 | + | |
253 | + } | |
254 | + } | |
255 | + | |
256 | + | |
257 | + | |
258 | + | |
259 | + static void Main(string[] args) | |
260 | + { | |
261 | + | |
262 | + Console.WriteLine("Enter BodyViewId"); | |
263 | + int BodyViewIndex = Convert.ToInt32(Console.ReadLine()); | |
264 | + | |
265 | + Program program = new Program(); | |
266 | + program.getAlreadyInsertedLayer(BodyViewIndex.ToString()); | |
267 | + program = null; | |
268 | + | |
269 | + } | |
270 | + | |
271 | + internal void getAlreadyInsertedLayer(string bodyviewId) | |
272 | + { | |
273 | + Console.WriteLine("AT " + DateTime.Now.ToString("yyyy-MM-ddThh:mm:sszzz") + "inside getAlreadyInsertedLayer"); | |
274 | + int totalLayers = 0; | |
275 | + int [] totalBodyReigons =null; | |
276 | + List<int> bodyRegions = new List<int>(); | |
277 | + | |
278 | + switch (Convert.ToInt32(bodyviewId)) | |
279 | + { | |
280 | + case 1: | |
281 | + totalLayers = 330; | |
282 | + totalBodyReigons = new int[6] {1,2,3,4,5,6}; | |
283 | + bodyRegions.Add(1); | |
284 | + bodyRegions.Add(2); | |
285 | + bodyRegions.Add(3); | |
286 | + bodyRegions.Add(4); | |
287 | + bodyRegions.Add(5); | |
288 | + bodyRegions.Add(6); | |
289 | + break; | |
290 | + case 2: | |
291 | + totalLayers = 288; | |
292 | + // totalBodyReigons = 6; | |
293 | + break; | |
294 | + case 3: | |
295 | + totalLayers = 127; | |
296 | + // totalBodyReigons = 6; | |
297 | + break; | |
298 | + case 4: | |
299 | + totalLayers = 186; | |
300 | + // totalBodyReigons = 6; | |
301 | + break; | |
302 | + case 5: | |
303 | + totalLayers = 229; | |
304 | + // totalBodyReigons = 6; | |
305 | + break; | |
306 | + case 6: | |
307 | + totalLayers = 289; | |
308 | + // totalBodyReigons = 6; | |
309 | + break; | |
310 | + case 7: | |
311 | + totalLayers = 130; | |
312 | + // totalBodyReigons = 6; | |
313 | + break; | |
314 | + case 8: | |
315 | + totalLayers = 186; | |
316 | + // totalBodyReigons = 6; | |
317 | + break; | |
318 | + case 9: | |
319 | + totalLayers = 64; | |
320 | + // totalBodyReigons = 6; | |
321 | + break; | |
322 | + case 10: | |
323 | + totalLayers = 72; | |
324 | + // totalBodyReigons = 6; | |
325 | + break; | |
326 | + case 11: | |
327 | + totalLayers = 64; | |
328 | + // totalBodyReigons = 6; | |
329 | + break; | |
330 | + case 12: | |
331 | + totalLayers = 72; | |
332 | + // totalBodyReigons = 6; | |
333 | + break; | |
334 | + } | |
335 | + | |
336 | + var client = new MongoClient(); | |
337 | + var db = client.GetDatabase("AIADB_bodyviewId" + bodyviewId.ToString()); | |
338 | + //var db = client.GetDatabase("AIAImageDB"); | |
339 | + | |
340 | + var col = db.GetCollection<BodyRegionImage>("DAImagesLogs"); | |
341 | + //var col = db.GetCollection<BodyRegionImage>("DAImages"); | |
342 | + | |
343 | + | |
344 | + FilterDefinition<BodyRegionImage>[] filterCondition = { | |
345 | + Builders<BodyRegionImage>.Filter.Eq("bodyViewIndex", Convert.ToInt32(bodyviewId))}; | |
346 | + | |
347 | + dynamic list = col.Find(Builders<BodyRegionImage>.Filter.And(filterCondition)).Project(Builders<BodyRegionImage>.Projection.Include("layerNumber").Include("bodyRegionId")).ToList(); | |
348 | + //collection.Find(new BsonDocument()).Project(Builders<BsonDocument>.Projection.Include("Price").Exclude("_id")).ToListAsync(); | |
349 | + // return list; | |
350 | + Dictionary<int, List<int>> layersToProcess = new Dictionary<int, List<int>>(); | |
351 | + | |
352 | + for (int i = 1; i <= totalLayers; i++) | |
353 | + { | |
354 | + List<int> bodyRegionForThisLayer = new List<int>(); | |
355 | + bodyRegionForThisLayer.Add(1); | |
356 | + bodyRegionForThisLayer.Add(2); | |
357 | + bodyRegionForThisLayer.Add(3); | |
358 | + bodyRegionForThisLayer.Add(4); | |
359 | + bodyRegionForThisLayer.Add(5); | |
360 | + bodyRegionForThisLayer.Add(6); | |
361 | + | |
362 | + int previousLayerNumber = 0; | |
363 | + int existingLayerNumber = 0; | |
364 | + bool isLayerMatched = false; | |
365 | + | |
366 | + foreach (dynamic lNumber in list) | |
367 | + { | |
368 | + existingLayerNumber = Convert.ToInt32((lNumber.GetValue("layerNumber")).ToString()); | |
369 | + | |
370 | + if (existingLayerNumber == i) | |
371 | + { | |
372 | + isLayerMatched = true; | |
373 | + int existingBodyRegionId = Convert.ToInt32((lNumber.GetValue("bodyRegionId")).ToString()); | |
374 | + | |
375 | + | |
376 | + if (bodyRegionForThisLayer.Contains(existingBodyRegionId)) { | |
377 | + //remove from bodyRegions list as this is already present | |
378 | + bodyRegionForThisLayer.Remove(existingBodyRegionId); | |
379 | + } | |
380 | + previousLayerNumber = existingLayerNumber; | |
381 | + | |
382 | + } | |
383 | + | |
384 | + else | |
385 | + { | |
386 | + | |
387 | + } | |
388 | + | |
389 | + } | |
390 | + if(isLayerMatched) | |
391 | + layersToProcess.Add(previousLayerNumber, bodyRegionForThisLayer); | |
392 | + else | |
393 | + layersToProcess.Add(i, bodyRegionForThisLayer); | |
394 | + } | |
395 | + Console.WriteLine("AT " + DateTime.Now.ToString("yyyy-MM-ddThh:mm:sszzz") + "after preparing list to process"); | |
396 | + | |
397 | + makeFileNameAndProcess(layersToProcess,Convert.ToInt32(bodyviewId)); | |
398 | + } | |
399 | + | |
400 | + | |
401 | + internal void makeFileNameAndProcess(Dictionary<int, List<int>> filesToProcess, int BodyViewIndex) | |
402 | + { | |
403 | + Console.WriteLine("AT " + DateTime.Now.ToString("yyyy-MM-ddThh:mm:sszzz") + "in makeFileNameAndProcess"); | |
404 | + | |
405 | + foreach (KeyValuePair<int, List<int>> pair in filesToProcess) | |
406 | + { | |
407 | + | |
408 | + | |
409 | + foreach (int item in pair.Value) | |
410 | + { | |
411 | + string fileName = "BodyView" + BodyViewIndex + "_layer" + pair.Key + "_bodyRegionId" + item+".json"; | |
412 | + | |
413 | + //string filePath = @"D:\100-PROJECTS\008-AIAHighlight.FileSave\AIAHighlight\AIAHighlight\data\" + fileName; | |
414 | + string filePath = @"C:\ADAM-AWS-FTP\ADAM-AWS\AIAHTML5\data\" + fileName; | |
415 | + getDataFromFileAndSaveInDB(filePath, BodyViewIndex); | |
416 | + } | |
417 | + | |
418 | + } | |
419 | + } | |
420 | + | |
421 | + internal void processFiles(string[] files,int bodyviewId) | |
422 | + { | |
423 | + | |
424 | + //without multithreading | |
425 | + foreach(string filename in files) | |
426 | + { | |
427 | + Console.WriteLine("AT " + DateTime.Now.ToString("yyyy-MM-ddThh:mm:sszzz") + "in processFiles for filename"); | |
428 | + getDataFromFileAndSaveInDB(filename, bodyviewId); | |
429 | + } | |
430 | + | |
431 | + } | |
432 | + | |
433 | + | |
434 | + | |
435 | + internal void getDataFromFileAndSaveInDB(string filePath,int bodyViewId) | |
436 | + { | |
437 | + if (File.Exists(filePath)) | |
438 | + { | |
439 | + string fileData; | |
440 | + using (StreamReader reader = new StreamReader(filePath)) | |
441 | + { | |
442 | + fileData = reader.ReadToEnd(); | |
443 | + | |
444 | + JObject data = JObject.Parse(fileData); | |
445 | + this.saveImageData(data, bodyViewId); | |
446 | + } | |
447 | + | |
448 | + | |
449 | + } | |
450 | + else | |
451 | + { | |
452 | + Console.WriteLine("FILE.NOT.FOUND AT" + | |
453 | + ": " + filePath); | |
454 | + | |
455 | + } | |
456 | + } | |
457 | + } | |
458 | +} | ... | ... |
600-POC/fileSave/jsonFile_generate/AJs/app.component.css
0 → 100644
600-POC/fileSave/jsonFile_generate/AJs/app.component.html
0 → 100644
1 | +<div> | |
2 | + bodyViewId: <input type="text" name="bodyViewId" [(ngModel)]="bodyViewId" /><div>{{bodyViewId}}</div> | |
3 | + layerNo: <input type="text" name="layerNo" [(ngModel)]="layerNo" /> | |
4 | + <button id="generateFile" (click)="generateFile()">Generate Files</button> | |
5 | +</div> | |
0 | 6 | \ No newline at end of file | ... | ... |
600-POC/fileSave/jsonFile_generate/AJs/app.component.spec.ts
0 → 100644
1 | +import { TestBed, async } from '@angular/core/testing'; | |
2 | + | |
3 | +import { AppComponent } from './app.component'; | |
4 | + | |
5 | +describe('AppComponent', () => { | |
6 | + beforeEach(async(() => { | |
7 | + TestBed.configureTestingModule({ | |
8 | + declarations: [ | |
9 | + AppComponent | |
10 | + ], | |
11 | + }).compileComponents(); | |
12 | + })); | |
13 | + | |
14 | + it('should create the app', async(() => { | |
15 | + const fixture = TestBed.createComponent(AppComponent); | |
16 | + const app = fixture.debugElement.componentInstance; | |
17 | + expect(app).toBeTruthy(); | |
18 | + })); | |
19 | + | |
20 | + it(`should have as title 'app works!'`, async(() => { | |
21 | + const fixture = TestBed.createComponent(AppComponent); | |
22 | + const app = fixture.debugElement.componentInstance; | |
23 | + expect(app.title).toEqual('app works!'); | |
24 | + })); | |
25 | + | |
26 | + it('should render title in a h1 tag', async(() => { | |
27 | + const fixture = TestBed.createComponent(AppComponent); | |
28 | + fixture.detectChanges(); | |
29 | + const compiled = fixture.debugElement.nativeElement; | |
30 | + expect(compiled.querySelector('h1').textContent).toContain('app works!'); | |
31 | + })); | |
32 | +}); | ... | ... |
600-POC/fileSave/jsonFile_generate/AJs/app.component.ts
0 → 100644
1 | + | |
2 | +import { Component, AfterViewInit, ViewChild } from '@angular/core'; | |
3 | +import { ImageService } from './services/image.service'; | |
4 | + | |
5 | +declare var jQuery: any; | |
6 | +declare var jinqJs: any; | |
7 | + | |
8 | +@Component({ | |
9 | + selector: 'app-root', | |
10 | + templateUrl: './app.component.html', | |
11 | + styleUrls: ['./app.component.css'], | |
12 | + providers: [ImageService] | |
13 | +}) | |
14 | +export class AppComponent implements AfterViewInit { | |
15 | + title = 'app works!'; | |
16 | + context: CanvasRenderingContext2D; | |
17 | + bodyViewData: any; | |
18 | + imageData: any; | |
19 | + imageDataCollection: Array<any>; | |
20 | + imageCount: number; | |
21 | + isLayerProcessCompleted: boolean; | |
22 | + totalBodyViews: number; | |
23 | + bodyViewIndex: number; | |
24 | + currentLayer: number; | |
25 | + datalayerLength: number; | |
26 | + bodyRegionInLayer: Array<any>;; | |
27 | + BRCounter: number; | |
28 | + layerNo: string; | |
29 | + bodyViewId: string; | |
30 | + remainingFiles75: any; | |
31 | + remainingFiles25: any; | |
32 | + bodyRegionId: number; | |
33 | + previousBodyViewId: number; | |
34 | + counter: number; | |
35 | + constructor(private imageService: ImageService) { | |
36 | + this.imageData = new Object(); | |
37 | + this.imageDataCollection = new Array<any>(); | |
38 | + this.isLayerProcessCompleted = true; | |
39 | + this.totalBodyViews = 12; | |
40 | + this.bodyViewIndex = 2; | |
41 | + this.currentLayer = 95; | |
42 | + this.previousBodyViewId = 0; | |
43 | + this.counter = 0; | |
44 | + } | |
45 | + | |
46 | + ngAfterViewInit(): void { | |
47 | + // this.getBodyViewJson(); | |
48 | + //for (let i = 1; i <= 12; i++) { | |
49 | + // this.imageService.getBodyViewData(i).subscribe((data) => { | |
50 | + // this.bodyViewData = data.json(); | |
51 | + // this.saveBodyViewImageData(); | |
52 | + // }); | |
53 | + //} | |
54 | + } | |
55 | + | |
56 | + | |
57 | + getBodyViewJson() { | |
58 | + console.log("inside getBodyViewJson for this.bodyViewIndex= " + this.bodyViewIndex); | |
59 | + this.previousBodyViewId = this.bodyViewIndex; | |
60 | + this.imageService.getBodyViewData(this.bodyViewIndex).subscribe((data) => { | |
61 | + console.log("Fetched body view json for bodyViewIndex: " + this.bodyViewIndex); | |
62 | + this.bodyViewData = data.json(); | |
63 | + this.getImageName(); | |
64 | + }); | |
65 | + } | |
66 | + | |
67 | + getImageName(): void { | |
68 | + | |
69 | + //var layerData = this.bodyViewData.filter(lNo => lNo._LayerNumber == this.layerNo); | |
70 | + //var bodyRegiondata = layerData.filter(br => br._BodyRegionId == this.bodyRegionId); | |
71 | + | |
72 | + //var layerData = this.bodyViewData.find(findData); | |
73 | + //var bodyRegiondata = layerData.filter(findData);\ | |
74 | + console.log("getImageName:" + this.currentLayer); | |
75 | + var layerNumber = this.currentLayer + 1; | |
76 | + console.log('layerNumber= ' + layerNumber); | |
77 | + var layerData = new jinqJs() | |
78 | + .from(this.bodyViewData.Layers.DataLayer) | |
79 | + .where('_LayerNumber == ' + layerNumber) | |
80 | + .select(); | |
81 | + alert("layerData= " + layerData[0]); | |
82 | + | |
83 | + | |
84 | + var bodyRegiondata = new jinqJs() | |
85 | + .from(layerData[0].BodyRegion) | |
86 | + .where('_BodyRegionId == ' + this.bodyRegionId) | |
87 | + .select(); | |
88 | + | |
89 | + alert("bodyRegiondata= " + bodyRegiondata); | |
90 | + | |
91 | + const imgName = bodyRegiondata[0].Image._ImageName.split('.')[0] + '_mci.png'; | |
92 | + const skintone = bodyRegiondata[0].Image._SkintTone; | |
93 | + const bodyRegionId = bodyRegiondata[0]._BodyRegionId; | |
94 | + | |
95 | + console.log("inside getImageName. imgName= " + imgName + ",skintone= " + skintone); | |
96 | + | |
97 | + this.drawImage(imgName, this.bodyViewIndex, this.currentLayer, bodyRegionId, 75, skintone); | |
98 | + | |
99 | + } | |
100 | + | |
101 | + findData(layer):any { | |
102 | + return layer._LayerNumber === this.layerNo; | |
103 | + } | |
104 | + saveBodyViewImageData(): void { | |
105 | + this.datalayerLength = this.bodyViewData.Layers.DataLayer.length; | |
106 | + console.log('this.datalayerLength= ' + this.datalayerLength); | |
107 | + console.log('this.bodyViewData.Layers.DataLayer = ' + this.bodyViewData.Layers.DataLayer); | |
108 | + this.processLayer(); | |
109 | + //for (let i = 0; i <= datalayerLength-1; i++) { | |
110 | + // const bodyRegions = this.bodyViewData.Layers.DataLayer[datalayerLength - i - 1].BodyRegion; | |
111 | + // let k = 1; | |
112 | + // this.imageCount = bodyRegions.length; | |
113 | + // for (let j = bodyRegions.length - 1; j >= 0; j--) { | |
114 | + // const imgName = bodyRegions[j].Image._ImageName.split('.')[0] + '_mci.png'; | |
115 | + // this.drawImage(imgName, 1, i, k, 75); | |
116 | + | |
117 | + // if (j === 0) { | |
118 | + // k = 1; | |
119 | + // } else { | |
120 | + // k = k + 1; | |
121 | + // } | |
122 | + | |
123 | + // } | |
124 | + //} | |
125 | + } | |
126 | + | |
127 | + processLayer(): void { | |
128 | + console.log("Processing started for layer: " + this.currentLayer + ' of bodyViewIndex: ' + this.bodyViewIndex + ', time: ' + new Date().toTimeString().replace(/.*(\d{2}:\d{2}:\d{2}).*/, "$1")); | |
129 | + this.imageDataCollection = null; | |
130 | + this.imageDataCollection = new Array<any>(); | |
131 | + this.BRCounter = 1; | |
132 | + this.bodyRegionInLayer = new Array<any>(); | |
133 | + console.log('inside processLayer. this.bodyViewData.Layers.DataLayer = ' + this.bodyViewData.Layers.DataLayer); | |
134 | + //console.log('this.bodyViewData.Layers.DataLayer[63].BodyRegion = ' + this.bodyViewData.Layers.DataLayer[63].BodyRegion); | |
135 | + //console.log('this.datalayerLength - this.currentLayer - 1= ' + (this.datalayerLength - this.currentLayer - 1)); | |
136 | + const bodyRegions = this.bodyViewData.Layers.DataLayer[this.datalayerLength - this.currentLayer - 1].BodyRegion; | |
137 | + //console.log('bodyRegions= ' + bodyRegions + ' this.bodyViewData.Layers.DataLayer[this.datalayerLength - this.currentLayer - 1].BodyRegion.length= ' + (this.bodyViewData.Layers.DataLayer[this.datalayerLength - this.currentLayer - 1].BodyRegion).length); | |
138 | + //console.log("Process layer: " + this.currentLayer + ", bodyRegions length= " + bodyRegions.length); | |
139 | + //console.log('abc= ' + bodyRegions._BodyRegionId + ', xyze= ' + bodyRegions.Image._ImageName); | |
140 | + //let k = 1; | |
141 | + if (this.bodyViewIndex == 9 || this.bodyViewIndex == 10 || this.bodyViewIndex == 11 || this.bodyViewIndex == 12) { | |
142 | + | |
143 | + this.imageCount = 1; | |
144 | + const imgName = bodyRegions.Image._ImageName.split('.')[0] + '_mci.png'; | |
145 | + const skintone = bodyRegions.Image._SkintTone; | |
146 | + const bodyRegionId = bodyRegions._BodyRegionId; | |
147 | + this.drawImage(imgName, this.bodyViewIndex, this.currentLayer, bodyRegionId, 25, skintone); | |
148 | + | |
149 | + } | |
150 | + else{ | |
151 | + this.imageCount = bodyRegions.length; | |
152 | + for (let j = bodyRegions.length - 1; j >= 0; j--) { | |
153 | + const imgName = bodyRegions[j].Image._ImageName.split('.')[0] + '_mci.png'; | |
154 | + const skintone = bodyRegions[j].Image._SkintTone; | |
155 | + const bodyRegionId = bodyRegions[j]._BodyRegionId; | |
156 | + //for missing BRs | |
157 | + // if (bodyRegionId == 2 || bodyRegionId == 3 || bodyRegionId == 6) { | |
158 | + | |
159 | + this.drawImage(imgName, this.bodyViewIndex, this.currentLayer, bodyRegionId, 25, skintone); | |
160 | + // } | |
161 | + | |
162 | + } //if (j === 0) { | |
163 | + // k = 1; | |
164 | + //} else { | |
165 | + // k = k + 1; | |
166 | + //} | |
167 | + | |
168 | + } | |
169 | + } | |
170 | + | |
171 | + drawImage(imageName: string, bodyViewIndex: number, layerNumber: number, bodyRegionIndex: number, zoom: number, skintone: string): void { | |
172 | + console.log('drawImage for bodyViewIndex= ' + bodyViewIndex + ',layerNumber= ' + layerNumber + ',bodyRegionIndex= ' + bodyRegionIndex); | |
173 | + //if (layerNumber == 0) { | |
174 | + // console.log('drawImage.in if block. for bodyViewIndex= ' + bodyViewIndex + ',layerNumber= ' + layerNumber + ',bodyRegionIndex= ' + bodyRegionIndex); | |
175 | + | |
176 | + // const img = new Image(); | |
177 | + // img.src = '../assets/images/da/' + zoom + '/body-views/' + bodyViewIndex + '/layers/' + layerNumber + '/' + bodyRegionIndex + '/' + skintone + '/' + imageName; | |
178 | + // img.onload = (() => { | |
179 | + // this.imageData.imageName = imageName; | |
180 | + // this.imageData.bodyViewIndex = bodyViewIndex; | |
181 | + // this.imageData.layerNumber = layerNumber; | |
182 | + // this.imageData.bodyRegion = bodyRegionIndex; | |
183 | + // const canvas: HTMLCanvasElement = document.createElement('canvas'); | |
184 | + // canvas.width = this.imageData.width = img.width; | |
185 | + // canvas.height = this.imageData.height = img.height; | |
186 | + // this.context = canvas.getContext('2d'); | |
187 | + // this.context.drawImage(img, 0, 0); | |
188 | + // this.imageData.data = Array.from(this.context.getImageData(0, 0, img.width, img.height).data); | |
189 | + // console.log(this.imageData); | |
190 | + // this.writeImageDataToJson(this.imageData); | |
191 | + // this.imageData = new Object(); | |
192 | + // }); | |
193 | + | |
194 | + | |
195 | + // } | |
196 | + | |
197 | + // else { | |
198 | + console.log('drawImage.in else block. for bodyViewIndex= ' + bodyViewIndex + ',layerNumber= ' + layerNumber + ',bodyRegionIndex= ' + bodyRegionIndex); | |
199 | + | |
200 | + var img = new Image(); | |
201 | + img.id = 'canvasImg'; | |
202 | + | |
203 | + img.src = '../assets/images/da/' + zoom + '/body-views/' + bodyViewIndex + '/layers/' + layerNumber + '/' + bodyRegionIndex + '/' + imageName; | |
204 | + img.onload = (() => { | |
205 | + console.log("onload. img.src= " + img.src); | |
206 | + this.imageData.imageName = imageName; | |
207 | + this.imageData.bodyViewIndex = bodyViewIndex; | |
208 | + this.imageData.layerNumber = layerNumber; | |
209 | + this.imageData.bodyRegion = bodyRegionIndex; | |
210 | + this.imageData.zoom = zoom; | |
211 | + var elem = document.getElementById("imgCanvas"); | |
212 | + if (elem != null) { | |
213 | + elem.parentNode.removeChild(elem); | |
214 | + elem = null; | |
215 | + } | |
216 | + var canvas: HTMLCanvasElement = document.createElement('canvas'); | |
217 | + canvas.id = 'imgCanvas'; | |
218 | + canvas.width = this.imageData.width = img.width; | |
219 | + canvas.height = this.imageData.height = img.height; | |
220 | + this.context = canvas.getContext('2d'); | |
221 | + this.context.drawImage(img, 0, 0); | |
222 | + this.imageData.data = Array.from(this.context.getImageData(0, 0, img.width, img.height).data); | |
223 | + console.log("imageData of of bodyViewIndex: " + this.bodyViewIndex + ", layerNumber: " + layerNumber + ", bodyRegionIndex: " + bodyRegionIndex + ", imgData= " + this.imageData); | |
224 | + this.writeImageDataToJson(this.imageData); | |
225 | + var elem1 = document.getElementById("canvasImg"); | |
226 | + if (elem1 != null) { | |
227 | + elem1.parentNode.removeChild(elem1); | |
228 | + elem1 = null; | |
229 | + } | |
230 | + this.imageData = new Object(); | |
231 | + }); | |
232 | + //} | |
233 | + // canvas.width = canvas.width; // to clear the canvas | |
234 | + | |
235 | + // console.log(img.src); | |
236 | + } | |
237 | + | |
238 | + writeImageDataToJson(imageData: any): void { | |
239 | + this.imageService.updateImageData(imageData).subscribe((resp) => { | |
240 | + console.log('inside subscribe of addToImageDataCollection: result= ' + 'bodyViewIndex:' + resp.bodyViewIndex + ',layerNumber:' + resp.layerNumber + ',bodyRegionId:' + resp.bodyRegionId + ', time: ' + new Date().toTimeString().replace(/.*(\d{2}:\d{2}:\d{2}).*/, "$1")); | |
241 | + if (this.counter < this.remainingFiles75.length) { | |
242 | + this.counter++; | |
243 | + this.getDataFromFile(this.remainingFiles75, this.counter); | |
244 | + } | |
245 | + }); | |
246 | + } | |
247 | + | |
248 | + addToImageDataCollection(imageData: any): void { | |
249 | + for (let i = 0; i < this.imageDataCollection.length; i++) { | |
250 | + if (this.imageDataCollection[i].imageName === imageData.imageName) { | |
251 | + return; | |
252 | + } | |
253 | + } | |
254 | + this.imageDataCollection.push(imageData); | |
255 | + console.log("this.imageDataCollection.length= " + this.imageDataCollection.length); | |
256 | + | |
257 | + if (this.imageDataCollection.length === this.imageCount) { | |
258 | + console.log("starting pushing to server for layer: " + this.currentLayer + " of bodyViewIndex: " + this.bodyViewIndex + ', time: ' + new Date().toTimeString().replace(/.*(\d{2}:\d{2}:\d{2}).*/, "$1")); | |
259 | + for (let i = 0; i < this.imageDataCollection.length; i++) { | |
260 | + this.imageService.updateImageData(this.imageDataCollection[i]).subscribe((resp) => { | |
261 | + | |
262 | + // alert("resp:" + resp.isSuccess); | |
263 | + // this.BRCounter++; | |
264 | + | |
265 | + this.bodyRegionInLayer.push({ 'bodyViewIndex': resp.bodyViewIndex, 'layerNumber': resp.layerNumber, 'bodyRegionId': resp.bodyRegionId }); | |
266 | + | |
267 | + console.log('inside subscribe of addToImageDataCollection: result= ' + 'bodyViewIndex:' + resp.bodyViewIndex + ',layerNumber:' + resp.layerNumber + ',bodyRegionId:' + resp.bodyRegionId + ', time: ' + new Date().toTimeString().replace(/.*(\d{2}:\d{2}:\d{2}).*/, "$1")); | |
268 | + //if (i === this.imageDataCollection.length - 1 && this.BRCounter == this.imageCount) | |
269 | + //{ | |
270 | + | |
271 | + if (this.bodyRegionInLayer.length > 0 && this.bodyRegionInLayer.length == this.imageCount) { | |
272 | + //comparign with this.datalayerLength - 2(-2 due to we have not processed from layer 0) | |
273 | + if ((this.currentLayer <= this.datalayerLength - 2)) { | |
274 | + this.currentLayer++; | |
275 | + this.processLayer(); | |
276 | + } | |
277 | + else { | |
278 | + if (this.bodyViewIndex < this.totalBodyViews) { | |
279 | + this.bodyViewIndex++; | |
280 | + //if (this.bodyViewIndex == 3) { | |
281 | + | |
282 | + //} | |
283 | + //else { | |
284 | + this.currentLayer = 1; | |
285 | + this.getBodyViewJson(); | |
286 | + //} | |
287 | + } | |
288 | + } | |
289 | + } | |
290 | + }); | |
291 | + } | |
292 | + } | |
293 | + } | |
294 | + | |
295 | + generateFile(): void { | |
296 | + | |
297 | + //this.imageService.getRemianingFilesData('../remainingFies/RemainingFiles25'); | |
298 | + | |
299 | + //this.imageService.getBodyViewData(this.bodyViewIndex).subscribe((data) => { | |
300 | + // // console.log("Fetched body view json for bodyViewIndex: " + this.bodyViewIndex); | |
301 | + // this.remainingFiles25 = data; | |
302 | + // //this.saveBodyViewImageData(); | |
303 | + //}); | |
304 | + | |
305 | + | |
306 | + this.imageService.getRemianingFilesData('../assets/remainingFies/RemainingFiles75.json').subscribe((data) => { | |
307 | + console.log("Fetched RemainingFiles75.data= ====" + data); | |
308 | + | |
309 | + this.remainingFiles75 = data; | |
310 | + console.log("this.remainingFiles75.length= " + this.remainingFiles75.length) | |
311 | + | |
312 | + this.getDataFromFile(this.remainingFiles75, this.counter); | |
313 | + //for (let i = 0; i < this.remainingFiles75.length; i++) { | |
314 | + | |
315 | + | |
316 | + //} | |
317 | + }); | |
318 | + } | |
319 | + | |
320 | + getDataFromFile(remainingFiles75,i): void { | |
321 | + | |
322 | + var filename = this.remainingFiles75[i]; | |
323 | + var spiltedFileName = filename.split('_'); | |
324 | + | |
325 | + var bodyViewString = spiltedFileName[0]; | |
326 | + // alert("bodyViewString: " + bodyViewString + "bodyViewString.indexOf('w'):" + bodyViewString.indexOf('w') + ".bodyViewString.Length: " + bodyViewString.length); | |
327 | + | |
328 | + var indexofW = bodyViewString.indexOf('w'); | |
329 | + var bodyViewId = bodyViewString.substring(indexofW + 1); | |
330 | + | |
331 | + | |
332 | + | |
333 | + var layerString = spiltedFileName[1]; | |
334 | + // alert("layerString: " + layerString + "layerString.indexOf('r'):" + layerString.indexOf('r') + ".layerString.Length: " + layerString.length); | |
335 | + | |
336 | + var indexofR = layerString.indexOf('r'); | |
337 | + var layerNo = layerString.substring(indexofR + 1); | |
338 | + | |
339 | + var brString = spiltedFileName[2]; | |
340 | + // alert("brString: " + brString + "brString.indexOf('id'):" + brString.indexOf("id") + ".brString.Length: " + brString.length); | |
341 | + | |
342 | + var indexofId = brString.indexOf("Id"); | |
343 | + var BRId = (brString.substring(indexofId + 2)).replace('.json', ''); | |
344 | + | |
345 | + this.currentLayer = parseInt(layerNo); | |
346 | + this.bodyViewIndex = parseInt(bodyViewId); | |
347 | + this.bodyRegionId = parseInt(BRId); | |
348 | + | |
349 | + console.log("bodyViewId= " + bodyViewId + ",layerNo= " + layerNo + ",BRId= " + BRId); | |
350 | + | |
351 | + | |
352 | + if (parseInt(layerNo) != 0) { | |
353 | + console.log("this.bodyViewIndex: " + this.bodyViewIndex + ", this.currentLayer: " + this.currentLayer + ", this.bodyRegionId:" + this.bodyRegionId); | |
354 | + this.getBodyViewJson(); | |
355 | + | |
356 | + } | |
357 | + //else { | |
358 | + // console.log("this.bodyViewIndex: " + this.bodyViewIndex + ", this.currentLayer: " + this.currentLayer + ", this.bodyRegionId:" + this.bodyRegionId); | |
359 | + // this.getBodyViewJson(); | |
360 | + //} | |
361 | + | |
362 | + } | |
363 | + | |
364 | + } | |
365 | + | |
366 | + | |
367 | + | ... | ... |
600-POC/fileSave/jsonFile_generate/AJs/app.module.ts
0 → 100644
1 | +import { BrowserModule } from '@angular/platform-browser'; | |
2 | +import { NgModule } from '@angular/core'; | |
3 | +import { FormsModule } from '@angular/forms'; | |
4 | +import { HttpModule } from '@angular/http'; | |
5 | + | |
6 | +import { AppComponent } from './app.component'; | |
7 | + | |
8 | +@NgModule({ | |
9 | + declarations: [ | |
10 | + AppComponent | |
11 | + ], | |
12 | + imports: [ | |
13 | + BrowserModule, | |
14 | + FormsModule, | |
15 | + HttpModule | |
16 | + ], | |
17 | + providers: [], | |
18 | + bootstrap: [AppComponent] | |
19 | +}) | |
20 | +export class AppModule { } | ... | ... |
600-POC/fileSave/jsonFile_generate/AJs/services/image.service.ts
0 → 100644
1 | +import { Injectable } from '@angular/core'; | |
2 | +import { Http, Response, Headers, URLSearchParams } from '@angular/http'; | |
3 | +import { Router } from '@angular/router'; | |
4 | + | |
5 | +import { Observable } from 'rxjs/Observable'; | |
6 | +import 'rxjs/add/operator/map'; | |
7 | +import 'rxjs/add/operator/catch'; | |
8 | + | |
9 | +declare var jQuery: any; | |
10 | + | |
11 | +@Injectable() | |
12 | +export class ImageService { | |
13 | + | |
14 | + constructor(private http: Http) { | |
15 | + | |
16 | + } | |
17 | + | |
18 | + public getRemianingFilesData(filePath: string): Observable<any> { | |
19 | + return this.http.get(filePath).map(this.getData).catch(this.handleError); | |
20 | + | |
21 | + } | |
22 | + public getBodyViewData(index: number): Observable<any> { | |
23 | + console.log("getBodyViewData.index :" + index); | |
24 | + return this.http.get('../assets/data/json/da/body-views/' + index + '/da_dat_layer_' + index + '.json'); | |
25 | + } | |
26 | + | |
27 | + public updateImageData(imageData: any): Observable<any> { | |
28 | + const headers = new Headers(); | |
29 | + headers.append('Content-Type', 'application/json'); | |
30 | + headers.append('bodyViewIndex', imageData.bodyViewIndex); | |
31 | + headers.append('layerNumber', imageData.layerNumber); | |
32 | + headers.append('bodyRegion', imageData.bodyRegion); | |
33 | + | |
34 | + let payload: string = JSON.stringify(imageData); | |
35 | + console.log('inside updateImageData.JSON.stringify(imageData)= ' + payload); | |
36 | + return this.http.post('/API/api/ProcessImage', payload, { headers: headers }) | |
37 | + .map(this.extractData) | |
38 | + .catch(this.handleError); | |
39 | + } | |
40 | + | |
41 | + //public updateImageData(imageData: any): any { | |
42 | + // const headers = new Headers(); | |
43 | + // headers.append('Content-Type', 'application/json'); | |
44 | + // let payload: string = JSON.stringify(imageData); | |
45 | + // console.log('inside updateImageData.JSON.stringify(imageData)= ' + payload); | |
46 | + // //return this.http.post('/API/api/ProcessImage', payload, { headers: headers }) | |
47 | + // // .map(this.extractData) | |
48 | + // // .catch(this.handleError); | |
49 | + // jQuery.ajax({ | |
50 | + // headers: { | |
51 | + // 'Accept': 'application/json', | |
52 | + // 'Content-Type': 'application/json' | |
53 | + // }, | |
54 | + // url: '/API/api/ProcessImage/Post', | |
55 | + // type: 'POST', | |
56 | + // data: { "value": payload }, | |
57 | + // success: function (result) { | |
58 | + // return result; | |
59 | + // } | |
60 | + // }); | |
61 | + //} | |
62 | +private getData(res:Response){ | |
63 | + const body = res.json(); | |
64 | + console.log("inside getData.body: "+body) | |
65 | + return body || {}; | |
66 | + } | |
67 | + | |
68 | + private extractData(res: Response) { | |
69 | + const body = res.json(); | |
70 | + return body || {}; | |
71 | + } | |
72 | + | |
73 | + private handleError(error: Response | any) { | |
74 | + // In a real world app, we might use a remote logging infrastructure | |
75 | + let errMsg: string; | |
76 | + if (error instanceof Response) { | |
77 | + const body = error.json() || ''; | |
78 | + const err = body.error || JSON.stringify(body); | |
79 | + errMsg = `${error.status} - ${error.statusText || ''} ${err}`; | |
80 | + } else { | |
81 | + errMsg = error.message ? error.message : error.toString(); | |
82 | + } | |
83 | + console.error(errMsg); | |
84 | + return Observable.throw(errMsg); | |
85 | + } | |
86 | +} | ... | ... |
600-POC/fileSave/jsonFile_generate/ProcessImageController.cs
0 → 100644
1 | +using AIAHighlight.Helpers; | |
2 | +using Newtonsoft.Json; | |
3 | +using Newtonsoft.Json.Linq; | |
4 | +using System; | |
5 | +using System.Collections.Generic; | |
6 | +using System.IO; | |
7 | +using System.Linq; | |
8 | +using System.Net; | |
9 | +using System.Net.Http; | |
10 | +using System.Threading.Tasks; | |
11 | +using System.Web; | |
12 | +using System.Web.Http; | |
13 | + | |
14 | +namespace AIAHighlight.Controllers | |
15 | +{ | |
16 | + public class ProcessImageController : ApiController | |
17 | + { | |
18 | + // GET: api/ProcessImage | |
19 | + public IEnumerable<string> Get() | |
20 | + { | |
21 | + return new string[] { "value1", "value2" }; | |
22 | + } | |
23 | + | |
24 | + // GET: api/ProcessImage/5 | |
25 | + public string Get(int id) | |
26 | + { | |
27 | + return "value"; | |
28 | + } | |
29 | + | |
30 | + // POST: api/ProcessImage | |
31 | + [HttpPost] | |
32 | + public async Task<HttpResponseMessage> Post(HttpRequestMessage request) | |
33 | + { | |
34 | + var httpRequest = HttpContext.Current.Request; | |
35 | + Stream requestStream = await request.Content.ReadAsStreamAsync(); | |
36 | + HttpResponseMessage result = null; | |
37 | + | |
38 | + IEnumerable<string> layerNumberHeaderValue = request.Headers.GetValues("layerNumber"); | |
39 | + var layerNumber = layerNumberHeaderValue.FirstOrDefault(); | |
40 | + | |
41 | + IEnumerable<string> bodyViewIndexHeaderValue = request.Headers.GetValues("bodyViewIndex"); | |
42 | + var bodyViewIndex = bodyViewIndexHeaderValue.FirstOrDefault(); | |
43 | + | |
44 | + IEnumerable<string> bodyRegionHeaderValue = request.Headers.GetValues("bodyRegion"); | |
45 | + var bodyRegionId = bodyRegionHeaderValue.FirstOrDefault(); | |
46 | + | |
47 | + if (requestStream != null) | |
48 | + { | |
49 | + | |
50 | + string fileName = "BodyView" + bodyViewIndex + "_layer" + layerNumber + "_bodyRegionId" + bodyRegionId; | |
51 | + // string filePath = "D:\\ADAM\\100-PROJECTS\\001-AIAHighlight.FileSave\\AIAHighlight.Serevr\\AIAHighlight\\data1\\75\\" + fileName + ".json"; | |
52 | + string filePath = "D:\\100-PROJECTS\\008-AIAHighlight.FileSave\\AIAHighlight\\AIAHighlight\\data1\\75\\" + fileName + ".json"; | |
53 | + | |
54 | + | |
55 | + try | |
56 | + { | |
57 | + using (FileStream fileStream = System.IO.File.Create(filePath, (int)requestStream.Length)) | |
58 | + { | |
59 | + // Fill the bytes[] array with the stream data | |
60 | + byte[] bytesInStream = new byte[requestStream.Length]; | |
61 | + // string response1 = (JsonConvert.SerializeObject(bytesInStream)); | |
62 | + requestStream.Read(bytesInStream, 0, (int)bytesInStream.Length); | |
63 | + // Use FileStream object to write to the specified file | |
64 | + fileStream.Write(bytesInStream, 0, bytesInStream.Length); | |
65 | + result = Request.CreateResponse(HttpStatusCode.Created, "TEMP.txt"); | |
66 | + } | |
67 | + return result; | |
68 | + } | |
69 | + catch (HttpException ex) | |
70 | + { | |
71 | + return result = Request.CreateResponse(HttpStatusCode.BadGateway, "Http Exception Come" + ex.Message); | |
72 | + } | |
73 | + catch (Exception ex) | |
74 | + { | |
75 | + return result = Request.CreateResponse(HttpStatusCode.BadGateway, "Http Exception Come" + ex.Message); | |
76 | + } | |
77 | + } | |
78 | + | |
79 | + return result; ; | |
80 | + } | |
81 | + //public HttpResponseMessage Post([FromBody]JObject image) | |
82 | + //{ | |
83 | + // dynamic response = new ProcessImageHelper().writeFile(image); | |
84 | + // return new HttpResponseMessage { StatusCode = HttpStatusCode.Created, Content = new StringContent(JsonConvert.SerializeObject(response)) }; | |
85 | + //} | |
86 | + | |
87 | + // PUT: api/ProcessImage/5 | |
88 | + //public void Put(int id, [FromBody]string value) | |
89 | + //{ | |
90 | + //} | |
91 | + | |
92 | + //// DELETE: api/ProcessImage/5 | |
93 | + //public void Delete(int id) | |
94 | + //{ | |
95 | + //} | |
96 | + } | |
97 | +} | ... | ... |