Ejemplo n.º 1
0
def storesNumber():
	if session["selectedCategories"]:
		catList = session["selectedCategories"]
		forms = []
		for cat in catList:
			forms.append(storesForm(prefix=cat))

		forms_with_categories = [(cat, form) for cat, form in zip(catList, forms)]


		if form_validated_on_submit(forms):
			#Dictionary that will be sent to the recommender in the follwoing format
			#{'FirstMall': {'Men\'s Clothing':8, 'Beauty Products':11, 'Consumer Electronics':11}}
			dictionary = {"XMALL":{}}

			#List of tuples that contains (cat, numberOfStores)
			list_ot_tuples = []

			for cat_form in forms_with_categories:
				list_ot_tuples.append((cat_form[0],cat_form[1].numberOfStores.data))

			dictionary["XMALL"] = dict(list_ot_tuples)

			recommender.dataset.update(dictionary)
			
			recommendations = recommender.custom_recommender(recommender.dataset,"XMALL")

			#Remove any previous recommendations that might have already been in session['recommendations'] 
			if (session.get('recommendations') != None):
				session.pop('recommendations')

			if recommendations:
				session['recommendations'] = recommendations
			# redirect(url_for('results'))

			return redirect(url_for('results'))

		else:
			return render_template('stores_number.html', catList = catList, form = forms_with_categories );

	return redirect(url_for('home'))
Ejemplo n.º 2
0
def storesNumber():
	if session["selectedCategories"]:
		catList = session["selectedCategories"]
		forms = []
		for cat in catList:
			forms.append(storesForm(prefix=cat))

		forms_with_categories = [(cat, form) for cat, form in zip(catList, forms)]


		if form_validated_on_submit(forms):
			#Dictionary that will be sent to the recommender in the following format
			#{'FirstMall': {'Men\'s Clothing':8, 'Beauty Products':11, 'Consumer Electronics':11}}
			dictionary = {"USERMALL":{}}

			#List of tuples that contains (cat, numberOfStores)
			list_ot_tuples = []

			for cat_form in forms_with_categories:
				list_ot_tuples.append((cat_form[0],cat_form[1].numberOfStores.data))

			dictionary["USERMALL"] = dict(list_ot_tuples)

			data = dataset.dict
			data.update(dictionary)

			#use a background process to run the recommender
			q = Queue(connection=conn)

			job = q.enqueue_call(func = custom_recommend, args=(data, "USERMALL"))
			#print custom_recommend(data,"USERMALL")

			return render_template('results.html', jobkey = job.get_id() )

		else:
			return render_template('stores_number.html', catList = catList, form = forms_with_categories );

	return redirect(url_for('home'))