mirror of
https://github.com/KeymonSoft/Ruteador-NonUI.git
synced 2026-04-19 05:39:31 +00:00
- Se agregaron varios TRY/CATCH para evitar que se muera la aplicacion en caso de parametros faltantes o equivocados.
This commit is contained in:
31
Mapa.bas
31
Mapa.bas
@@ -155,21 +155,26 @@ Sub ruteoCompleto(ruta As String) As ResumableSub 'ignore
|
||||
' Next
|
||||
' Log("*****************************************")
|
||||
' Log(js.NextObject)
|
||||
Private m As Map = js1.NextObject
|
||||
ts.Put(ruta, CreateMap("code":"KO", "duration":0, "distance":0, "puntos":0))
|
||||
Try
|
||||
Private m As Map = js1.NextObject
|
||||
' Private estatus As String = m.Get("code")
|
||||
Private rutas As Map = m.Get("routes").as(List).Get(0)
|
||||
' Private waypoints As List = m.Get("waypoints")
|
||||
' Log("Response: " & estatus)
|
||||
' Log("Duration: " & rutas.Get("duration"))
|
||||
' Log("Distance: " & rutas.Get("distance"))
|
||||
' Log("Legs: " & rutas.Get("legs").As(List).Size)
|
||||
' Log("Waypoints: " & waypoints.Size)
|
||||
Private steps As List
|
||||
steps.Initialize
|
||||
steps = rutas.Get("legs").as(List).get("steps")
|
||||
Log("STEPS SIZE: " & steps.Size)
|
||||
ts.Put(ruta, CreateMap("code":"Ok", "duration":rutas.Get("duration"), "distance":rutas.Get("distance"), "puntos":rutas.Get("legs").As(List).Size))
|
||||
Private rutas As Map = m.Get("routes").as(List).Get(0)
|
||||
' Private waypoints As List = m.Get("waypoints")
|
||||
' Log("Response: " & estatus)
|
||||
' Log("Duration: " & rutas.Get("duration"))
|
||||
' Log("Distance: " & rutas.Get("distance"))
|
||||
' Log("Legs: " & rutas.Get("legs").As(List).Size)
|
||||
' Log("Waypoints: " & waypoints.Size)
|
||||
Private steps As List
|
||||
steps.Initialize
|
||||
steps = rutas.Get("legs").as(List).get("steps")
|
||||
Log("STEPS SIZE: " & steps.Size)
|
||||
ts.Put(ruta, CreateMap("code":"OK", "duration":rutas.Get("duration"), "distance":rutas.Get("distance"), "puntos":rutas.Get("legs").As(List).Size))
|
||||
' Log(">>>>>>>>>>>>>>>>>>>>>>>>>>>" & ts)
|
||||
Catch
|
||||
Log(LastException)
|
||||
End Try
|
||||
Return 1
|
||||
End Sub
|
||||
|
||||
|
||||
@@ -201,33 +201,37 @@ Sub generaMatrizLocal(ruta As String) 'ignore
|
||||
Log("#################################################################")
|
||||
' Log($"delete from ${ruta}_punteo"$)
|
||||
Log("Generamos matriz LOCAL")
|
||||
db.ExecNonQuery($"delete from ${ruta}_punteo"$)
|
||||
' Log($"delete from ${ruta}_matriz"$)
|
||||
db.ExecNonQuery($"delete from ${ruta}_matriz"$)
|
||||
' matriz = ""
|
||||
punteoLista.Initialize
|
||||
' Private otroPunto() As String
|
||||
Private lasCols, losVals As String
|
||||
Private c As ResultSet = db.ExecQuery($"select * from ${ruta}_puntos"$)
|
||||
' Dim h As String = c.GetString("id")
|
||||
db.ExecNonQuery($"insert into ${ruta}_punteo (pos, id, nombre, lat, lon) values ('0', '${c.GetString("id")}', 'Almacen', ${c.Getdouble("lat")}, ${c.Getdouble("lon")})"$)
|
||||
' Log($"insert into ${ruta}_punteo (pos, id, nombre, lat, lon) values ('0', '${c.GetString("id")}', 'Almacen', ${c.Getdouble("lat")}, ${c.Getdouble("lon")})"$)
|
||||
punteoLista.Add(c.GetString("id")) 'Lista para ruteoNearestInsertion, ponemos el primer punto (almacen).
|
||||
Do While c.NextRow
|
||||
lasCols = "idT"
|
||||
' Log($"${c.GetString("id")}, ${c.GetString("nombre")}, ${c.GetString("lat")}, ${c.GetString("lon")}"$)
|
||||
Private d As ResultSet = db.ExecQuery($"select * from ${ruta}_puntos"$)
|
||||
losVals = $"'${c.GetString("id")}'"$
|
||||
Do While d.NextRow
|
||||
Private laDist As Double = calculateDistance1(c.GetDouble("lat"), c.GetDouble("lon"), d.GetDouble("lat"), d.GetDouble("lon"))
|
||||
lasCols = $"${lasCols}, '${d.GetString("id")}'"$
|
||||
losVals = $"${losVals}, '${laDist}'"$
|
||||
' Log($"(${c.GetString("id")},${d.GetString("id")}) - Dist entre ${c.GetString("nombre")} y ${d.GetString("nombre")} = ${laDist}"$)
|
||||
Try
|
||||
db.ExecNonQuery($"delete from ${ruta}_punteo"$)
|
||||
' Log($"delete from ${ruta}_matriz"$)
|
||||
db.ExecNonQuery($"delete from ${ruta}_matriz"$)
|
||||
' matriz = ""
|
||||
punteoLista.Initialize
|
||||
' Private otroPunto() As String
|
||||
Private lasCols, losVals As String
|
||||
Private c As ResultSet = db.ExecQuery($"select * from ${ruta}_puntos"$)
|
||||
' Dim h As String = c.GetString("id")
|
||||
db.ExecNonQuery($"insert into ${ruta}_punteo (pos, id, nombre, lat, lon) values ('0', '${c.GetString("id")}', 'Almacen', ${c.Getdouble("lat")}, ${c.Getdouble("lon")})"$)
|
||||
' Log($"insert into ${ruta}_punteo (pos, id, nombre, lat, lon) values ('0', '${c.GetString("id")}', 'Almacen', ${c.Getdouble("lat")}, ${c.Getdouble("lon")})"$)
|
||||
punteoLista.Add(c.GetString("id")) 'Lista para ruteoNearestInsertion, ponemos el primer punto (almacen).
|
||||
Do While c.NextRow
|
||||
lasCols = "idT"
|
||||
' Log($"${c.GetString("id")}, ${c.GetString("nombre")}, ${c.GetString("lat")}, ${c.GetString("lon")}"$)
|
||||
Private d As ResultSet = db.ExecQuery($"select * from ${ruta}_puntos"$)
|
||||
losVals = $"'${c.GetString("id")}'"$
|
||||
Do While d.NextRow
|
||||
Private laDist As Double = calculateDistance1(c.GetDouble("lat"), c.GetDouble("lon"), d.GetDouble("lat"), d.GetDouble("lon"))
|
||||
lasCols = $"${lasCols}, '${d.GetString("id")}'"$
|
||||
losVals = $"${losVals}, '${laDist}'"$
|
||||
' Log($"(${c.GetString("id")},${d.GetString("id")}) - Dist entre ${c.GetString("nombre")} y ${d.GetString("nombre")} = ${laDist}"$)
|
||||
Loop
|
||||
' Log($"${lasCols}${CRLF}${losVals}"$)
|
||||
db.ExecNonQuery($"insert into ${ruta}_matriz (${lasCols}) values (${losVals})"$)
|
||||
Loop
|
||||
' Log($"${lasCols}${CRLF}${losVals}"$)
|
||||
db.ExecNonQuery($"insert into ${ruta}_matriz (${lasCols}) values (${losVals})"$)
|
||||
Loop
|
||||
Log("Matriz LOCAL generada")
|
||||
Log("Matriz LOCAL generada")
|
||||
Catch
|
||||
Log(LastException)
|
||||
End Try
|
||||
' generaMatrizOSRM
|
||||
End Sub
|
||||
|
||||
@@ -236,52 +240,56 @@ Sub generaMatrizOSRM(ruta As String) As ResumableSub 'ignore
|
||||
Log("################################################################")
|
||||
Log("############# Main/generaMatrizOSRM ####################")
|
||||
Log("################################################################")
|
||||
db.ExecNonQuery($"delete from ${ruta}_punteo"$)
|
||||
db.ExecNonQuery($"delete from ${ruta}_matrizOSRM"$)
|
||||
' matriz = "OSRM"
|
||||
punteoLista.Initialize
|
||||
Private c As ResultSet = db.ExecQuery($"select * from ${ruta}_puntos"$)
|
||||
db.ExecNonQuery($"insert into ${ruta}_punteo (pos, id, nombre, lat, lon) values ('0', '${c.GetString("id")}', 'Almacen', ${c.Getdouble("lat")}, ${c.Getdouble("lon")})"$)
|
||||
punteoLista.Add(c.GetString("id")) 'Lista para ruteoNearestInsertion, ponemos el primer punto (almacen).
|
||||
Private lasCoords = "", lasCols = "idT", losIds = c.GetString("id") As String 'ignore
|
||||
Private listLasCols As List
|
||||
listLasCols.Initialize
|
||||
Do While c.NextRow
|
||||
listLasCols.Add(c.GetString("Id"))
|
||||
If lasCoords = "" Then
|
||||
lasCoords = $"${c.GetString("lon")},${c.GetString("lat")}"$
|
||||
lasCols = $"${lasCols},'${c.GetString("Id")}'"$
|
||||
Else
|
||||
lasCoords = $"${lasCoords};${c.GetString("lon")},${c.GetString("lat")}"$
|
||||
lasCols = $"${lasCols},'${c.GetString("Id")}'"$
|
||||
Try
|
||||
db.ExecNonQuery($"delete from ${ruta}_punteo"$)
|
||||
db.ExecNonQuery($"delete from ${ruta}_matrizOSRM"$)
|
||||
' matriz = "OSRM"
|
||||
punteoLista.Initialize
|
||||
Private c As ResultSet = db.ExecQuery($"select * from ${ruta}_puntos"$)
|
||||
db.ExecNonQuery($"insert into ${ruta}_punteo (pos, id, nombre, lat, lon) values ('0', '${c.GetString("id")}', 'Almacen', ${c.Getdouble("lat")}, ${c.Getdouble("lon")})"$)
|
||||
punteoLista.Add(c.GetString("id")) 'Lista para ruteoNearestInsertion, ponemos el primer punto (almacen).
|
||||
Private lasCoords = "", lasCols = "idT", losIds = c.GetString("id") As String 'ignore
|
||||
Private listLasCols As List
|
||||
listLasCols.Initialize
|
||||
Do While c.NextRow
|
||||
listLasCols.Add(c.GetString("Id"))
|
||||
If lasCoords = "" Then
|
||||
lasCoords = $"${c.GetString("lon")},${c.GetString("lat")}"$
|
||||
lasCols = $"${lasCols},'${c.GetString("Id")}'"$
|
||||
Else
|
||||
lasCoords = $"${lasCoords};${c.GetString("lon")},${c.GetString("lat")}"$
|
||||
lasCols = $"${lasCols},'${c.GetString("Id")}'"$
|
||||
End If
|
||||
Loop
|
||||
Log(">>>>>>>>>>>> " & lasCols & CRLF & lasCoords)
|
||||
Dim j As HttpJob
|
||||
j.Initialize("", Me)
|
||||
j.Download($"http://router.project-osrm.org/table/v1/driving/${lasCoords}"$)
|
||||
Wait For (j) JobDone(j As HttpJob)
|
||||
If j.Success Then
|
||||
' Log(j.GetString)
|
||||
Private j0 As String = j.GetString
|
||||
End If
|
||||
Loop
|
||||
Log(">>>>>>>>>>>> " & lasCols & CRLF & lasCoords)
|
||||
Dim j As HttpJob
|
||||
j.Initialize("", Me)
|
||||
j.Download($"http://router.project-osrm.org/table/v1/driving/${lasCoords}"$)
|
||||
Wait For (j) JobDone(j As HttpJob)
|
||||
If j.Success Then
|
||||
' Log(j.GetString)
|
||||
Private j0 As String = j.GetString
|
||||
End If
|
||||
j.Release
|
||||
' StopMessageLoop
|
||||
Private durs As String = j0.SubString2(j0.IndexOf($""durations""$)+12, j0.IndexOf($""sources""$)).Replace("[","")
|
||||
Private dur1() As String = Regex.Split("]", durs)
|
||||
Log(durs)
|
||||
For i = 0 To dur1.Length - 1
|
||||
Private estosVals As String = dur1(i)
|
||||
If estosVals.StartsWith(",") Then estosVals = $"${estosVals.SubString(1)}"$
|
||||
If estosVals.Length > 0 Then
|
||||
estosVals = $"'${listLasCols.get(i)}',${estosVals}"$
|
||||
Log(estosVals)
|
||||
' Log($"insert into ${ruta}_matrizOSRM (${lasCols}) values (${estosVals})"$)
|
||||
db.ExecNonQuery($"insert into ${ruta}_matrizOSRM (${lasCols}) values (${estosVals})"$)
|
||||
End If
|
||||
Next
|
||||
' fx.ShowExternalDocument($"http://router.project-osrm.org/table/v1/driving/${lasCoords}"$)
|
||||
Log("Matriz OSRM generada")
|
||||
j.Release
|
||||
' StopMessageLoop
|
||||
Private durs As String = j0.SubString2(j0.IndexOf($""durations""$)+12, j0.IndexOf($""sources""$)).Replace("[","")
|
||||
Private dur1() As String = Regex.Split("]", durs)
|
||||
Log(durs)
|
||||
For i = 0 To dur1.Length - 1
|
||||
Private estosVals As String = dur1(i)
|
||||
If estosVals.StartsWith(",") Then estosVals = $"${estosVals.SubString(1)}"$
|
||||
If estosVals.Length > 0 Then
|
||||
estosVals = $"'${listLasCols.get(i)}',${estosVals}"$
|
||||
Log(estosVals)
|
||||
' Log($"insert into ${ruta}_matrizOSRM (${lasCols}) values (${estosVals})"$)
|
||||
db.ExecNonQuery($"insert into ${ruta}_matrizOSRM (${lasCols}) values (${estosVals})"$)
|
||||
End If
|
||||
Next
|
||||
' fx.ShowExternalDocument($"http://router.project-osrm.org/table/v1/driving/${lasCoords}"$)
|
||||
Log("Matriz OSRM generada")
|
||||
Catch
|
||||
Log(LastException)
|
||||
End Try
|
||||
End Sub
|
||||
|
||||
Sub b_ruteo_Click
|
||||
@@ -295,9 +303,11 @@ Sub ruteo(ruta As String, matriz As String) 'ignore
|
||||
Log("#####################################################")
|
||||
db.ExecNonQuery($"delete from ${ruta}_punteo"$)
|
||||
punteoLista.Initialize
|
||||
Private c As ResultSet = db.ExecQuery($"select * from ${ruta}_puntos"$)
|
||||
db.ExecNonQuery($"insert into ${ruta}_punteo (pos, id, nombre, lat, lon) values ('0', '${c.GetString("id")}', 'Almacen', ${c.Getdouble("lat")}, ${c.Getdouble("lon")})"$)
|
||||
punteoLista.Add(c.GetString("id")) 'Lista para ruteoNearestInsertion, ponemos el primer punto de la lista de coordenadas.
|
||||
Private c As ResultSet = db.ExecQuery($"select * from ${ruta}_puntos 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")})"$)
|
||||
punteoLista.Add(c.GetString("id")) 'Lista para ruteoNearestInsertion, ponemos el primer punto de la lista de coordenadas.
|
||||
Loop
|
||||
|
||||
' Private c As ResultSet = db.ExecQuery($"select * from ${ruta}_puntos where id = 'CCINCIO' limit 1"$)
|
||||
' Do While c.NextRow
|
||||
@@ -409,18 +419,23 @@ Sub tiempos(ruta As String) As ResumableSub 'ignore
|
||||
'' Log(colroot)
|
||||
'' Next
|
||||
' Log("*****************************************")
|
||||
Private m As Map = js.NextObject
|
||||
Log(m)
|
||||
Private estatus As String = m.Get("code")
|
||||
Private rutas As Map = m.Get("routes").as(List).Get(0)
|
||||
Private waypoints As List = m.Get("waypoints")
|
||||
' Log("Response: " & estatus)
|
||||
' Log("Duration: " & rutas.Get("duration"))
|
||||
' Log("Distance: " & rutas.Get("distance"))
|
||||
' Log("Legs: " & rutas.Get("legs").As(List).Size)
|
||||
' Log("Waypoints: " & waypoints.Size)
|
||||
ts.Put(ruta, CreateMap("code":"Ok", "duration":rutas.Get("duration"), "distance":rutas.Get("distance"), "puntos":rutas.Get("legs").As(List).Size))
|
||||
' Log(">>>>>>>>>>>>>>>>>>>>>>>>>>>" & ts)
|
||||
ts.Put(ruta, CreateMap("code":"KO", "duration":0, "distance":0, "puntos":0))
|
||||
Try
|
||||
Private m As Map = js.NextObject
|
||||
Log(m)
|
||||
Private estatus As String = m.Get("code")
|
||||
Private rutas As Map = m.Get("routes").as(List).Get(0)
|
||||
Private waypoints As List = m.Get("waypoints")
|
||||
Log("Response: " & estatus)
|
||||
' Log("Duration: " & rutas.Get("duration"))
|
||||
' Log("Distance: " & rutas.Get("distance"))
|
||||
' Log("Legs: " & rutas.Get("legs").As(List).Size)
|
||||
' Log("Waypoints: " & waypoints.Size)
|
||||
ts.Put(ruta, CreateMap("code":"OK", "duration":rutas.Get("duration"), "distance":rutas.Get("distance"), "puntos":rutas.Get("legs").As(List).Size))
|
||||
' Log(">>>>>>>>>>>>>>>>>>>>>>>>>>>" & ts)
|
||||
Catch
|
||||
Log(LastException)
|
||||
End Try
|
||||
Return 1
|
||||
End Sub
|
||||
|
||||
|
||||
@@ -10,12 +10,12 @@ ModuleBreakpoints2=
|
||||
ModuleBreakpoints3=
|
||||
ModuleBreakpoints4=
|
||||
ModuleBreakpoints5=
|
||||
ModuleClosedNodes0=3,4,5,6,7,8,10,11,14,16,17,19,21,22,23,24,25
|
||||
ModuleClosedNodes0=3,4,5,6,8,10,11,14,17,19,21,22,23,24,25
|
||||
ModuleClosedNodes1=
|
||||
ModuleClosedNodes2=
|
||||
ModuleClosedNodes3=
|
||||
ModuleClosedNodes4=
|
||||
ModuleClosedNodes5=
|
||||
NavigationStack=Main,Process_Globals,26,6,Main,ruteoNearestInsertion,491,6,Main,generaMatrizOSRM,210,0,Main,generaMatrizLocal,182,0,Main,creaTablas,122,0,rutaCompleta,Initialize,12,0,Mapa,Handle,54,0,Ruteador,Handle,63,6,rutaCompleta,Handle,55,6,Main,ruteo,285,6
|
||||
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
|
||||
SelectedBuild=0
|
||||
VisibleModules=5,3,4,1,2
|
||||
|
||||
@@ -99,13 +99,14 @@ Sub generaMatrizRuteoTiempos(r As String, resp As ServletResponse, ruta As Strin
|
||||
tempMap.Put("api", matriz)
|
||||
If matriz = "" Then tempMap.Put("api", "Local")
|
||||
'Ponemos la ruta, almacen, tiempos, distancias y la lista de las coordenadas en un mapa para regresarla en un JSON.
|
||||
tempMap.Put("code", "Ok")
|
||||
tempMap.Put("code", "OK")
|
||||
tempMap.Put("ruta", ruta)
|
||||
tempMap.Put("almacen", almacen)
|
||||
tempMap.Put("duration", ts.Get("duration"))
|
||||
tempMap.Put("distance", ts.Get("distance"))
|
||||
tempMap.Put("puntos", ts.Get("puntos"))
|
||||
tempMap.Put("coords", listCoords)
|
||||
If tempMap.get("puntos") = 0 Then tempMap.Put("code", "KO")
|
||||
' Log(tempMap)
|
||||
js.Initialize(tempMap)
|
||||
StopMessageLoop
|
||||
@@ -139,13 +140,14 @@ Sub tiempos(r As String, resp As ServletResponse, ruta As String, almacen As Str
|
||||
Main.db.Close
|
||||
tempMap.Put("api", matriz)
|
||||
If matriz = "" Then tempMap.Put("api", "Local")
|
||||
tempMap.Put("code", "Ok")
|
||||
tempMap.Put("code", "OK")
|
||||
tempMap.Put("ruta", ruta)
|
||||
tempMap.Put("almacen", almacen)
|
||||
tempMap.Put("duration", ts.Get("duration"))
|
||||
tempMap.Put("distance", ts.Get("distance"))
|
||||
tempMap.Put("puntos", ts.Get("puntos"))
|
||||
tempMap.Put("coords", listCoords)
|
||||
If tempMap.get("puntos") = 0 Then tempMap.Put("code", "KO")
|
||||
' Log(tempMap)
|
||||
js.Initialize(tempMap)
|
||||
StopMessageLoop
|
||||
|
||||
@@ -156,21 +156,26 @@ Sub ruteoCompleto(ruta As String) As ResumableSub 'ignore
|
||||
' Next
|
||||
' Log("*****************************************")
|
||||
' Log(js.NextObject)
|
||||
Private m As Map = js1.NextObject
|
||||
ts.Put(ruta, CreateMap("code":"KO", "duration":0, "distance":0, "puntos":0))
|
||||
Try
|
||||
Private m As Map = js1.NextObject
|
||||
' Private estatus As String = m.Get("code")
|
||||
Private rutas As Map = m.Get("routes").as(List).Get(0)
|
||||
' Private waypoints As List = m.Get("waypoints")
|
||||
' Log("Response: " & estatus)
|
||||
' Log("Duration: " & rutas.Get("duration"))
|
||||
' Log("Distance: " & rutas.Get("distance"))
|
||||
' Log("Legs: " & rutas.Get("legs").As(List).Size)
|
||||
' Log("Waypoints: " & waypoints.Size)
|
||||
Private steps As List
|
||||
steps.Initialize
|
||||
steps = rutas.Get("legs").as(List).get(0).As(Map).Get("steps")
|
||||
Log("STEPS SIZE: " & steps.Size)
|
||||
ts.Put(ruta, CreateMap("code":"Ok", "duration":rutas.Get("duration"), "distance":rutas.Get("distance"), "puntos":rutas.Get("legs").As(List).Size))
|
||||
' Log(">>>>>>>>>>>>>>>>>>>>>>>>>>>" & ts)
|
||||
Private rutas As Map = m.Get("routes").as(List).Get(0)
|
||||
' Private waypoints As List = m.Get("waypoints")
|
||||
' Log("Response: " & estatus)
|
||||
' Log("Duration: " & rutas.Get("duration"))
|
||||
' Log("Distance: " & rutas.Get("distance"))
|
||||
' Log("Legs: " & rutas.Get("legs").As(List).Size)
|
||||
' Log("Waypoints: " & waypoints.Size)
|
||||
Private steps As List
|
||||
steps.Initialize
|
||||
steps = rutas.Get("legs").as(List).get(0).As(Map).Get("steps")
|
||||
Log("STEPS SIZE: " & steps.Size)
|
||||
ts.Put(ruta, CreateMap("code":"OK", "duration":rutas.Get("duration"), "distance":rutas.Get("distance"), "puntos":rutas.Get("legs").As(List).Size))
|
||||
' Log(">>>>>>>>>>>>>>>>>>>>>>>>>>>" & ts)
|
||||
Catch
|
||||
Log(LastException)
|
||||
End Try
|
||||
Return 1
|
||||
End Sub
|
||||
|
||||
|
||||
Reference in New Issue
Block a user