query_processing.py 文件源码

python
阅读 19 收藏 0 点赞 0 评论 0

项目:Topik 作者: saurabh-deochake 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号