Open hyperchi opened 8 years ago
@Jelly-Yu Let's do this part first then do the really time tweets display.
@Jelly-Yu I mean real time tweets display.
I would slightly recommend do the real time tweets.. and realtime barchart.. This one requires a little more spec.. more clarifications. Like what kind of data structure do you wanna use... where do you maintain those stocks symbols.. when input do what kind of search do you wanna use? not simple at all.. If you do not wanna redesign the whole thing, later on.
for the realtime barchart one as what I've told you today.. you can cowork with the new guy..
import and analyze the data within a cache
tweets --> analyze in cache (1) --> store in mongo db (2) --> show in UI. (1) and (2) should be paral This will make the display become much much faster.
remember leave everything variable.. define a method then call it. reduce hardcode.
If you wanna do search I have a little small code for you guys to use.. use Trie.
BTW. Auto completion feature. should not be in need right now. Maybe we won't need it until May. Just paste here for future usage..
class PrefixTree:
def __init__(self):
self._end = None
self.root = {}
# construct a trie based on the input
def makeTrie(self, words):
for word in words:
cur_hash = self.root
for letter in word:
cur_hash = cur_hash.setdefault(letter, {})
cur_hash[self._end] = self._end
def searchWord(self, word):
cur_hash = self.root
for letter in word:
if letter in cur_hash:
cur_hash = cur_hash[letter]
else:
return False
if self._end in cur_hash:
return True
return False
def getPrefix(self, prefix):
cur_hash = self.root
for letter in prefix:
if cur_hash.get(letter, None):
cur_hash = cur_hash[letter]
else:
return False, None
return True, cur_hash
def bfs(self, trie):
res = []
queue = []
for key in trie:
queue.append([key, trie[key]])
while queue:
path, top = queue.pop(0)
print top, bool(top)
if top:
for key in top:
if key:
queue.append([path+key, top[key]])
else:
res.append(path)
else:
res.append("")
return res
def getRecommendations(self, prefix):
is_exit, cur_hash = self.getPrefix(prefix)
if cur_hash:
res = self.bfs(cur_hash)
if is_exit:
return map(lambda x: prefix + x, res)
return [prefix]
words = ["jake", 'jazz', 'just', 'jaketyjust']
prefix_tree = PrefixTree()
prefix_tree.makeTrie(words)
print prefix_tree.root
print prefix_tree.getRecommendations('jakety')
Now we only have hardcode stock symbol and show several stocks. A feature we would possibly wanna do is to let user choose what stocks they wanna follow. and based on input showing stock charts.
Note that this is not just stock price char, it is also about barchart. as we may need to analyze more stocks in the future. This change seems much more important than most of other features. @Jelly-Yu @qiuzhihui Hardcoding is a bad habit. But a good start. yea.