Пример #1
0
	def load_task_list(self, attribute,task_list,selected_color, deselected_color, empty_message="There's no tasks here =/"):
		dados = data.retrieve_data(attr=attribute)
		if len(dados) == 0:
			task_list.add_widget(Label(text=empty_message))
		else:
			for c in task_list.children:
				 if type(c).__name__ == 'Label':
				 	task_list.remove_widget(c)
			

		item_args_converter = lambda row_index, obj:{'name':'[b][size=16]' + obj.name + '[/size][/b]',
										'date': '[i]' + obj.date + '[/i]',
										'value': obj.value[:60] + '...',
										'selected_color' : selected_color,
										'deselected_color' : deselected_color,
										'size_hint_y': None,
										'screen_manager': self.screen_manager,
										'task_board':self,
										'task_parent': obj,
										'height':150,
										'is_selected':False,
										'markup':True}

		list_adapter = ListAdapter(data=dados,
									args_converter = item_args_converter,
									selection_mode = 'single',
									propagate_selection_to_data=False,
									allow_empty_selection=False,
									cls=ListTask)
		task_list.adapter = list_adapter
Пример #2
0
	def save_task(self, uuid_value=None, attr='opened', go_back_screen=False):
		if uuid_value != None:
			self.current_task_uuid = uuid_value
			task = data.retrieve_data(uuid_value)
			value = task.value
			title = task.name
		else:
			value = self.value_input.text.strip()
			title = self.title_input.text.strip()		

		if len(value) <= 0:
			return;

		if len(title) <= 0:
			title = value[0:30] + "..."

		if self.current_task_uuid == "":
			self.current_task_uuid = str(uuid.uuid4())

		data.create_data(self.current_task_uuid,title,time.strftime("%H:%M:%S %d/%m/%Y"),value,attr)
		
		self.clear_create()

		if go_back_screen:
			self.go_back_screen()
		else:
			self.go_home()
Пример #3
0
def send_data(request):
	""" View to return the list of options if user_input is empty, otherwise sends the capital of the
		country with corresponding user_input id.
		Returns invalid input message if the length of the mobile is not equal to 10 or 11 or the session
		id is empty.
		Fetches the country capital data from the sqlite database file ~/code/ussd/country_capital_db
	"""
	# Retrieving data given through url
	session_id = request.GET.get('session_id')
	mobile_no = request.GET.get('mobile_no')
	response = ''
	error = ''
	user_input = ''
	
	# Checking if user input. Value error is raised if user_input is empty.
	# Type error is raised if no user_input value is given.
	
	try:
		user_input = int(request.GET.get('user_input'))
	except ValueError:
		# Blank user_input option is given
		db_items = Country_Capital.objects.all()
		response = retrieve_data(db_items)
	except TypeError:
		# No user_input parameter in url
		error = set_error(error, ERROR_MSGS['NO_USER_INPUT'])
	
	# To check if a country with corresponding user_input exists and set error if not.
	# If user_input value is zero it will return false for if user_input: 
	# So we are making an exception to occur if user_input is zero. 
	if user_input or user_input == 0: 
		try:
			# Getting item with corresponding user_input
			searched_item = Country_Capital.objects.get(id__exact=user_input)
			response = searched_item.__dict__['capital']
		except:
			# No item with corresponding id.
			error = set_error(error, ERROR_MSGS['INVALID_USER_INPUT'])
	
	
	# Checking if the given mobile number is valid 
	if len(mobile_no) not in (10,11):
		error = set_error(error, ERROR_MSGS['INVALID_MOBILENO'])
	else:
		request.session['mobile_no'] = mobile_no	
		
	# Checks if the given session id is valid and setting it	
	if session_id :
		request.session['id'] = session_id
	else:
		error = set_error(error, ERROR_MSGS['INVALID_SESSIONID'])

			
	# If there is an error return it, otherwise return the country list or capital of selected country	
	if error:
		return HttpResponse(error)
	else:
		return HttpResponse(response)	
Пример #4
0
def predict(model, file_to_path):
    _, X_test, _, _ = data.retrieve_data()

    # predicting results
    print("PREDICTION: ")
    y_predict = model.predict(X_test)
    unique, counts = np.unique(y_predict, return_counts=True)
    print(dict(zip(unique, counts)))

    util.save_as_pkl(y_predict, file_to_path)
Пример #5
0
def create_model():
    X_train, _, y_train, _ = data.retrieve_data()

    # define and run SVM model
    model = SVC(kernel='linear', verbose=True, C=10)
    model.fit(X_train, y_train)  #trains model

    util.save_as_pkl(model, "../models/SVM.pkl")

    return model
