Skip to content

Instantly share code, notes, and snippets.

@mmourafiq
Last active December 11, 2015 23:09
Show Gist options
  • Save mmourafiq/4675100 to your computer and use it in GitHub Desktop.
Save mmourafiq/4675100 to your computer and use it in GitHub Desktop.
class Topic(object):
"""
Topic
@type _id: int
@param _id: the id of the topic
@type _x: float
@param _x: the x coordinate in the plane
@type _y: float
@param _y: the y coordinate in the plane
@type _current_distance: float
@param _current_distance: the current distance from the origin(origin being the query coordiantaes)
@type _qn: int
@param _qn: the number of questions associated with this topics
@type _questions: list
@param _questions: the list of the questions associated with this topic
"""
def __init__(self, id, x, y):
self._id = id
self._x = x
self._y = y
self._current_distance = 0
self._qn = 0
self._questions = []
def __gt__(self, topic):
delta = self._current_distance - topic._current_distance
if delta < -THRESHOLD:
return True
if delta > THRESHOLD:
return False
return True if self._id > topic._id else False
def add(self, question):
self._qn += 1
self._questions.append(question)
def get_questions(self, qn, questions):
go_on = True
for question in self._questions:
if question not in questions:
questions.append(question)
qn -= 1
if qn == 0:
go_on = False
break
return sorted(questions, reverse=True), qn, go_on
def set_current_distance(self, origin_x, origin_y):
self._current_distance = self.euclidean_dis(self._x, self._y, origin_x, origin_y)
@staticmethod
def euclidean_dis(x1, y1, x2, y2):
return math.sqrt(pow(x1 - x2, 2) + pow(y1 - y2, 2))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment