def test():
    # create a random matrix in the file
    gen_random.gen_random_array(1000000, 25, "matrix.txt")

    # splits the matrix into training and test data
    split_file("matrix.txt", "matrix_train.txt", "matrix_test.txt")
    start = time.time()
    coefs = linreg.get_coefficients("matrix_train.txt")
    predict_buy, predict_sell = get_recommended_buys("matrix_test.txt", coefs)
    print time.time() - start
def test_parallel(rows, cols, num_threads):
    """
    returns time of linear regression using parallel choelsky 
    """
    gen_random.gen_random_array(rows, cols, "parallel_matrix.txt")
    split_file("parallel_matrix.txt", "parallel_matrix_train.txt", "parallel_matrix_test.txt")
    start = time.time()
    coefs = linreg.parallel_get_coefficients(file_name="parallel_matrix_train.txt", num_threads=num_threads)
    reg_time = time.time() - start
    # return time in seconds of lin reg
    return reg_time
Example #3
0
def get_data(request):
	rows = int(request.POST.get("rows"))
	cols = int(request.POST.get("columns"))	

	#create a random matrix in the file
	gen_random.gen_random_array(rows, cols, home_dir + "matrix.txt")

	#splits the matrix into training and test data
	test_regression.split_file(home_dir + "matrix.txt", home_dir + "matrix_train.txt", home_dir + "matrix_test.txt")

	start = time.time()
	coefs = get_coefficients(home_dir + "matrix_train.txt")

	#tests the coefs
	predict_buy, predict_sell = test_regression.get_recommended_buys(home_dir + "matrix_test.txt", coefs)
	elapsed = time.time() - start

	#gets the top buys and sells	
	top_buys = sorted(predict_buy, key=lambda x: x["change"], reverse=True)[:50]
	top_sells = sorted(predict_sell, key=lambda x: x["change"], reverse=True)[:50]

	#gets the (simulated) event names for the buys and sells
	event_names = os.listdir(home_dir + "../../snapshots_by_event")
	event_names = [home_dir + "../../snapshots_by_event/" + x for x in event_names if x[-4:]==".txt"]

	top_buys = test_regression.get_events_from_simulation(top_buys, event_names)
	top_sells = test_regression.get_events_from_simulation(top_sells, event_names)

	#resorts (as prices may have been updated with true ticket prices)
	top_buys = sorted(top_buys, key=lambda x: x["change"], reverse=True)
	top_sells = sorted(top_sells, key=lambda x: x["change"], reverse=True)

	response = {}
	response['time'] = elapsed

	response["buy_events"] = top_buys
	response["sell_events"] = top_sells



	'''
	#read random data for each of the rows	
	files = os.listdir("../../snapshots_by_event")
	files = ["../../snapshots_by_event/" + x for x in files if x[-4:]==".txt"]

	#gets metadata
	#metadata = ['event_id', 'last_chance', 'act_primary', 'venue_name', 'eventLocation_facet_str', 'zip']
	for i in range(len(predict_buy[:50])):
		cur_file = np.random.choice(files)
		with open(cur_file, "r+") as inputfile:
			metadata = inputfile.next().split("\t")
			predict_buy_events.append(metadata)

	for i in range(len(predict_sell[:50])):
		cur_file = np.random.choice(files)
		with open(cur_file, "r+") as inputfile:
			metadata = inputfile.next().split("\t")
			predict_sell_events.append(metadata)

	response["buy_events"] = predict_buy_events
	response["sell_events"] = predict_sell_events

	#gets the times, in index 1
	for x in response["buy_events"]:
		cur_time = x[1]		
		parsed_time = datetime.datetime.strptime(cur_time, "%Y-%m-%dT%XZ")
		formatted_time = parsed_time.strftime("%c")
		x[1] = formatted_time

	for x in response["sell_events"]:
		cur_time = x[1]		
		parsed_time = datetime.datetime.strptime(cur_time, "%Y-%m-%dT%XZ")
		formatted_time = parsed_time.strftime("%c")
		x[1] = formatted_time

	'''

	#return HttpResponse(json.dumps(response), content_type="application/json")
	return render(request, "mysite/events.html", response)