Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def insert_hash_compare():
- # input value
- value_mongo1 = request.form['id1']
- value_mongo2 = request.form['id2']
- # collection mongo
- online_news_hash = mongo_insert.db.online_news_hash
- # get hash1 & hash2
- compare_hash1 = online_news_hash.find_one({'_id' : value_mongo1})
- compare_hash2 = online_news_hash.find_one({'_id' : value_mongo2})
- hash1 = compare_hash1['hash']
- hash2 = compare_hash2['hash']
- dec1 = int(hash1, 16);
- dec2 = int(hash2, 16);
- bin1 = bin(dec1)
- bin2 = bin(dec2)
- xor_bin = int(bin1, 2) ^ int(bin2, 2)
- distance = bin(xor_bin).count("1")
- divider = len(hash1) * 4
- result = 1 - (distance / float(divider))
- hash_accuracy = {
- 'accuracy': float(result)
- }
- return json.dumps(hash_accuracy)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement