def getSoldDate(web_data,lot_id) :
	#Method getSoldDate: 
	#Usage: Get lot's sell/sold date from lot's html source page, also it can get the information about the lot has been sold or still biding. 
	#Two parameter, the first parameter is the lot's html source page
	#The second parameter is the lot's ID (Why it needs that? Because if there is an error happened, the lot's ID would print into the error log file). 
	#Normally, the method would return a list with two element. 
	#The first element is index about the item has been sold or not with integer type. 
	#If the first element equals 0, means that the item has not been sold yet. 
	#If the first element equals 1, means that the item has already been sold. 
	#The second element is the date that the item would/will be sold, and the data type is datetime object.  
	#The timezone is your local time zone. 
	#If there is an error happened in this method, it would return ['']. 
	try :
		bid_day_remain = re.findall('\"Days\":(.*?),',web_data)[0]
		days_num = 0
		lot_sold = 0
		lot_sell_date = datetime.now()
		if re.match('-',bid_day_remain) :
			lot_sold = 1
			days_num = int(re.findall('.*?([0-9]+)',bid_day_remain)[0])
			lot_sell_date = lot_sell_date - timedelta( days = days_num )
		else : 
			days_num = int(bid_day_remain)
			lot_sell_date = lot_sell_date + timedelta( days = days_num)	
		return [lot_sold,lot_sell_date]
	except Exception,e :
		ErrorHandling.errorOutput(lot_id,'Catch sold date Failed',repr(e),3)
		return ['']
Beispiel #2
0
	def mysqlStoreData (self) : 
	#Method for storing the data into MySql database
	#The method would check if you want to store the data into MySql database in your setting in config.py file
	#Before calling this method, please ensure that you have already create a table in database in appropriate format. 
	#If you don't know what is appropriate format is, please take a look at MySqlIni.py. There is a method createTable(), and it would help you. 
	#Actually, the users do not required to create a table first. You can edit config.py file, and set: MySqlTableExisted = 0. Then the program would automatically create a table before catch the data. 
	#This method has return value. 
	#If there is no error and storage successful, the method would return 1
	#If there is an error happened, the method would tried to repeat the storage for at maxitum 3 times til storage successful, and return 1.
	#If it has error happened for three tims and storage failure, the method would return 0
		if config.UseMySqlDataBase == 1 :
			flag = 0
			while flag < 3 :
				try :
					#---------------------------------------------------------------------------------------------------
					#Mysql Database operation
					db = MySQLdb.connect(config.MySqlHost,config.MySqlUser,config.MySqlPassword,config.MySqlDatabase)
					cursor = db.cursor()
					cursor.execute("INSERT INTO " + config.MysqlTableName + "(lot_id, author_name, author_birth, author_death, author_race, lot_name, lot_year, lot_info, lot_info_addi, lot_desc, lot_provenance, est_upp, est_low, biding_price, biding_number, lot_status, ending_date) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)", (self.lot_id, self.artest.encode('utf-8'), self.artest_birth, self.artest_death, self.artest_race.encode('utf-8'), self.lot_name.encode('utf-8'), self.lot_year, self.lot_info.encode('utf-8'), self.lot_info_2.encode('utf-8'), self.lot_desc.encode('utf-8'), self.lot_provenance.encode('utf-8'), self.est_up, self.est_low, self.bid_price, self.bid_number, self.lot_sold, self.lot_sell_date.strftime('%Y-%m-%d 0:0:0')))
					db.commit()
					db.close()
					#-----------------------------------------------------------------------------------------------------
					return 1
				except MySQLdb.Error, e:
					#If there is error happened: 
					if flag < 2 : 
						ErrorHandling.errorOutput(self.lot_id,'DataBase Error',repr(e),1)
						flag = flag + 1
						continue
					else :
						ErrorHandling.errorOutput(self.lot_id,'DataBase Error',repr(e),2)
						return 0
