def findTopDistResults(self):
db = MySQLdb.connect(host="localhost", # your host, usually localhost
user="spd", # your username
passwd="meraPassword", # your password
db="topik") # name of the data base
curP = db.cursor()
curT = db.cursor()
curPop = db.cursor()
curP.execute("SELECT * from posts;")
curT.execute("CREATE OR REPLACE TABLE temp_distScore(score DOUBLE,uid NVARCHAR(20),pid NVARCHAR(20) PRIMARY KEY) engine=InnoDB;")
db.commit()
rows = curP.fetchall()
for row in rows:
q_l = (self.lat,self.lng)
row_l = (row[3],row[4])
dist = vincenty(q_l, row_l).miles
if(self.r >= dist):
distScore = float(self.r-dist)/self.r
else:
distScore = 0
curT.execute("INSERT INTO temp_distScore (score,uid,pid) VALUES (%s,%s,%s)",(distScore,row[1],row[5]))
db.commit()
curP.close()
curT.close()
db.close()
return
评论列表
文章目录