Browse Source

Stable version 2.0

ricardo valls 3 years ago
parent
commit
0cc48b90d5
30 changed files with 672 additions and 335 deletions
  1. 7 2
      WorkerService1/WebApplication3/Clases/Constants.cs
  2. 2 0
      WorkerService1/WebApplication3/Clases/DatosPostAcuifero.cs
  3. 1 0
      WorkerService1/WebApplication3/Clases/Fichero.cs
  4. 108 55
      WorkerService1/WebApplication3/Clases/Parser.cs
  5. 9 0
      WorkerService1/WebApplication3/Clases/Proceso.cs
  6. 0 1
      WorkerService1/WebApplication3/Clases/QueueWorker.cs
  7. 2 1
      WorkerService1/WebApplication3/Clases/RechargeData.cs
  8. 16 8
      WorkerService1/WebApplication3/Clases/Utilities.cs
  9. 8 7
      WorkerService1/WebApplication3/Clases/WellData.cs
  10. 1 1
      WorkerService1/WebApplication3/Clases/Worker.cs
  11. 12 7
      WorkerService1/WebApplication3/Clases/ZoneData.cs
  12. 72 50
      WorkerService1/WebApplication3/Controllers/AcuiferoController.cs
  13. 2 0
      WorkerService1/WebApplication3/Controllers/BalanceHidricoController.cs
  14. 13 6
      WorkerService1/WebApplication3/Controllers/PiezometriaController.cs
  15. 62 52
      WorkerService1/WebApplication3/Controllers/PozoController.cs
  16. 99 10
      WorkerService1/WebApplication3/Controllers/RecargasController.cs
  17. 3 2
      WorkerService1/WebApplication3/Controllers/ServiceQueueController.cs
  18. 63 44
      WorkerService1/WebApplication3/Controllers/ServicioController.cs
  19. 138 81
      WorkerService1/WebApplication3/Controllers/SimulacionController.cs
  20. 5 4
      WorkerService1/WebApplication3/Controllers/TsPiezometerController.cs
  21. 3 2
      WorkerService1/WebApplication3/Controllers/TsPozoController.cs
  22. 3 2
      WorkerService1/WebApplication3/Controllers/TsRecargaController.cs
  23. 2 0
      WorkerService1/WebApplication3/Models/Acuifero.cs
  24. 14 0
      WorkerService1/WebApplication3/Models/AquiferContext.cs
  25. 1 0
      WorkerService1/WebApplication3/Models/DatosBalanceIn.cs
  26. 1 0
      WorkerService1/WebApplication3/Models/DatosBalanceOut.cs
  27. 20 0
      WorkerService1/WebApplication3/Models/Piezometer.cs
  28. 2 0
      WorkerService1/WebApplication3/Models/Pozo.cs
  29. 2 0
      WorkerService1/WebApplication3/Models/Simulacion.cs
  30. 1 0
      WorkerService1/WebApplication3/Models/TSPozo.cs

+ 7 - 2
WorkerService1/WebApplication3/Clases/Constants.cs View File

7
 {
7
 {
8
     public static class Constants
8
     public static class Constants
9
     {
9
     {
10
-        public const string PathZip = @"C:\Users\Admin\Desktop\";
11
-        public const string PathExtract = @"C:\Users\Admin\Desktop\TestExtract\";
10
+        //public const string PathZip = @"C:\Users\Admin\Desktop\";
11
+        public const string PathZip = @"C:\Users\Admin\Documents\modflow_models\";
12
+        //public const string PathExtract = @"C:\Users\Admin\Desktop\TestExtract\";
13
+        public const string PathExtract = @"C:\Users\Admin\Documents\modflow_models\temp\";
12
         public const string PathModflow = @"C:\Users\Admin\Downloads\MF2005.1_12\MF2005.1_12\bin\mf2005.exe";
14
         public const string PathModflow = @"C:\Users\Admin\Downloads\MF2005.1_12\MF2005.1_12\bin\mf2005.exe";
13
         public static readonly Dictionary<string, string> _recharge_geometry_colors = new()
15
         public static readonly Dictionary<string, string> _recharge_geometry_colors = new()
14
         {
16
         {
21
             { "7", "#660099" },
23
             { "7", "#660099" },
22
             { "8", "#266A2E" }
24
             { "8", "#266A2E" }
23
         };
25
         };
26
+        public const string SVGFileName = "vector_image.svg";
27
+        public const string PNGFileName = "color_map.png";
28
+        public const string GeoJsonFileName = "vector_image.geojson";
24
     }
29
     }
25
 }
30
 }

+ 2 - 0
WorkerService1/WebApplication3/Clases/DatosPostAcuifero.cs View File

1
 using System;
1
 using System;
2
+using System.Collections;
2
 using System.Collections.Generic;
3
 using System.Collections.Generic;
3
 using System.Linq;
4
 using System.Linq;
4
 using System.Threading.Tasks;
5
 using System.Threading.Tasks;
9
     {
10
     {
10
         public string Nombre { get; set; }
11
         public string Nombre { get; set; }
11
         public Fichero Fichero { get; set; }
12
         public Fichero Fichero { get; set; }
13
+        
12
     }
14
     }
13
 }
15
 }

+ 1 - 0
WorkerService1/WebApplication3/Clases/Fichero.cs View File

9
     {
9
     {
10
         public string Nombre { get; set; }
10
         public string Nombre { get; set; }
11
         public string Base64 { get; set; }
11
         public string Base64 { get; set; }
12
+        public byte[] Test { get; set; }
12
     }
13
     }
13
 }
14
 }

+ 108 - 55
WorkerService1/WebApplication3/Clases/Parser.cs View File

75
                                 //cont += (wellData[index].ScreenIntervals * 2) - 1;
75
                                 //cont += (wellData[index].ScreenIntervals * 2) - 1;
76
                                 intervalSkipped = true;
76
                                 intervalSkipped = true;
77
                                 //leemos tantas lineas hay como intervalos de pantalla (al ser 2 parametros por cada intervalo es nIntervalos * 2
77
                                 //leemos tantas lineas hay como intervalos de pantalla (al ser 2 parametros por cada intervalo es nIntervalos * 2
78
-                                //for (int i = 0; i < wellData[index].ScreenIntervals * 2; i++)
78
+                                List<string> linesAux = new();
79
                                 for (int i = 0; i < wellData.ScreenIntervals * 2; i++)
79
                                 for (int i = 0; i < wellData.ScreenIntervals * 2; i++)
80
                                 {
80
                                 {
81
-                                    file.ReadLine();
81
+                                    linesAux.Add(file.ReadLine());
82
                                     cont++;
82
                                     cont++;
83
                                 }
83
                                 }
84
+                                wellData.Bot = linesAux[0];
85
+                                wellData.Top = linesAux[1];
84
 
86
 
85
                                 break;
87
                                 break;
86
                             default:
88
                             default:
101
                         else
103
                         else
102
                         {
104
                         {
103
                             TimeSerieInterno ts = new TimeSerieInterno();
105
                             TimeSerieInterno ts = new TimeSerieInterno();
104
-                            string aux = "";
106
+                            //string aux = "";
105
                             //Rate rate = new Rate();
107
                             //Rate rate = new Rate();
106
                             ts.Hora = ln;
108
                             ts.Hora = ln;
107
                             //rate.StartTime = float.Parse(ln.Replace('.', ','));
109
                             //rate.StartTime = float.Parse(ln.Replace('.', ','));
108
 
110
 
109
                             ln = file.ReadLine();
111
                             ln = file.ReadLine();
112
+                            ts.HoraEnd = ln;
110
                             cont++;
113
                             cont++;
111
                             
114
                             
112
-                            if(cont == finalBloque - 1)
113
-                            {
114
-                                aux = ln;
115
-                            }
115
+                            //if(cont == finalBloque - 1)
116
+                            //{
117
+                            //    aux = ln;
118
+                            //}
116
 
119
 
117
                             ln = file.ReadLine();
120
                             ln = file.ReadLine();
118
                             cont++;
121
                             cont++;
127
                             //wellData[index].Rates.Add(rate);
130
                             //wellData[index].Rates.Add(rate);
128
                             wellData.Rates.Add(ts);
131
                             wellData.Rates.Add(ts);
129
 
132
 
130
-                            if(aux != "")
131
-                            {
132
-                                ts = new TimeSerieInterno();
133
-                                ts.Hora = aux;
134
-                                ts.Valor = value;
135
-                                ts.Info = ln.Replace(exploded[0] + ' ', "");
136
-                                wellData.Rates.Add(ts);
137
-                            }
133
+                            //if(aux != "")
134
+                            //{
135
+                            //    ts = new TimeSerieInterno();
136
+                            //    ts.Hora = aux;
137
+                            //    ts.Valor = value;
138
+                            //    ts.Info = ln.Replace(exploded[0] + ' ', "");
139
+                            //    wellData.Rates.Add(ts);
140
+                            //}
138
                         }
141
                         }
139
                     }
142
                     }
140
 
143
 
180
                 Console.WriteLine(data[rechargeBlockInex]);
183
                 Console.WriteLine(data[rechargeBlockInex]);
181
                 string[] explode = data[rechargeBlockInex].Split("\r\n");
184
                 string[] explode = data[rechargeBlockInex].Split("\r\n");
182
 
185
 
183
-                for(int i = 3; i < explode.Length; i++)
186
+                for (int i = 1; i < explode.Length; i++)
184
                 {
187
                 {
185
                     string[] values = explode[i].Split(" ", StringSplitOptions.RemoveEmptyEntries);
188
                     string[] values = explode[i].Split(" ", StringSplitOptions.RemoveEmptyEntries);
186
 
189
 
187
                     //Si hay cambio de propiedad se crea otro RechargeData
190
                     //Si hay cambio de propiedad se crea otro RechargeData
188
-                    if(rechargeProperty != values[0])
191
+                    if (rechargeProperty != values[0])
189
                     {
192
                     {
190
-                        if(rechargeProperty != "")
193
+                        if (rechargeProperty != "")
191
                         {
194
                         {
192
                             recharges.Add(rechargeData);
195
                             recharges.Add(rechargeData);
193
                         }
196
                         }
195
                         rechargeData = new RechargeData();
198
                         rechargeData = new RechargeData();
196
                         rechargeData.Nombre = "Recarga_" + values[0];
199
                         rechargeData.Nombre = "Recarga_" + values[0];
197
                         rechargeProperty = values[0];
200
                         rechargeProperty = values[0];
201
+                        //Al hacer el cambio
202
+                        i += 2;
203
+                        values = explode[i].Split(" ", StringSplitOptions.RemoveEmptyEntries);
198
                     }
204
                     }
199
 
205
 
200
                     timeSerie = new TimeSerieInterno();
206
                     timeSerie = new TimeSerieInterno();
201
                     timeSerie.Hora = values[2];
207
                     timeSerie.Hora = values[2];
208
+                    timeSerie.HoraEnd = values[3];
202
                     timeSerie.Valor = values[1];
209
                     timeSerie.Valor = values[1];
203
                     timeSerie.Info = values[4] + " " + values[5];
210
                     timeSerie.Info = values[4] + " " + values[5];
204
 
211
 
205
                     rechargeData.Rates.Add(timeSerie);
212
                     rechargeData.Rates.Add(timeSerie);
206
                     
213
                     
207
-                    //se anyade el ultimo registro de tiempo ya que solo nos quedamos con la primera marca de tiempo de cada linea
208
-                    if(i == explode.Length - 1)
209
-                    {
210
-                        timeSerie = new TimeSerieInterno();
211
-                        timeSerie.Hora = values[3];
212
-                        timeSerie.Valor = values[1];
213
-                        timeSerie.Info = values[4] + " " + values[5];
214
-                        rechargeData.Rates.Add(timeSerie);
215
-                    }
214
+                    ////se anyade el ultimo registro de tiempo ya que solo nos quedamos con la primera marca de tiempo de cada linea
215
+                    //if(i == explode.Length - 1)
216
+                    //{
217
+                    //    timeSerie = new TimeSerieInterno();
218
+                    //    timeSerie.Hora = values[3];
219
+                    //    timeSerie.Valor = values[1];
220
+                    //    timeSerie.Info = values[4] + " " + values[5];
221
+                    //    rechargeData.Rates.Add(timeSerie);
222
+                    //}
216
                 }
223
                 }
217
                 recharge_geometry = data[rechargeBlockInex + layers];
224
                 recharge_geometry = data[rechargeBlockInex + layers];
218
 
225
 
244
 
251
 
245
             aux.RemoveAll(x => x.Contains("WHS") || x.Contains("NDC") || x.Contains("CLB") || x == "");
252
             aux.RemoveAll(x => x.Contains("WHS") || x.Contains("NDC") || x.Contains("CLB") || x == "");
246
 
253
 
254
+            List<string> units = new();
255
+            foreach (string row in aux)
256
+            {
257
+                if (!aux.Contains("LIST"))
258
+                {
259
+                    string[] rowSplit = row.Split(" ", StringSplitOptions.RemoveEmptyEntries);
260
+
261
+                    units.Add(rowSplit[1]);
262
+                }
263
+            }
264
+
247
             foreach (string row in aux)
265
             foreach (string row in aux)