def getLotInfoAddi(web_data,lot_id) :
	#Method getLotInfoAddi:
	#Usage: Get the lot's additional information, the extention of lot's general information for this lot. 
	#Two parameter, the first parameter is the lot's html source page
	#The second parameter is the lot's ID (Why it needs that? Because if there is an error happened, the lot's ID would print into the error log file). 
	#Normally, the method would return the lot's additional information in string type
	#If there is an error happened, it would return ''(empty). 
	try :
		return re.findall('<p>(.*?)</p><div class=\"lot-id\">',web_data)[0]
	except Exception,e :
		ErrorHandling.errorOutput(lot_id,'Catch Lot\' additional information Failed',repr(e),3)
		return ''
def getBidNum(web_data,lot_id) :
	#Method getBidNum:
	#Usage: Get the lot's bid number (how many bid for this lot). 
	#Two parameter, the first parameter is the lot's html source page
	#The second parameter is the lot's ID (Why it needs that? Because if there is an error happened, the lot's ID would print into the error log file). 
	#Normally, the method would return the lot's bid number in integer type
	#If there is an error happened, it would return 0. 
	try :
		return int(re.findall('\"NumberOfBids\":([0-9]+),',web_data)[0])
	except Exception,e :
		ErrorHandling.errorOutput(lot_id,'Catch Bidding Number Failed',repr(e),3)
		return 0
def getLotInfo(web_data,lot_id) :
	#Method getLotInfo:
	#Usage: Get the lot's general information, such as the dimention, color, size, and texture. 
	#Two parameter, the first parameter is the lot's html source page
	#The second parameter is the lot's ID (Why it needs that? Because if there is an error happened, the lot's ID would print into the error log file). 
	#Normally, the method would return the lot's general information in string type
	#If there is an error happened, it would return ''(empty). 
	try :
		return re.findall('<div class=\"lot-info\"><p class=\"description\">(.*?)</p>',web_data)[0]
	except Exception,e :
		ErrorHandling.errorOutput(lot_id,'Catch Lot\' information Failed',repr(e),3)
		return ''
def getLotName(web_data,lot_id) :
	#Method getLotName:
	#Usage: Get the lot's name/title. 
	#Two parameter, the first parameter is the lot's html source page
	#The second parameter is the lot's ID (Why it needs that? Because if there is an error happened, the lot's ID would print into the error log file). 
	#Normally, the method would return the lot's name/title in string type
	#If there is an error happened, it would return ''(empty). 
	try :
		return re.findall('<h3 class=\"lot-name\"><i>(.*?)</i>',web_data)[0]
	except Exception,e :
		ErrorHandling.errorOutput(lot_id,'Catch Lot\' Name Failed',repr(e),3)
		return ''
def getDealPrice(web_data,lot_id) :
	#Method getDealPrice:
	#Usage: Get the lot's final price (if the bidding is not complete, this method would get the last bid price). 
	#Two parameter, the first parameter is the lot's html source page
	#The second parameter is the lot's ID (Why it needs that? Because if there is an error happened, the lot's ID would print into the error log file). 
	#Normally, the method would return the lot's final price (for last bid) in integer type
	#If there is an error happened, it would return 0. 
	try :
		return int(re.findall('\"CurrentPrice\":([0-9]+).*?,',web_data)[0])
	except Exception,e :
		ErrorHandling.errorOutput(lot_id,'Catch deal price Failed',repr(e),3)
		return 0
def getAuthorname (web_data,lot_id) :
	#Method getAuthorname:
	#Usage: Get the artist's Name for this lot. 
	#Two parameter, the first parameter is the lot's html source page
	#The second parameter is the lot's ID (Why it needs that? Because if there is an error happened, the lot's ID would print into the error log file). 
	#Normally, the method would return the artist's name in string type
	#If there is an error happened, it would return ''(empty). 
	try :
		return re.findall('serverViewData\.ArtistFullName = \"(.*?)\"',web_data)[0]
	except Exception,e :
		ErrorHandling.errorOutput(lot_id,'Catch Artest\' Name Failed',repr(e),3)
		return ''
def getLotDesc(web_data,lot_id) :
	#Method getLotDesc:
	#Usage: Get the lot's artistic description. 
	#Two parameter, the first parameter is the lot's html source page
	#The second parameter is the lot's ID (Why it needs that? Because if there is an error happened, the lot's ID would print into the error log file). 
	#Normally, the method would return the lot's artistic description in string type
	#If there is an error happened, it would return ''(empty). 
	try :
		return re.findall('<div id=\"lotDescriptionWraper\"><p>(.*?)</p></div>',web_data)[0]
	except Exception,e :
		ErrorHandling.errorOutput(lot_id,'Catch Lot\' description Failed',repr(e),3)
		return ''
def getLotYear(web_data,lot_id) :
	#Method getLotYear:
	#Usage: Get the lot's creation year. 
	#Two parameter, the first parameter is the lot's html source page
	#The second parameter is the lot's ID (Why it needs that? Because if there is an error happened, the lot's ID would print into the error log file). 
	#Normally, the method would return the lot's creation year in integer type
	#If there is an error happened, it would return 0. 
	try :
		lot_year_place = re.findall('<h3 class=\"lot-name\"><i>.*?</i>(.*?)</h3>',web_data)[0]
		lot_year = 0
		if re.search('[0-9]',lot_year_place) :
			lot_year = int(re.findall('([0-9]{4})',lot_year_place)[0])
		return lot_year
	except Exception,e :
		ErrorHandling.errorOutput(lot_id,'Catch the year of creation Failed',repr(e),3)
		return 0
    def __appendZs__(self, points):
        try:

            newcoords = ""
            coordpairs = points.split(';')
            pointGeometryList = []
            fields=["SHAPE@X", "SHAPE@Y"]
            rows = arcpy.da.SearchCursor(points, fields)
            for row in rows:
                coordpair = str(row[0]) + ' ' + str(row[1])
                arcpy.AddMessage('coords: ' + coordpair)
                result = arcpy.GetCellValue_management(self.islyr, coordpair)
                e = result.getOutput(0)
                if e != 'NoData':
                    v = int(e) + self.height
                else:
                    v = self.height
                if len(newcoords)>0:
                    newcoords += ";" + coordpair + " " + str(v)
                else:
                    newcoords +=  coordpair + " " + str(v)
            del rows
            del row
            arcpy.AddMessage('newcoords: ' + newcoords)
            return newcoords
        except arcpy.ExecuteError:
            EH = ErrorHandling.ErrorHandling()
            line, filename, err = EH.trace()
            m = "Python error on " + line + " of " + __file__ + \
                " : with error - " + err
            arcpy.AddError(m)
    def __makeObserver__(self, observers, name, wkid = None):
        try:
            arcpy.AddMessage("Creating observer...")
##            curwkid = None
##            if wkid:
##                curwkid = wkid
##                sref = arcpy.SpatialReference(wkid)
##            else:
##                curwkid = self.wkidin
##                sref = self.srIn
##            arcpy.SpatialReference(self.wkidin)
            obs = self.__createFC__(observers, self.sref, name)
            arcpy.AddMessage("observation fc: " + arcpy.Describe(obs).name)
            #obsproj = os.path.join(self.scratchgdb, name+'_proj')
            obsout = os.path.join(self.scratchgdb, name+'out')
            obs.save(obsout);

