class Tasks: current_index_ = 0 all_amount_ = 0 undone_amount_ = 0 current_task_ = Task() db = DataBase() def __init__(self): self.undone_tasks_ = self.db.undone_tasks() self.done_tasks_ = self.db.done_tasks() self.date_ = date.today() def get_current(self): frogs = [] usual = [] if not (self.date_ in self.undone_tasks_): return for i in range(self.current_index_, len(self.undone_tasks_[self.date_])): x = self.undone_tasks_[self.date_][i] if x.is_frog_: frogs.append(x) else: usual.append(x) for i in range(0, self.current_index_): x = self.undone_tasks_[self.date_][i] if x.is_frog_: frogs.append(x) else: usual.append(x) self.undone_amount_ = len(frogs) + len(usual) self.all_amount_ = self.undone_amount_ + ( len(self.done_tasks_[self.date_]) if (self.date_ in self.done_tasks_) else 0) if len(frogs) > 0: self.current_task_ = frogs[len(frogs) - 1] else: self.current_task_ = usual[len(usual) - 1] def done(self): if not (self.date_ in self.done_tasks_): self.done_tasks_[self.date_] = [] self.done_tasks_[self.date_].append(self.current_task_) self.db.add_old_task(self.current_task_) self.db.delete_task(self.current_task_) self.undone_tasks_[self.date_].remove(self.current_task_) self.undone_amount_ -= 1 if not self.undone_tasks_[self.date_]: del self.undone_tasks_[self.date_] def delete(self, task): self.db.delete_task(task) self.undone_tasks_[task.date_].remove(task) if not self.undone_tasks_[task.date_]: del self.undone_tasks_[task.date_] def skip(self): # false if frog, true otherwise if self.current_task_.is_frog_: return False self.current_index_ += 1 self.current_index_ %= len(self.undone_tasks_[self.date_]) def add(self, task): # adds a new task in our database self.db.add_new_task(task) if task.date_ not in self.undone_tasks_: self.undone_tasks_[task.date_] = [] self.undone_tasks_[task.date_].append(task)
print("Invalid file...") exit(1) # Split the first line and check simulator metadata #print(lines[0].split(' ')) info_split = lines[0].split() # Parse task data from input file tasks = list() for i in range(1, len(lines)): #print(lines[i]) if info_split[0] == OPCE_STR: task_split = lines[i].split(' ') task_id = int(task_split[0]) task_duration = int(task_split[1]) task = Task(task_id, 10000, task_duration) task.next_start = 100000 new_list = list() for k in range(2, len(task_split)): new_list.append(int(task_split[k])) task.wait = new_list else: task_split = lines[i].split(' ') task_period = int(task_split[0]) task_duration = int(task_split[1]) if info_split[0] == SCHED_STR: task_prio = int(task_split[2]) task_sched_type = task_split[3].rstrip() task = Task(i, task_period, task_duration, task_prio, task_sched_type) if task_sched_type == "RR": task.rr_remaining = int(info_split[2])
def test_add_a_task(self): task_list = TaskList() task = Task() self.assert_equal(True, task_list.add_task(task)) self.assert_equal(1, len(task_list.tasks))
import argparse from helpers import dump_np_array from task import Task parser = argparse.ArgumentParser() parser.add_argument("taxicab_task_file", type=str, help="Path to taxicab task file") parser.add_argument("output", type=str, help="Path to output file") args = parser.parse_args() task = Task(args.taxicab_task_file) dump_np_array(task.adjacency_matrix, args.output)
if nFilesDone == nFiles: # this is the case when all is done print ' DONE all files have been produced.\n' continue elif nFilesDone < nFiles: # second most frequent case: work started but not completed print ' files missing, submit the missing ones.\n' else: # weird, more files found than available print '\n ERROR more files found than available in dataset. NO ACTION on this dataset' print ' done: %d all: %d'%(nFilesDone,nFiles) cmd = 'addDataset.py --exec --dataset=' + datasetName print ' updating the dataset from dbs: ' + cmd os.system(cmd) # if work not complete consider further remainder print '\n # # # # New dataset: %s # # # # \n'%(datasetName) # Get sample info, make request and generate the task sample = Sample(datasetName,dbs,useExistingLfns,useExistingLfns,useExistingSites) request = Request(scheduler,sample,config,version,py) task = Task(generateCondorId(),request) # Submit task if submit: cleanupTask(task) submitTask(task) # Cleanup task (careful all tasks being submitted get cleaned up) if cleanup and row not in incompleteResults: cleanupTask(task) sys.exit(0)
from task import Task #from connection import Connection import sys while (True): op = raw_input("Enter desired operation: ") if op == 'INSERT': name = raw_input('Enter task name: ') desc = raw_input('Enter task description: ') task_object = Task(name, desc) Task.insert_into_db(task_object) print("New element was added successfully") elif op == 'DELETE': name = raw_input('Enter task name: ') desc = raw_input('Enter task description: ') task_object = Task(name, desc) Task.del_from_db(task_object) print("Element was deleted successfully") elif op == 'UPDATE': old_name = raw_input('Enter task old name: ') old_desc = raw_input('Enter task old description: ') name = raw_input('Enter task new name: ') desc = raw_input('Enter task new description: ') old_task_object = Task(old_name, old_desc) new_task_object = Task(name, desc) Task.update_db_element(old_task_object, new_task_object) print("Element was updated successfully") elif op == 'GET_ONE': id = raw_input('Enter id: ') task = Task('null', 'null') task.id = id
def new_task(self): task = Task() task.set_taskname(input("Task Name: ")) task.set_taskdesc(input("Description: ")) self.taskboard.append(task)
def test_has_snoozed_date_when_snoozed_is_in_the_past() -> None: assert not has_snoozed_date(Task(snooze=date.today() - timedelta(days=2)))
def test_has_snoozed_date_when_snoozed_is_in_the_future() -> None: assert has_snoozed_date(Task(snooze=date.today() + timedelta(days=2)))
def test_is_urgent_task_in_the_distant_future() -> None: task = Task(due=date(9999, 1, 1)) assert not is_urgent(task)
def test_has_snoozed_date_when_not_snoozed() -> None: assert not has_snoozed_date(Task())
def test_is_urgent_undue_task() -> None: task = Task(due=None) assert not is_urgent(task)
def test_is_urgent_due_task() -> None: task = Task(due=date(5, 3, 2)) assert is_urgent(task)
def test_is_urgent_task() -> None: task = Task() assert not is_urgent(task)
def setup_game(self): # Decide scale of game based on user input self.players_left = self.prompt_for_players() # impostors = list() # if self.players_left > 6: # impo1 = random.choice(self.living_players) # impo2 = random.choice(self.living_players) # impostors.append(impo1) # impostors.append(impo2) # else: # impostors.append(random.choice(self.living_players)) # print(x) # if x in impostors: # self.living_impostors.update(x=Impostor(x)) # else: # self.living_crewmates.update(x=Crewmate(x)) # Generate two common tasks per living player commons = list(Task.common_tasks.keys()) for x in self.living_players: playa = Crewmate(x) self.living_crewmates.append(playa) randos = list() somethin = random.choice(commons) somethinelse = random.choice(commons) randos.append( (somethin, random.choice(Task.common_tasks[somethin]))) randos.append( (somethinelse, random.choice(Task.common_tasks[somethinelse]))) for r in randos: t = Task(r[0], r[1]) self.tasks_remaining.append(t) #self.players_left += 1 # Generate unique tasks for x in Task.unique_tasks: t = Task(x, Task.unique_tasks[x]) self.tasks_remaining.append(t) # Spawn players impo = random.choice(self.living_players) # Cheat # print(impo) for x in self.living_crewmates: boi = x.name if (boi == impo): self.living_crewmates.remove(x) x.roam() self.imp = Impostor(impo) self.living_impostors.append(Impostor(impo)) # Generate a sabotage from the impostor(s) for x in self.living_impostors: t = x.sabotage() self.tasks_remaining.append(t) for t in self.tasks_remaining: crewie = random.choice(self.living_crewmates) crewie.tasks.append(t) print(self.living_players, self.living_impostors, self.living_crewmates)
def test_is_completed() -> None: assert not is_completed(Task()) assert is_completed(Task(completed=date(1, 1, 1)))
# ----------------------------------------------------------------------------- # Copyright (c) 2016, Nicolas P. Rougier # Distributed under the (new) BSD License. # ----------------------------------------------------------------------------- import numpy as np import matplotlib.pyplot as plt from task import Task from model import Model seed = np.random.randint(0, 1000) np.random.seed(seed) model = Model("model-guthrie.json") task = Task("task-guthrie.json") print("-" * 30) print("Seed: %d" % seed) print("Model: %s" % model.filename) print("Task: %s" % task.filename) print("-" * 30) trial = task[0] model.process(task, trial, stop=False, debug=False) cog = model["CTX"]["cog"].history[:3000] mot = model["CTX"]["mot"].history[:3000] fig = plt.figure(figsize=(12, 5)) plt.subplots_adjust(bottom=0.15) duration = 3.0
def test_is_important() -> None: assert not is_important(Task()) assert not is_important(Task(importance=Importance.Unimportant)) assert is_important(Task(importance=Importance.Important))
import pandas as pd from task import Material, Task if __name__ == "__main__": mdf = pd.read_csv('material.csv', delimiter=";") jdf = pd.read_csv('jobs.csv', delimiter=';') materials = {} tasks = {} for _, job_number, material_number, qty, dd in jdf.itertuples(): material = materials.get(material_number) if material is None: dur = int(mdf[mdf['Material'] == material_number]['Duration']) material = Material(material_number, dur) materials[material_number] = material task = Task(job_number, material, qty, dd) tasks[job_number] = task for task in sorted(tasks.values(), key=lambda x: x.due_date): task.set_predecessors() for task in sorted(tasks.values(), key=lambda x: x.due_date, reverse=True): task.set_successors() print(task for task in tasks)
def test_snooze_empty_task() -> None: task = Task() assert task.snooze is None
from config import Config import mysql.connector from task import Task import os import json import time c = Config() t = Task(c) def connect2Mysql(): conn = mysql.connector.connect(user='******', password='******', database='flow4.0', use_unicode=True) cursor = conn.cursor() return conn, cursor def readNotes(): conn, cursor = connect2Mysql() cursor.execute( 'SELECT * from flow_item where status = 0 Order By modify_time Desc') values = cursor.fetchall() cursor.execute('UPDATE temp set value = 0 where name = %s', ('has_new', )) conn.commit() cursor.close() conn.close()
params = Params() params.extra_text = 'speed_reward_multip__concatenate' params.exploration_mu = 0 params.exploration_theta = 0.15 params.exploration_sigma = 0.02 #0.002 params.actor_learning_rate = 1.0e-5 # 0.0001 params.critic_learning_rate = 0.001 # 0.001 params.tau = 0.001 params.actor_net_cells = [16 * 2, 16 * 2] params.critic_net_cells = [16 * 2, 32 * 2] params.gamma = 0.99 # test_values = [1.0e-3, 1.0e-4, 1.0e-5,1.0e-6, 1.0e-7] # actor_learning_rate # test_values = [1.0e-2, 1.0e-3, 1.0e-4,1.0e-5] # critic_learning_rate # test_values = [0.9, 0.99] # gamma # test_values = [0.2, 0.02, 0.002, 0.0002] # exploration_sigma # test_values = [0.1, 0.01, 0.001, 0.0001] # tau # test_values = [0.9, 0.99] # gammaç # test_values = ['speed_reward_multip__concatenate'] test_values = ['speed_reward_multip__add'] # Think how to do the networks batch. for test_value in test_values: params.extra_text = test_value task = Task(init_pose=init_pose, init_velocities=init_velocities, target_pos=target_pos) agent = DDPG(task, params, buffer_size=buffer_size, batch_size=batch_size) run_training(agent, task, params, num_episodes, file_output)
logs.info("Retrieve arguments for each model...") kwargs_splitter = get_splitter_information(parameters) kwargs_compression = get_compression_information(parameters) kwargs_transformation = get_data_transformation_information(parameters) kwargs_estimator_model = get_estimator_model_information(parameters) logs.validate() logs.info("Instanciations of the classes...") splitter = Splitter(**kwargs_splitter) compressor = Compressor(**kwargs_compression) transformer = Transformer(**kwargs_transformation) estimator_model = EstimatorModel(**kwargs_estimator_model) logs.validate() logs.info("Defining Pipeline flow...") splitter_cv_external = Task([splitter.split], name='splitter_cv_external') ## Internal Pipeline splitter_cv_internal = Task( [splitter.split], input_dependencies=[splitter_cv_external], name='splitter_cv_internal', flatten_inputs=[True]) # define the splitting strategy compressor_internal = Task( [compressor.compress], input_dependencies=[splitter_cv_internal], name='compressor_internal', flatten_inputs=[True], unflatten_output='automatic') # define the data compression method transform_data_internal = Task( [transformer.make_regressor, transformer.scale], input_dependencies=[splitter_cv_internal, compressor_internal],
args = get_args() os.environ["TF_CPP_MIN_LOG_LEVEL"]="3" if args.process_unit == "CPU": config = tf.ConfigProto( device_count={'CPU' : 1, 'GPU' : 0}, intra_op_parallelism_threads=1, inter_op_parallelism_threads=1) set_session(tf.Session(config=config)) else: config = tf.ConfigProto( device_count={'CPU' : 1, 'GPU' : 1}) config.gpu_options.per_process_gpu_memory_fraction = 1 set_session(tf.Session(config=config)) task = Task(args) if task.args.init and task.args.model is None and task.args.mode == "train": load_memories(task, rnd=False) if task.args.model is not None: task.agent.load_model_weights("./{}" .format(task.args.model)) task.agent.update_target_net() task.agent.current_epsilon = 0.1 if task.args.init and task.args.mode == "train": load_memories(task, rnd=True) if task.args.vids: task.env = wrappers.Monitor(task.env, "./", video_callable=lambda episode_id: episode_id%1==0, force=True)
%load_ext autoreload %autoreload 2 import csv import numpy as np from task import Task # Modify the values below to give the quadcopter a different starting position. runtime = 5. # time limit of the episode init_pose = np.array([0., 0., 10., 0., 0., 0.]) # initial pose # [x, y, z, phi, theta, psi] init_velocities = np.array([0., 0., 0.]) # initial velocities # x_velocity, y_velocity, z_velocity init_angle_velocities = np.array([0., 0., 0.]) # initial angle velocities # phi_velocity, theta_velocity, psi_velocity file_output = 'data.txt' # file name for saved results # Setup task = Task(init_pose, init_velocities, init_angle_velocities, runtime) agent = Basic_Agent(task) done = False labels = ['time', 'x', 'y', 'z', 'phi', 'theta', 'psi', 'x_velocity', 'y_velocity', 'z_velocity', 'phi_velocity', 'theta_velocity', 'psi_velocity', 'rotor_speed1', 'rotor_speed2', 'rotor_speed3', 'rotor_speed4'] results = {x : [] for x in labels} # Run the simulation, and save the results. with open(file_output, 'w') as csvfile: writer = csv.writer(csvfile) writer.writerow(labels) while True: rotor_speeds = agent.act() _, _, done = task.step(rotor_speeds) to_write = [task.sim.time] + list(task.sim.pose) + list(task.sim.v) + list(task.sim.angular_v) + list(rotor_speeds)
def new_tasks(self, test=False): self.tasks += [{ 'runtimes': ['15:05' if not test else runtimes()], 'task': Task('new', 'ClientTask', sym, **data) } for sym, data in Firebase().get('new').items() if sym != 'Dummy2'] return self.tasks
def enqueue_message(): data = request.get_json() manager.enqueue_task(Task(data['message'])) return 'OK', 200
get_ipython().magic('load_ext autoreload') get_ipython().magic('autoreload 2') import csv import numpy as np from task import Task # Modify the values below to give the quadcopter a different starting position. runtime = 5. # time limit of the episode init_pose = np.array([0., 0., 10., 0., 0., 0.]) # initial pose init_velocities = np.array([0., 0., 0.]) # initial velocities init_angle_velocities = np.array([0., 0., 0.]) # initial angle velocities file_output = 'data.txt' # file name for saved results # Setup task = Task(init_pose, init_velocities, init_angle_velocities, runtime) agent = Basic_Agent(task) done = False labels = [ 'time', 'x', 'y', 'z', 'phi', 'theta', 'psi', 'x_velocity', 'y_velocity', 'z_velocity', 'phi_velocity', 'theta_velocity', 'psi_velocity', 'rotor_speed1', 'rotor_speed2', 'rotor_speed3', 'rotor_speed4' ] results = {x: [] for x in labels} # Run the simulation, and save the results. with open(file_output, 'w') as csvfile: writer = csv.writer(csvfile) writer.writerow(labels) while True: rotor_speeds = agent.act()
import sys import pandas as pd from agents.policy_search import PolicySearch_Agent from agents.agent import DDGP from task import Task import tensorflow as tf import numpy as np num_episodes = 1000 target_pos = np.array([0., 0., 10.]) task = Task(target_pos=target_pos) agent = DDGP(task) best_score = [0] with tf.device('/device:GPU:0'): for i_episode in range(1, num_episodes + 1): state = agent.reset_episode() # start a new episode score = 0 while True: action = agent.act(state) next_state, reward, done = task.step(action) score = score + reward agent.step(action, reward, next_state, done) state = next_state if done: print("\rEpisode = {:4d}, score = {:7.3f} (best = {:7.3f})". format(i_episode, score, max(best_score)), end="\n") best_score.append(score) break sys.stdout.flush()
def push_tasks(self, User, delays, callback = None): Tasks = [Task(User, delay, callback) for delay in delays] self.queue.push(User, Tasks)