248
             {
266
             {
249
                 string[] rowSplit = row.Split(" ", StringSplitOptions.RemoveEmptyEntries);
267
                 string[] rowSplit = row.Split(" ", StringSplitOptions.RemoveEmptyEntries);
251
 
269
 
252
                 if (rowSplit[0] == "LIST" && int.Parse(rowSplit[1]) < 10)
270
                 if (rowSplit[0] == "LIST" && int.Parse(rowSplit[1]) < 10)
253
                 {
271
                 {
254
-                    rowSplit[1] = "12";
272
+                    if (!units.Contains("11"))
273
+                    {
274
+                        rowSplit[1] = "11";
275
+                    } 
276
+                    else if (!units.Contains("12"))
277
+                    {
278
+                        rowSplit[1] = "12";
279
+                    }
280
+                    else if (!units.Contains("13"))
281
+                    {
282
+                        rowSplit[1] = "13";
283
+                    }
284
+                    else if (!units.Contains("14"))
285
+                    {
286
+                        rowSplit[1] = "14";
287
+                    }
255
                 }
288
                 }
256
 
289
 
257
                 //Se tiene que parsear la 3a parte del string porque contiene la ruta absoluta del ordenador donde se han originado los ficheros
290
                 //Se tiene que parsear la 3a parte del string porque contiene la ruta absoluta del ordenador donde se han originado los ficheros
419
 
452
 
420
         public ZoneBalance[] ParseWholeModelBalance(string textfile)
453
         public ZoneBalance[] ParseWholeModelBalance(string textfile)
421
         {
454
         {
422
-            
455
+
423
             string text = File.ReadAllText(textfile);
456
             string text = File.ReadAllText(textfile);
424
             string[] data = text.Split(" DRAWDOWN WILL BE SAVED ON UNIT  151 AT END OF TIME STEP   10, STRESS PERIOD", StringSplitOptions.RemoveEmptyEntries);
457
             string[] data = text.Split(" DRAWDOWN WILL BE SAVED ON UNIT  151 AT END OF TIME STEP   10, STRESS PERIOD", StringSplitOptions.RemoveEmptyEntries);
425
 
458
 
440
                 current.Type = 2;
473
                 current.Type = 2;
441
 
474
 
442
 
475
 
443
-                List<string> data_aux = data[i].Split("\r\n").ToList();
444
-                string[] split = data_aux[2].Split("STRESS PERIOD");
476
+                List<string> data_aux = data[i].Split("\r\n", StringSplitOptions.RemoveEmptyEntries).ToList();
477
+                string[] split = data_aux[2].Split("STRESS PERIOD", StringSplitOptions.RemoveEmptyEntries);
445
 
478
 
446
 
479
 
447
                 #region IN
480
                 #region IN
448
-                split = data_aux[10].Split("STORAGE =", StringSplitOptions.RemoveEmptyEntries);
481
+                split = data_aux[8].Split("STORAGE =", StringSplitOptions.RemoveEmptyEntries);
449
                 cummulative.In.Storage = split[1].Trim();
482
                 cummulative.In.Storage = split[1].Trim();
450
                 current.In.Storage = split[2].Trim();
483
                 current.In.Storage = split[2].Trim();
451
 
484
 
452
-                split = data_aux[11].Split("CONSTANT HEAD =", StringSplitOptions.RemoveEmptyEntries);
485
+                split = data_aux[9].Split("CONSTANT HEAD =", StringSplitOptions.RemoveEmptyEntries);
453
                 cummulative.In.ConstantHead = split[1].Trim();
486
                 cummulative.In.ConstantHead = split[1].Trim();
454
                 current.In.ConstantHead = split[2].Trim();
487
                 current.In.ConstantHead = split[2].Trim();
455
 
488
 
456
-                split = data_aux[12].Split("DRAINS =", StringSplitOptions.RemoveEmptyEntries);
457
-                cummulative.In.Drains = split[1].Trim();
458
-                current.In.Drains = split[2].Trim();
489
+                if (data_aux[10].Contains("DRAINS"))
490
+                {
491
+                    split = data_aux[10].Split("DRAINS =", StringSplitOptions.RemoveEmptyEntries);
492
+                    cummulative.In.Drains = split[1].Trim();
493
+                    current.In.Drains = split[2].Trim();
494
+                }
495
+                else
496
+                {
497
+                    split = data_aux[10].Split("WELLS =", StringSplitOptions.RemoveEmptyEntries);
498
+                    cummulative.In.Wells = split[1].Trim();
499
+                    current.In.Wells = split[2].Trim();
500
+                }
459
 
501
 
460
-                split = data_aux[13].Split("RECHARGE =", StringSplitOptions.RemoveEmptyEntries);
502
+                split = data_aux[11].Split("RECHARGE =", StringSplitOptions.RemoveEmptyEntries);
461
                 cummulative.In.Recharge = split[1].Trim();
503
                 cummulative.In.Recharge = split[1].Trim();
462
                 current.In.Recharge = split[2].Trim();
504
                 current.In.Recharge = split[2].Trim();
463
 
505
 
464
-                split = data_aux[15].Split("TOTAL IN =", StringSplitOptions.RemoveEmptyEntries);
506
+                split = data_aux[13].Split("TOTAL IN =", StringSplitOptions.RemoveEmptyEntries);
465
                 cummulative.In.Total = split[1].Trim();
507
                 cummulative.In.Total = split[1].Trim();
466
                 current.In.Total = split[2].Trim();
508
                 current.In.Total = split[2].Trim();
467
                 #endregion
509
                 #endregion
468
 
510
 
469
                 #region OUT
511
                 #region OUT
470
-                split = data_aux[19].Split("STORAGE =", StringSplitOptions.RemoveEmptyEntries);
512
+                split = data_aux[16].Split("STORAGE =", StringSplitOptions.RemoveEmptyEntries);
471
                 cummulative.Out.Storage = split[1].Trim();
513
                 cummulative.Out.Storage = split[1].Trim();
472
                 current.Out.Storage = split[2].Trim();
514
                 current.Out.Storage = split[2].Trim();
473
 
515
 
474
-                split = data_aux[20].Split("CONSTANT HEAD =", StringSplitOptions.RemoveEmptyEntries);
516
+                split = data_aux[17].Split("CONSTANT HEAD =", StringSplitOptions.RemoveEmptyEntries);
475
                 cummulative.Out.ConstantHead = split[1].Trim();
517
                 cummulative.Out.ConstantHead = split[1].Trim();
476
                 current.Out.ConstantHead = split[2].Trim();
518
                 current.Out.ConstantHead = split[2].Trim();
477
 
519
 
478
-                split = data_aux[21].Split("DRAINS =", StringSplitOptions.RemoveEmptyEntries);
479
-                cummulative.Out.Drains = split[1].Trim();
480
-                current.Out.Drains = split[2].Trim();
520
+                if (data_aux[18].Contains("DRAINS"))
521
+                {
522
+                    split = data_aux[18].Split("DRAINS =", StringSplitOptions.RemoveEmptyEntries);
523
+                    cummulative.Out.Drains = split[1].Trim();
524
+                    current.Out.Drains = split[2].Trim();
525
+                }
526
+                else
527
+                {
528
+                    split = data_aux[18].Split("WELLS =", StringSplitOptions.RemoveEmptyEntries);
529
+                    cummulative.Out.Wells = split[1].Trim();
530
+                    current.Out.Wells = split[2].Trim();
531
+                }
481
 
532
 
482
-                split = data_aux[22].Split("RECHARGE =", StringSplitOptions.RemoveEmptyEntries);
533
+                split = data_aux[19].Split("RECHARGE =", StringSplitOptions.RemoveEmptyEntries);
483
                 cummulative.Out.Recharge = split[1].Trim();
534
                 cummulative.Out.Recharge = split[1].Trim();
484
                 current.Out.Recharge = split[2].Trim();
535
                 current.Out.Recharge = split[2].Trim();
485
 
536
 
486
-                split = data_aux[24].Split("TOTAL OUT =", StringSplitOptions.RemoveEmptyEntries);
537
+                split = data_aux[21].Split("TOTAL OUT =", StringSplitOptions.RemoveEmptyEntries);
487
                 cummulative.Out.Total = split[1].Trim();
538
                 cummulative.Out.Total = split[1].Trim();
488
                 current.Out.Total = split[2].Trim();
539
                 current.Out.Total = split[2].Trim();
489
                 #endregion
540
                 #endregion
490
 
541
 
491
-                split = data_aux[26].Split("IN - OUT =", StringSplitOptions.RemoveEmptyEntries);
542
+                split = data_aux[22].Split("IN - OUT =", StringSplitOptions.RemoveEmptyEntries);
492
                 cummulative.TotalInOut = split[1].Trim();
543
                 cummulative.TotalInOut = split[1].Trim();
493
                 current.TotalInOut = split[2].Trim();
544
                 current.TotalInOut = split[2].Trim();
494
 
545
 
495
-                split = data_aux[28].Split("PERCENT DISCREPANCY =", StringSplitOptions.RemoveEmptyEntries);
546
+                split = data_aux[23].Split("PERCENT DISCREPANCY =", StringSplitOptions.RemoveEmptyEntries);
496
                 cummulative.PercentDiscrepancy = split[1].Trim();
547
                 cummulative.PercentDiscrepancy = split[1].Trim();
497
                 current.PercentDiscrepancy = split[2].Trim();
548
                 current.PercentDiscrepancy = split[2].Trim();
498
 
549
 
569
                             piezometria.Add(p);
620
                             piezometria.Add(p);
570
                             
621
                             
571
                         }
622
                         }
623
+
624
+                        Logger.WriteLog("Ya se ha leido el fichero");
572
                     }
625
                     }
573
                 }catch(Exception ex)
626
                 }catch(Exception ex)
574
                 {
627
                 {
584
 
637
 
585
             string text = File.ReadAllText(file);
638
             string text = File.ReadAllText(file);
586
 
639
 
587
-            List<string> data = text.Split("\r\n").ToList();
640
+            List<string> data = text.Split("\r\n", StringSplitOptions.RemoveEmptyEntries).ToList();
588
             //string geolocationData = data[2];
641
             //string geolocationData = data[2];
589
-            string geolocation_line = data.Find(x=> x.Contains("<Georeference"));
642
+            string geolocation_line = data.Find(x => x.Contains("<Georeference"));
643
+
644
+            string[] geolocation_data = geolocation_line.Split(" ", StringSplitOptions.RemoveEmptyEntries);
645
+            string[] world_origin_x = geolocation_data[3].Split("World_Origin_X=", StringSplitOptions.RemoveEmptyEntries);
646
+            string[] world_origin_y = geolocation_data[4].Split("World_Origin_Y=", StringSplitOptions.RemoveEmptyEntries);
590
 
647
 
591
-            string[] geolocation_data = geolocation_line.Split(" ");
592
-            string[] world_origin_x = geolocation_data[1].Split("=");
593
-            string[] world_origin_y = geolocation_data[2].Split("=");
594
 
648
 
595
-            
596
-            worldX = world_origin_x[1].Replace("\"",string.Empty);
597
-            worldY = world_origin_y[1].Replace("\"",string.Empty);
649
+            worldX = world_origin_x[0].Replace("\"", string.Empty);
650
+            worldY = world_origin_y[0].Replace("\"", string.Empty);
598
         }
651
         }
599
 
652
 
600
         public WellData[] parseWellCSV(string file)
653
         public WellData[] parseWellCSV(string file)

+ 9 - 0
WorkerService1/WebApplication3/Clases/Proceso.cs View File

55
             proceso.StartInfo.Arguments = script+" "+headFile+" "+rows+" "+cols+" "+isolines;
55
             proceso.StartInfo.Arguments = script+" "+headFile+" "+rows+" "+cols+" "+isolines;
56
             proceso.StartInfo.UseShellExecute = false;
56
             proceso.StartInfo.UseShellExecute = false;
57
         }
57
         }
58
+
59
+        public void SetParametersSVG2Json(string workingDirectory, string fileName)
60
+        {
61
+            proceso.StartInfo.WorkingDirectory = workingDirectory;
62
+            proceso.StartInfo.FileName = "svg2geojson";
63
+            proceso.StartInfo.Arguments = fileName;
64
+            proceso.StartInfo.UseShellExecute = false;
65
+
66
+        }
58
         public int GetPid()
67
         public int GetPid()
59
         {
68
         {
60
             return proceso.Id;
69
             return proceso.Id;

+ 0 - 1
WorkerService1/WebApplication3/Clases/QueueWorker.cs View File

22
             _logger = logger;
22
             _logger = logger;
23
 
23
 
24
             var aquiferContext = new AquiferContext();
24
             var aquiferContext = new AquiferContext();
25
-            servicioController = new ServicioController(aquiferContext);
26
             simulacionController = new SimulacionController(aquiferContext);
25
             simulacionController = new SimulacionController(aquiferContext);
27
             serviceQueueController = new ServiceQueueController(aquiferContext);
26
             serviceQueueController = new ServiceQueueController(aquiferContext);
28
         }
27
         }

+ 2 - 1
WorkerService1/WebApplication3/Clases/RechargeData.cs View File

15
         public string Nombre { get; set; }
15
         public string Nombre { get; set; }
16
         public List<TimeSerieInterno> Rates { get; set; }
16
         public List<TimeSerieInterno> Rates { get; set; }
17
 
17
 