##            if(curwkid != self.wkidproc):
##                arcpy.AddMessage("Projecting observers...")
##                arcpy.AddMessage("projected observation fc: " + obsproj)
##                arcpy.Project_management(obs,obsproj,self.srProc)
##                obsout = obsproj
##            else:
##                obsout=obs
            h=self.height
            arcpy.AddField_management(obsout, "OFFSETA", "DOUBLE", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")
            arcpy.CalculateField_management(obsout, "OFFSETA", h, "PYTHON", "")
            return obsout
        except arcpy.ExecuteError:
            EH = ErrorHandling.ErrorHandling()
            line, filename, err = EH.trace()
            m = "Python error on " + line + " of " + __file__ + \
                " : with error - " + err
            arcpy.AddError(m)
def getLotProv(web_data,lot_id) :
	#Method getLotProv:
	#Usage: Get the lot's provenance. 
	#Two parameter, the first parameter is the lot's html source page
	#The second parameter is the lot's ID (Why it needs that? Because if there is an error happened, the lot's ID would print into the error log file). 
	#Normally, the method would return the lot's provenance information in string type
	#If there is an error happened or there is no provenance information, it would return ''(empty). 
	try :
		lot_provenance = '';
		if re.search('lot-history-text',web_data) :
			lot_provenance = re.findall('<ul class=\"lot-history-text\">(.*?)</ul>',web_data)[0]
			lot_provenance = re.sub('</li>','<br>',lot_provenance)
			lot_provenance = re.sub('<li>','',lot_provenance)
		return lot_provenance
	except Exception,e :
		ErrorHandling.errorOutput(lot_id,'Catch Lot\' provenance Failed',repr(e),3)
		return ''
    def createViewshed(self):
        try:
            tempEnvironment0 = arcpy.env.extent
            arcpy.env.extent = self.buffer
            tempEnvironment1 = arcpy.env.cellSize
            arcpy.env.cellSize = self.cellsize
            arcpy.AddMessage("cellsize: " + str(arcpy.env.cellSize))
            tempEnvironment2 = arcpy.env.mask
            arcpy.env.mask = self.buffer
            #outraster = sa.Viewshed(self.islyr, self.obsproc, 1, "FLAT_EARTH", 0.13)
            outraster = sa.Visibility(self.islyr,
                                      self.obsproc,
                                      analysis_type="FREQUENCY",
                                      nonvisible_cell_value="ZERO",
                                      z_factor=1,
                                      curvature_correction="CURVED_EARTH",
                                      refractivity_coefficient=0.13,
                                      observer_offset=self.height,
                                      outer_radius=self.radius,
                                      vertical_upper_angle=90,
                                      vertical_lower_angle=-90)
            #outrastertemp = os.path.join(r"C:\GEE\visibility", 'outvis')
            #outraster.save(outrastertemp)
            vshedtmp = os.path.join("in_memory", 'vshedtmp')
            vsheddis = os.path.join("in_memory", 'vsheddis')
            #vshed_proj = os.path.join(self.scratchgdb, 'vshedproj')
            arcpy.AddMessage("temp vshed fc:" + vshedtmp)
            arcpy.AddMessage("dissolved vshed fc: " + vsheddis)
            arcpy.env.extent = tempEnvironment0
            arcpy.env.cellSize = tempEnvironment1
            arcpy.env.mask = tempEnvironment2
            arcpy.RasterToPolygon_conversion(outraster, vshedtmp,
                                             "NO_SIMPLIFY", "VALUE")
            arcpy.Dissolve_management(vshedtmp, vsheddis, "gridcode", "",
                                      "MULTI_PART", "DISSOLVE_LINES")

            ##            if(self.wkidproc != self.wkidout):
            ##                arcpy.AddMessage("Projecting output vshed...")
            ##                arcpy.AddMessage("projected vshed fc: " + vshed_proj)
            ##                arcpy.Project_management(vsheddis, vshed_proj, self.srOut)
            ##                vshed=vshed_proj
            ##            else:
            ##                vshed=vsheddis
            #vistmp = os.path.join('in_memory', 'visibility')
            vis = os.path.join(self.scratchgdb, 'visibility')
            arcpy.AddMessage('creating output viewshed: ' + vis)
            arcpy.Clip_analysis(vsheddis, self.mask, vis, "")
            arcpy.AddMessage("Coppying to output...")
            #arcpy.CopyFeatures_management(vistmp, vis)
            fset = arcpy.FeatureSet()
            fset.load(vis)
            return fset
        except arcpy.ExecuteError:
            EH = ErrorHandling.ErrorHandling()
            line, filename, err = EH.trace()
            m = "Python error on " + line + " of " + __file__ + \
                " : with error - " + err
            arcpy.AddError(m)
def getEst(web_data,lot_id) :
	#Method getEst: 
	#Usage: Get lot's estimated price from lot's html source page. 
	#Two parameter, the first parameter is the lot's html source page
	#The second parameter is the lot's ID (Why it needs that? Because if there is an error happened, the lot's ID would print into the error log file). 
	#Normally, the method would return a list with two element. There is a lower bound of estimation and upper bound of estimation. 
	#The first element is the lower bound of the estimation price with integer type. 
	#The second element is the upper bound of the estimation price with integer type. 
	#If there is an error happened in this method, it would return ['']. 
	try :
		est = re.findall('\"Estimate\":\"(.*?) USD\"',web_data)[0]
		est = est.replace(',','')
		est_low = int(re.findall('([0-9]+).*?[0-9]+',est)[0])
		est_up = int(re.findall('[0-9]+.*?([0-9]+)',est)[0])
		return [est_low,est_up]
	except Exception,e :
		ErrorHandling.errorOutput(lot_id,'Catch Lot\' estimate values Failed',repr(e),3)
		return ['']
def urlReq(flag,lot_id) :
	#Method urlReq: 
	#Usage: Get response from URL request, if the artnet.com is not accessiable, the program would try at maxium four times until the artnet.com response to the URL request. 
	#Return ''(empty) if artnet.com is not accessiable for three times
	#Normally, the method would return the certain lot's html source page, and the method has already delete all the wrap and the space between all the html lable. 
	#For the first parameter, please put 0. 
	#For the second parameter, please input the lot's ID. 
	if flag > 3 :
		ErrorHandling.errorOutput(lot_id,'Network Connection Error','Cannot Connect to artnet.com',2)
		return ''
	else :
		try :
			web = requests.get("https://www.artnet.com/auctions/Pages/Lots/" + str(lot_id) + ".aspx").text
			web_data = re.sub(r'[\r]+[\n]+[\s]+','',web)
			web_data = web_data.replace('\r','').replace('\n','').replace('\t','')
			return web_data
		except Exception,e :
			ErrorHandling.errorOutput(lot_id,'Network Connection Error','Cannot Connect to artnet.com',1)
			return urlReq(flag + 1,lot_id)
Beispiel #17
0
 def __CalculateCellSize__(self, ds):
     try:
         arcpy.AddMessage("Calculating cellsize...")
         width = arcpy.Describe(ds).extent.width
         height = arcpy.Describe(ds).extent.height
         return max(float(max(width, height)) / 2000.0, 30.0)
     except arcpy.ExecuteError:
         EH = ErrorHandling.ErrorHandling()
         line, filename, err = EH.trace()
         m = "Python error on " + line + " of " + __file__ + \
             " : with error - " + err
         arcpy.AddError(m)
def getArtestDetail (web_data,lot_id) :
	#Method getArtestDetail: 
	#Usage: Get artist's nationality, artist's birth year, and artist's death year from lot's html source page. 
	#Two parameter, the first parameter is the lot's html source page
	#The second parameter is the lot's ID (Why it needs that? Because if there is an error happened, the lot's ID would print into the error log file). 
	#Normally, the method would return a list with three element. 
	#The first element is the artist's nationality with string type. 
	#The second element is the artist's birth year with integer type. 
	#The third element is the artist's death year with integer type. 
	#If the method cannot found the artist's nation in html source page, the first element would be 'Unknown'
	#If the method cannot found the artist's birth or death year, the second or the third element would be 0. 
	#If there is an error happened in this method, it would return ['']. 
	try :
		artest_detail = re.findall('<div class=\"artist-details\">(.*?)</div>',web_data)[0]
		artest_race = 'Unknown'
		artest_birth = 0
		artest_death = 0
		if re.search(',', artest_detail) :
			artest_detail_ = artest_detail.split(',')
			artest_race = artest_detail_[0]
			if re.search('b.', artest_detail_[1]) :
				artest_birth = int(re.findall('.*?([0-9]{4})',artest_detail_[1])[0])
			else : 
				artest_date = re.findall('([0-9]{4}).*?([0-9]{4})',artest_detail_[1])[0]
				artest_birth = int(artest_date[0])
				artest_death = int(artest_date[1])
		else :
			if re.search('[0-9]',artest_detail) :
				if re.search('b.', artest_detail) :
					artest_birth = int(re.findall('.*?([0-9]{4})',artest_detail)[0])
				else : 
					artest_date = re.findall('([0-9]{4}).*?([0-9]{4})',artest_detail)[0]
					artest_birth = int(artest_date[0])
					artest_death = int(artest_date[1])
			else :
				artest_race = artest_detail
		return [artest_race,artest_birth,artest_death]
	except Exception,e :
		ErrorHandling.errorOutput(lot_id,'Catch Artest\' Detail Failed',repr(e),3)
		return ['']
 def __makeBuffers__(self, radius):
     try:
         arcpy.AddMessage("Creating buffer...")
         bufferfc = os.path.join("in_memory", "buffers")
         arcpy.AddMessage("buffer fc: " + bufferfc)
         arcpy.Buffer_analysis(self.obsproc, bufferfc, radius, "FULL", "ROUND", "ALL")
         return bufferfc
     except arcpy.ExecuteError:
         EH = ErrorHandling.ErrorHandling()
         line, filename, err = EH.trace()
         m = "Python error on " + line + " of " + __file__ + \
             " : with error - " + err
         arcpy.AddError(m)
 def __CreateISLayer__(self, service):
     try:
         arcpy.AddMessage("Creating image service layer...")
         outislyr=os.path.join("in_memory",'ras_dsm')
         arcpy.AddMessage("image service layer: " + outislyr)
         arcpy.MakeImageServerLayer_management(service, outislyr, self.buffer, "", "CLOSEST_TO_CENTER", "", "", "", self.cellsize)
         return outislyr
     except arcpy.ExecuteError:
         EH = ErrorHandling.ErrorHandling()
         line, filename, err = EH.trace()
         m = "Python error on " + line + " of " + __file__ + \
             " : with error - " + err
         arcpy.AddError(m)
Beispiel #21
0
    def createViewshed(self):
        try:
            tempEnvironment0 = arcpy.env.extent
            arcpy.env.extent = self.buffer
            tempEnvironment1 = arcpy.env.cellSize
            arcpy.env.cellSize = self.cellsize
            tempEnvironment2 = arcpy.env.mask
            arcpy.env.mask = self.buffer
            outraster = sa.Viewshed(self.islyr, self.obsproc, 1,
                                    "CURVED_EARTH", 0.13)
            #outrastertemp = os.path.join(self.scratch, 'outvis')
            #outraster.save(outrastertemp)
            vshedtmp = os.path.join("in_memory", 'vshedtmp')
            vsheddis = os.path.join("in_memory", 'vsheddis')
            #vshed_proj = os.path.join(self.scratchgdb, 'vshedproj')
            arcpy.AddMessage("temp vshed fc:" + vshedtmp)
            arcpy.AddMessage("dissolved vshed fc: " + vsheddis)
            arcpy.env.extent = tempEnvironment0
            arcpy.env.cellSize = tempEnvironment1
            arcpy.env.mask = tempEnvironment2
            arcpy.RasterToPolygon_conversion(outraster, vshedtmp, "SIMPLIFY",
                                             "VALUE")
            arcpy.Dissolve_management(vshedtmp, vsheddis, "gridcode", "",
                                      "MULTI_PART", "DISSOLVE_LINES")

            ##            if(self.wkidproc != self.wkidout):
            ##                arcpy.AddMessage("Projecting output vshed...")
            ##                arcpy.AddMessage("projected vshed fc: " + vshed_proj)
            ##                arcpy.Project_management(vsheddis, vshed_proj, self.srOut)
            ##                vshed=vshed_proj
            ##            else:
            ##                vshed=vsheddis
            #vistmp = os.path.join('in_memory', 'visibility')
            vis = os.path.join(self.scratchgdb, 'visibility')
            arcpy.AddMessage('creating output viewshed: ' + vis)
            arcpy.Clip_analysis(vsheddis, self.mask, vis, "")
            arcpy.AddMessage("Coppying to output...")
            #arcpy.CopyFeatures_management(vistmp, vis)
            fset = arcpy.FeatureSet()
            fset.load(vis)
            return fset
        except arcpy.ExecuteError:
            EH = ErrorHandling.ErrorHandling()
            line, filename, err = EH.trace()
            m = "Python error on " + line + " of " + __file__ + \
                " : with error - " + err
            arcpy.AddError(m)
    def __CreateMask__(self, jsonGeo):
        try:
            arcpy.AddMessage("Creating mask...")
            jsonPoly = json.loads(jsonGeo)
            rings=arcpy.Array()
            for ring in jsonPoly['rings']:
                points = arcpy.Array();
                for coord in ring:
                    x=coord[0]
                    y=coord[1]
                    z=None
                    if len(coord)>2:
                        z=coord[2]
                    #z=coord[3]
                    p=arcpy.Point()
                    p.X=x
                    p.Y=y
                    if z:
                        p.Z=z
                    points.add(p)
                rings.add(points)
            wkid = jsonPoly['spatialReference']['wkid']
            polySrIn = arcpy.SpatialReference(wkid)
            polygon=arcpy.Polygon(rings,polySrIn)
            features = []
            masktmp = os.path.join("in_memory", 'masktmp')
            arcpy.AddMessage("mask fc: " + masktmp)
            #mask_proj = os.path.join(self.scratchgdb, 'maskproj')

            features.append(polygon)
            arcpy.CopyFeatures_management(features, masktmp)
##            if(wkid != self.wkidproc):
##                arcpy.AddMessage("Projecting mask...")
##                arcpy.AddMessage("projected mask fc: " + mask_proj)
##                arcpy.Project_management(masktmp, mask_proj, self.srProc)
##                mask = mask_proj
##            else:
##                mask = masktmp
            return masktmp
        except arcpy.ExecuteError:
            EH = ErrorHandling.ErrorHandling()
            line, filename, err = EH.trace()
            m = "Python error on " + line + " of " + __file__ + \
                " : with error - " + err
            arcpy.AddError(m)
    def __CreateISLayer__(self, service):
        try:
            arcpy.AddMessage("Creating image service layer...")
            outislyr = os.path.join("in_memory", 'ras_dsm')
            #outislyr2 = os.path.join(r"C:\GEE\visibility", "outislyr2")

            arcpy.AddMessage("image service layer: " + outislyr)
            arcpy.MakeImageServerLayer_management(service, outislyr,
                                                  self.buffer, "",
                                                  "CLOSEST_TO_CENTER", "", "",
                                                  "")
            #filteredraster = sa.FocalStatistics(outislyr, "", "MEAN", "")
            #newraster = Raster(outislyr)
            #newraster.save(outislyr2)
            #return filteredraster
            return outislyr
        except arcpy.ExecuteError:
            EH = ErrorHandling.ErrorHandling()
            line, filename, err = EH.trace()
            m = "Python error on " + line + " of " + __file__ + \
                " : with error - " + err
            arcpy.AddError(m)
    def __createFC__(self, points, sr, name):
        try:
            #'-34.04 68.5,-34.05'
            coordpairs = points.split(';')
            pointGeometryList = []
            has_z = False
            for coordpair in coordpairs:
                pt = arcpy.Point()
                coords = coordpair.split(' ')
                arcpy.AddMessage(coords)
                pt.X = float(coords[0])
                pt.Y = float(coords[1])

                if len(coords) > 2:
                    has_z = True
                    arcpy.AddMessage('adding z...')
                    pt.z = float(coords[2])
                pointGeometry = arcpy.PointGeometry(pt, sr, has_z)

                pointGeometryList.append(pointGeometry)
            #path = self.scratch + os.sep + 'scratch.gdb' + os.sep + name
            path=os.path.join("in_memory",name)
            arcpy.AddMessage('path to sourcept: ' + path)
            arcpy.AddMessage(path)
            arcpy.CopyFeatures_management(pointGeometryList, path)
            fset = arcpy.FeatureSet()
            fset.load(path)
            self.pt = fset
            return fset

        except arcpy.ExecuteError:
            EH = ErrorHandling.ErrorHandling()
            line, filename, err = EH.trace()
            m = "Python error on " + line + " of " + __file__ + \
                " : with error - " + err
            arcpy.AddError(m)
    else:
        print 'The program cannot connect to the MySql database/nFor Detail, please take a look at error log'
        exit()

#-------------------------------------------------------------------------------------------------------------------------

#Start the loop for Lot's ID
while (start < end):
    #In the loop, the variable 'start' is the lot's ID.

    #Check if the web(url) is visitable
    web_data = engine.urlReq(0, start)
    #If the web(url) is visitable, the program would start to analysis the data. If not, the program would abandon this Lot's Data and start to analysis the next lot
    #Variable web_data is the result of url request.
    if web_data == '':
        ErrorHandling.logFail(start)
        start = start + 1
        continue

    #Chect if the lot is existed. There is some lot's id with empty page. If this lot is an empty page, the program would abandon this Lot's Data and start to analysis the next lot.
    if not engine.isLotExisted(web_data):
        ErrorHandling.logNotFound(start)
        start = start + 1
        continue

    #The program would get all the data we need from web_data variable
    ad = engine.getArtestDetail(web_data, start)
    artest_race = ''
    artest_birth = 0
    artest_death = 0
    if not ad[0] == '':
Beispiel #26
0
    def sensor_calibration(self):
        print("Extracting calibration parameters")
        # Number of calibration trials
        cal_trials = 100

        max_ir = 0
        min_ir = 1000000

        max_x = 0
        min_x = 1000000

        max_y = 0
        min_y = 1000000

        max_z = 0
        min_z = 1000000

        n = 0
        while n < cal_trials:
            # IR sensor calibration (for proximity sensing) tuned on a log scale
            val_ir = self.lightSensor.readIR()
            try:
                # cal_ir = log(self.lightSensor.readIR())
                if val_ir == 0:
                    raise ErrorHandling.IRIOError(
                        message="Error - IR value received " + str(val_ir),
                        ir_sensor=self.lightSensor)
                cal_ir = log(val_ir)
            except ErrorHandling.IRIOError:
                # print("Error - IR value received =", str(val_ir))
                # self.lightSensor._reset()
                # time.sleep(0.01)
                # self.lightSensor._load_calibration()
                # time.sleep(0.01)
                # print("Light Sensor reset")
                n -= 1
                continue

            max_ir, min_ir = self.min_max_test(raw=cal_ir,
                                               max=max_ir,
                                               min=min_ir,
                                               med_bool=None)

            # Gyroscope data calibration (to get a sense of left versus right)
            max_x, min_x = self.min_max_test(raw=self.agSensor.getX(),
                                             max=max_x,
                                             min=min_x,
                                             med_bool=None)
            max_y, min_y = self.min_max_test(raw=self.agSensor.getY(),
                                             max=max_y,
                                             min=min_y,
                                             med_bool=None)
            max_z, min_z = self.min_max_test(raw=self.agSensor.getZ(),
                                             max=max_z,
                                             min=min_z,
                                             med_bool=None)

            n += 1
            time.sleep(0.01)

        # Get calibration arrays
        cal_max_array = np.array([max_ir, max_x, max_y, max_z])
        print("Max array:", cal_max_array)

        cal_min_array = np.array([min_ir, min_x, min_y, min_z])
        print("Min array:", cal_min_array)

        cal_med_array = np.add(cal_max_array, cal_min_array) / 2
        print("Median array:", cal_med_array)

        return cal_max_array, cal_min_array, cal_med_array