- Se agregaron mas TRY/CATCH y se agregó el parametro "f", para especifiar un punto que debe ser el punto final (destino)

This commit is contained in:
2024-04-25 01:50:43 -06:00
parent 156e3b1d94
commit c6a5220797
5 changed files with 195 additions and 137 deletions

View File

@@ -89,6 +89,7 @@ Sub generaMatrizRuteoTiempos(r As String, resp As ServletResponse, ruta As Strin
Loop
Main.db.Close
StopMessageLoop
Main.error = ""
resp.ContentType = "text/html"
resp.Write($"<a href="https://osm.quelltextlich.at/viewer-js.html?kml_url=https://pi.famguerra.com/kmz.php?c=${listCoords}">Mapa</a>"$)
@@ -112,8 +113,8 @@ Sub tiempos(r As String, resp As ServletResponse, ruta As String, almacen As Str
Log("Iniciamos ruteoCompleto")
ruteoCompleto(r)
StopMessageLoop
Main.error = ""
resp.ContentType = "text/html"
resp.Write($"<a href="https://osm.quelltextlich.at/viewer-js.html?kml_url=https://pi.famguerra.com/kmz.php?c=${listCoords}">Mapa</a>"$)
Return 1

View File

@@ -50,6 +50,8 @@ Sub Process_Globals
Dim inicio As String = "", final As String = ""
' Dim coords As List
' Dim estePunto() As String
Dim error As String = ""
dim msg as string = ""
End Sub
Sub AppStart (Args() As String)
@@ -153,16 +155,15 @@ Sub creaTablas(params As Map)
Private estasCoords As String = params.Get("coords")
Private hash As String = params.Get("hash")
Private ruta As String = $"${params.Get("ruta")}A${almacen}_${hash}"$
db.BeginTransaction
Try
' Log($"drop table if exists ${ruta}_matriz"$)
' Log($"drop table if exists ${ruta}_matriz"$
db.ExecNonQuery($"drop table if exists ${ruta}_matriz"$)
' Log($"drop table if exists ${ruta}_matrizOSRM"$)
db.ExecNonQuery($"drop table if exists ${ruta}_matrizOSRM"$)
' Log($"drop table if exists ${ruta}_puntos"$)
db.ExecNonQuery($"drop table if exists ${ruta}_puntos"$)
Catch
Log(LastException)
End Try
db.ExecNonQuery($"create table if not exists ${ruta}_puntos (id TEXT, nombre TEXT, lat TEXT, lon TEXT)"$)
' Log($"create table if not exists ${ruta}_puntos (id TEXT, nombre TEXT, lat TEXT, lon TEXT)"$)
db.ExecNonQuery($"create table if not exists ${ruta}_punteo (pos TEXT, id TEXT, nombre TEXT, lat TEXT, lon TEXT)"$)
@@ -172,9 +173,13 @@ Sub creaTablas(params As Map)
For i = 0 To f.Length - 1
' Log(f(i))
Private pars() As String = Regex.Split(",", f(i))
If pars(2) > 0 Or pars(2) > 0 Then
If pars.Length < 3 Then Log("####################" & CRLF & "Se necesita el id del cliente, la longitud y la latitud" & CRLF & "##############################")
' Log($"(${i}, ${pars(0)}, 'a', ${pars(2)}, ${pars(1)})"$)
db.ExecNonQuery($"insert into ${ruta}_puntos (id, nombre, lat, lon) values ('CC${pars(0)}','a', ${pars(2)}, ${pars(1)})"$)
db.ExecNonQuery($"insert into ${ruta}_puntos (id, nombre, lat, lon) values ('_${pars(0)}','a', ${pars(2)}, ${pars(1)})"$)
Else
msg = "Hay puntos con coordenadas en CERO, se eliminaron."
End If
Next
Private colsMatriz As String = "idT TEXT"
@@ -185,6 +190,12 @@ Sub creaTablas(params As Map)
' Log(colsMatriz)
db.ExecNonQuery($"create table if not exists ${ruta}_matriz (${colsMatriz})"$)
db.ExecNonQuery($"create table if not exists ${ruta}_matrizOSRM (${colsMatriz})"$)
db.TransactionSuccessful
Catch
Log(LastException)
If error = "" Then error = LastException
db.Rollback
End Try
End Sub
Private Sub b_generaMatriz_Click
@@ -231,6 +242,7 @@ Sub generaMatrizLocal(ruta As String) 'ignore
Log("Matriz LOCAL generada")
Catch
Log(LastException)
If error = "" Then error = LastException
End Try
' generaMatrizOSRM
End Sub
@@ -289,6 +301,7 @@ Sub generaMatrizOSRM(ruta As String) As ResumableSub 'ignore
Log("Matriz OSRM generada")
Catch
Log(LastException)
If error = "" Then error = LastException
End Try
End Sub
@@ -301,6 +314,7 @@ Sub ruteo(ruta As String, matriz As String) 'ignore
Log("#####################################################")
Log("############# Main/ruteo ####################")
Log("#####################################################")
If checkIfTableExists(ruta&"_puntos") Then
db.ExecNonQuery($"delete from ${ruta}_punteo"$)
punteoLista.Initialize
Private c As ResultSet = db.ExecQuery($"select * from ${ruta}_puntos limit 1"$)
@@ -319,11 +333,11 @@ Sub ruteo(ruta As String, matriz As String) 'ignore
If final <> "" Then ' Si en los parametros se especifica un punto de destino (punto final), se agrega aqui a la lista, se agrega como segundo punto, porque todos los demas puntos de la lista se van a agregar ENTRE estos dos puntos iniciales.
Log("Agregamos punto final.")
Private pf() As String = Regex.Split(",", final) ' Obtenemos id, lon y lat.
Private c As ResultSet = db.ExecQuery($"select * from ${ruta}_puntos where id = 'CC${pf(0)}' limit 1"$)
Private c As ResultSet = db.ExecQuery($"select * from ${ruta}_puntos where id = '_${pf(0)}' limit 1"$)
Do While c.NextRow
db.ExecNonQuery($"insert into ${ruta}_punteo (pos, id, nombre, lat, lon) values ('0', '${c.GetString("id")}', 'Almacen', ${c.Getdouble("lat")}, ${c.Getdouble("lon")})"$)
Loop
punteoLista.Add("CC" & pf(0))
punteoLista.Add("_" & pf(0))
c.Close
End If
@@ -340,6 +354,7 @@ Sub ruteo(ruta As String, matriz As String) 'ignore
ruteoNearestInsertion2
cualAlgoritmo = " (NI2)"
End If
End If
End Sub
Private Sub b_verRuta_Click
@@ -385,6 +400,7 @@ Sub tiempos(ruta As String) As ResumableSub 'ignore
Log("############# Main/tiempos ####################")
Log("#######################################################")
' Log("Tiempos: " & ruta)
If checkIfTableExists(ruta&"_punteo") Then
Private c As ResultSet = db.ExecQuery($"select * from ${ruta}_punteo"$)
Private estasCoords As String = ""
Do While c.NextRow
@@ -394,7 +410,6 @@ Sub tiempos(ruta As String) As ResumableSub 'ignore
estasCoords = $"${estasCoords};${c.GetString("lon")},${c.GetString("lat")}"$
End If
Loop
' fx.ShowExternalDocument($"http://router.project-osrm.org/route/v1/driving/${estasCoords}"$)
Private d() As String
d = Regex.Split(";", estasCoords)
' Log("$$$$$$ " & d.Length)
@@ -412,7 +427,7 @@ Sub tiempos(ruta As String) As ResumableSub 'ignore
' StopMessageLoop
Private js As JSONParser
js.Initialize(j0)
' Log(j0)
Log(j0)
' Log("*****************************************")
' Log(js)
'' For Each colroot As Map In js
@@ -435,7 +450,9 @@ Sub tiempos(ruta As String) As ResumableSub 'ignore
' Log(">>>>>>>>>>>>>>>>>>>>>>>>>>>" & ts)
Catch
Log(LastException)
If error = "" Then error = LastException
End Try
End If
Return 1
End Sub
@@ -616,6 +633,7 @@ Public Sub calculateDistance3(lat1 As Double, lon1 As Double, lat2 As Double, lo
Return Round(Yards)
Catch
Log("CalcDistance " & LastException)
if error = "" then error = LastException
Return -1
End Try
End Sub
@@ -641,3 +659,17 @@ Private Sub cb_api_SelectedIndexChanged(Index As Int, Value As Object)
' api = Index
' If Index = 0 Then matriz = "" Else matriz = "OSRM"
End Sub
'Revisamos que la tabla exista.
Sub checkIfTableExists(table As String) As Boolean
' B4XPages.MainPage.db.InitializeSQLite(File.DirApp, "kmt.db", True)
Private r As ResultSet = db.ExecQuery($"Select name FROM sqlite_master WHERE Type='table' AND name='${table}'"$)
If r.NextRow Then
' B4XPages.MainPage.db.close
' Log($"NAME: ${r.GetString("name")}"$)
Return True
Else
' B4XPages.MainPage.db.close
Return False
End If
End Sub

View File

@@ -10,12 +10,12 @@ ModuleBreakpoints2=
ModuleBreakpoints3=
ModuleBreakpoints4=
ModuleBreakpoints5=
ModuleClosedNodes0=3,4,5,6,8,10,11,14,17,19,21,22,23,24,25
ModuleClosedNodes0=3,4,5,6,8,11,14,17,19,21,24
ModuleClosedNodes1=
ModuleClosedNodes2=
ModuleClosedNodes3=
ModuleClosedNodes4=
ModuleClosedNodes5=
NavigationStack=Main,ruteo,283,6,Mapa,Handle,54,0,Main,creaTablas,132,0,Main,generaMatrizLocal,204,1,Main,generaMatrizOSRM,214,1,Main,tiempos,410,3,Ruteador,generaMatrizRuteoTiempos,95,6,Ruteador,tiempos,136,1,Mapa,ruteoCompleto,166,3,rutaCompleta,ruteoCompleto,167,2
NavigationStack=Main,generaMatrizOSRM,275,0,Main,tiempos,424,5,Mapa,generaMatrizRuteoTiempos,85,0,Mapa,tiempos,108,0,rutaCompleta,generaMatrizRuteoTiempos,85,0,rutaCompleta,tiempos,105,0,Main,calculateDistance3,607,0,Ruteador,tiempos,166,0,Ruteador,generaMatrizRuteoTiempos,103,6,Main,creaTablas,155,6,Main,ruteo,308,0
SelectedBuild=0
VisibleModules=5,3,4,1,2

View File

@@ -88,6 +88,7 @@ Sub generaMatrizRuteoTiempos(r As String, resp As ServletResponse, ruta As Strin
Log(ts)
Private tempMap As Map
tempMap.Initialize
If checkIfTableExists(r&"_punteo") Then
Private p As ResultSet = Main.db.ExecQuery($"select * from ${r}_punteo"$)
Private listCoords As List
listCoords.Initialize
@@ -106,13 +107,35 @@ Sub generaMatrizRuteoTiempos(r As String, resp As ServletResponse, ruta As Strin
tempMap.Put("distance", ts.Get("distance"))
tempMap.Put("puntos", ts.Get("puntos"))
tempMap.Put("coords", listCoords)
tempMap.Put("mensaje", Main.msg)
If tempMap.get("puntos") = 0 Then tempMap.Put("code", "KO")
' Log(tempMap)
js.Initialize(tempMap)
StopMessageLoop
Main.error = ""
Main.msg = ""
'Regresamos en un JSON la info del ruteo.
resp.ContentType = "text/html"
resp.Write(js.ToString)
Else
tempMap.Put("api", "")
tempMap.Put("code", "KO")
tempMap.Put("error", Main.error)
tempMap.Put("ruta", ruta)
tempMap.Put("almacen", almacen)
tempMap.Put("duration", 0)
tempMap.Put("distance", 0)
tempMap.Put("puntos", 0)
tempMap.Put("coords", "")
tempMap.Put("mensaje", Main.msg)
' Log(tempMap)
js.Initialize(tempMap)
StopMessageLoop
Main.error = ""
Main.msg = ""
resp.ContentType = "text/html"
resp.Write(js.ToString)
End If
Return 1
End Sub
@@ -147,10 +170,13 @@ Sub tiempos(r As String, resp As ServletResponse, ruta As String, almacen As Str
tempMap.Put("distance", ts.Get("distance"))
tempMap.Put("puntos", ts.Get("puntos"))
tempMap.Put("coords", listCoords)
tempMap.Put("mensaje", Main.msg)
If tempMap.get("puntos") = 0 Then tempMap.Put("code", "KO")
' Log(tempMap)
js.Initialize(tempMap)
StopMessageLoop
Main.error = ""
Main.msg = ""
resp.ContentType = "text/html"
resp.Write(js.ToString)
Log("###################################################################" & CRLF)

View File

@@ -90,8 +90,8 @@ Sub generaMatrizRuteoTiempos(r As String, resp As ServletResponse, ruta As Strin
Loop
Main.db.Close
StopMessageLoop
Main.error = ""
resp.ContentType = "text/html"
resp.Write($"<a href="https://osm.quelltextlich.at/viewer-js.html?kml_url=https://pi.famguerra.com/kmz.php?c=${listCoords}">Mapa</a>"$)
Return 1
End Sub
@@ -110,11 +110,10 @@ Sub tiempos(r As String, resp As ServletResponse, ruta As String, almacen As Str
End If
Loop
Main.db.Close
' Log("Iniciamos ruteoCompleto")
' ruteoCompleto(r)
StopMessageLoop
Main.error = ""
resp.ContentType = "text/html"
resp.Write($"<a href="https://osm.quelltextlich.at/viewer-js.html?kml_url=https://pi.famguerra.com/kmz.php?c=${listCoords}">Mapa</a>"$)
Return 1