18
-        public Recarga ToRecarga(uint acuifero)
18
+        public Recarga ToRecarga(uint acuifero,uint simId)
19
         {
19
         {
20
             Recarga recarga = new Recarga();
20
             Recarga recarga = new Recarga();
21
 
21
 
22
             recarga.IdAcuifero = acuifero;
22
             recarga.IdAcuifero = acuifero;
23
+            recarga.IdSimulacion = simId;
23
             recarga.Nombre = this.Nombre;
24
             recarga.Nombre = this.Nombre;
24
 
25
 
25
             return recarga;
26
             return recarga;

+ 16 - 8
WorkerService1/WebApplication3/Clases/Utilities.cs View File

2
 using System.Collections.Generic;
2
 using System.Collections.Generic;
3
 using System.Drawing;
3
 using System.Drawing;
4
 using System.Drawing.Imaging;
4
 using System.Drawing.Imaging;
5
+using System.IO;
5
 using System.Linq;
6
 using System.Linq;
6
 using System.Threading.Tasks;
7
 using System.Threading.Tasks;
7
 
8
 
9
 {
10
 {
10
     public static class Utilities
11
     public static class Utilities
11
     {
12
     {
12
-        public static bool String2Png(string data)
13
+        public static string String2Png(string data)
13
         {
14
         {
14
-            Logger.WriteLog("im in");
15
-            bool result = true;
16
             List<string> rows = data.Split("\r\n",StringSplitOptions.RemoveEmptyEntries).ToList<string>();
15
             List<string> rows = data.Split("\r\n",StringSplitOptions.RemoveEmptyEntries).ToList<string>();
17
-            Logger.WriteLog("rows has a lenght of" + rows.Count);
18
             List<string> cols = rows[0].Split(" ",StringSplitOptions.RemoveEmptyEntries).ToList<string>();
16
             List<string> cols = rows[0].Split(" ",StringSplitOptions.RemoveEmptyEntries).ToList<string>();
19
-            Logger.WriteLog("cols has a length of " + cols.Count);
20
             int width = cols.Count;
17
             int width = cols.Count;
21
             int height = rows.Count;
18
             int height = rows.Count;
22
             int[,] integers = new int[height, width];
19
             int[,] integers = new int[height, width];
23
             int stride = width * 4;
20
             int stride = width * 4;
21
+            string fileName = @"C:\Users\Admin\Desktop\AAAA\green.png";
24
 
22
 
25
             string[,] array2Db = new string[height, width];
23
             string[,] array2Db = new string[height, width];
26
             for(int i= 0; i < height; i++)
24
             for(int i= 0; i < height; i++)
34
             }
32
             }
35
 
33
 
36
             // Fill array with random values
34
             // Fill array with random values
37
-            Random random = new Random();
38
             for (int x = 0; x < height; ++x)
35
             for (int x = 0; x < height; ++x)
39
             {
36
             {
40
                 for (int y = 0; y < width; ++y)
37
                 for (int y = 0; y < width; ++y)
57
 
54
 
58
             using (b)
55
             using (b)
59
             {
56
             {
60
-                b.Save(@"C:\Users\Admin\Desktop\AAAA\green.png", ImageFormat.Png);
57
+                b.Save(fileName, ImageFormat.Png);
58
+            }
59
+            return fileName;
60
+        }
61
+
62
+        public static void BinaryToFile(byte[] ba, string fileName)
63
+        {
64
+            using (FileStream fs = new FileStream(fileName, FileMode.Create))
65
+            {
66
+                using (BinaryWriter bw = new BinaryWriter(fs))
67
+                {
68
+                    bw.Write(ba);
69
+                }
61
             }
70
             }
62
-            return result;
63
         }
71
         }
64
     }
72
     }
65
 }
73
 }

+ 8 - 7
WorkerService1/WebApplication3/Clases/WellData.cs View File

30
         public string Bot { get; set; }
30
         public string Bot { get; set; }
31
         public string Top { get; set; }
31
         public string Top { get; set; }
32
         public int PumpPeriods { get; set; }
32
         public int PumpPeriods { get; set; }
33
+        
33
         public List<TimeSerieInterno> Rates { get; set; }
34
         public List<TimeSerieInterno> Rates { get; set; }
34
         
35
         
35
 
36
 
36
 
37
 
37
-        public Pozo ToPozo(uint acuifero)
38
+        public Pozo ToPozo(uint acuifero, uint simId)
38
         {
39
         {
39
             Pozo p = new Pozo();
40
             Pozo p = new Pozo();
40
-
41
             p.IdAquifero = acuifero;
41
             p.IdAquifero = acuifero;
42
-            p.IdSimulacion = null;
43
-            p.Longitud = this.X;
44
-            p.Latitud = this.Y;
42
+            p.IdSimulacion = simId;
43
+            p.X = this.X;
44
+            p.Y = this.Y;
45
             //p.Maximo = float.Parse(this.ZMax);
45
             //p.Maximo = float.Parse(this.ZMax);
46
-            p.Maximo = "0";
46
+            p.Maximo = ZMax;
47
             //p.Minimo = float.Parse(this.ZMin);
47
             //p.Minimo = float.Parse(this.ZMin);
48
-            p.Minimo = "0";
48
+            p.Minimo = ZMin;
49
             p.Nombre = this.WellName;
49
             p.Nombre = this.WellName;
50
+            p.Active = (this.ActiveFlag) ? (uint)1 : (uint)0;
50
             return p;
51
             return p;
51
         }
52
         }
52
 
53
 

+ 1 - 1
WorkerService1/WebApplication3/Clases/Worker.cs View File

42
                         proceso.Started = false;
42
                         proceso.Started = false;
43
                         proceso.Detected = true;
43
                         proceso.Detected = true;
44
 
44
 
45
-                        int terminado = await servicioController.setTerminado(proceso.GetPid());
45
+                        int terminado = await servicioController.SetTerminado(proceso.GetPid());
46
                         
46
                         
47
                         if( terminado > 0)
47
                         if( terminado > 0)
48
                         {
48
                         {

+ 12 - 7
WorkerService1/WebApplication3/Clases/ZoneData.cs View File

12
         public string Storage { get; set; }
12
         public string Storage { get; set; }
13
         public string ConstantHead { get; set; }
13
         public string ConstantHead { get; set; }
14
         public string Drains { get; set; }
14
         public string Drains { get; set; }
15
+        public string Wells { get; set; }
15
         public string Recharge { get; set; }
16
         public string Recharge { get; set; }
16
         public string Total { get; set; }
17
         public string Total { get; set; }
17
 
18
 
33
             Storage = dataIn.Storage;
34
             Storage = dataIn.Storage;
34
             ConstantHead = dataIn.ConstantHead;
35
             ConstantHead = dataIn.ConstantHead;
35
             Drains = dataIn.Drains;
36
             Drains = dataIn.Drains;
37
+            Wells = dataIn.Wells;
36
             Recharge = dataIn.Recharge;
38
             Recharge = dataIn.Recharge;
37
             Total = dataIn.Total;
39
             Total = dataIn.Total;
38
             ZoneConnections = new List<ZoneConnection>();
40
             ZoneConnections = new List<ZoneConnection>();
39
         }
41
         }
40
 
42
 
41
-        public ZoneData(DatosBalanceOut dataIn)
43
+        public ZoneData(DatosBalanceOut dataOut)
42
         {
44
         {
43
-            Id = dataIn.Id;
44
-            Storage = dataIn.Storage;
45
-            ConstantHead = dataIn.ConstantHead;
46
-            Drains = dataIn.Drains;
47
-            Recharge = dataIn.Recharge;
48
-            Total = dataIn.Total;
45
+            Id = dataOut.Id;
46
+            Storage = dataOut.Storage;
47
+            ConstantHead = dataOut.ConstantHead;
48
+            Drains = dataOut.Drains;
49
+            Wells = dataOut.Wells;
50
+            Recharge = dataOut.Recharge;
51
+            Total = dataOut.Total;
49
             ZoneConnections = new List<ZoneConnection>();
52
             ZoneConnections = new List<ZoneConnection>();
50
         }
53
         }
51
 
54
 
55
             datosIn.Storage = this.Storage;
58
             datosIn.Storage = this.Storage;
56
             datosIn.ConstantHead = this.ConstantHead;
59
             datosIn.ConstantHead = this.ConstantHead;
57
             datosIn.Drains = this.Drains;
60
             datosIn.Drains = this.Drains;
61
+            datosIn.Wells = this.Wells;
58
             datosIn.Recharge = this.Recharge;
62
             datosIn.Recharge = this.Recharge;
59
             datosIn.Total = this.Total;
63
             datosIn.Total = this.Total;
60
             datosIn.IdBalance = idBalance;
64
             datosIn.IdBalance = idBalance;
68
             datosOut.Storage = this.Storage;
72
             datosOut.Storage = this.Storage;
69
             datosOut.ConstantHead = this.ConstantHead;
73
             datosOut.ConstantHead = this.ConstantHead;
70
             datosOut.Drains = this.Drains;
74
             datosOut.Drains = this.Drains;
75
+            datosOut.Wells = this.Wells;
71
             datosOut.Recharge = this.Recharge;
76
             datosOut.Recharge = this.Recharge;
72
             datosOut.Total = this.Total;
77
             datosOut.Total = this.Total;
73
             datosOut.IdBalance = idBalance;
78
             datosOut.IdBalance = idBalance;

+ 72 - 50
WorkerService1/WebApplication3/Controllers/AcuiferoController.cs View File

38
 
38
 
39
         // GET: api/Acuifero/5
39
         // GET: api/Acuifero/5
40
         [HttpGet("{id}")]
40
         [HttpGet("{id}")]
41
+        [ProducesResponseType(200)]
42
+        [ProducesResponseType(404)]
41
         public async Task<ActionResult<Acuifero>> GetAcuifero(uint id)
43
         public async Task<ActionResult<Acuifero>> GetAcuifero(uint id)
42
         {
44
         {
43
             var acuifero = await _context.Acuiferos.FindAsync(id);
45
             var acuifero = await _context.Acuiferos.FindAsync(id);
50
             return acuifero;
52
             return acuifero;
51
         }
53
         }
52
 
54
 
53
-        [HttpGet("GeoRecharge/{id}")]
54
-        public async Task<bool> GetRechargeColorMap(uint id)
55
+        [HttpGet("ColorMap/{id}")]
56
+        public async Task<ActionResult<string>> GetRechargeColorMap(uint id)
55
         {
57
         {
56
             Acuifero aquifer = await _context.Acuiferos.FindAsync(id);
58
             Acuifero aquifer = await _context.Acuiferos.FindAsync(id);
57
 
59
 
58
-            return Utilities.String2Png(aquifer.RechargeGeometry);
59
-
60
+            return Ok(aquifer.RechargeColorMap);
60
         }
61
         }
61
 
62
 
62
         // PUT: api/Acuifero/5
63
         // PUT: api/Acuifero/5
63
         // To protect from overposting attacks, see https://go.microsoft.com/fwlink/?linkid=2123754
64
         // To protect from overposting attacks, see https://go.microsoft.com/fwlink/?linkid=2123754
64
         [HttpPut("{id}")]
65
         [HttpPut("{id}")]
66
+        [ProducesResponseType(200)]
67
+        [ProducesResponseType(400)]
68
+        [ProducesResponseType(404)]
65
         public async Task<IActionResult> PutAcuifero(uint id, [FromBody] DatosPostAcuifero datos)
69
         public async Task<IActionResult> PutAcuifero(uint id, [FromBody] DatosPostAcuifero datos)
66
         {
70
         {
67
 
71
 
99
                 await _context.SaveChangesAsync();
103
                 await _context.SaveChangesAsync();
100
                 Pozo[] pozos = pozoController.GetPozosAcuiferoSimulacionInicial(acuifero.Id);
104
                 Pozo[] pozos = pozoController.GetPozosAcuiferoSimulacionInicial(acuifero.Id);
101
                 Recarga[] recargas = recargaController.GetRecargasAcuiferoSimulacionInicial(acuifero.Id);
105
                 Recarga[] recargas = recargaController.GetRecargasAcuiferoSimulacionInicial(acuifero.Id);
106
+                uint simId = GetSimZeroId(acuifero.Id);
102
 
107
 
103
                 foreach (Pozo p in pozos)
108
                 foreach (Pozo p in pozos)
104
                 {
109
                 {
119
                 //3- Parseamos pozos
124
                 //3- Parseamos pozos
120
                 if (System.IO.File.Exists(pozoFile))
125
                 if (System.IO.File.Exists(pozoFile))
121
                 {
126
                 {
122
-                    await pozoController.ParseoFichero(acuifero.Id, pozoFile);
127
+                    await pozoController.ParseoFichero(acuifero.Id, pozoFile,simId);
123
                 }
128
                 }
124
                 //4- Parseamos recargas
129
                 //4- Parseamos recargas
125
                 if (System.IO.File.Exists(recargaFile))
130
                 if (System.IO.File.Exists(recargaFile))
126
                 {
131
                 {
127
-                    await recargaController.ParseoFichero(acuifero.Id, recargaFile);
132
+                    await recargaController.ParseoFichero(acuifero.Id, recargaFile,simId);
128
                 }
133
                 }
129
 
134
 
130
             }
135
             }
143
             return CreatedAtAction("GetAcuifero", new { id = acuifero.Id }, acuifero);
148
             return CreatedAtAction("GetAcuifero", new { id = acuifero.Id }, acuifero);
144
         }
149
         }
145
 
150
 
151
+        [NonAction]
152
+        public uint GetSimZeroId(uint aquiferId)
153
+        {
154
+            var sim = _context.Simulaciones.Where(x => x.IdAcuifero == aquiferId && x.SimulacionAcuifero == 0).First();
155
+
156
+            return sim.Id;
157
+        }
158
+
159
+        [HttpPost("TestBinary")]
160
+        public bool TestBinario([FromBody] DatosPostAcuifero datos)
161
+        {
162
+            string file = Constants.PathZip + "test.zip";
163
+            Utilities.BinaryToFile(datos.Fichero.Test, file);
164
+
165
+            if (System.IO.File.Exists(file)) 
166
+            {
167
+                return true;
168
+            }
169
+            else
170
+            {
171
+                return false;
172
+            }
173
+
174
+        }
146
         // POST: api/Acuifero
175
         // POST: api/Acuifero
147
         // To protect from overposting attacks, see https://go.microsoft.com/fwlink/?linkid=2123754
176
         // To protect from overposting attacks, see https://go.microsoft.com/fwlink/?linkid=2123754
148
         [HttpPost]
177
         [HttpPost]
178
+        [ProducesResponseType(201)]
179
+        [ProducesResponseType(409)]
149
         public async Task<ActionResult<Acuifero>> PostAcuifero([FromBody] DatosPostAcuifero datos)
180
         public async Task<ActionResult<Acuifero>> PostAcuifero([FromBody] DatosPostAcuifero datos)
150
         {
181
         {
151
-            Acuifero acuifero = new Acuifero();
182
+            Acuifero acuifero = new ();
152
             acuifero.Nombre = datos.Nombre;
183
             acuifero.Nombre = datos.Nombre;
153
-            string pathZip = @"C:\Users\Admin\Desktop\";
154
-            string pathExtract = @"C:\Users\Admin\Desktop\TestExtract\";
184
+            //string pathZip = @"C:\Users\Admin\Desktop\";
185
+            //string pathExtract = @"C:\Users\Admin\Desktop\TestExtract\";
155
             string pozoFile, recargaFile;
186
             string pozoFile, recargaFile;
156
             List<string> files;
187
             List<string> files;
157
             Parser parser = new();
188
             Parser parser = new();
158
 
189
 
159
-            try
160
-            {
161
-                byte[] tempBytes = Convert.FromBase64String(datos.Fichero.Base64);
162
-                System.IO.File.WriteAllBytes(pathZip + datos.Fichero.Nombre, tempBytes);
190
+            //try
191
+            //{
192
+            //    byte[] tempBytes = Convert.FromBase64String(datos.Fichero.Base64);
193
+            //    System.IO.File.WriteAllBytes(Constants.PathZip + datos.Fichero.Nombre, tempBytes);
163
 
194
 
164
-            }
165
-            catch (Exception ex)
166
-            {
167
-                return Problem(ex.Message);
168
-            }
195
+            //}
196
+            //catch (Exception ex)
197
+            //{
198
+            //    return Problem(ex.Message);
199
+            //}
169
 
200
 
170
             acuifero.Fichero = datos.Fichero.Nombre;
201
             acuifero.Fichero = datos.Fichero.Nombre;
171
 
202
 
174
 
205
 
175
                 //Como se crea el acuifero, no tiene simulacion 0, por lo que se insertan los datos de los pozos y recargas
206
                 //Como se crea el acuifero, no tiene simulacion 0, por lo que se insertan los datos de los pozos y recargas
176
                 //1- Descomprimimos el fichero zip
207
                 //1- Descomprimimos el fichero zip
177
-                ZipFile.ExtractToDirectory(pathZip + datos.Fichero.Nombre, pathExtract, true);
178
-                files = Directory.GetFiles(pathExtract).ToList<string>();
208
+                ZipFile.ExtractToDirectory(Constants.PathZip + datos.Fichero.Nombre, Constants.PathExtract, true);
209
+                files = Directory.GetFiles(Constants.PathExtract+datos.Nombre).ToList<string>();
179
                 //1.2 - Obtencion de coordenadas de origen (en el mundo) del modelo
210
                 //1.2 - Obtencion de coordenadas de origen (en el mundo) del modelo
180
                 string geoFile = files.Find(x => x.Contains(".vmf"));
211
                 string geoFile = files.Find(x => x.Contains(".vmf"));
212
+                Logger.WriteLog("geofile " + geoFile);
181
                 string world_origin_x, world_origin_y;
213
                 string world_origin_x, world_origin_y;
182
 
214
 
183
                 parser.GetGeolocalizationFromFile(geoFile, out world_origin_x, out world_origin_y);
215
                 parser.GetGeolocalizationFromFile(geoFile, out world_origin_x, out world_origin_y);
188
                 _context.Acuiferos.Add(acuifero);
220
                 _context.Acuiferos.Add(acuifero);
189
                 await _context.SaveChangesAsync();
221
                 await _context.SaveChangesAsync();
190
 
222
 
223
+                Simulacion sim = new ();
224
+                sim.IdAcuifero = acuifero.Id;
225
+                sim.Nombre = "Sim_0";
226
+                sim.SimulacionAcuifero = 0;
227
+                await PostSimulationZero(sim);
228
+
191
                 //2- Obtenemos nombre de los ficheros de pozos y recargas 
229
                 //2- Obtenemos nombre de los ficheros de pozos y recargas 
192
                 pozoFile = files.Find(x => x.Contains(".VMW"));
230
                 pozoFile = files.Find(x => x.Contains(".VMW"));
193
                 recargaFile = files.Find(x => x.Contains(".VMP"));
231
                 recargaFile = files.Find(x => x.Contains(".VMP"));
195
                 //3- Parseamos pozos
233
                 //3- Parseamos pozos
196
                 if (System.IO.File.Exists(pozoFile))
234
                 if (System.IO.File.Exists(pozoFile))
197
                 {
235
                 {
198
-                    await pozoController.ParseoFichero(acuifero.Id, pozoFile);
236
+                    await pozoController.ParseoFichero(acuifero.Id, pozoFile,sim.Id);
199
                 }
237
                 }
200
                 //4- Parseamos recargas
238
                 //4- Parseamos recargas
201
                 if (System.IO.File.Exists(recargaFile))
239
                 if (System.IO.File.Exists(recargaFile))
202
                 {
240
                 {
203
-                    await recargaController.ParseoFichero(acuifero.Id, recargaFile);
241
+                    await recargaController.ParseoFichero(acuifero.Id, recargaFile, sim.Id);
204
                 }
242
                 }
205
             }
243
             }
206
             catch (DbUpdateException)
244
             catch (DbUpdateException)
218
             return CreatedAtAction("GetAcuifero", new { id = acuifero.Id }, acuifero);
256
             return CreatedAtAction("GetAcuifero", new { id = acuifero.Id }, acuifero);
219
         }
257
         }
