Example #1
0
def dequeuehistory(request):
	date = datetime.datetime(datetime.datetime.today().year, datetime.datetime.today().month, datetime.datetime.today().day)
	
	historychanges = TallstreetHistoryChanges.get_or_insert(request.POST['historychanges'])
	history = TallstreetHistory.get_or_insert(request.POST['historychanges'])
	
	if not history:
		historychanges.delete()
		return HttpResponse("Can't Find History", mimetype="text/plain")
	if date in history.dates:
		historychanges.delete()
		return HttpResponse("Already Done", mimetype="text/plain")
	
	universe = TallstreetUniverse.get_by_key_name(request.POST['universe'])
	history.universe = universe
	history.changes.insert(0, long(historychanges.change))
	history.dates.insert(0, date)
	history.put()
	
	logging.debug(history.universe.money)
	history.universe.money += long(round(history.universe.money * (1.0 * history.changes[0] / 100)))
	
	investors = TallstreetPortfolio.get_investors(history.universe.url, history.universe.tag)
	
	logging.debug(history.universe.url.url)
	logging.debug(history.universe.money)
	history.universe.put()
	logging.debug(history.changes)
	for investor in investors:
		update_portfolio_gain(investor.parent(), history.universe.url, history.universe.tag, history.changes[0])
		
	historychanges.delete()
	
	logging.debug("Success")
	return HttpResponse("Success", mimetype="text/plain")
Example #2
0
	def items(self, obj):
		ratings = []
		historychanges =  TallstreetHistoryChanges.get_all()
		for historychange in historychanges:
			history = TallstreetHistory.get_or_insert(historychange.key().id_or_name())
			
			if not history:
				historychange.delete()
				continue
			try:
				universe = history.universe
			except:
				historychange.delete()
				continue
			logging.debug(history.universe.money)
			history.universe.money += long(round(history.universe.money * (1.0 * history.changes[0] / 100)))
			
			investors = TallstreetPortfolio.get_investors(history.universe.url, history.universe.tag)
			
			logging.debug(history.universe.url.url)
			logging.debug(history.universe.money)
			history.universe.put()
			logging.debug(history.changes)
			for investor in investors:
				update_portfolio_gain(investor.parent(), history.universe.url, history.universe.tag, history.changes[0])
				
			historychange.delete()
		users =  User.need_new_money()		
		for user in users:
			update_new_money(user)
			
		return []
Example #3
0
  def HandleEntity(self, entity):
	if not entity['tag']:
		return []
	url = datastore_types.Key.from_path("TallstreetUrls", 'url' + entity['url'])
	keyword = datastore_types.Key.from_path("TallstreetTags", 'tag' + entity['tag'])
	history = TallstreetHistory.get_or_insert(key_name="history%s%s" % (keyword, url))
	universe = datastore_types.Key.from_path("TallstreetUniverse", "universe%s%s" % (keyword, url))	  
	history.universe = universe
	history.changes.insert(0, entity['change'])
	history.dates.insert(0, datetime.datetime.strptime(entity['date'], "%Y-%m-%d %H:%M:%S"))
	history.put()
	return []
Example #4
0
	def items(self, obj):
		ratings = []
		ips = []
		clicks =  TallstreetClick.get_all()
		history = False
		for click in clicks:
			click.delete()
			logging.debug("Analysing %s %s %s %s %s" % (click.url, click.keyword, click.ip, click.type, click.rating))
			url = TallstreetUrls.get_url(click.url)
			if not url:
				logging.debug("No url")
				continue
			
			keyword = TallstreetTags.get_by_key_name("tag%s" %click.keyword.lower())
			if not keyword:
				logging.debug("No keyword")
				continue
			
			universe = TallstreetUniverse.get_universe(keyword, url)	 
			if not universe:			
				logging.debug("No universe")
				continue 
			
			if ips == []:
				historychanges = TallstreetHistoryChanges.get_or_insert(key_name="history%s%s" % (keyword.key(), url.key()))
				ips = historychanges.ips		
			
			change = 0
			if click.type == 'C':
				change = 1
			elif click.type == 'R' and click.rating == 5:
				change = 50
			elif click.type == 'R' and click.rating == 4:
				change = 20
			elif click.type == 'R' and click.rating == 3:
				change = 10
			elif click.type == 'R' and click.rating == 2:
				change = 5
			elif click.type == 'R' and click.rating == 1:
				change = -20
				
			date = datetime.datetime(click.time.year, click.time.month, click.time.day)
			
			
			if click.ip + click.type in ips:
				continue
			ips.append(click.ip + click.type)
			
			if not history:
				history = TallstreetHistory.get_or_insert(key_name="history%s%s" % (keyword.key(), url.key()))
				history.universe = universe
				history.changes.insert(0, long(change))
				history.dates.insert(0, date)
			elif history.universe != universe or history.dates[0] != date:			
				logging.debug("Adding history %s %s %s" % (ips, history.changes[0], history.dates[0]))
				historychanges = TallstreetHistoryChanges.get_or_insert(history.key().id_or_name())
				historychanges.ips = ips
				historychanges.put()
				history.put()
				ips = []
				history = TallstreetHistory.get_or_insert(key_name="history%s%s" % (keyword.key(), url.key()))
				history.changes.insert(0, long(change))
				history.dates.insert(0, date)
				history.universe = universe
			else:					
				logging.debug("Add Change %s" % (change))
				history.changes[0] += long(change)
				
				
		
		if history:
			logging.debug("Adding history %s %s %s" % (ips, history.changes[0], history.dates[0]))
			historychanges = TallstreetHistoryChanges.get_or_insert(history.key().id_or_name())
			historychanges.ips = ips
			historychanges.put()
			history.put()	
		return []