Exemplo n.º 1
0
def make_special_user():
	house_area, house_type, income, cooler_heater_type = 1, 1, 1, 1
	user_email = "User%d%d%d%d"%(house_area, house_type, income, cooler_heater_type)
	password = '******'
	
	u = User(user_email, password)
	db.session.add(u)
	db.session.commit()

	ui = UserInfo._make_user_info_with_email(user_email, house_area, house_type, income, cooler_heater_type)
	db.session.add(ui)
	db.session.commit()

	DEFAULT_YEAR, DEFAULT_MOONTH, DEFAULT_DAY, DEFAULT_TIME = 2013, 12, 1, 0

	special_energy_set = [3, 3, 5, 4, 6, 5, 2, 9, 1, 8, 5, 7, 4, 9, 3, 5, 2, 7, 7, 6, 1, 1, 1, 1, 6, 2, 9, 5, 9, 5]

	dt = datetime(DEFAULT_YEAR, DEFAULT_MOONTH, DEFAULT_DAY, DEFAULT_TIME)
	for day_plus in xrange(1, 31):
		for time_plus in xrange(0,24):
			
			
			energy_amount = special_energy_set[day_plus-1]*200

			ed = EnergyData._make_energy_data_with_email(user_email, dt, energy_amount)
			db.session.add(ed)
			dt += timedelta(hours=1)

	db.session.commit()
Exemplo n.º 2
0
    def tmp_test_goal(self):
        u = User('goal', 'goal')
        db.session.add(u)
        db.session.commit()
        
        ui = UserInfo._make_user_info_with_email('goal', 5, 3, 9, 3)
        db.session.add(ui)
        db.session.commit()

        rv = self.goal('goal', '5')
        
        assert rv.data=='True'

        assert User.query.filter_by(email='goal').first().user_info.first().goal==5
Exemplo n.º 3
0
def make_users():
	for house_area in xrange(5, len(HOUSE_AREA)):
		for house_type in xrange(0,4):
			for income in xrange(9,10):
				for cooler_heater_type in xrange(3, 4): 
					user_email = "User%d%d%d%d"%(house_area, house_type, income, cooler_heater_type)
					password = '******'
					
					u = User(user_email, password)
					db.session.add(u)
					db.session.commit()

					ui = UserInfo._make_user_info_with_email(user_email, house_area, house_type, income, cooler_heater_type)
					db.session.add(ui)
					db.session.commit()
Exemplo n.º 4
0
    def tmp_test_info_setup(self):
        self.make_users()
        print 'Make Users : %d'%(len(User.query.all() ) )
        self.ptrol_all_users()

        print UserInfo.query.count() == 12
        print User.query.count() == 12
        pprint(User.query.all())

        test_user = User('test_user5393', '5393')
        db.session.add(test_user)
        db.session.commit()

        test_user_info = UserInfo._make_user_info_with_email('test_user5393', 5, 3, 9, 3)
        db.session.add(test_user_info)
        db.session.commit()
        
        assert UserInfo.query.count() == 13
        assert User.query.count() == 13

        test_user = User.find_by_email('test_user5393')
        test_user_info = test_user.user_info.first()
        
        print test_user_info.get_avg_energy_data_with_date(datetime(2013, 10, 1, 1), datetime(2013, 10, 31, 23, 59, 59))

        self.sign_up('test_user7193', '7193')   
        self.sign_in('test_user7193', '7193')   
        self.info_setup('test_user7193', 7, 1, 9 , 3)

        test_user = User.find_by_email('test_user7193')
        test_user_info = test_user.user_info.first()
        
        print test_user_info.get_avg_energy_data_with_date(datetime(2013, 10, 1, 1), datetime(2013, 10, 31, 23, 59, 59))

        print '++++++++++++++++++++++++++++++++++++++++++++++++++++++++'
        rv = self.getmonthdata('User7193')
        print rv.data 
        print '++++++++++++++++++++++++++++++++++++++++++++++++++++++++'
Exemplo n.º 5
0
	def dispatch_request(self):
		try:
			email = request.form['userEmail']
			house_type = int(request.form['houseType'])
			house_area = int(request.form['houseArea'])
			income_type  = int(request.form['incomeType'])
			cooler_heater_type = int(request.form['coolerHeaterType'])

			ui = UserInfo._make_user_info_with_email(email, house_area, house_type, \
				income_type, cooler_heater_type)

			db.session.add(ui)
			db.session.commit()

			user_info = UserInfo.query.filter_by(house_area=house_area, house_type=house_type\
				, income_type=income_type, cooler_heater_type=cooler_heater_type).first()
			avg_data = user_info.get_avg_energy_data_with_date(datetime(2013, 12, 1, 1), datetime(2013, 12, 31, 23, 59, 59))

			return str(avg_data)

		except IntegrityError, e:
			print 'Aleady Exist User Info for %r'%email
			return '10'