import datetime
|
|
from pub.extactJSON import ParserMOI as moiParser
|
from pub.queryMoi import QueryElevation as moiEvApi
|
from pub.postgis import Dbconnect
|
|
from parser import Updateev0
|
from parser import GetMoiEvBy84
|
|
class Db():
|
|
def __init__(self,dbConf):
|
self.dbConf=dbConf
|
self.updateid=0
|
self.dtStart=datetime.datetime.now()
|
self.dtNext=datetime.datetime.now()
|
|
def resetTabelEv(self,tablename,dbSRS='3826',srcgeom='geom',desgeom='geom'):
|
#print (self.dbConf)
|
self.gis3d= Dbconnect()
|
print('setEv')
|
self.gis3d.tryConn(self.dbConf)
|
|
print('db ok')
|
poi= Updateev0 (tablename,self.updDB,dbSRS=dbSRS,srcgeom=srcgeom,desgeom=desgeom) #self.writeFile)
|
|
#other connection
|
self.gis3d.fetchTable( self.dbConf,
|
poi.sql_sel() ,
|
fnProc=poi
|
)
|
self.gis3d.destroyConn()
|
|
def getTableEv(self,tablename,limit=100,dbSRS='3826',srcgeom='geom',desgeom='geom'):
|
|
self.gis3d= Dbconnect()
|
print('getEv')
|
|
self.gis3d.tryConn(self.dbConf)
|
|
print('db ok,limit={},srs={}'.format(limit,dbSRS))
|
|
poi= GetMoiEvBy84 (tablename,self.updDB,limit=limit,fnErr=self.writeFile,dbSRS=dbSRS,srcgeom=srcgeom,desgeom=desgeom) #self.writeFile) #self.updDB) #self.writeFile)
|
#poi= GetMoiEvBy84 (tablename,self.writeFile,limit=limit,fnErr=self.writeFile,dbSRS=dbSRS,srcgeom=srcgeom,desgeom=desgeom) #self.writeFile) #self.updDB) #self.writeFile)
|
|
self.dtStart=datetime.datetime.now()
|
#other connection
|
self.gis3d.fetchTable( self.dbConf,
|
poi.sql_sel() ,
|
fnProc=poi
|
)
|
print ('total {}'.format(datetime.datetime.now()-self.dtStart))
|
self.gis3d.destroyConn()
|
|
|
def updDB(self,sql_upd,wkt,id,table):
|
|
#print('update id',id)
|
#self.updateid=self.updateid+1
|
if(self.updateid % 100 == 0):
|
dtnow= datetime.datetime.now()
|
print('count:',self.updateid,'{}({})({} @ {})'.format(table,id,dtnow-self.dtNext, dtnow-self.dtStart))
|
self.dtNext=datetime.datetime.now()
|
|
self.updateid=self.updateid+1
|
#print ('update!{}'.format(id,wkt))
|
self.gis3d.executeWithConn(sql_upd.format(wkt,id))
|
# # print('nothing')
|
|
def writeFile(self,sql_upd,wkt,id,table):
|
#print('writefile',id)
|
print(id)
|
fname='logs/{}.{}.log'.format(table,self.dtStart.strftime('%Y%m%d_%H%M%S') )
|
print ('error@({})-->{}'.format(id,fname ) )
|
fp = open(fname, "a")
|
lines =[sql_upd.format(wkt,id),";\n"]
|
# ["One\n", "Two\n", "Three\n", "Four\n", "Five\n"]
|
fp.writelines(lines)
|
fp.close()
|