Skip to content

Commit

Permalink
No commit message
Browse files Browse the repository at this point in the history
  • Loading branch information
fdiaz authored and fdiaz committed Apr 8, 2022
1 parent c4fbdc8 commit 2eac530
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 54 deletions.
4 changes: 2 additions & 2 deletions importrules/codigoINE/ruleCodigoINE.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ def postprocess (self, report, feature):
#COMPROBAR SI ESTAN BIEN
if feature.get("INE_PROVINCIA") != None:
prov=feature.get("COD_PROVINCIA")
ineProv=feature.get("INE_PROVINCIA")
ineProv=feature.getString("INE_PROVINCIA")
storeP = self.repo.getStore("ARENA2_TR_INE_PROVINCIA")

builder = ExpressionUtils.createExpressionBuilder()
Expand Down Expand Up @@ -315,7 +315,7 @@ def possibleMun (self, mun, storeM):
###
class CodigoINERuleFactory(RuleFactory):
def __init__(self):
RuleFactory.__init__(self,"[GVA] Fail if not add INE Code (LRS)")
RuleFactory.__init__(self,"[GVA] Fail if not add INE Code")

def create(self, **args):
rule = CodigoINERule(self, **args)
Expand Down
5 changes: 4 additions & 1 deletion importrules/conteoVehiculos.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,10 @@ def execute(self, report, feature):
toReport = False
builder = StringBuilder()
for key in conteoPorTablas.keys():
if conteoPorTablas[key] != conteoPorFeature[key]:
n = conteoPorFeature[key]
if n == None:
n = 0
if conteoPorTablas[key] != n:
if toReport:
builder.append(", ")
toReport = True
Expand Down
4 changes: 2 additions & 2 deletions importrules/fechaCierre.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ def execute(self, report, feature):
#print DataTypeUtils.toDate(self.fechaDeCierreString), type(DataTypeUtils.toDate(self.fechaDeCierreString))
#print DataTypeUtils.toDate(self.fechaDeCierre)
#print ".. compare:", fecha <= self.fechaDeCierre
print "Test:", self.fechaDeCierre, fecha, fecha <= self.fechaDeCierre
print type(self.fechaDeCierre), type(fecha)
#print "Test:", self.fechaDeCierre, fecha, fecha <= self.fechaDeCierre
#print type(self.fechaDeCierre), type(fecha)
if fecha <= self.fechaDeCierre:
print ".. added"
report.add(
Expand Down
29 changes: 27 additions & 2 deletions importrules/geocode.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
from addons.AccidentRate.roadcatalog import geocodificar, checkRequirements
from addons.AccidentRate.importrules.titularidad import CODERR_CARRETERAKM_NO_ENCONTRADA
from addons.AccidentRate.importrules.titularidad import CODERR_KM_NO_ENCONTRADO
from addons.AccidentRate.importrules.titularidad import CODERR_CARRETERA_NO_INDICADA, TITULARIDAD_AUTONOMICA


from addons.Arena2Importer.Arena2ImportLocator import getArena2ImportManager
from addons.Arena2Importer.integrity import Transform, TransformFactory, Rule, RuleFactory, RuleFixer
Expand All @@ -23,6 +25,10 @@ def apply(self, feature, *args):
if feature.getType().get("LID_ACCIDENTE") == None:
# Si no es la tabla de accidentes no hacenos nada
return
carretera = feature.get("CARRETERA")
if carretera in ("",None):
feature.set("MAPA",None)
return
p, f, msg = geocodificar(
feature.get("FECHA_ACCIDENTE"),
feature.get("CARRETERA"),
Expand Down Expand Up @@ -109,12 +115,31 @@ def execute(self, report, feature):
# Si no es la tabla de accidentes no hacenos nada
return
titularidad_accidente = feature.get("TITULARIDAD_VIA")
carretera = feature.get("CARRETERA")
calleNombre = feature.get("CALLE_NOMBRE")
if not (calleNombre in ("",None)):
return
if carretera in ("",None):
errcode = CODERR_CARRETERA_NO_INDICADA
report.add(
feature.get("ID_ACCIDENTE"),
errcode,
"Ni carretera ni calle indicadas",
fixerID="IgnoreGeocodeError",
selected=True,
CARRETERA=feature.get("CARRETERA"),
PK=feature.get("KM"),
TITULARIDAD_ACCIDENTE=titularidad_accidente,
FECHA=feature.get("FECHA_ACCIDENTE"),
PROVINCIA=feature.get("COD_PROVINCIA")
)
return
p, f, msg = geocodificar(
feature.get("FECHA_ACCIDENTE"),
feature.get("CARRETERA"),
carretera,
feature.get("KM")
)
if p==None:
if p==None and titularidad_accidente == TITULARIDAD_AUTONOMICA:
errcode = CODERR_CARRETERAKM_NO_ENCONTRADA
if msg.lower().startswith("kilometro"):
errcode = CODERR_KM_NO_ENCONTRADO
Expand Down
5 changes: 5 additions & 0 deletions importrules/titularidad.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
CODERR_TITULARIDADCARRETERAKM_NO_ENCONTRADA = 102
CODERR_TITULARIDAD_INCORRECTA = 103
CODERR_TITULARIDAD_AUTONOMICA_SIN_CARETERA = 104
CODERR_CARRETERA_NO_INDICADA = 105

TITULARIDAD_DESCONOCIDA = 0
TITULARIDAD_ESTATAL = 1
Expand Down Expand Up @@ -183,6 +184,10 @@ def selfRegister():
CODERR_KM_NO_ENCONTRADO,
"%s - km no encontrado" % CODERR_KM_NO_ENCONTRADO
)
manager.addRuleErrorCode(
CODERR_CARRETERA_NO_INDICADA,
"%s - Carretera no indicada" % CODERR_CARRETERA_NO_INDICADA
)
manager.addRuleErrorCode(
CODERR_TITULARIDADCARRETERAKM_NO_ENCONTRADA,
"%s - Titularidad autonomica y carretera/km no encontrada" % CODERR_TITULARIDADCARRETERAKM_NO_ENCONTRADA
Expand Down
88 changes: 41 additions & 47 deletions roadcatalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use_plugin("org.gvsig.lrs.app.mainplugin")

from java.lang import String
from java.text import SimpleDateFormat
from org.gvsig.tools.dispose import DisposeUtils
from org.gvsig.tools.util import CachedValue
Expand All @@ -20,26 +21,19 @@

class StretchFeatureStoreCache(CachedValue):
def reload(self):
#store = getCarreterasManager().getStretchFeatureStore()
dataManager = DALLocator.getDataManager()
pool = dataManager.getDataServerExplorerPool()
#explorerParams = pool.get("carreteras_gva")#.getExplorerParameters()

#if explorerParams==None:
ws = dataManager.getDatabaseWorkspace("ARENA2_DB")

# Tags values CONFIG table
poolCarreterasSchema = ws.get("TRAMOS_CARRETERAS_SCHEMA")
poolCarreterasName = ws.get("TRAMOS_CARRETERAS_NAME")
tramosSchemaName = ws.get("TRAMOS_CARRETERAS_SCHEMA")
tramosTableName = ws.get("TRAMOS_CARRETERAS_NAME")

repo = ws.getStoresRepository()
server_explorer = ws.getServerExplorer()
explorer_params = server_explorer.get(poolCarreterasName)
explorer_params.setSchema(poolCarreterasSchema)
explorer_params = server_explorer.get(tramosTableName)
explorer_params.setSchema(tramosSchemaName)
explorer_name = explorer_params.getProviderName()

store = dataManager.openStore(explorer_name, explorer_params)
#store.dispose()
self.setValue(store)

lrsManager = None
Expand All @@ -58,34 +52,43 @@ def getStretchFeatureStore():


def checkRequirements():
"""
dataManager = DALLocator.getDataManager()
s = ""
s = u""
if getLRSManager()==None:
s += "No se ha podido acceder al plugin de LRS, es posible que no se encuentre instalado.\n"
pool = dataManager.getDataServerExplorerPool()
if pool.get("carreteras_gva")==None:
s += "No se ha podido localizar la conexion 'carreteras_gva' para poder acceder a las capas de carreteras\n"
else:
try:
explorerParams = pool.get("carreteras_gva").getExplorerParameters()
poolCarreterasSchema = DALLocator.getDataManager().getDatabaseWorkspace("ARENA2_DB").get("TRAMOS_CARRETERAS_SCHEMA")
explorerParams.setSchema(poolCarreterasSchema)
explorer = dataManager.openServerExplorer(explorerParams.getProviderName(), explorerParams)
poolCarreterasName = DALLocator.getDataManager().getDatabaseWorkspace("ARENA2_DB").get("TRAMOS_CARRETERAS_NAME")
params = explorer.get(poolCarreterasName)
explorer.dispose()
except:
params = None
if params == None:
s += "No se ha podido acceder a la tabla 'layers.tramos_carreteras'.\n"
s += u"No se ha podido acceder al plugin de LRS, es posible que no se encuentre instalado.\n"
try:
ws = dataManager.getDatabaseWorkspace("ARENA2_DB")
if ws == None:
s += u"No se ha encontrado el espacio de trabajo de ARENA2_DB.\n"
else:
if not ws.isConnected():
s += u"No se está conectado a un espacio de trabajo de ARENA2_DB.\n"
else:
tramosSchemaName = ws.get("TRAMOS_CARRETERAS_SCHEMA")
if tramosSchemaName in ("", None):
s += u"No se ha encontrado la variable de configuración 'TRAMOS_CARRETERAS_SCHEMA'.\n"

tramosTableName = ws.get("TRAMOS_CARRETERAS_NAME")
if tramosTableName in ("", None):
s += u"No se ha encontrado la variable de configuración 'TRAMOS_CARRETERAS_NAME'.\n"
else:
try:
repo = ws.getStoresRepository()
server_explorer = ws.getServerExplorer()
explorer_params = server_explorer.get(tramosTableName)
explorer_params.setSchema(tramosSchemaName)
explorer_name = explorer_params.getProviderName()

store = dataManager.openStore(explorer_name, explorer_params)
store.dispose()
except:
s += u"No se ha podido acceder a la tabla '%s', revise las variable de configuración 'TRAMOS_CARRETERAS_SCHEMA' y 'TRAMOS_CARRETERAS_NAME'.\n"%tramosTableName
except:
s += u"No se ha podido acceder a la tabla de tramos de carreteras.\n"
if s.strip() == "":
return None
return s
"""
return None

def getVigentStretchesQuery(store, fecha):
builder = ExpressionUtils.createExpressionBuilder()
filtro = builder.and(
Expand All @@ -99,13 +102,6 @@ def getVigentStretchesQuery(store, fecha):
))
).toString()

