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 dequeuerating(request):
	url = TallstreetUrls.get_url(request.POST['url'])
	if not url:
		logging.debug("no url %s " % request.POST['url'])
		return HttpResponse("No Url", mimetype="text/plain")
	
	keyword = TallstreetTags.get_by_key_name("tag%s" %request.POST['keyword'].lower())
	if not keyword:
		logging.debug("no Keyword")
		return HttpResponse("No Keyword", mimetype="text/plain")
	
	universe = TallstreetUniverse.get_universe(keyword, url)	 
	if not universe:	
		logging.debug("no Universe")		
		return HttpResponse("No Universe", mimetype="text/plain")
	
	historychanges = TallstreetHistoryChanges.get_or_insert(key_name="history%s%s" % (keyword.key(), url.key()))
	ips = historychanges.ips
		
	change = 0
	if request.path == '/queue/click':
		change = 1
	elif request.path == '/queue/rating' and request.POST['rating'] == '5':
		change = 50
	elif request.path == '/queue/rating' and request.POST['rating'] == '4':
		change = 20
	elif request.path == '/queue/rating' and request.POST['rating'] == '3':
		change = 10
	elif request.path == '/queue/rating' and request.POST['rating'] == '2':
		change = 5
	elif request.path == '/queue/rating' and request.POST['rating'] == '1':
		change = -20

	date = datetime.datetime(datetime.datetime.today().year, datetime.datetime.today().month, datetime.datetime.today().day)
	

	if request.POST['ip'] + request.path in ips:
		return HttpResponse("Already Rated", mimetype="text/plain")
	ips.append(request.POST['ip'] + request.path)

	historychanges.ips = ips
	historychanges.change += change
	historychanges.put()
	
	t = Task(url='/queue/calchistory', params={'historychanges': historychanges.key().id_or_name(), 'universe': universe.key().id_or_name()}, name=historychanges.key().id_or_name() + date.strftime('%Y%m%d'), eta=date + datetime.timedelta(days=1))
	logging.debug(t)
	try:
		t.add('historyqueue')
	except TaskAlreadyExistsError:
		pass
	logging.debug("Success")
	return HttpResponse("Success", mimetype="text/plain")
Example #3
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 []