220
 
258
 
259
+        [NonAction]
260
+        public async Task<ActionResult<Simulacion>> PostSimulationZero(Simulacion simulacion)
261
+        {
262
+            _context.Simulaciones.Add(simulacion);
263
+            await _context.SaveChangesAsync();
264
+
265
+            return CreatedAtAction("GetSimulacion", new { id = simulacion.Id }, simulacion);
266
+        }
267
+
221
         // DELETE: api/Acuifero/5
268
         // DELETE: api/Acuifero/5
222
         [HttpDelete("{id}")]
269
         [HttpDelete("{id}")]
270
+        [ProducesResponseType(404)]
271
+        [ProducesResponseType(209)]
223
         public async Task<IActionResult> DeleteAcuifero(int id)
272
         public async Task<IActionResult> DeleteAcuifero(int id)
224
         {
273
         {
225
             var acuifero = await _context.Acuiferos.FindAsync(id);
274
             var acuifero = await _context.Acuiferos.FindAsync(id);
251
 
300
 
252
             return string.Empty;
301
             return string.Empty;
253
         }
302
         }
254
-
255
-        [NonAction]
256
-        public async Task<IActionResult> SetRechargeGeometry(uint id, string recharge_geometry)
257
-        {
258
-            Acuifero aquifer = _context.Acuiferos.Find(id);
259
-
260
-            aquifer.RechargeGeometry = recharge_geometry;
261
-
262
-            _context.Entry(aquifer).State = EntityState.Modified;
263
-
264
-            try
265
-            {
266
-                await _context.SaveChangesAsync();
267
-            }
268
-            catch (DbUpdateConcurrencyException)
269
-            {
270
-                if (!AcuiferoExists(id))
271
-                {
272
-                    return NotFound();
273
-                }
274
-                else
275
-                {
276
-                    throw;
277
-                }
278
-            }
279
-
280
-            return CreatedAtAction("GetAcuifero", new { id = aquifer.Id }, aquifer);
281
-        }
303
+        
282
     }
304
     }
283
 }
305
 }

+ 2 - 0
WorkerService1/WebApplication3/Controllers/BalanceHidricoController.cs View File

114
         // POST: api/TsPozo
114
         // POST: api/TsPozo
115
         // To protect from overposting attacks, see https://go.microsoft.com/fwlink/?linkid=2123754
115
         // To protect from overposting attacks, see https://go.microsoft.com/fwlink/?linkid=2123754
116
         [HttpPost]
116
         [HttpPost]
117
+        [ProducesResponseType(200)]
118
+        [ProducesResponseType(409)]
117
         public async Task<ActionResult<uint>> PostBalance(BalanceHidrico balance)
119
         public async Task<ActionResult<uint>> PostBalance(BalanceHidrico balance)