#dateFormatter = SimpleDateFormat("dd/MM/yyyy")
#formatedDate = dateFormatter.format(fecha)
#filtro = "( fecha_entrada <= '%s' OR fecha_entrada IS NULL) AND ('%s' <= fecha_salida OR fecha_salida IS NULL)" % (
# formatedDate,
# formatedDate
#)

query = store.createFeatureQuery()
query.addFilter(filtro)
return query
Expand All @@ -128,7 +124,6 @@ def geocodificar(fecha, carretera, pk):

builder = ExpressionUtils.createExpressionBuilder()
expression = builder.eq(builder.variable("matricula"), builder.constant(carretera)).toString()
#expression = "matricula = '%s'" % carretera
try:
query.addFilter(expression)
query.retrievesAllAttributes()
Expand All @@ -142,10 +137,9 @@ def geocodificar(fecha, carretera, pk):
# LRS devuelve un Point2DM y falla al guardarse en la BBDD (H2 por lo menos)
location = GeometryUtils.createPoint(location.getX(), location.getY())
return (location, strech, None)
return (None, None, "kilometro %s no encontrado en '%s'." % (pk,carretera))
return (None, None, "kilometro %.3f no encontrado a fecha %s en '%s'." % (pk/1000,String.format("%td/%tm/%tY",fecha,fecha,fecha),carretera))
finally:
DisposeUtils.disposeQuietly(streches)
#DisposeUtils.disposeQuietly(strechesStore)

def findOwnership(fecha, carretera, pk):
if fecha == None or carretera == None or pk == None:
Expand All @@ -158,17 +152,17 @@ def findOwnership(fecha, carretera, pk):
builder.and( builder.le(builder.variable("pk_i"), builder.constant(pk)))
builder.and( builder.ge(builder.variable("pk_f"), builder.constant(pk)))
expression = builder.toString()
#expression = "matricula = '%s' and pk_i >= %s and pk_f <= %s" % (carretera, pk, pk)
query.addFilter(expression)
query.retrievesAllAttributes()
feature = strechesStore.findFirst(query)
#DisposeUtils.disposeQuietly(strechesStore)
if feature == None:
return None
return feature.get("titularidad")


def main(*args):
print checkRequirements()

def main0(*args):
from java.util import Date
fecha = Date()
builder = ExpressionUtils.createExpressionBuilder()
Expand Down

0 comments on commit 2eac530

Please sign in to comment.