Пример #6
0
def accuracy_NN():
    X_train, X_test, y_train, y_test = data.retrieve_data()
    model = neural_network.retrieve_model()

    # evaluate the model
    _, accuracy_model = model.evaluate(X_train, y_train, verbose=False)
    print('Accuracy of model on dataset: %.2f' % (accuracy_model * 100))

    # evaluate the algorithm
    _, accuracy_algorithm = model.evaluate(X_test, y_test, verbose=False)
    print('Accuracy of algorithm on test data: %.2f' % (accuracy_algorithm * 100))

    return accuracy_algorithm * 100
Пример #7
0
def accuracy_SVM():
    X_train, X_test, y_train, y_test = data.retrieve_data()
    model = support_vector_machine.retrieve_model()

    # evaluate the model
    accuracy_model = model.score(X_train, y_train)
    print('Accuracy of model on dataset: %.2f' % (accuracy_model * 100))

    # evaluate the algorithm
    accuracy_algorithm = model.score(X_test, y_test)
    print('Accuracy of algorithm on test data: %.2f' % (accuracy_algorithm * 100))

    return accuracy_algorithm * 100
Пример #8
0
 def test_action_sample(self):
     data = retrieve_data()
     env = BTC(data)
     for i in range(5):
         state = env.reset()
         score = 0
         done = False
         while not done:
             action = env.sample_action()
             state_, reward, done, info = env.step(action)
             score += reward
             state = state_
     self.assertTrue(0 <= action <= 8)
Пример #9
0
 def test_agent(self):
     data = retrieve_data()
     env = BTC(data)
     agent = Agent(lr=0.0003, input_dims=env.observation_space.shape[0],n_actions=env.action_space.shape[0],
                   batch_size=64, epsilon=1.0, env=env)
     for i in range(5):
         state = env.reset()
         done = False
         while not done:
             action = agent.pick_action(state)
             state_, reward, done, info = env.step(action)
             state = state_
             self.assertTrue(0 <= action <= 8)
Пример #10
0
	def load_last_tasks_page(self):
		dados = data.retrieve_data(size=5,attr='opened')
		self.last_tasks.clear_widgets()

		if len(dados) == 0:
			self.last_tasks.parent.add_widget(Label(text=self.text))

		for r in dados[0:5]:
			task = AccordionTask()
			task.task_parent = r
			task.unique_id = r.unique_id
			task.name = r.name
			task.date = r.date
			task.value = r.value
			task.attributes = r.attributes
			task.screen_manager = self.screen_manager
			task.full_screen = self.full_screen
			task.task_board = self
			self.last_tasks.add_widget(task)
Пример #11
0
def create_model():
    X_train, _, y_train, _ = data.retrieve_data()

    # define the keras model
    model = Sequential()
    model.add(Dense(100, input_dim=8, activation='relu'))
    model.add(Dense(100, activation='relu'))
    model.add(Dense(1, activation='sigmoid'))

    # compile the keras model
    model.compile(loss='binary_crossentropy',
                  optimizer='adam',
                  metrics=['accuracy'])

    # fit the keras model on the dataset
    model.fit(X_train, y_train, epochs=50, batch_size=10)

    util.save_as_pkl(model, "../models/NN.pkl")

    return model
Пример #12
0
from agent import Agent
from env import BTC
from data import retrieve_data
import numpy as np
import matplotlib.pyplot as plt
from tqdm import trange
import argparse

if __name__ == '__main__':
    parser = argparse.ArgumentParser(description="DDQN on Bitcoin")
    parser.add_argument('-load', type=bool, default=False)
    parser.add_argument('-games', type=int, default=1000)
    args = parser.parse_args()
    # Load agent, retrieve bitcoin data, and create environment
    load_agent = args.load
    data = retrieve_data()
    env = BTC(data, 5000)
    # Create Agent
    if load_agent:
        print('Trained Agent Loading...')
        agent = Agent(lr=0.0003,
                      input_dims=env.observation_space.shape[0],
                      n_actions=env.action_space.shape[0],
                      batch_size=16,
                      epsilon=0.1,
                      env=env,
                      replace=1000)
        agent.load()
    else:
        print('Untrained Agent Loading...')
        agent = Agent(lr=0.0003,
Пример #13
0
	def update_tasks(self):
		self.registros = data.retrieve_data(size=5,attr='opened')
Пример #14
0
	def go_edit_task(self, uuid_value):
		self.screen_manager.current = 'Add New'
		task = data.retrieve_data(uuid_value)
		self.title_input.text = task.name
		self.value_input.text = task.value
		self.current_task_uuid = uuid_value