118
         {
120
         {
119
             _context.BalancesHidricos.Add(balance);
121
             _context.BalancesHidricos.Add(balance);

+ 13 - 6
WorkerService1/WebApplication3/Controllers/PiezometriaController.cs View File

10
 
10
 
11
 namespace WebApplication3.Controllers
11
 namespace WebApplication3.Controllers
12
 {
12
 {
13
-    [Route("api/[controller]")]
14
-    [ApiController]
13
+    //[Route("api/[controller]")]
14
+    //[ApiController]
15
+    [ApiExplorerSettings(IgnoreApi = true)]
15
     public class PiezometriaController : ControllerBase
16
     public class PiezometriaController : ControllerBase
16
     {
17
     {
17
         private readonly AquiferContext _context;
18
         private readonly AquiferContext _context;
34
 
35
 
35
         // GET: api/Pozo/5
36
         // GET: api/Pozo/5
36
         [HttpGet("{id}")]
37
         [HttpGet("{id}")]
38
+        [ProducesResponseType(200)]
39
+        [ProducesResponseType(404)]
37
         public async Task<ActionResult<Piezometria>> GetPozo(uint id)
40
         public async Task<ActionResult<Piezometria>> GetPozo(uint id)
38
         {            
41
         {            
39
             var piezometria = await _context.Piezometria.FindAsync(id);
42
             var piezometria = await _context.Piezometria.FindAsync(id);
89
         // POST: api/Pozo
92
         // POST: api/Pozo
90
         // To protect from overposting attacks, see https://go.microsoft.com/fwlink/?linkid=2123754
93
         // To protect from overposting attacks, see https://go.microsoft.com/fwlink/?linkid=2123754
91
         [HttpPost]
94
         [HttpPost]
95
+        [ProducesResponseType(200)]
96
+        [ProducesResponseType(409)]
92
         public async Task<ActionResult<Piezometria>> PostPiezometria(Piezometria piezometria)
97
         public async Task<ActionResult<Piezometria>> PostPiezometria(Piezometria piezometria)
93
         {
98
         {
94
             Logger.WriteLog("Se procede a guardar piezometria");
99
             Logger.WriteLog("Se procede a guardar piezometria");
113
                     throw;
118
                     throw;
114
                 }
119
                 }
115
             }
120
             }
116
-
117
-
118
-            return CreatedAtAction("GetPiezometria", new { id = piezometria.Id }, piezometria);
121
+            
122
+            return Ok(piezometria);
123
+            //return CreatedAtAction("GetPiezometria", new { id = piezometria.Id }, piezometria);
119
         }
124
         }
120
 
125
 
121
         // DELETE: api/Pozo/5
126
         // DELETE: api/Pozo/5
122
         [HttpDelete("{id}")]
127
         [HttpDelete("{id}")]
128
+        [ProducesResponseType(404)]
129
+        [ProducesResponseType(204)]
123
         public async Task<IActionResult> DeletePiezometria(uint id)
130
         public async Task<IActionResult> DeletePiezometria(uint id)
124
         {
131
         {
125
             var piezometria = await _context.Piezometria.FindAsync(id);
132
             var piezometria = await _context.Piezometria.FindAsync(id);
140
         }
147
         }
141
 
148
 
142
         [NonAction]
149
         [NonAction]
143
-        public void getDimensions(uint idSimulacion, out int rows, out int cols)
150
+        public void GetDimensions(uint idSimulacion, out int rows, out int cols)
144
         {
151
         {
145
             Piezometria piezometria = _context.Piezometria.Where(x => x.IdSimulacion == idSimulacion).FirstOrDefault();
152
             Piezometria piezometria = _context.Piezometria.Where(x => x.IdSimulacion == idSimulacion).FirstOrDefault();
146
             rows = piezometria.Rows;
153
             rows = piezometria.Rows;

+ 62 - 52
WorkerService1/WebApplication3/Controllers/PozoController.cs View File

27
 
27
 
28
         // GET: api/Pozo
28
         // GET: api/Pozo
29
         [HttpGet]
29
         [HttpGet]
30
-        public async Task<ActionResult<IEnumerable<Pozo>>> GetPozos()
30
+        
31
+        public async Task<ActionResult<IEnumerable<DatosPozoRecarga>>> GetPozos()
31
         {
32
         {
32
-            return await _context.Pozos.ToListAsync();
33
+            var pozos = await _context.Pozos.ToListAsync();
34
+            List<DatosPozoRecarga> result = new();
35
+
36
+            foreach(Pozo p in pozos)
37
+            {
38
+                DatosPozoRecarga datosPozo = new DatosPozoRecarga();
39
+                datosPozo.Id = p.Id;
40
+                datosPozo.Nombre = p.Nombre;
41
+                datosPozo.Latitud = p.Latitud;
42
+                datosPozo.Longitud = p.Longitud;
43
+                datosPozo.Maximo = p.Maximo;
44
+                datosPozo.Minimo = p.Minimo;
45
+                datosPozo.Simulacion = p.IdSimulacion;
46
+                datosPozo.Ts = _tsPozoController.GetTsPozo(p.Id);
47
+                result.Add(datosPozo);
48
+            }
49
+
50
+            return result;
33
         }
51
         }
34
 
52
 
35
         // GET: api/Pozo/5
53
         // GET: api/Pozo/5
36
         [HttpGet("{id}")]
54
         [HttpGet("{id}")]
55
+        [ProducesResponseType(200)]
56
+        [ProducesResponseType(404)]
37
         public async Task<ActionResult<DatosPozoRecarga>> GetPozo(uint id)
57
         public async Task<ActionResult<DatosPozoRecarga>> GetPozo(uint id)
38
         {            
58
         {            
39
             var pozo = await _context.Pozos.FindAsync(id);
59
             var pozo = await _context.Pozos.FindAsync(id);
57
             return datosPozo;
77
             return datosPozo;
58
         }
78
         }
59
 
79
 
80
+        [HttpGet("Simulacion/{id}")]
81
+        public async Task<ActionResult<IEnumerable<DatosPozoRecarga>>> GetPozosFromSimulation(uint id)
82
+        {
83
+            var pozos = await _context.Pozos.Where(x => x.IdSimulacion == id).ToListAsync();
84
+
85
+            List<DatosPozoRecarga> result = new();
86
+
87
+            foreach (Pozo p in pozos)
88
+            {
89
+                DatosPozoRecarga datosPozo = new DatosPozoRecarga();
90
+                datosPozo.Id = p.Id;
91
+                datosPozo.Nombre = p.Nombre;
92
+                datosPozo.Latitud = p.Latitud;
93
+                datosPozo.Longitud = p.Longitud;
94
+                datosPozo.Maximo = p.Maximo;
95
+                datosPozo.Minimo = p.Minimo;
96
+                datosPozo.Simulacion = p.IdSimulacion;
97
+                datosPozo.Ts = _tsPozoController.GetTsPozo(p.Id);
98
+                result.Add(datosPozo);
99
+            }
100
+
101
+            return result;
102
+
103
+        }
104
+
60
         // PUT: api/Pozo/5
105
         // PUT: api/Pozo/5
61
         // To protect from overposting attacks, see https://go.microsoft.com/fwlink/?linkid=2123754
106
         // To protect from overposting attacks, see https://go.microsoft.com/fwlink/?linkid=2123754
62
         [HttpPut("{id}")]
107
         [HttpPut("{id}")]
108
+        [ProducesResponseType(201)]
109
+        [ProducesResponseType(400)]
110
+        [ProducesResponseType(404)]
63
         public async Task<IActionResult> PutPozo(uint id, [FromBody] DatosPozoRecarga datos)
111
         public async Task<IActionResult> PutPozo(uint id, [FromBody] DatosPozoRecarga datos)
64
         {
112
         {
65
             Pozo pozo = _context.Pozos.Find(id);
113
             Pozo pozo = _context.Pozos.Find(id);
100
         // POST: api/Pozo
148
         // POST: api/Pozo
101
         // To protect from overposting attacks, see https://go.microsoft.com/fwlink/?linkid=2123754
149
         // To protect from overposting attacks, see https://go.microsoft.com/fwlink/?linkid=2123754
102
         [HttpPost]
150
         [HttpPost]
151
+        [ProducesResponseType(201)]
152
+        [ProducesResponseType(409)]
103
         public async Task<ActionResult<Pozo>> PostPozo([FromBody] DatosPozoRecarga datos)
153
         public async Task<ActionResult<Pozo>> PostPozo([FromBody] DatosPozoRecarga datos)
104
         {
154
         {
105
             Pozo pozo = new Pozo();
155
             Pozo pozo = new Pozo();
147
 
197
 
148
         // DELETE: api/Pozo/5
198
         // DELETE: api/Pozo/5
149
         [HttpDelete("{id}")]
199
         [HttpDelete("{id}")]
200
+        [ProducesResponseType(201)]
201
+        [ProducesResponseType(404)]
150
         public async Task<IActionResult> DeletePozo(uint id)
202
         public async Task<IActionResult> DeletePozo(uint id)
151
         {
203
         {
152
             var pozo = await _context.Pozos.FindAsync(id);
204
             var pozo = await _context.Pozos.FindAsync(id);
166
             return _context.Pozos.Any(e => e.Id == id);
218
             return _context.Pozos.Any(e => e.Id == id);
167
         }
219
         }
168
 
220
 
169
-        //api/Pozo/parsea/1
170
-        [HttpPost("Parsea/{acuifero}")]
171
-        public async Task<ActionResult<IEnumerable<Pozo>>> ParseoFicheroPostman(uint acuifero)
172
-        {
173
-            
174
-            Parser wellParser = new Parser();
175
-            string file = @"C:\Users\Admin\Desktop\ASD\infoPozos.VMW";
176
-            WellData[] wells =  wellParser.ParseWellData(file);
177
-
178
-            foreach(WellData w in wells)
179
-            {
180
-                Pozo pozo = w.ToPozo(acuifero);
181
-                _context.Pozos.Add(pozo);
182
-
183
-                try
184
-                {
185
-                    await _context.SaveChangesAsync();
186
-
187
-                    foreach (TimeSerieInterno ts in w.Rates)
188
-                    {
189
-                        TsPozo tsPozo = new TsPozo();
190
-                        tsPozo.IdPozo = pozo.Id;
191
-                        tsPozo.MarcaTiempo = ts.Hora;
192
-                        tsPozo.Valor = ts.Valor;
193
-
194
-                        await _tsPozoController.PostTsPozo(tsPozo);
195
-                    }
196
-
197
-                }
198
-                catch (DbUpdateException)
199
-                {
200
-                    if (PozoExists(pozo.Id))
201
-                    {
202
-                        return Conflict();
203
-                    }
204
-                    else
205
-                    {
206
-                        throw;
207
-                    }
208
-                }
209
-            }
210
-
211
-            return await _context.Pozos.ToListAsync();
212
-        }
213
-
214
         [NonAction]
221
         [NonAction]
215
-        public async Task<ActionResult<IEnumerable<Pozo>>> ParseoFichero(uint acuifero, string file)
222
+        public async Task<ActionResult<IEnumerable<Pozo>>> ParseoFichero(uint acuifero, string file,uint simId)
216
         {
223
         {
217
             var s = acuifero;
224
             var s = acuifero;
218
             Parser wellParser = new Parser();
225
             Parser wellParser = new Parser();
221
 
228
 
222
             foreach (WellData w in wells)
229
             foreach (WellData w in wells)
223
             {
230
             {
224
-                Pozo pozo = w.ToPozo(acuifero);
231
+                Pozo pozo = w.ToPozo(acuifero, simId);
225
                 _context.Pozos.Add(pozo);
232
                 _context.Pozos.Add(pozo);
226
 
233
 
227
                 try
234
                 try
233
                         TsPozo tsPozo = new TsPozo();
240
                         TsPozo tsPozo = new TsPozo();
234
                         tsPozo.IdPozo = pozo.Id;
241
                         tsPozo.IdPozo = pozo.Id;
235
                         tsPozo.MarcaTiempo = ts.Hora;
242
                         tsPozo.MarcaTiempo = ts.Hora;
243
+                        tsPozo.MarcaTiempoEnd = ts.HoraEnd;
236
                         tsPozo.Valor = ts.Valor;
244
                         tsPozo.Valor = ts.Valor;
237
                         tsPozo.InfoComplementaria = ts.Info;
245
                         tsPozo.InfoComplementaria = ts.Info;
238
 
246
 
257
         }
265
         }
258
 
266
 
259
         [NonAction]
267
         [NonAction]
260
-        public async Task<ActionResult<IEnumerable<Pozo>>> PostMultipleWells(uint aquiferId,WellData[] wellDatas)
268
+        public async Task<ActionResult<IEnumerable<Pozo>>> PostMultipleWells(uint aquiferId,WellData[] wellDatas, uint simulationId)
261
         {
269
         {
262
             foreach (WellData w in wellDatas)
270
             foreach (WellData w in wellDatas)
263
             {
271
             {
264
-                Pozo pozo = w.ToPozo(aquiferId);
272
+                Pozo pozo = w.ToPozo(aquiferId, simulationId);
265
                 _context.Pozos.Add(pozo);
273
                 _context.Pozos.Add(pozo);
266
 
274
 
267
                 try
275
                 try
312
         public async void SetPozosSimulacion(uint? acuiferoId, uint? simulacionId)
320
         public async void SetPozosSimulacion(uint? acuiferoId, uint? simulacionId)
313
         {
321
         {
314
             //Obtenemos los pozos del acuifero
322
             //Obtenemos los pozos del acuifero
315
-            Pozo[] pozos = _context.Pozos.Where(x => x.IdAquifero == acuiferoId).ToArray<Pozo>();
323
+            Pozo[] pozos = _context.Pozos.Where(x => x.IdAquifero == acuiferoId && x.IdSimulacion == null).ToArray<Pozo>();
316
 
324
 
317
             foreach(Pozo p in pozos)
325
             foreach(Pozo p in pozos)
318
             {
326
             {
321
                 _context.Pozos.Add(pozo);
329
                 _context.Pozos.Add(pozo);
322
             }
330
             }
323
             await _context.SaveChangesAsync();
331
             await _context.SaveChangesAsync();
332
+
333
+
324
         }
334
         }
325
 
335
 
326
         [NonAction]
336
         [NonAction]

+ 99 - 10
WorkerService1/WebApplication3/Controllers/RecargasController.cs View File

27
 
27
 
28
         // GET: api/Recargas
28
         // GET: api/Recargas
29
         [HttpGet]
29
         [HttpGet]
30
-        public async Task<ActionResult<IEnumerable<Recarga>>> GetRecargas()
30
+        public async Task<ActionResult<IEnumerable<DatosPozoRecarga>>> GetRecargas()
31
         {
31
         {
32
-            return await _context.Recargas.ToListAsync();
32
+            var recargas =  await _context.Recargas.ToListAsync();
33
+            List<DatosPozoRecarga> result = new();
34
+
35
+            foreach(Recarga r in recargas)
36
+            {
37
+                DatosPozoRecarga datosRecarga = new();
38
+                datosRecarga.Id = r.Id;
39
+                datosRecarga.Nombre = r.Nombre;
40
+                datosRecarga.Latitud = r.Latitud;
41
+                datosRecarga.Longitud = r.Longitud;
42
+                datosRecarga.Simulacion = r.IdSimulacion;
43
+                datosRecarga.Ts = tsRecargaController.GetTsRecarga(r.Id);
44
+                result.Add(datosRecarga);
45
+            }
46
+
47
+            return result;
33
         }
48
         }
34
 
49
 
35
         // GET: api/Recargas/5
50
         // GET: api/Recargas/5
36
         [HttpGet("{id}")]
51
         [HttpGet("{id}")]
52
+        [ProducesResponseType(200)]
53
+        [ProducesResponseType(404)]
37
         public async Task<ActionResult<DatosPozoRecarga>> GetRecarga(uint id)
54
         public async Task<ActionResult<DatosPozoRecarga>> GetRecarga(uint id)
38
         {
55
         {
39
             var recarga = await _context.Recargas.FindAsync(id);
56
             var recarga = await _context.Recargas.FindAsync(id);
57
         }
74
         }
58
 
75
 
59
         // PUT: api/Recargas/5
76
         // PUT: api/Recargas/5
60
-        // To protect from overposting attacks, see https://go.microsoft.com/fwlink/?linkid=2123754
61
         [HttpPut("{id}")]
77
         [HttpPut("{id}")]
78
+        [ProducesResponseType(201)]
79
+        [ProducesResponseType(400)]
80
+        [ProducesResponseType(404)]
62
         public async Task<IActionResult> PutRecarga(uint id, [FromBody] DatosPozoRecarga datos)
81
         public async Task<IActionResult> PutRecarga(uint id, [FromBody] DatosPozoRecarga datos)
63
         {
82
         {
64
             Recarga recarga = _context.Recargas.Find(id);
83
             Recarga recarga = _context.Recargas.Find(id);
99
         }
118
         }
100
 
119
 
101
         // POST: api/Recargas
120
         // POST: api/Recargas
102
-        // To protect from overposting attacks, see https://go.microsoft.com/fwlink/?linkid=2123754
103
         [HttpPost]
121
         [HttpPost]
122
+        [ProducesResponseType(201)]
123
+        [ProducesResponseType(409)]
104
         public async Task<ActionResult<Recarga>> PostRecarga([FromBody] DatosPozoRecarga datos)
124
         public async Task<ActionResult<Recarga>> PostRecarga([FromBody] DatosPozoRecarga datos)
105
         {
125
         {
106
             Recarga recarga = new Recarga();
126
             Recarga recarga = new Recarga();
164
         [NonAction]
184
         [NonAction]
165
         public async void SetRecargasSimulacion(uint? acuiferoId, uint? simulacionId)
185
         public async void SetRecargasSimulacion(uint? acuiferoId, uint? simulacionId)
166
         {
186
         {
167
-            Recarga[] recargas = _context.Recargas.Where(x => x.IdAcuifero == acuiferoId).ToArray<Recarga>();
187
+            Recarga[] recargas = _context.Recargas.Where(x => x.IdAcuifero == acuiferoId && x.IdSimulacion == null).ToArray<Recarga>();
168
 
188
 
169
             foreach (Recarga r in recargas)
189
             foreach (Recarga r in recargas)
170
             {
190
             {
204
         }
224
         }
205
 
225
 
206
         [NonAction]
226
         [NonAction]
207
-        public async Task<ActionResult<IEnumerable<Recarga>>> ParseoFichero(uint aquifer, string file)
227
+        public async Task<ActionResult<IEnumerable<Recarga>>> ParseoFichero(uint aquifer, string file, uint simId)
208
         {
228
         {
209
             Parser parser = new Parser();
229
             Parser parser = new Parser();
210
             //string file = @"C:\Users\Admin\Desktop\ASD\infoPozos.VMW";
230
             //string file = @"C:\Users\Admin\Desktop\ASD\infoPozos.VMW";
211
             RechargeData[] recharges = parser.ParseRechargeData(file, out string recharge_geometry);
231
             RechargeData[] recharges = parser.ParseRechargeData(file, out string recharge_geometry);
212
-            //await aquiferController.SetRechargeGeometry(aquifer, recharge_geometry);
213
-            return await PostMultipleRecharges(aquifer,recharges);
232
+            await SetRechargeGeometry(aquifer, recharge_geometry);
233
+
234
+            string fileName = Utilities.String2Png(recharge_geometry);
235
+
236
+            Byte[] bytes = System.IO.File.ReadAllBytes(fileName);
237
+            String base64Image = Convert.ToBase64String(bytes);
238
+
239
+            await SetRechargeMapColor(aquifer, base64Image);
240
+
241
+            return await PostMultipleRecharges(aquifer,recharges,simId);
242
+        }
243
+
244
+        [NonAction]
245
+        public async Task<Acuifero> SetRechargeGeometry(uint id, string recharge_geometry)
246
+        {
247
+            Acuifero aquifer = _context.Acuiferos.Find(id);
248
+
249
+            aquifer.RechargeGeometry = recharge_geometry;
250
+
251
+            _context.Entry(aquifer).State = EntityState.Modified;
252
+
253
+            try
254
+            {
255
+                await _context.SaveChangesAsync();
256
+            }
257
+            catch (DbUpdateConcurrencyException)
258
+            {
259
+                if (!AcuiferoExists(id))
260
+                {
261
+                    return null;
262
+                }
263
+                else
264
+                {
265
+                    throw;
266
+                }
267
+            }
268
+
269
+            return aquifer;
270
+        }
271
+
272
+        [NonAction]
273
+        public async Task<bool> SetRechargeMapColor(uint id, string base64)
274
+        {
275
+            Acuifero aquifer = _context.Acuiferos.Find(id);
276
+
277
+            aquifer.RechargeColorMap = base64;
278
+
279
+            _context.Entry(aquifer).State = EntityState.Modified;
280
+
281
+            try
282
+            {
283
+                await _context.SaveChangesAsync();
284
+            }
285
+            catch (DbUpdateConcurrencyException)
286
+            {
287
+                if (!AcuiferoExists(id))
288
+                {
289
+                    return false;
290
+                }
291
+                else
292
+                {
293
+                    throw;
294
+                }
295
+            }
296
+            return true;
297
+        }
298
+
299
+        private bool AcuiferoExists(uint id)
300
+        {
301
+            return _context.Acuiferos.Any(e => e.Id == id);
214
         }
302
         }
215
 
303
 
216
         [NonAction]
304
         [NonAction]
217
-        public async Task<ActionResult<IEnumerable<Recarga>>> PostMultipleRecharges(uint aquifer, RechargeData[] recharges)
305
+        public async Task<ActionResult<IEnumerable<Recarga>>> PostMultipleRecharges(uint aquifer, RechargeData[] recharges, uint simId)
218
         {
306
         {
219
             foreach (RechargeData r in recharges)
307
             foreach (RechargeData r in recharges)
220
             {
308
             {
221
-                Recarga recarga = r.ToRecarga(aquifer);
309
+                Recarga recarga = r.ToRecarga(aquifer,simId);
222
                 _context.Recargas.Add(recarga);
310
                 _context.Recargas.Add(recarga);
223
 
311
 
224
                 try
312
                 try
231
                         TsRecarga tsRecarga = new(); 
319
                         TsRecarga tsRecarga = new(); 
232
                         tsRecarga.IdRecarga = recarga.Id;
320
                         tsRecarga.IdRecarga = recarga.Id;
233
                         tsRecarga.MarcaTiempo = ts.Hora;
321
                         tsRecarga.MarcaTiempo = ts.Hora;
322
+                        tsRecarga.MarcaTiempoEnd = ts.HoraEnd;
234
                         tsRecarga.Valor = ts.Valor;
323
                         tsRecarga.Valor = ts.Valor;
235
 
324
 
236
                         await tsRecargaController.PostTsRecarga(tsRecarga);
325
                         await tsRecargaController.PostTsRecarga(tsRecarga);

+ 3 - 2
WorkerService1/WebApplication3/Controllers/ServiceQueueController.cs View File

10
 
10
 
11
 namespace WebApplication3.Controllers
11
 namespace WebApplication3.Controllers
12
 {
12
 {
13
-    [Route("api/queue")]
14
-    [ApiController]
13
+    //[Route("api/queue")]
14
+    //[ApiController]
15
+    [ApiExplorerSettings(IgnoreApi = true)]
15
     public class ServiceQueueController : ControllerBase
16
     public class ServiceQueueController : ControllerBase
16
     {
17
     {
17
         private readonly AquiferContext _context;
18
         private readonly AquiferContext _context;

+ 63 - 44
WorkerService1/WebApplication3/Controllers/ServicioController.cs View File

11
 
11
 
12
 namespace WebApplication3.Controllers
12
 namespace WebApplication3.Controllers
13
 {
13
 {
14
-    [Route("api/servicio")]
15
-    [ApiController]
14
+    //[Route("api/servicio")]
15
+    //[ApiController]
16
+    [ApiExplorerSettings(IgnoreApi = true)]
16
     public class ServicioController : ControllerBase
17
     public class ServicioController : ControllerBase
17
     {
18
     {
18
         private readonly AquiferContext _context;
19
         private readonly AquiferContext _context;
117
         }
118
         }
118
 
119
 
119
         // GET: api/Servicio/simula
120
         // GET: api/Servicio/simula
120
-        [HttpGet("simularest")]
121
-        public Task<ActionResult<Servicio>> SimulaRest()
122
-        {
123
-            string respuesta = "";
124
-
125
-            Proceso proceso = Proceso.GetInstance();
126
-            proceso.setParametersModflow(@"C:\Users\Admin\Desktop\TestExtract\simulaicionsimulacion_test", "AA.modflow.in");
127
-            try
128
-            {
129
-                if (!proceso.Started)
130
-                {
131
-                    proceso.Start();
132
-                    respuesta = "Id: " + proceso.GetPid();
133
-                    Servicio s = new Servicio();
134
-                    s.Id = GetLastId() + 1;
135
-                    s.Pid = (uint)proceso.GetPid();
136
-                    s.Terminado = 0;
137
-                    return PostServicio(s);
138
-                }
139
-            }
140
-            catch (Exception ex)
141
-            {
142
-                respuesta = ex.Message;
143
-                throw;
144
-            }
145
-
146
-
147
-            return null;
148
-
149
-        }
121
+        //[HttpGet("simularest")]
122
+        //public Task<ActionResult<Servicio>> SimulaRest()
123
+        //{
124
+        //    string respuesta = "";
125
+
126
+        //    Proceso proceso = Proceso.GetInstance();
127
+        //    proceso.setParametersModflow(@"C:\Users\Admin\Desktop\TestExtract\simulaicionsimulacion_test", "AA.modflow.in");
128
+        //    try
129
+        //    {
130
+        //        if (!proceso.Started)
131
+        //        {
132
+        //            proceso.Start();
133
+        //            respuesta = "Id: " + proceso.GetPid();
134
+        //            Servicio s = new Servicio();
135
+        //            s.Id = GetLastId() + 1;
136
+        //            s.Pid = (uint)proceso.GetPid();
137
+        //            s.Terminado = 0;
138
+        //            return PostServicio(s);
139
+        //        }
140
+        //    }
141
+        //    catch (Exception ex)
142
+        //    {
143
+        //        respuesta = ex.Message;
144
+        //        throw;
145
+        //    }
146
+
147
+
148
+        //    return null;
149
+
150
+        //}
150
 
151
 
151
         [NonAction]
152
         [NonAction]
152
         public async Task<ActionResult<Servicio>> SimulaModflow(string workingDirectory, string arguments)
153
         public async Task<ActionResult<Servicio>> SimulaModflow(string workingDirectory, string arguments)
154
             string respuesta = "";
155
             string respuesta = "";
155
 
156
 
156
             Proceso proceso = Proceso.GetInstance();
157
             Proceso proceso = Proceso.GetInstance();
157
-            Logger logger = Logger.GetInstance();
158
             proceso.ResetProcess();
158
             proceso.ResetProcess();
159
             proceso.setParametersModflow(workingDirectory, arguments);
159
             proceso.setParametersModflow(workingDirectory, arguments);
160
 
160
 
164
                 {
164
                 {
165
                     proceso.Start();
165
                     proceso.Start();
166
                     respuesta = "Id: " + proceso.GetPid();
166
                     respuesta = "Id: " + proceso.GetPid();
167
-                    Servicio s = new Servicio();
167
+                    Servicio s = new ();
168
                     s.Id = GetLastId() + 1;
168
                     s.Id = GetLastId() + 1;
169
                     s.Pid = (uint)proceso.GetPid();
169
                     s.Pid = (uint)proceso.GetPid();
170
                     s.Terminado = 0;
170
                     s.Terminado = 0;
191
         public async Task<ActionResult<Servicio>> SimulaZoneBudget(string workingDirectory, string budgetFile, string zoneFile)
191
         public async Task<ActionResult<Servicio>> SimulaZoneBudget(string workingDirectory, string budgetFile, string zoneFile)
192
         {
192
         {
193
             string respuesta = "";
193
             string respuesta = "";
194
-            Logger logger = Logger.GetInstance();
194
+            
195
             Logger.WriteLog("working directory: " + workingDirectory + " | budgetFile: " + budgetFile + " | zoneFile: " + zoneFile);
195
             Logger.WriteLog("working directory: " + workingDirectory + " | budgetFile: " + budgetFile + " | zoneFile: " + zoneFile);
196
             Proceso proceso = Proceso.GetInstance();
196
             Proceso proceso = Proceso.GetInstance();
197
             proceso.ResetProcess();
197
             proceso.ResetProcess();
203
                 {
203
                 {
204
                     proceso.Start();
204
                     proceso.Start();
205
                     respuesta = "Id: " + proceso.GetPid();
205
                     respuesta = "Id: " + proceso.GetPid();
206
-                    Servicio s = new Servicio();
206
+                    Servicio s = new ();
207
                     s.Id = GetLastId() + 1;
207
                     s.Id = GetLastId() + 1;
208
                     s.Pid = (uint)proceso.GetPid();
208
                     s.Pid = (uint)proceso.GetPid();
209
                     s.Terminado = 0;
209
                     s.Terminado = 0;
231
         [NonAction]
231
         [NonAction]
232
         public async Task<ActionResult<Servicio>> GetIsolinesWithPython(string workingDirectory,string headFile, int rows, int cols)
232
         public async Task<ActionResult<Servicio>> GetIsolinesWithPython(string workingDirectory,string headFile, int rows, int cols)
233
         {
233
         {
234
-            Logger logger = Logger.GetInstance();
234
+            
235
             Proceso proceso = Proceso.GetInstance();
235
             Proceso proceso = Proceso.GetInstance();
236
             int isolines = 30;
236
             int isolines = 30;
237
             proceso.ResetProcess();
237
             proceso.ResetProcess();
238
             proceso.setParametersPython(workingDirectory,headFile,rows,cols,isolines);
238
             proceso.setParametersPython(workingDirectory,headFile,rows,cols,isolines);
239
             proceso.Start();
239
             proceso.Start();
240
-            Servicio s = new Servicio();
240
+            Servicio s = new ();
241
             s.Id = GetLastId() + 1;
241
             s.Id = GetLastId() + 1;
242
             s.Pid = (uint)proceso.GetPid();
242
             s.Pid = (uint)proceso.GetPid();
243
             s.Terminado = 0;
243
             s.Terminado = 0;
248
             return postServicio;
248
             return postServicio;
249
         }
249
         }
250
 
250
 
251
+        [NonAction]
252
+        public async Task<ActionResult<Servicio>> GetGeoJsonFromSVG(string workingDirectory, string headFile)
253
+        {
254
+            Proceso proceso = Proceso.GetInstance();
255
+            proceso.ResetProcess();
256
+            proceso.SetParametersSVG2Json(workingDirectory, headFile);
257
+            proceso.Start();
258
+            Servicio s = new ();
259
+            s.Id = GetLastId() + 1;
260
+            s.Pid = (uint)proceso.GetPid();
261
+            s.Terminado = 0;
262
+            s.Inicio = DateTime.Now.ToString();
263
+            s.Tipo = "SVG2GEOJSON";
264
+            var postServicio = await PostServicio(s); ;
265
+            proceso.WaitForExit();
266
+            return postServicio;
267
+        }
268
+
251
         // GET: api/Servicio/stopped
269
         // GET: api/Servicio/stopped
252
         [HttpGet("stopped")]
270
         [HttpGet("stopped")]
253
         public bool HasStopped()
271
         public bool HasStopped()
267
         [HttpGet("lastid")]
285
         [HttpGet("lastid")]
268
         public uint GetLastId()
286
         public uint GetLastId()
269
         {
287
         {
270
-            if(_context.Servicios.Count() == 0)
288
+            if(!_context.Servicios.Any())
271
             {
289
             {
272
                 return 0;
290
                 return 0;
273
             }
291
             }
285
         }
303
         }
286
 
304
 
287
         [NonAction]
305
         [NonAction]
288
-        public async Task<int> setTerminado(int pid)
306
+        public async Task<int> SetTerminado(int pid)
289
         {
307
         {
290
-
291
-            Servicio servicio = _context.Servicios.FromSqlRaw("SELECT * FROM servicio WHERE pid = {0} ORDER BY id DESC", pid).First();
308
+            Servicio servicio = _context.Servicios.Where(x => x.Pid == pid).OrderByDescending(x => x.Id).First(); ;
309
+            //Servicio servicio = _context.Servicios.FromSqlRaw("SELECT * FROM servicio WHERE pid = {0} ORDER BY id DESC", pid).First();
292
 
310
 
293
             servicio.Terminado = 1;
311
             servicio.Terminado = 1;
294
             servicio.Fin = DateTime.Now.ToString();
312
             servicio.Fin = DateTime.Now.ToString();
298
             {
316
             {
299
                 result = await _context.SaveChangesAsync();
317
                 result = await _context.SaveChangesAsync();
300
             }
318
             }
301
-            catch (DbUpdateConcurrencyException)
319
+            catch (DbUpdateConcurrencyException ex)
302
             {
320
             {
303
-                
321
+                Logger.WriteLog(ex.Message);
322
+                Logger.WriteLog(ex.InnerException.Message);
304
             }
323
             }
305
 
324
 
306
             Logger.WriteLog("TERMINADO " + pid);
325
             Logger.WriteLog("TERMINADO " + pid);

+ 138 - 81
WorkerService1/WebApplication3/Controllers/SimulacionController.cs View File

20
     {
20
     {
21
         
21
         
22
         private readonly AquiferContext _context;
22
         private readonly AquiferContext _context;
23
-        private PozoController pozoController;
24
-        private RecargasController recargasController;
25
-        private AcuiferoController acuiferoController;
26
-        private ServicioController serviceController;
27
-        private BalanceHidricoController balanceHidricoController;
28
-        private PiezometriaController piezometriaController;
29
-        private ServiceQueueController serviceQueueController;
23
+        private readonly PozoController pozoController;
24
+        private readonly RecargasController recargasController;
25
+        private readonly AcuiferoController acuiferoController;
26
+        private readonly ServicioController serviceController;
27
+        private readonly BalanceHidricoController balanceHidricoController;
28
+        private readonly PiezometriaController piezometriaController;
29
+        private readonly ServiceQueueController serviceQueueController;
30
 
30
 
31
         public SimulacionController(AquiferContext context)
31
         public SimulacionController(AquiferContext context)
32
         {
32
         {
49
 
49
 
50
         // GET: api/Simulacion/5
50
         // GET: api/Simulacion/5
51
         [HttpGet("{id}")]
51
         [HttpGet("{id}")]
52
+        [ProducesResponseType(200)]
53
+        [ProducesResponseType(404)]
52
         public async Task<ActionResult<Simulacion>> GetSimulacion(uint id)
54
         public async Task<ActionResult<Simulacion>> GetSimulacion(uint id)
53
         {
55
         {
54
             var simulacion = await _context.Simulaciones.FindAsync(id);
56
             var simulacion = await _context.Simulaciones.FindAsync(id);
64
         // POST: api/Simulacion
66
         // POST: api/Simulacion
65
         // To protect from overposting attacks, see https://go.microsoft.com/fwlink/?linkid=2123754
67
         // To protect from overposting attacks, see https://go.microsoft.com/fwlink/?linkid=2123754
66
         [HttpPost]
68
         [HttpPost]
69
+        [ProducesResponseType(201)]
67
         public async Task<ActionResult<Simulacion>> PostSimulacion(Simulacion simulacion)
70
         public async Task<ActionResult<Simulacion>> PostSimulacion(Simulacion simulacion)
68
         {
71
         {
69
             _context.Simulaciones.Add(simulacion);
72
             _context.Simulaciones.Add(simulacion);
77
         }
80
         }
78
 
81
 
79
         [HttpPost("Simula/{simulacionId}")]
82
         [HttpPost("Simula/{simulacionId}")]
83
+        [ProducesResponseType(200)]
84
+
80
         public async Task<bool> QueueSim(uint simulacionId)
85
         public async Task<bool> QueueSim(uint simulacionId)
81
         {
86
         {
82
             Simulacion simulacion = _context.Simulaciones.Find(simulacionId);
87
             Simulacion simulacion = _context.Simulaciones.Find(simulacionId);
83
 
88
 
84
-            ServiceQueue serviceQueue = new ServiceQueue();
89
+            ServiceQueue serviceQueue = new ();
85
             serviceQueue.IdSimulacion = simulacionId;
90
             serviceQueue.IdSimulacion = simulacionId;
86
             serviceQueue.IdAcuifero = simulacion.IdAcuifero;
91
             serviceQueue.IdAcuifero = simulacion.IdAcuifero;
87
 
92
 
90
             return true;
95
             return true;
91
         }
96
         }
92
 
97
 
93
-        [HttpPut("UpdateSimWellData")]
98
+        [HttpPut("{simulationId}/UpdateSimWellData")]
99
+        [ProducesResponseType(200)]
100
+
94
         public async Task<ActionResult<bool>> UpdateSimWellsFromCsv(uint simulationId, [FromBody] DatosPostSimulacion data)
101
         public async Task<ActionResult<bool>> UpdateSimWellsFromCsv(uint simulationId, [FromBody] DatosPostSimulacion data)
95
         {
102
         {
96
             bool result = true;
103
             bool result = true;
114
 
121
 
115
             WellData[] wellDatas = parser.parseWellCSV(file);
122
             WellData[] wellDatas = parser.parseWellCSV(file);
116
 
123
 
117
-            await pozoController.PostMultipleWells((uint)sim.IdAcuifero,wellDatas);
124
+            await pozoController.PostMultipleWells((uint)sim.IdAcuifero,wellDatas, simulationId);
118
 
125
 
119
             return result;
126
             return result;
120
         }
127
         }
121
 
128
 
122
-        [HttpPut]
129
+        [HttpPut("{simulationId}/UpdateRechargeWellData")]
130
+        [ProducesResponseType(200)]
131
+
123
         public async Task<ActionResult<bool>> UpdateSimRechargesFromCsv(uint simulationId, [FromBody] DatosPostSimulacion data)
132
         public async Task<ActionResult<bool>> UpdateSimRechargesFromCsv(uint simulationId, [FromBody] DatosPostSimulacion data)
124
         {
133
         {
125
             bool result = true;
134
             bool result = true;
144
             RechargeData[] rechargeDatas = parser.parseRechargeCSV(file);
153
             RechargeData[] rechargeDatas = parser.parseRechargeCSV(file);
145
 
154
 
146
             
155
             
147
-            await recargasController.PostMultipleRecharges((uint)sim.IdAcuifero, rechargeDatas);
156
+            await recargasController.PostMultipleRecharges((uint)sim.IdAcuifero, rechargeDatas,sim.Id);
148
 
157
 
149
             return result;
158
             return result;
150
         }
159
         }
151
 
160
 
152
         // PUT: api/Simulacion/5
161
         // PUT: api/Simulacion/5
153
-        // To protect from overposting attacks, see https://go.microsoft.com/fwlink/?linkid=2123754s
154
         [HttpPut("{id}")]
162
         [HttpPut("{id}")]
163
+        [ProducesResponseType(201)]
164
+        [ProducesResponseType(400)]
165
+        [ProducesResponseType(404)]
166
+
155
         public async Task<IActionResult> PutSimulacion(uint id, [FromBody] DatosPostSimulacion datos)
167
         public async Task<IActionResult> PutSimulacion(uint id, [FromBody] DatosPostSimulacion datos)
156
         {
168
         {
157
             Simulacion simulacion = _context.Simulaciones.Find(id);
169
             Simulacion simulacion = _context.Simulaciones.Find(id);
187
 
199
 
188
         // DELETE: api/Simulacion/5
200
         // DELETE: api/Simulacion/5
189
         [HttpDelete("{id}")]
201
         [HttpDelete("{id}")]
202
+        [ProducesResponseType(209)]
190
         public async Task<IActionResult> DeleteSimulacion(uint id)
203
         public async Task<IActionResult> DeleteSimulacion(uint id)
191
         {
204
         {
192
             var simulacion = await _context.Simulaciones.FindAsync(id);
205
             var simulacion = await _context.Simulaciones.FindAsync(id);
204
         [NonAction]
217
         [NonAction]
205
         public async Task<bool> SimulaAsync(ServiceQueue serviceQueue)
218
         public async Task<bool> SimulaAsync(ServiceQueue serviceQueue)
206
         {
219
         {
207
-            Logger logger = Logger.GetInstance();
208
             await serviceQueueController.SetCorriendo(serviceQueue.Id);
220
             await serviceQueueController.SetCorriendo(serviceQueue.Id);
209
 
221
 
210
             uint simulacionId = (uint)serviceQueue.IdSimulacion;
222
             uint simulacionId = (uint)serviceQueue.IdSimulacion;
215
             Logger.WriteLog("estoy simulando");
227
             Logger.WriteLog("estoy simulando");
216
             if (zip != string.Empty)
228
             if (zip != string.Empty)
217
             {
229
             {
218
-                Parser parser = new Parser();
219
-                string zip_name = "simulaicion" + simulacion.Nombre;
230
+                Parser parser = new ();
231
+                string zip_name = "simulacion" + simulacion.Nombre;
220
                 string zip_copy = zip_name + ".zip";
232
                 string zip_copy = zip_name + ".zip";
221
                 System.IO.File.Copy(Constants.PathZip + zip, Constants.PathZip + zip_copy, true);
233
                 System.IO.File.Copy(Constants.PathZip + zip, Constants.PathZip + zip_copy, true);
222
 
234
 
225
                 Directory.CreateDirectory(workingDirectory);
237
                 Directory.CreateDirectory(workingDirectory);
226
                 ZipFile.ExtractToDirectory(Constants.PathZip + zip_copy, workingDirectory, true);
238
                 ZipFile.ExtractToDirectory(Constants.PathZip + zip_copy, workingDirectory, true);
227
 
239
 
240
+                workingDirectory += zip.Replace(".zip", "\\");
228
                 //Obtenemos fichero de pozo y recargas
241
                 //Obtenemos fichero de pozo y recargas
229
                 List<string> files = Directory.GetFiles(workingDirectory).ToList<string>();
242
                 List<string> files = Directory.GetFiles(workingDirectory).ToList<string>();
230
 
243
 
233
                 string inFile = files.Find(x => x.Contains(".MODFLOW.IN") || x.Contains(".modflow.in"));
246
                 string inFile = files.Find(x => x.Contains(".MODFLOW.IN") || x.Contains(".modflow.in"));
234
                 string zoneFile = files.Find(x => x.Contains(".ZBI") || x.Contains(".zbi"));
247
                 string zoneFile = files.Find(x => x.Contains(".ZBI") || x.Contains(".zbi"));
235
 
248
 
249
+                Logger.WriteLog("ficheros clave buscados");
250
+
236
                 //3- Parseamos pozos
251
                 //3- Parseamos pozos
237
                 if (System.IO.File.Exists(pozoFile))
252
                 if (System.IO.File.Exists(pozoFile))
238
                 {
253
                 {
254
+                    Logger.WriteLog("vamos con los pozos");
239
                     List<WellData> infoPozosFichero = parser.ParseWellData(pozoFile).ToList<WellData>();
255
                     List<WellData> infoPozosFichero = parser.ParseWellData(pozoFile).ToList<WellData>();
240
                     List<Pozo> pozos = pozoController.GetPozosSimulacion(simulacionId);
256
                     List<Pozo> pozos = pozoController.GetPozosSimulacion(simulacionId);
241
-                    List<string> lines = new List<string>();
257
+                    List<string> lines = new();
258
+
242
 
259
 
243
                     //Por ahora asumimos que el fichero tiene la misma cantidad de pozos que en bbdd para esta simulacion
260
                     //Por ahora asumimos que el fichero tiene la misma cantidad de pozos que en bbdd para esta simulacion
244
                     string[] maxDefault = infoPozosFichero[0].ZMax.Split(" ");
261
                     string[] maxDefault = infoPozosFichero[0].ZMax.Split(" ");
245
 
262
 
246
-
247
                     lines.Add(pozos.Count.ToString());
263
                     lines.Add(pozos.Count.ToString());
248
                     foreach (Pozo p in pozos)
264
                     foreach (Pozo p in pozos)
249
                     {
265
                     {
250
                         List<TsPozo> timeSeriesPozo = pozoController.GetTsPozoFromPozo(p.Id);
266
                         List<TsPozo> timeSeriesPozo = pozoController.GetTsPozoFromPozo(p.Id);
251
                         lines.Add("0"); //Activo o inactivo
267
                         lines.Add("0"); //Activo o inactivo
252
                         lines.Add(p.Nombre);
268
                         lines.Add(p.Nombre);
253
-                        lines.Add(p.Latitud.ToString());
254
-                        lines.Add(p.Longitud.ToString());
269
+                        lines.Add(p.X.ToString());
270
+                        lines.Add(p.Y.ToString());
255
                         lines.Add(p.Minimo.ToString());
271
                         lines.Add(p.Minimo.ToString());
256
                         maxDefault[0] = p.Maximo.ToString();
272
                         maxDefault[0] = p.Maximo.ToString();
257
                         string aux = String.Join(' ', maxDefault);
273
                         string aux = String.Join(' ', maxDefault);
258
                         lines.Add(aux); //Maximo
274
                         lines.Add(aux); //Maximo
259
                         lines.Add(infoPozosFichero[0].ScreenIntervals.ToString()); //screen intervals
275
                         lines.Add(infoPozosFichero[0].ScreenIntervals.ToString()); //screen intervals
260
-                        lines.Add(infoPozosFichero[0].Top);
261
                         lines.Add(infoPozosFichero[0].Bot);
276
                         lines.Add(infoPozosFichero[0].Bot);
277
+                        lines.Add(infoPozosFichero[0].Top);
262
                         lines.Add(timeSeriesPozo.Count.ToString());
278
                         lines.Add(timeSeriesPozo.Count.ToString());
263
 
279
 
264
-                        for (int i = 0; i < timeSeriesPozo.Count - 1; i++)
280
+                        for (int i = 0; i < timeSeriesPozo.Count; i++)
265
                         {
281
                         {
266
                             lines.Add(timeSeriesPozo[i].MarcaTiempo);
282
                             lines.Add(timeSeriesPozo[i].MarcaTiempo);
267
-                            lines.Add(timeSeriesPozo[i + 1].MarcaTiempo);
268
-                            lines.Add(timeSeriesPozo[i].Valor.ToString() + " " + timeSeriesPozo[i].InfoComplementaria);
283
+                            lines.Add(timeSeriesPozo[i].MarcaTiempoEnd);
284
+                            lines.Add(timeSeriesPozo[i].Valor + " " + timeSeriesPozo[i].InfoComplementaria);
269
                         }
285
                         }
270
                     }
286
                     }
271
 
287
 
272
                     //System.IO.File.WriteAllLines(@"C:\Users\Admin\Desktop\Test.VMW", lines);
288
                     //System.IO.File.WriteAllLines(@"C:\Users\Admin\Desktop\Test.VMW", lines);
273
                     System.IO.File.WriteAllLines(pozoFile, lines);
289
                     System.IO.File.WriteAllLines(pozoFile, lines);
274
-
290
+                    Logger.WriteLog("pozos terminados");
275
                 }
291
                 }
276
 
292
 
277
 
293
 
278
                 //4- Parseamos recargas
294
                 //4- Parseamos recargas
279
                 if (System.IO.File.Exists(recargaFile))
295
                 if (System.IO.File.Exists(recargaFile))
280
                 {
296
                 {
297
+                    Logger.WriteLog("vamos con recargas");
281
                     List<Recarga> recargas = recargasController.GetRecargasSimulacion(simulacionId);
298
                     List<Recarga> recargas = recargasController.GetRecargasSimulacion(simulacionId);
282
 
299
 
283
                     string text = System.IO.File.ReadAllText(recargaFile);
300
                     string text = System.IO.File.ReadAllText(recargaFile);
288
                     int rechargeBlockInex = blankLinePerBlock * 2;
305
                     int rechargeBlockInex = blankLinePerBlock * 2;
289
 
306
 
290
 
307
 
291
-                    List<string> lines = new List<string>();
308
+                    List<string> lines = new();
292
 
309
 
293
                     //Hasta el bloque de recargas vamos poniendo el texto que le precede
310
                     //Hasta el bloque de recargas vamos poniendo el texto que le precede
294
                     for (int i = 0; i < rechargeBlockInex; i++)
311
                     for (int i = 0; i < rechargeBlockInex; i++)
305
                     {
322
                     {
306
                         List<TsRecarga> tsRecarga = recargasController.GetTsRecargaFromRecaga(r.Id);
323
                         List<TsRecarga> tsRecarga = recargasController.GetTsRecargaFromRecaga(r.Id);
307
                         lines.Add(index + " 1 Index 1");
324
                         lines.Add(index + " 1 Index 1");
308
-                        lines.Add("1 rchr entries");
309
-                        lines.Add(index + " " + tsRecarga[0].Valor + "               " + tsRecarga[0].MarcaTiempo + "               " + tsRecarga[1].MarcaTiempo + " " + tsRecarga[0].InfoComplementaria);
325
+                        lines.Add(tsRecarga.Count + " rchr entries");
326
+                        tsRecarga.ForEach(x =>
327
+                            lines.Add(index + " " + x.Valor + "               " + x.MarcaTiempo + "               " + x.MarcaTiempoEnd + " " + x.InfoComplementaria)
328
+                        );
329
+                        //lines.Add(index + " " + tsRecarga[0].Valor + "               " + tsRecarga[0].MarcaTiempo + "               " + tsRecarga[1].MarcaTiempo + " " + tsRecarga[0].InfoComplementaria);
310
 
330
 
311
                     }
331
                     }
312
                     lines.Add("");
332
                     lines.Add("");
332
                 //Primeramente, para ejecutar el modelo, hay que modificar el contenido del fichero con extension .in para que no de error al ejecutarse el modelo
352
                 //Primeramente, para ejecutar el modelo, hay que modificar el contenido del fichero con extension .in para que no de error al ejecutarse el modelo
333
                 if (System.IO.File.Exists(inFile))
353
                 if (System.IO.File.Exists(inFile))
334
                 {
354
                 {
355
+                    Logger.WriteLog("tratamos el fichero .IN");
335
                     List<string> inFileLines = parser.ParseInFile(inFile);
356
                     List<string> inFileLines = parser.ParseInFile(inFile);
336
                     System.IO.File.WriteAllLines(inFile, inFileLines);
357
                     System.IO.File.WriteAllLines(inFile, inFileLines);
337
                 }
358
                 }
383
 
404
 
384
                         uint balanceDataInId = dataIn.Value;
405
                         uint balanceDataInId = dataIn.Value;
385
 
406
 
386
-                        List<ConexionZonasIn> conexionZonasIns = new List<ConexionZonasIn>();
407
+                        List<ConexionZonasIn> conexionZonasIns = new();
387
 
408
 
388
                         zone.In.ZoneConnections.ForEach(x => conexionZonasIns.Add(x.ToConexionIn(balanceDataInId)));
409
                         zone.In.ZoneConnections.ForEach(x => conexionZonasIns.Add(x.ToConexionIn(balanceDataInId)));
389
 
410
 
392
                         var dataOut = await balanceHidricoController.PostBalanceOut(zone.Out.ToDatosBalanceOut(balanceId));
413
                         var dataOut = await balanceHidricoController.PostBalanceOut(zone.Out.ToDatosBalanceOut(balanceId));
393
                         uint balanceDataOutId = dataOut.Value;
414
                         uint balanceDataOutId = dataOut.Value;
394
 
415
 
395
-                        List<ConexionZonasOut> conexionZonasOuts = new List<ConexionZonasOut>();
416
+                        List<ConexionZonasOut> conexionZonasOuts = new();
396
 
417
 
397
                         zone.Out.ZoneConnections.ForEach(x => conexionZonasOuts.Add(x.ToConexionOut(balanceDataOutId)));
418
                         zone.Out.ZoneConnections.ForEach(x => conexionZonasOuts.Add(x.ToConexionOut(balanceDataOutId)));
398
 
419
 
406
                 {
427
                 {
407
                     Logger.WriteLog("inicio balance modelo entero");
428
                     Logger.WriteLog("inicio balance modelo entero");
408
                     ZoneBalance[] modelBalance = parser.ParseWholeModelBalance(modelResultsFile);
429
                     ZoneBalance[] modelBalance = parser.ParseWholeModelBalance(modelResultsFile);
409
-
430
+                    Logger.WriteLog("este es el lenght del balance entero " + modelBalance.Length);
410
                     //insertamos en bbdd
431
                     //insertamos en bbdd
411
-                    foreach (ZoneBalance zone in modelBalance)
432
+                    try
412
                     {
433
                     {
413
-                        var result = await balanceHidricoController.PostBalance(zone.ToBalanceHidrico(simulacionId));
414
-                        uint balanceId = result.Value;
434
+                        foreach (ZoneBalance zone in modelBalance)
435
+                        {
436
+                            var result = await balanceHidricoController.PostBalance(zone.ToBalanceHidrico(simulacionId));
437
+                            uint balanceId = result.Value;
415
 
438
 
416
-                        await balanceHidricoController.PostBalanceIn(zone.In.ToDatosBalanceIn(balanceId));
417
-                        await balanceHidricoController.PostBalanceOut(zone.Out.ToDatosBalanceOut(balanceId));
439
+                            await balanceHidricoController.PostBalanceIn(zone.In.ToDatosBalanceIn(balanceId));
440
+                            await balanceHidricoController.PostBalanceOut(zone.Out.ToDatosBalanceOut(balanceId));
441
+                        }
442
+                    }
443
+                    catch (Exception ex)
444
+                    {
445
+                        Logger.WriteLog(ex.Message);
446
+                        Logger.WriteLog(ex.InnerException.Message);
447
+                        throw;
418
                     }
448
                     }
419
                     Logger.WriteLog("fin balance modelo entero");
449
                     Logger.WriteLog("fin balance modelo entero");
420
                 }
450
                 }
431
                     }
461
                     }
432
                     Logger.WriteLog("fin piezometria");
462
                     Logger.WriteLog("fin piezometria");
433
                 }
463
                 }
434
-                piezometriaController.getDimensions(simulacionId, out int rows, out int cols);
464
+                piezometriaController.GetDimensions(simulacionId, out int rows, out int cols);
435
 
465
 
436
                 await serviceController.GetIsolinesWithPython(workingDirectory, piezometryFile, rows, cols);
466
                 await serviceController.GetIsolinesWithPython(workingDirectory, piezometryFile, rows, cols);
437
                 Thread.Sleep(5000);
467
                 Thread.Sleep(5000);
438
-
439
-                Byte[] bytes = System.IO.File.ReadAllBytes(workingDirectory + "test.png");
468
+                Logger.WriteLog("ya tengo la imagen de isolineas");
469
+                Logger.WriteLog(workingDirectory + Constants.SVGFileName);
470
+                Byte[] bytes = System.IO.File.ReadAllBytes(workingDirectory + Constants.SVGFileName);
440
                 String base64Image = Convert.ToBase64String(bytes);
471
                 String base64Image = Convert.ToBase64String(bytes);
441
 
472
 
442
-
473
+                Logger.WriteLog("guardo imagen de isolineas");
474
+                Logger.WriteLog(base64Image);
443
                 await SetIsolinesImage(simulacionId, base64Image);
475
                 await SetIsolinesImage(simulacionId, base64Image);
444
-
445
-
476
+                Logger.WriteLog("ya esta guardada");
477
+                /*
478
+                 * se transforma la imagen vectorial obtenida anteriormente para transformarla en un geojson
479
+                 */
480
+                string svgFile = workingDirectory + Constants.SVGFileName;
481
+                await serviceController.GetGeoJsonFromSVG(workingDirectory, svgFile);
482
+
483
+                await SetGeoJson(simulacionId, workingDirectory+Constants.GeoJsonFileName);
484
+                
446
                 await serviceQueueController.SetTerminado(serviceQueue.Id);
485
                 await serviceQueueController.SetTerminado(serviceQueue.Id);
447
                 Logger.WriteLog("terminado");
486
                 Logger.WriteLog("terminado");
487
+                try
488
+                {
489
+                    System.IO.Directory.Delete(workingDirectory);
490
+                }catch(Exception ex)
491
+                {
492
+                    Logger.WriteLog(ex.Message);
493
+                    Logger.WriteLog(ex.InnerException.Message);
494
+                }
448
             }
495
             }
449
             return true;
496
             return true;
450
         }
497
         }
451
 
498
 
499
+            
500
+        [HttpGet("Geojson/{id}")]
501
+        [ProducesResponseType(200)]
452
 
502
 
453
-        [HttpGet("Geojson")]
454
-        public GeoJson GetGeoJson()
503
+        public async Task<GeoJson> GetGeoJson(uint id)
455
         {
504
         {
456
-            string allText = System.IO.File.ReadAllText(@"C:\Users\Admin\Desktop\AAAA\test_aa.geojson");
457
-            allText = allText.Replace("[[[","[[");
458
-            allText = allText.Replace("]]]", "]]");
459
-            GeoJson jsonObject = JsonConvert.DeserializeObject<GeoJson>(allText);
505
+            Simulacion s = await _context.Simulaciones.FindAsync(id);
506
+            GeoJson jsonObject = JsonConvert.DeserializeObject<GeoJson>(s.Geojson);
460
             return jsonObject;
507
             return jsonObject;
461
         }
508
         }
509
+
510
+
462
         private bool SimulacionExists(uint id)
511
         private bool SimulacionExists(uint id)
463
         {
512
         {
464
             return _context.Simulaciones.Any(e => e.Id == id);
513
             return _context.Simulaciones.Any(e => e.Id == id);
465
         }
514
         }
466
 
515
 
467
-        private async Task<IActionResult> SetIsolinesImage(uint simulacionId, string imageBase64)
516
+        private async Task<IActionResult> SetGeoJson(uint simulationId, string geojsonFile)
468
         {
517
         {
469
-            var simulacion = _context.Simulaciones.Find(simulacionId);
518
+            string allText = System.IO.File.ReadAllText(geojsonFile);
519
+            allText = allText.Replace("[[[","[[");
520
+            allText = allText.Replace("]]]", "]]");
470
 
521
 
471
-            if (simulacionId != simulacion.Id)
522
+            var simulation = _context.Simulaciones.Find(simulationId);
523
+
524
+            if (simulationId!= simulation.Id)
472
             {
525
             {
473
                 return BadRequest();
526
                 return BadRequest();
474
             }
527
             }
475
 
528
 
476
 
529
 
477
-            simulacion.IsolineImage = imageBase64;
530
+            simulation.Geojson = allText;
478
 
531
 
479
-            _context.Entry(simulacion).State = EntityState.Modified;
532
+            _context.Entry(simulation).State = EntityState.Modified;
480
 
533
 
481
             try
534
             try
482
             {
535
             {
484
             }
537
             }
485
             catch (DbUpdateConcurrencyException)
538
             catch (DbUpdateConcurrencyException)
486
             {
539
             {
487
-                if (!SimulacionExists(simulacionId))
540
+                if (!SimulacionExists(simulationId))
488
                 {
541
                 {
489
                     return NotFound();
542
                     return NotFound();
490
                 }
543
                 }
494
                 }
547
                 }
495
             }
548
             }
496
 
549
 
497
-            return CreatedAtAction("GetSimulacion", new { id = simulacion.Id }, simulacion);
550
+            return CreatedAtAction("GetSimulacion", new { id = simulation.Id }, simulation);
551
+
498
         }
552
         }
499
 
553
 
500
-        /*
501
-         * TEST ENDPOINTS
502
-         */
503
-        [HttpPost("Simula/Python/{simulacionId}")]
504
-        public async Task<bool> SimIsolinesWithPython(uint simulacionId)
554
+        private async Task<IActionResult> SetIsolinesImage(uint simulacionId, string imageBase64)
505
         {
555
         {
506
-            string workingDirectory = @"C:\Users\Admin\Desktop\TestExtract\simulaicionsimulacion_test\";
507
-            string headFile = @"C:\Users\Admin\Desktop\TestExtract\simulaicionsimulacion_test\EJEMPLO_SOTIEL.HDS";
556
+            Simulacion simulacion = _context.Simulaciones.Find(simulacionId);
557
+            Logger.WriteLog("sim "+simulacion.Id);
558
+            if (simulacionId != simulacion.Id)
559
+            {
560
+                return BadRequest();
561
+            }
508
 
562
 
509
-            int rows, cols;
510
-            piezometriaController.getDimensions(simulacionId, out rows, out cols);
511
-            await serviceController.GetIsolinesWithPython(workingDirectory, headFile, rows, cols);
512
-            Thread.Sleep(3000);
513
-            return true;
514
-        }
515
 
563
 
516
-        [HttpGet("Piezometria")]
517
-        public async Task<ActionResult<IEnumerable<Simulacion>>> SimPiezometria()
518
-        {
519
-            Logger.WriteLog("inicio piezometria");
520
-            Parser parser = new Parser();
521
-            string piezometryFile = @"C:\Users\Admin\Desktop\TestExtract\simulaicionsimulacion_test\EJEMPLO_SOTIEL.HDS";
522
-            List<Piezometria> piezometrias = parser.ParseBinaryFile(piezometryFile, 4);
523
-            Logger.WriteLog("Fin parseo fichero binario");
524
-            Logger.WriteLog("Hay " + piezometrias.Count + " elementos de piezometria");
525
-            foreach (Piezometria p in piezometrias)
564
+            simulacion.IsolineImage = imageBase64;
565
+            Logger.WriteLog(imageBase64);
566
+
567
+            _context.Entry(simulacion).State = EntityState.Modified;
568
+
569
+            try
570
+            {
571
+                await _context.SaveChangesAsync();
572
+            }
573
+            catch (Exception ex)
526
             {
574
             {
527
-                await piezometriaController.PostPiezometria(p);
575
+                if (!SimulacionExists(simulacionId))
576
+                {
577
+                    return NotFound();
578
+                }
579
+                else
580
+                {
581
+                    Logger.WriteLog(ex.Message);
582
+                    Logger.WriteLog(ex.InnerException.Message);
583
+                    throw;
584
+                }
528
             }
585
             }
529
-            Logger.WriteLog("fin piezometria");
530
-            return await GetSimulaciones();
586
+            Logger.WriteLog("OKIDOKI ISO SAVED");
587
+            return CreatedAtAction("GetSimulacion", new { id = simulacion.Id }, simulacion);
531
         }
588
         }
532
     }
589
     }
533
 }
590
 }

+ 5 - 4
WorkerService1/WebApplication3/Controllers/TsPiezometerController.cs View File

10
 
10
 
11
 namespace WebApplication3.Controllers
11
 namespace WebApplication3.Controllers
12
 {
12
 {
13
-    [Route("api/[controller]")]
14
-    [ApiController]
13
+    //[Route("api/[controller]")]
14
+    //[ApiController]
15
+    [ApiExplorerSettings(IgnoreApi = true)]
15
     public class TsPiezometerController: ControllerBase
16
     public class TsPiezometerController: ControllerBase
16
     {
17
     {
17
         private readonly AquiferContext _context;
18
         private readonly AquiferContext _context;
37
             //var tsPozo = await _context.TsPozos.FindAsync(id);
38
             //var tsPozo = await _context.TsPozos.FindAsync(id);
38
             var tsPiezometers = _context.TsPiezometers.Where(x => x.PiezometerId == id);
39
             var tsPiezometers = _context.TsPiezometers.Where(x => x.PiezometerId == id);
39
 
40
 
40
-            List<TimeSerie> timeSeries = new List<TimeSerie>();
41
+            List<TimeSerie> timeSeries = new ();
41
             TimeSerie timeSerie = null;
42
             TimeSerie timeSerie = null;
42
 
43
 
43
             if (tsPiezometers == null)
44
             if (tsPiezometers == null)
47
 
48
 
48
             foreach(TsPiezometer tsp in tsPiezometers)
49
             foreach(TsPiezometer tsp in tsPiezometers)
49
             {
50
             {
50
-                timeSerie = new TimeSerie();
51
+                timeSerie = new ();
51
                 timeSerie.Hora = tsp.Day;
52
                 timeSerie.Hora = tsp.Day;
52
                 timeSerie.Valor = tsp.Quote;
53
                 timeSerie.Valor = tsp.Quote;
53
                 timeSeries.Add(timeSerie);
54
                 timeSeries.Add(timeSerie);

+ 3 - 2
WorkerService1/WebApplication3/Controllers/TsPozoController.cs View File

10
 
10
 
11
 namespace WebApplication3.Controllers
11
 namespace WebApplication3.Controllers
12
 {
12
 {
13
-    [Route("api/[controller]")]
14
-    [ApiController]
13
+    //[Route("api/[controller]")]
14
+    //[ApiController]
15
+    [ApiExplorerSettings(IgnoreApi = true)]
15
     public class TsPozoController : ControllerBase
16
     public class TsPozoController : ControllerBase
16
     {
17
     {
17
         private readonly AquiferContext _context;
18
         private readonly AquiferContext _context;

+ 3 - 2
WorkerService1/WebApplication3/Controllers/TsRecargaController.cs View File

10
 
10
 
11
 namespace WebApplication3.Controllers
11
 namespace WebApplication3.Controllers
12
 {
12
 {
13
-    [Route("api/[controller]")]
14
-    [ApiController]
13
+    //[Route("api/[controller]")]
14
+    //[ApiController]
15
+    [ApiExplorerSettings(IgnoreApi = true)]
15
     public class TsRecargaController : ControllerBase
16
     public class TsRecargaController : ControllerBase
16
     {
17
     {
17
         private readonly AquiferContext _context;
18
         private readonly AquiferContext _context;

+ 2 - 0
WorkerService1/WebApplication3/Models/Acuifero.cs View File

13
         public string WorldOriginX { get; set; }
13
         public string WorldOriginX { get; set; }
14
         public string WorldOriginY { get; set; }
14
         public string WorldOriginY { get; set; }
15
         public string RechargeGeometry { get; set; }
15
         public string RechargeGeometry { get; set; }
16
+        public string RechargeColorMap { get; set; }
17
+
16
     }
18
     }
17
 }
19
 }

+ 14 - 0
WorkerService1/WebApplication3/Models/AquiferContext.cs View File

75
                 entity.Property(e => e.WorldOriginX).HasColumnName("world_origin_x");
75
                 entity.Property(e => e.WorldOriginX).HasColumnName("world_origin_x");
76
                 entity.Property(e => e.WorldOriginY).HasColumnName("world_origin_y");
76
                 entity.Property(e => e.WorldOriginY).HasColumnName("world_origin_y");
77
                 entity.Property(e => e.RechargeGeometry).HasColumnName("recharge_geometry");
77
                 entity.Property(e => e.RechargeGeometry).HasColumnName("recharge_geometry");
78
+                entity.Property(e => e.RechargeColorMap).HasColumnName("recharge_color_map");
79
+
78
 
80
 
79
 
81
 
80
 
82
 
250
                     .HasMaxLength(255)
252
                     .HasMaxLength(255)
251
                     .HasColumnName("isoline_image");
253
                     .HasColumnName("isoline_image");
252
 
254
 
255
+                entity.Property(e => e.Geojson)
256
+                    .HasMaxLength(255)
257
+                    .HasColumnName("geojson");
258
+
259
+                entity.Property(e => e.SimulacionAcuifero)
260
+                    .HasColumnType("int(10) unsigned")
261
+                    .HasColumnName("simulacion_acuifero")
262
+                    .HasDefaultValueSql("0");
263
+
253
                 entity.HasKey(e => e.Id)
264
                 entity.HasKey(e => e.Id)
254
                 .HasName("id");
265
                 .HasName("id");
255
             });
266
             });
358
                 entity.Property(e => e.Recharge).HasColumnName("recharge");
369
                 entity.Property(e => e.Recharge).HasColumnName("recharge");
359
 
370
 
360
                 entity.Property(e => e.Drains).HasColumnName("drains");
371
                 entity.Property(e => e.Drains).HasColumnName("drains");
372
+                entity.Property(e => e.Wells).HasColumnName("wells");
373
+
361
 
374
 
362
                 entity.Property(e => e.ConstantHead).HasColumnName("constant_head");
375
                 entity.Property(e => e.ConstantHead).HasColumnName("constant_head");
363
 
376
 
385
                 entity.Property(e => e.Recharge).HasColumnName("recharge");
398
                 entity.Property(e => e.Recharge).HasColumnName("recharge");
386
 
399
 
387
                 entity.Property(e => e.Drains).HasColumnName("drains");
400
                 entity.Property(e => e.Drains).HasColumnName("drains");
401
+                entity.Property(e => e.Wells).HasColumnName("wells");
388
 
402
 
389
                 entity.Property(e => e.ConstantHead).HasColumnName("constant_head");
403
                 entity.Property(e => e.ConstantHead).HasColumnName("constant_head");
390
 
404
 

+ 1 - 0
WorkerService1/WebApplication3/Models/DatosBalanceIn.cs View File

13
         public string Storage { get; set; }
13
         public string Storage { get; set; }
14
         public string ConstantHead { get; set; }
14
         public string ConstantHead { get; set; }
15
         public string Drains { get; set; }
15
         public string Drains { get; set; }
16
+        public string Wells { get; set; }
16
         public string Recharge { get; set; }
17
         public string Recharge { get; set; }
17
         public string Total { get; set; }
18
         public string Total { get; set; }
18
 
19
 

+ 1 - 0
WorkerService1/WebApplication3/Models/DatosBalanceOut.cs View File

13
         public string Storage { get; set; }
13
         public string Storage { get; set; }
14
         public string ConstantHead { get; set; }
14
         public string ConstantHead { get; set; }
15
         public string Drains { get; set; }
15
         public string Drains { get; set; }
16
+        public string Wells { get; set; }
16
         public string Recharge { get; set; }
17
         public string Recharge { get; set; }
17
         public string Total { get; set; }
18
         public string Total { get; set; }
18
 
19
 

+ 20 - 0
WorkerService1/WebApplication3/Models/Piezometer.cs View File

1
+using System;
2
+using System.Collections.Generic;
3
+using WebApplication3.Clases;
4
+
5
+#nullable disable
6
+
7
+namespace WebApplication3.Models
8
+{
9
+    public partial class Piezometer
10
+    {
11
+        public uint Id { get; set; }
12
+        public string Name { get; set; }
13
+        public string X { get; set; }
14
+        public string Y { get; set; }
15
+        public string Z { get; set; }
16
+        public string Prof { get; set; }
17
+        public string ScreenTop { get; set; }
18
+        public string ScreenBot { get; set; }
19
+    }
20
+}

+ 2 - 0
WorkerService1/WebApplication3/Models/Pozo.cs View File

22
         public string Prof { get; set; }
22
         public string Prof { get; set; }
23
         public string ScreenTop { get; set; }
23
         public string ScreenTop { get; set; }
24
         public string ScreenBot { get; set; }
24
         public string ScreenBot { get; set; }
25
+        public uint Active { get; set; }
25
 
26
 
26
         public Pozo Copy(uint? idSimulacion)
27
         public Pozo Copy(uint? idSimulacion)
27
         {
28
         {
33
             pozo.Maximo = this.Maximo;
34
             pozo.Maximo = this.Maximo;
34
             pozo.Minimo = this.Minimo;
35
             pozo.Minimo = this.Minimo;
35
             pozo.Nombre = this.Nombre;
36
             pozo.Nombre = this.Nombre;
37
+            pozo.Active = this.Active;
36
             return pozo;
38
             return pozo;
37
         }
39
         }
38
     }
40
     }

+ 2 - 0
WorkerService1/WebApplication3/Models/Simulacion.cs View File

11
         public uint? IdAcuifero { get; set; }
11
         public uint? IdAcuifero { get; set; }
12
         public string Nombre { get; set; }
12
         public string Nombre { get; set; }
13
         public string IsolineImage { get; set; }
13
         public string IsolineImage { get; set; }
14
+        public string Geojson { get; set; }
15
+        public uint SimulacionAcuifero { get; set; }
14
     }
16
     }
15
 }
17
 }

+ 1 - 0
WorkerService1/WebApplication3/Models/TSPozo.cs View File

22
             tsPozo.IdPozo = pozoId;
22
             tsPozo.IdPozo = pozoId;
23
             tsPozo.Valor = this.Valor;
23
             tsPozo.Valor = this.Valor;
24
             tsPozo.MarcaTiempo = this.MarcaTiempo;
24
             tsPozo.MarcaTiempo = this.MarcaTiempo;
25
+            tsPozo.MarcaTiempoEnd = this.MarcaTiempoEnd;
25
             tsPozo.InfoComplementaria = this.InfoComplementaria;
26
             tsPozo.InfoComplementaria = this.InfoComplementaria;
26
 
27
 
27
             return tsPozo;
28
             return tsPozo;