Exemplo n.º 1
0
def initialize():
    DATABASE.connect()
    DATABASE.create_tables([House, Agent], safe=True)
    try:
        House.create(plot_no="kawang_34",
                     no_rooms=5,
                     rent=20000,
                     no_bathrooms=2,
                     location="Kawangware, Nairobi",
                     nearby_amenities="Kawangware Primary",
                     rating=5)
        House.create(plot_no="kawang_35",
                     no_rooms=4,
                     rent=15000,
                     no_bathrooms=1,
                     location="Kawangware, Nairobi",
                     nearby_amenities="Kawangware Group of schools",
                     rating=5)
    except IntegrityError:
        pass

    try:
        Agent.create(
            name="john doe",
            business_number="0712345678",
            email="*****@*****.**",
        )
    except IntegrityError:
        pass

    DATABASE.close()
Exemplo n.º 2
0
    def GetContext(self):

        tAgent = Agent()
        tAgentList = []
        tAgentOrders = []
        tAgentDonations = []
        tAgentRequest = self.request.get('agent')
        context = {}

        tAgentList = Agent.all()
        context['agents'] = tAgentList
        if (tAgentRequest != ""):
            tAgent = Agent.get(tAgentRequest)

            tAgentOrdersQuery = Order.all()
            tAgentOrdersQuery.filter('orderAgent', str(tAgentRequest))
            tAgentOrdersQuery.order('-orderCompleted')
            tAgentOrders = tAgentOrdersQuery.fetch(100)

            tAgentDonorsQuery = DonorRecord.all()
            tAgentDonorsQuery.filter('donorAgent', tAgent.agentId)
            tAgentDonorsQuery.order('-donorDate')
            tAgentDonations = tAgentDonorsQuery.fetch(100)

            #logging.debug("Agent Order Count: " + str(len(tAgentOrders)))
            #logging.debug("Agent Donation Count: " + str(len(tAgentDonations)))

            context['agent'] = tAgent
            context['orders'] = tAgentOrders
            context['donations'] = tAgentDonations
            context['extended'] = 'True'

        return context
 def GetContext(self):
         
     tAgent = Agent()
     tAgentList = []
     tAgentOrders = []
     tAgentDonations = []
     tAgentRequest = self.request.get('agent')
     context = {}
     
     tAgentList = Agent.all()
     context['agents'] = tAgentList
     if (tAgentRequest != ""):
         tAgent = Agent.get(tAgentRequest)
         
         tAgentOrdersQuery = Order.all()
         tAgentOrdersQuery.filter('orderAgent', str(tAgentRequest))
         tAgentOrdersQuery.order('-orderCompleted')
         tAgentOrders = tAgentOrdersQuery.fetch(100)
         
         tAgentDonorsQuery = DonorRecord.all()
         tAgentDonorsQuery.filter('donorAgent', tAgent.agentId)
         tAgentDonorsQuery.order('-donorDate')
         tAgentDonations = tAgentDonorsQuery.fetch(100)
         
         #logging.debug("Agent Order Count: " + str(len(tAgentOrders)))
         #logging.debug("Agent Donation Count: " + str(len(tAgentDonations)))
         
         context['agent'] = tAgent
         context['orders'] = tAgentOrders
         context['donations'] = tAgentDonations
         context['extended'] = 'True'
         
     return context
Exemplo n.º 4
0
def agent_worker(config, policy, learner_w_queue, global_episode, n_agent,
                 log_dir, training_on, replay_queue, update_step):
    agent = Agent(config,
                  policy,
                  global_episode=global_episode,
                  n_agent=n_agent,
                  log_dir=log_dir)
    agent.run(training_on, replay_queue, learner_w_queue, update_step)
Exemplo n.º 5
0
 def __init__(self, name, pars, nrenvs=1, job=None, experiment=None):
     Agent.__init__(self, name, pars, nrenvs, job, experiment)
     self.coef_value = 0.5
     self.ppo_steps = 5
     self.clip_param = 0.2
     self.max_grad_norm = 0.5
     self.eps_threshold = 0.1
     self.use_clipped_value_loss = True
Exemplo n.º 6
0
def agent_worker(config, policy, learner_w_queue, global_episode, i, agent_type,
                 experiment_dir, training_on, replay_queue, update_step):
    agent = Agent(config,
                  policy=policy,
                  global_episode=global_episode,
                  n_agent=i,
                  agent_type=agent_type,
                  log_dir=experiment_dir)
    agent.run(training_on, replay_queue, learner_w_queue, update_step)
Exemplo n.º 7
0
def add_agent():
    agent_data = dict(request.form.items())
    Agent.create(
        name=agent_data.get('name', 'john doe'),
        business_number=agent_data.get('business_number'),
        email=agent_data.get('email'),
    )
    result = {'status': 'success'}
    return jsonify(result)
Exemplo n.º 8
0
 def test_evaluate(self):
     self.env = Env(
         balance=250000,
         FX_DATA_FILE='../data/raw/FX_Demo/sample_USD_JPY_S5.pickle')
     self.agent = Agent()
     self.agent.model.compile(optimizer=Adam(), loss="mse")
     state = (self.env.balance, self.env.stock_balance)
     y = self.agent.evaluate(state=state)
     assert y.shape == (3, )
     assert any(y) is True
Exemplo n.º 9
0
 def test_act(self):
     self.env = Env(
         balance=250000,
         FX_DATA_FILE='../data/raw/FX_Demo/sample_USD_JPY_S5.pickle')
     self.agent = Agent()
     self.agent.model.compile(optimizer=Adam(), loss="mse")
     state = (self.env.balance, self.env.stock_balance)
     action = self.agent.act(state, epsilon=0.1)
     action_state = False
     if action == 0 or action == 1 or action == 2:
         action_state = True
     assert action_state is True
Exemplo n.º 10
0
 def get(self):
     tAgentQuery = Agent().all()
     tAgentQuery.filter('agentOnline', True)
     
     tAgents = tAgentQuery.fetch(10)
     if (len(tAgents) > 0):
         self.response.out.write(str(len(tAgents)))
     else:
         self.response.out.write(str(0))
     exit
 
         
 def test_train(self):
     env = Env(balance=250000,
               FX_DATA_FILE='../data/raw/FX_Demo/sample_USD_JPY_S5.pickle')
     agent = Agent(input_data_shape=(10, ))
     mount_agent = Agent(actions=10, input_data_shape=(10, ))
     print(len(env.fx_time_data_buy))
     trainer = Trainer_priority(env,
                                agent,
                                mount_agent,
                                data_end_index=len(env.fx_time_data_buy) -
                                2)
     trainer.train()
Exemplo n.º 12
0
    def post(self):
        tOrderKey = self.request.get('orderid')

        #logging.debug("tOrderKey: " + tOrderKey)

        tPaOrder = PaOrder()
        tPaOrder = PaOrder.get(tOrderKey)

        tUser = users.get_current_user()
        tAgent = Agent().GetAgentByEmail(str(tUser.email()))

        if (tPaOrder.paOrderDeliver == False and tPaOrder.paOrderLock == False
                and tAgent.agentIsEnabled == True):
            tGoldAmount = tPaOrder.paAmountInt

            tGoldAmountLong = tGoldAmount
            tGoldAmount = tGoldAmount / 1000000

            if (tAgent.agentGoldSupply == None):
                tAgent.agentGoldSupply = 0

            tCommission = tGoldAmount * 0.05 + 0.50

            tAgent.agentGoldSupply = int(
                tAgent.agentGoldSupply) - int(tGoldAmountLong)
            tAgent.agentCurrentCommission = tAgent.agentCurrentCommission + tCommission
            tAgent.agentTotalCommission = tAgent.agentTotalCommission + tCommission

            tAgentOrders = tAgent.agentOrders  #Add order to agent pa orders
            tAgentOrders.append(tOrderKey)
            tAgent.agentOrders = tAgentOrders

            tAgent.agentCurrentOrderTotal = tAgent.agentCurrentOrderTotal + 1

            tAgentKey = tAgent.put()

            tPaOrder.paDeliveryAgent = str(tAgent.agentId)
            tPaOrder.paDeliveryAgentNick = tAgent.agentNickName
            tPaOrder.paOrderDeliver = True
            tPaOrder.paOrderLock = True
            tKey = tPaOrder.put()

            #logging.debug("Delivery by Agent: " + str(tAgentKey))
            #logging.debug("Delivery of Order: " + str(tKey))

            self.response.headers[
                'Cache-Control'] = 'Cache-Control: no-cache, must-revalidate'
            self.response.headers['Content-Type'] = 'Content-Type: plain/text'
            self.response.out.write("Order Delivered")
        else:
            #logging.debug('Attempted to Deliver ' + tOrderKey + " by Agent " + tAgent.agentId)
            self.response.headers[
                'Cache-Control'] = 'Cache-Control: no-cache, must-revalidate'
            self.response.headers['Content-Type'] = 'Content-Type: plain/text'
            self.response.out.write("Order Not Deliverable")
Exemplo n.º 13
0
    def PostContext(self):
        tContext = {}
        tAgent = Agent()

        tUser = self.GetUser()
        tAgent = Agent.GetAgentByEmail(tUser.email())
        tSaveAgent = False
        tNewNick = self.request.get('nick')
        tSoundOpt = self.request.get('sound')

        if (tNewNick != None and len(tNewNick) > 0):
            tAgent.agentNickName = tNewNick
            tSaveAgent = True

        if (tSoundOpt != None and len(tSoundOpt) > 0):
            tSoundOpt = str(tSoundOpt)
            if (tSoundOpt == "true"):
                tAgent.agentSoundPreference = 'True'
                tSaveAgent = True
            elif (tSoundOpt == "false"):
                tAgent.agentSoundPreference = 'False'
                tSaveAgent = True

        if (tSaveAgent):
            tAgent.put()
        self.LOCATION = "/"
        self.REDIRECT = True
        return tContext
Exemplo n.º 14
0
    def post(self):
        tUrl = "https://api-3t.paypal.com/nvp"
        tPaypalPayload = {}
        tPaypal = PaypalRefund()
        tAgent = Agent()
        tOrder = Order()
        tUser = users.get_current_user()

        tTransId = str(self.request.get('orderid'))

        tAgentEmail = str(tUser.email())
        tAgent = Agent().GetAgentByEmail(tAgentEmail)
        tRefundAgent = tAgentEmail

        tOrderQuery = Order.all()
        tOrderQuery.filter("orderTransactionId", tTransId)
        #logging.debug("Transaction id: " + tTransId)
        tOrder = tOrderQuery.get()

        if (tOrder.orderDeliver != 'True'):

            tPaypalPayload['METHOD'] = "RefundTransaction"
            tPaypalPayload['TRANSACTIONID'] = tTransId

            tPayloadEncoded = tPaypal.GeneratePayload(tPaypalPayload)

            request_cookies = mechanize.CookieJar()
            request_opener = mechanize.build_opener(
                mechanize.HTTPCookieProcessor(request_cookies))
            request_opener.addheaders = [('Content-Type',
                                          'application/x-www-form-urlencoded')]
            mechanize.install_opener(request_opener)

            tResponse = mechanize.urlopen(url=tUrl,
                                          timeout=25.0,
                                          data=tPayloadEncoded)
            #logging.debug("Mechanize Package")
            #logging.debug("Url: " + tUrl)
            #logging.debug("Data: " + str(tPaypalPayload))

            tResult = tResponse.read()
            #logging.debug(tResult)

            tOrder.orderIsRefunded = "True"
            tOrder.orderRefundAgent = tRefundAgent
            tOrder.orderLocked = "True"
            tOrder.orderRefundId = ""
            tOrder.put()

            self.response.out.write("Order Locked and Refunded")
Exemplo n.º 15
0
 def PostContext(self):
     tContext = {}
     if (self.IsUserAdmin()):
         try:
             tAgentKey = self.request.get('custid')
             tAgent = Agent()
             tAgent = Agent().get(tAgentKey)
             tAgent.agentCurrentCommission = 0.0
             tAgent.put()
             self.response.out.write("Success")
         except:
             self.response.out.write("Error")
         tContext['nowrite'] = True
     return tContext
     
Exemplo n.º 16
0
def run(params, task_id, job_dir, name=None):
    keys = params.keys()
    agent_keys = [key for key in keys if 'agent' in key]
    meta = params.pop('__meta__')
    verbose = meta['verbose']
    trial_num = meta['trial_num']
    protocol = meta['protocol']
    experiment_name = meta['experiment_name']
    prepare_environment(meta)
    # Load Agents Based on Model
    agents = []
    for agent_key in agent_keys:
        agent_params = params.pop(agent_key)
        agents += [Agent(agent_dict=agent_params, name=agent_key)]
    params['agents'] = agents

    # Load Protocol and Train (Results callback will collect results)
    module_name = 'protocols.%s.train' % (protocol)
    train = getattr(import_module(module_name), 'train')

    info, results = train(**params,
                          verbose=False)

    # AFTER DONE TRAINING SAVE RESULTS FILE
    results.insert(0, {'experiment_name': experiment_name,
                       'protocol': protocol,
                       'trial_num': trial_num,
                       **info})
    if name is not None:
        result_file = '%s.npy' % name
    else:
        result_file = '%i.npy' % task_id
    np.save(result_file, results)
    save_file(job_dir, result_file)
 def GetOnlineAgents(self):
     FETCH_NUMBER = 30
     tAgentQuery = Agent.all()
     tAgentQuery.filter("agentOnline", True)
     tAgentQuery.order("-agentCurrentOrderTotal")
     tAgents = tAgentQuery.fetch(FETCH_NUMBER)
     return tAgents
Exemplo n.º 18
0
 def GetOnlineAgents(self):
     FETCH_NUMBER = 30
     tAgentQuery = Agent.all()
     tAgentQuery.filter("agentOnline", True)
     tAgentQuery.order("-agentCurrentOrderTotal")
     tAgents = tAgentQuery.fetch(FETCH_NUMBER)
     return tAgents
 def GetAssignedAgent(self, pOrder = None):
     tAgent = Agent()
     tAssignment = DeliveryAssignment()
     tAgents = []
     Switch = {}
     tOrder = PaOrder()
     tOrder = pOrder
     
     #Need to implement these methods
     #Switch[(1,2)] = tPaypal.UseFullAndBackupAgents
     #Switch[(0,2)] = tPaypal.UseBackupAgent
     #Switch[(2,2)] = tPaypal.UseFullAgent
     Switch[(0,0)] = tAssignment.AssignNoAgent
     Switch[(0,1)] = tAssignment.UseBackupAgent
     Switch[(1,0)] = tAssignment.UseFullAgent
     Switch[(1,1)] = tAssignment.UseFullAndBackupAgents
     Switch[(2,0)] = tAssignment.UseFullAgent
     Switch[(2,1)] = tAssignment.UseFullAndBackupAgents
     Switch[(3,0)] = tAssignment.UseFullAgent
     Switch[(3,1)] = tAssignment.UseFullAgent
     
     
     #Based on the raw online numbers of each group
     tCurrentState = (tAssignment.GetNumberofOnlineFullAgents(), tAssignment.GetNumberofOnlineBackupAgents())
     #logging.debug("Current State" + str(tCurrentState))
     
     #The end agent will be handled in each function
     tAgent = Switch[tCurrentState]()
     if (tOrder != None):
         try:
             #logging.debug("Agent Current Total: " + str(tAgent.agentCurrentOrderTotal))
             #logging.debug("Order Quantity: " + str(tOrder.paAmountInt))
             tAgent.agentCurrentOrderTotal = tAgent.agentCurrentOrderTotal + 1
             #logging.debug("New Agent Current Total: " + str(tAgent.agentCurrentOrderTotal))
             tAgent.agentNotify = True
             tAgent.put()
             #logging.debug("GetAssignedAgent returning agent: " + str(tAgent.agentId))
             return tAgent
         except:
             #logging.debug("Hit an error")
             return "No Agent Online"
     else:
         try:
             return tAgent
         except:
             return "No Agent Online"
Exemplo n.º 20
0
def main():
    # Training settings
    parser = argparse.ArgumentParser(description='PyTorch Poly Echo')
    parser = add_experiment_args(parser)
    args = parser.parse_args()
    np.set_printoptions(formatter={'float': '{: 0.3f}'.format})
    params_file = os.path.join(WORK_DIR, '%s.json' % args.task_id)
    with open(params_file) as file:
        params = json.load(file)

    keys = params.keys()
    agent_keys = [key for key in keys if 'agent' in key]
    num_agents = len(agent_keys)
    meta = params.pop('__meta__')
    verbose = meta['verbose']
    trial_num = meta['trial_num']
    protocol = meta['protocol']
    experiment_name = meta['experiment_name']
    prepare_environment(meta)
    agents = []
    for agent_key in agent_keys:
        agent_params = params.pop(agent_key)
        agents += [Agent(agent_dict=agent_params, name=agent_key)]

    if num_agents == 2:
        A = agents[0]
        B = agents[1]
    else:
        A = agents[0]
        B = agents[0]
    # Load Protocol
    module_name = 'protocols.%s.trainer' % (protocol)
    trainer = getattr(import_module(module_name), 'trainer')
    total_batches_sent = 0
    results, symbols_sent = [], []
    test_SNR_dbs = get_test_SNR_dbs()[
        params['bits_per_symbol']]['ber_roundtrip']
    num_iterations = params['num_iterations']
    total_iterations = num_iterations + (1 if num_agents == 2 else 0)
    for i in range(total_iterations):
        B, A, batches_sent = trainer(agents=[A, B],
                                     bits_per_symbol=params['bits_per_symbol'],
                                     batch_size=params['batch_size'],
                                     train_SNR_db=params['train_SNR_db'],
                                     signal_power=params['signal_power'],
                                     backwards_only=(i == num_iterations))
        total_batches_sent += batches_sent
        if i % params['results_every'] == 0:
            result = test(agent1=agents[0],
                          agent2=agents[1] if num_agents == 2 else None,
                          bits_per_symbol=params['bits_per_symbol'],
                          test_SNR_dbs=test_SNR_dbs,
                          signal_power=params['signal_power'],
                          test_batch_size=params['test_batch_size'])
            test_bers = result['test_bers']
            print('Test: Roundtrip BER: ', test_bers)
        symbols_sent += [total_batches_sent * params['batch_size']]
    results += [result]
def main():
    env = gym.make(FLAGS.env_name)
    agent = Agent(num_actions=env.action_space.n, config=FLAGS)

    if FLAGS.train:  # Train mode
        for _ in range(FLAGS.num_episodes):
            terminal = False
            observation = env.reset()
            for _ in range(random.randint(1, FLAGS.no_op_steps)):
                last_observation = observation
                observation, _, _, _ = env.step(0)  # Do nothing
            state = agent.get_initial_state(observation, last_observation)
            while not terminal:
                last_observation = observation
                action = agent.get_action(state)
                observation, reward, terminal, _ = env.step(action)
                # env.render()
                processed_observation = preprocess(observation, last_observation)
                state = agent.run(state, action, reward, terminal, processed_observation)
    else:  # Test mode
        # env.monitor.start(ENV_NAME + '-test')
        for _ in range(FLAGS.num_episodes_at_test):
            terminal = False
            observation = env.reset()
            for _ in range(random.randint(1, FLAGS.no_op_steps)):
                last_observation = observation
                observation, _, _, _ = env.step(0)  # Do nothing
            state = agent.get_initial_state(observation, last_observation)
            while not terminal:
                last_observation = observation
                action = agent.get_action_at_test(state)
                observation, _, terminal, _ = env.step(action)
                env.render()
                processed_observation = preprocess(observation, last_observation)
                state = np.append(state[1:, :, :], processed_observation, axis=0)
 def GetAvailableBackupAgents(self):
     FETCH_NUMBER = 30
     tAgentQuery = Agent.all()
     tAgentQuery.filter("agentOnline", True)
     tAgentQuery.filter("agentCurrentOrderTotal <", 1)
     tAgentQuery.filter("agentIsFullAgent", False)
     tAgentQuery.order("-agentCurrentOrderTotal")
     tAgents = tAgentQuery.fetch(FETCH_NUMBER)
     return tAgents
Exemplo n.º 23
0
    def get(self):
        tAgent = Agent()
        tAgentsOnline = []
        
        tCurrentTime = datetime.datetime.now()
        tIncrement = datetime.timedelta(minutes = -30)
        tTime = tIncrement + tCurrentTime
        
        tAgentQuery = Agent().all()
        tAgentQuery.filter("agentOnline", True)
        tAgentQuery.filter("agentLastActive <", tTime)
        
        tAgentsOnline = tAgentQuery.fetch(10)

        if (len(tAgentsOnline) > 0):
            for tAgent in tAgentsOnline:
                tAgent.agentOnline = False
                tAgent.put()
 def get(self):
     tAgent = Agent()
     tUser = users.get_current_user()
     if (tUser):
         tAgent = Agent().GetAgentByEmail(tUser.email())
         if (tAgent.agentOnline == True):
             if (tAgent.agentNotify == True):
                 tAgent.agentNotify = False
                 tAgent.put()
                 self.response.out.write("1")
             elif (tAgent.agentNotify == False):
                 self.response.out.write("0")
             else:
                 self.response.out.write("0")
                 tAgent.agentNotify = False
                 tAgent.put()
         else:
             self.response.out.write("2")
Exemplo n.º 25
0
 def GetAvailableBackupAgents(self):
     FETCH_NUMBER = 30
     tAgentQuery = Agent.all()
     tAgentQuery.filter("agentOnline", True)
     tAgentQuery.filter("agentCurrentOrderTotal <", 30000000)
     tAgentQuery.filter("agentIsFullAgent", False)
     tAgentQuery.order("-agentCurrentOrderTotal")
     tAgents = tAgentQuery.fetch(FETCH_NUMBER)
     return tAgents
Exemplo n.º 26
0
def list_saloons():
    agents = Agent.select()
    results = []
    for agent in agents:
        results.append({
            'name': agent.name,
            'business_number': agent.business_number,
            'email': agent.email,
        })
    return jsonify(results)
Exemplo n.º 27
0
 def post(self):
     tOrderKey = self.request.get('orderid')
     
     #logging.debug("tOrderKey: " + tOrderKey)
     
     tPaOrder = PaOrder()
     tPaOrder = PaOrder.get(tOrderKey)
     
     tUser = users.get_current_user()
     tAgent = Agent().GetAgentByEmail(str(tUser.email()))
     
     if (tPaOrder.paOrderDeliver == False and tPaOrder.paOrderLock == False and tAgent.agentIsEnabled == True):
         tGoldAmount = tPaOrder.paAmountInt
         
         tGoldAmountLong = tGoldAmount
         tGoldAmount = tGoldAmount / 1000000
         
         if (tAgent.agentGoldSupply == None):
             tAgent.agentGoldSupply = 0
         
         tCommission = tGoldAmount * 0.05 + 0.50
         
         tAgent.agentGoldSupply = int(tAgent.agentGoldSupply) - int(tGoldAmountLong)
         tAgent.agentCurrentCommission = tAgent.agentCurrentCommission + tCommission
         tAgent.agentTotalCommission = tAgent.agentTotalCommission + tCommission
         
         tAgentOrders = tAgent.agentOrders #Add order to agent pa orders
         tAgentOrders.append(tOrderKey)
         tAgent.agentOrders = tAgentOrders           
         
         tAgent.agentCurrentOrderTotal = tAgent.agentCurrentOrderTotal + 1
         
         tAgentKey = tAgent.put()
         
         tPaOrder.paDeliveryAgent = str(tAgent.agentId)
         tPaOrder.paDeliveryAgentNick = tAgent.agentNickName
         tPaOrder.paOrderDeliver = True
         tPaOrder.paOrderLock = True
         tKey = tPaOrder.put()
         
         #logging.debug("Delivery by Agent: " + str(tAgentKey))
         #logging.debug("Delivery of Order: " + str(tKey))
         
         self.response.headers['Cache-Control'] = 'Cache-Control: no-cache, must-revalidate'
         self.response.headers['Content-Type'] = 'Content-Type: plain/text'
         self.response.out.write("Order Delivered")
     else:
         #logging.debug('Attempted to Deliver ' + tOrderKey + " by Agent " + tAgent.agentId)
         self.response.headers['Cache-Control'] = 'Cache-Control: no-cache, must-revalidate'
         self.response.headers['Content-Type'] = 'Content-Type: plain/text'
         self.response.out.write("Order Not Deliverable")    
Exemplo n.º 28
0
def main():

    parser = argparse.ArgumentParser(
        description='Execute train reinforcement learning.')
    parser.add_argument(
        '--dataset_name',
        type=str,
        default="../data/raw/FX_Demo/sample10000_USD_JPY_S5.pickle",
        help='an integer for the accumulator')

    args = parser.parse_args()
    print(args.dataset_name)
    env = Env(balance=250000, FX_DATA_FILE=args.dataset_name)
    agent = Agent(input_data_shape=(10, ))
    mount_agent = Agent(actions=10, input_data_shape=(10, ))
    trainer = Trainer(env,
                      agent,
                      mount_agent,
                      Adam(lr=1e-6),
                      data_end_index=len(env.fx_time_data_buy) - 2)
    trainer.train()
Exemplo n.º 29
0
 def PostContext(self):
     
     tUser = self.GetUser()
     tDonor = DonorRecord()
     
     tDonatorRsName = self.request.get('name')
     #logging.debug("Quantity Entered: " + str(self.request.get('quantity')))
     tDonatorAmount = int(self.request.get('quantity'))
     tDonatorNote = self.request.get('memo')
     tDonatorForumName = self.request.get('fname')
     tFormEmail = self.request.get('email')
     tAgentGold = self.request.get('agentgold')
     
     tDonor.donorAgent = tUser.email()
     tDonor.donorForumName = tDonatorForumName
     tDonor.donorMemo = tDonatorNote
     tDonor.donorRsName = tDonatorRsName
     tDonor.donorGoldAmount = int(tDonatorAmount)
     tDonor.put()
     
     tAgent = Agent()
     try:
         if (len(tFormEmail) > 0):
             tAgent = Agent().GetAgentByEmail(tFormEmail)
         else: 
             tAgent = Agent().GetAgentByEmail(str(tUser.email()))
     except:
         tAgent = Agent().GetAgentByEmail(str(tUser.email()))
     
     if (tAgent.agentGoldSupply == None):
         tAgent.agentGoldSupply = 0
         
     if (tDonatorAmount < 0):
         #logging.debug(str(tAgentGold))
         tDonatorAmount = tDonatorAmount / 1000000.0
         if (tAgentGold == 'on'):
             tCommission = tDonatorAmount * 0.65 * -1.0
         else:
             tAgent.agentGoldSupply += int(tDonatorAmount * 1000000.0)
             tCommission = tDonatorAmount * 0.05 * -1.0
         #logging.debug("Agent Commission: " + str(tDonatorAmount * -1.0))
         tAgent.agentCurrentCommission += tCommission
         tAgent.agentTotalCommission += tCommission
     else:
         tAgent.agentGoldSupply += tDonatorAmount
         
     tAgent.put()
     
     return {}
     
     
 
 
     
                 
 def post(self):
     tAgentQuery = Agent().all()
     tAgentList = tAgentQuery.fetch(100)
     agent = Agent()
     
     for agent in tAgentList:
         agent.agentOnline = False
         agent.put()
     
     self.response.out.write("Success")
Exemplo n.º 31
0
 def PostContext(self):
     tContext = {}
     if (self.IsUserAdmin()):
         try:
             tAgentKey = self.request.get('custid')
             tAgent = Agent()
             tAgent = Agent().get(tAgentKey)
             tAgent.agentCurrentCommission = 0.0
             tAgent.put()
             self.response.out.write("Success")
         except:
             self.response.out.write("Error")
         tContext['nowrite'] = True
     return tContext
Exemplo n.º 32
0
 def post(self):
     tAgent = Agent()
     tUser = users.get_current_user()
     if (tUser):
         tAgent = Agent().GetAgentByEmail(tUser.email())
         tAgent.put()
         #logging.debug("Action by Agent: " + tUser.email())
         if (tAgent.agentOnline == False):
             self.response.out.write("offline")
         else:
             self.response.out.write("online")
Exemplo n.º 33
0
    def UseFullAgent(self):
        tAgent = Agent()
        tAgents = []
        tPaypal = PaypalOrder()
        tOnlineAgents = tPaypal.GetNumberofOnlineFullAgents()
        tAvailableAgents = tPaypal.GetNumberofAvailableFullAgents()

        if (tOnlineAgents > 0 and tAvailableAgents == 0):
            tPaypal.ResetOnlineAgents()

        tAgents = tPaypal.GetAvailableFullAgents()

        try:
            tAgent = tAgents[0]
            return tAgent
        except:
            return "No Agent Online"
 def get(self):
     tAgent = Agent()
     tUser = users.get_current_user()
     if (tUser):
         tAgent = Agent().GetAgentByEmail(tUser.email())
         if(tAgent.agentOnline == True):
             if (tAgent.agentNotify == True):
                 tAgent.agentNotify = False
                 tAgent.put()
                 self.response.out.write("1")
             elif (tAgent.agentNotify == False):
                 self.response.out.write("0")
             else:
                 self.response.out.write("0")
                 tAgent.agentNotify = False
                 tAgent.put()
         else:
             self.response.out.write("2")
             
Exemplo n.º 35
0
 def post(self):
     tUser = users.get_current_user()
     tAgent = Agent().GetAgentByEmail(tUser.email())
     tStatus = tAgent.agentOnline
     
     if (tStatus == False):
         tAgent.agentOnline = True
         tAgent.agentCurrentOrderTotal = 100
         tReturn = "You're Online!"
     else:
         tAgent.agentOnline = False
         tReturn = "You're Offline!"
         
     tAgent.put()
     
     self.response.out.write(tReturn)
     exit
Exemplo n.º 36
0
    def GetAssignedAgent(self, pOrder=None):
        tAgent = Agent()
        tPaypal = PaypalOrder()
        tAgents = []
        Switch = {}
        tOrder = Order()
        tOrder = pOrder

        #Need to implement these methods
        #Switch[(1,2)] = tPaypal.UseFullAndBackupAgents
        #Switch[(0,2)] = tPaypal.UseBackupAgent
        #Switch[(2,2)] = tPaypal.UseFullAgent
        Switch[(0, 0)] = tPaypal.AssignNoAgent
        Switch[(0, 1)] = tPaypal.UseBackupAgent
        Switch[(1, 0)] = tPaypal.UseFullAgent
        Switch[(1, 1)] = tPaypal.UseFullAndBackupAgents
        Switch[(2, 0)] = tPaypal.UseFullAgent
        Switch[(2, 1)] = tPaypal.UseFullAndBackupAgents
        Switch[(3, 0)] = tPaypal.UseFullAgent
        Switch[(3, 1)] = tPaypal.UseFullAgent

        #Based on the raw online numbers of each group
        tCurrentState = (tPaypal.GetNumberofOnlineFullAgents(),
                         tPaypal.GetNumberofOnlineBackupAgents())
        #logging.debug("Current State" + str(tCurrentState))

        #The end agent will be handled in each function
        tAgent = Switch[tCurrentState]()
        if (tOrder != None):
            try:
                #logging.debug("Agent Current Total: " + str(tAgent.agentCurrentOrderTotal))
                #logging.debug("Order Quantity: " + str(tOrder.orderQuantity))
                tAgent.agentCurrentOrderTotal = tAgent.agentCurrentOrderTotal + int(
                    tOrder.orderQuantity)
                #logging.debug("New Agent Current Total: " + str(tAgent.agentCurrentOrderTotal))
                tAgent.agentNotify = True
                tAgent.put()
                #logging.debug("GetAssignedAgent returning agent: " + str(tAgent.agentId))
                return tAgent.agentId
            except:
                #logging.debug("Hit an error")
                return "No Agent Online"
        else:
            try:
                return str(tAgent.agentId)
            except:
                return "No Agent Online"
Exemplo n.º 37
0
    def UseFullAndBackupAgents(self):
        tAgent = Agent()
        tAgents = []
        tPaypal = PaypalOrder()

        tOnlineBackups = tPaypal.GetNumberofOnlineBackupAgents()
        tAvailableBackups = tPaypal.GetNumberofAvailableBackupAgents()
        tOnlineAgents = tPaypal.GetNumberofOnlineFullAgents()
        tAvailableAgents = tPaypal.GetNumberofAvailableFullAgents()

        tTotalOnline = tOnlineAgents + tOnlineBackups
        tTotalAvailable = tAvailableAgents + tAvailableBackups

        if (tTotalOnline > 0 and tTotalAvailable == 0):
            tPaypal.ResetOnlineAgents()

        tAgents = tPaypal.GetAvailableAgents()
        try:
            tAgent = tAgents[0]
            return tAgent
        except:
            return "No Agent Online"
Exemplo n.º 38
0
    def UseBackupAgent(self):
        #logging.debug("UseBackupAgent Called")
        tAgent = Agent()
        tAgents = []
        tPaypal = PaypalOrder()
        tOnlineBackups = tPaypal.GetNumberofOnlineBackupAgents()
        tAvailableBackups = tPaypal.GetNumberofAvailableBackupAgents()
        #logging.debug("Online Backups: " + str(tOnlineBackups))
        #logging.debug("Available Backups: " + str(tAvailableBackups))

        if (tOnlineBackups > 0 and tAvailableBackups == 0):
            #logging.debug("Resetting Online Agents")
            tPaypal.ResetOnlineAgents()

        tAgents = tPaypal.GetAvailableBackupAgents()

        try:
            tAgent = tAgents[0]
            #logging.debug("UseBackupAgent Returning " + str(tAgent.agentId))
            return tAgent
        except:
            #logging.debug("Error in UseBackupAgent")
            return "No Agent Online"
Exemplo n.º 39
0
 def get(self):
     tUser = self.GetUser()
     locale.setlocale(locale.LC_ALL, "")
     tContext = {}
     tContext['login'] = users.create_login_url(self.request.uri)
     tContext['logout'] = users.create_logout_url(self.request.uri)
     tContext['error'] = ''
     tContext['TIME'] = str(datetime.datetime.now())
     
     if (tUser == None):
         if (self.GetLocation() != "../views/index.html"):
             self.redirect("/")
         else:
             tContext['error'] = 'Login is required to access the portal'
             tTemplate = os.path.join(os.path.dirname(__file__), "../views/index.html")
             self.response.out.write(render(tTemplate, tContext))
         return
     else:
         self.USER = tUser
         tContext['user'] = tUser
         tContext.update(self.GetContext())
         tLocation = self.GetLocation()
         tRedirect = self.GetRedirect()
         
         #logging.debug("User: "******"Context: " + str(tContext))
         #logging.debug("Location: " + str(tLocation))
         #logging.debug("Redirect: " + str(tRedirect))
           
         #if(tContext.has_key('agent')):
         #    tAgent = tContext['agent']
         #else:
         try:
             tAgent = Agent().GetAgentByEmail(str(tUser.email()))
         except:
             tAgent = Agent()          
                 
         if(tAgent.agentSoundDelay == None or tAgent.agentSoundDelay == ""):
             tAgent.agentSoundDelay = 10000
             
         if(tAgent.agentSoundSelection == None or tAgent.agentSoundSelection == ""):
             tAgent.agentSoundSelection = "beep"
         
         if(tAgent.agentSoundRepeat == None or tAgent.agentSoundRepeat == ""):
             tAgent.agentSoundRepeat = 1
                     
         #logging.debug("Sound delay: " + str(tAgent.agentSoundDelay))
         #logging.debug("Sound selection: " + str(tAgent.agentSoundSelection))
         #logging.debug("Sound repeat: " + str(tAgent.agentSoundRepeat))            
         tContext['agent'] = tAgent
         
         logging.debug('Context: ' + str(tContext))
         
         if tAgent.agentIsAdmin:
             tContext['isAdmin'] = 'True'
         
         if(tAgent.agentIsEnabled == False):
             tContext['error'] = 'Your agent access is not active'
             tTemplate = os.path.join(os.path.dirname(__file__), "../views/index.html")
             self.response.out.write(render(tTemplate, tContext))
             return
         
         if(tRedirect == False):
             tTemplate = os.path.join(os.path.dirname(__file__), tLocation)
             self.response.out.write(render(tTemplate, tContext))
         else:
             self.redirect(tLocation)
Exemplo n.º 40
0
 def post(self):
     tOrderKey = self.request.get('orderid')
     tAgentGold = self.request.get('agentgold')
     
     #logging.debug("tOrderKey: " + tOrderKey)
     #logging.debug("tAgentGold: " + tAgentGold)
     tOrder = Order()
     tOrder = Order.get(tOrderKey)
     tUser = users.get_current_user()
     tAgent = Agent().GetAgentByEmail(str(tUser.email()))
     
     if (tOrder.orderDeliver == "" or tOrder.orderDeliver == 'False' and tOrder.orderLocked != 'True' and tAgent.agentIsEnabled == True):
             
         tGoldAmount = tOrder.orderQuantity
         tPromoCode = ""
         tPromoCode = tOrder.orderPromotionalCode
         tPromo = Promo()
         tPromoCode = tPromoCode.lower()
         tReferCode = tOrder.orderReferralCode
         tCustomerLookup = CustomerHandler()
         tCustomer = Customer()
         
         tCustomer = Customer().get(str(tOrder.orderCustomer))
         # Promo codes get unlimited uses per customer
         # tUsedBonus = Order.GetCustomerPromoCodes(tCustomer.customerPaypalId)
         # tUsedBonus = tCustomer.customerUsedBonus
         # logging.debug("Customer used bonuses: " + str(tUsedBonus))
         # logging.debug("Order Promo Code: " + str(tPromoCode))
         tUsedBonus = [] 
         
         try:
             tPromo = Promo.GetPromoByCode(tPromoCode)
             # logging.debug(str(tPromo.promoGoldAmount))
             # logging.debug(str(tPromo.promoPercentage))
             # logging.debug(str(tPromo.promoIsActive))
             
             if ((tPromo.promoIsActive) and (tPromo.promoUses <= tPromo.promoLimit)):
                 if (tPromo.promoLimit != 0):
                     tPromo.promoUses = tPromo.promoUses + 1
                 
                 if((tPromoCode in tUsedBonus) == True):
                     tPercentBonus = 0.0
                 else:
                     tPercentBonus = float(tGoldAmount) * tPromo.promoPercentage
                     #tUsedBonus.append(tPromoCode)
                     
                 tGoldAmount = tGoldAmount + tPercentBonus
                 tGoldAmount = tGoldAmount + tPromo.promoGoldAmount
                 tTotalBonusFloat = tPercentBonus + tPromo.promoGoldAmount
                 tOrder.orderBonusQuantity = int(tTotalBonusFloat)     
         except:
             tOrder.orderBonusQuantity = 0
             
         tGoldAmountLong = tGoldAmount
         tGoldAmount = tGoldAmount / 1000000
         
         tOrderValue = float(tOrder.orderCost)
         
         #if(tOrder.orderIsGenerated == True):
             #tGoldAmountLong = 0
             #tGoldAmount = 0
         
             
         tStockManager = StockManager()
         tStockManager.LoadAccounts()            
         tStockManager.PlaceOrder(tGoldAmountLong * -1, tOrder.orderGoldType)            
                         
         #if tOrder.orderGoldType == '07':
             #tStockAccountManager.Set07Stock(int(tGoldAmountLong * -1))
         #else:
             #tStockAccountManager.SetEOCStock(int(tGoldAmountLong * -1))
                         
         tCommission = float(tOrderValue) * 0.05 + 0.50
         
         if tCommission >= 10.0:
             tCommission = 10.0                           
             
         tAgent.agentCurrentCommission = float(tAgent.agentCurrentCommission + tCommission)
         tAgent.agentTotalCommission = float(tAgent.agentTotalCommission + tCommission)                
         
         tAgentOrders = tAgent.agentOrders
         tAgentOrders.append(tOrderKey)
         tAgent.agentOrders = tAgentOrders
         tAgentKey = tAgent.put()
         tOrder.orderDeliveryAgent = str(tAgent.agentId)
         tOrder.orderAgent = str(tAgentKey)
         tOrder.orderDeliver = 'True'
         tKey = tOrder.put()
         
         #logging.debug("Delivery by Agent: " + str(tAgentKey))
         #logging.debug("Delivery of Order: " + str(tKey))
         
         #taskqueue.add(url='/calcreferral', countdown = 1, params={'key' : str(tKey) } )
         
         self.response.headers['Cache-Control'] = 'Cache-Control: no-cache, must-revalidate'
         self.response.headers['Content-Type'] = 'Content-Type: plain/text'
         self.response.out.write("Order Delivered")
     else:
         #logging.debug('Attempted to Deliver ' + tOrderKey + " by Agent " + tAgent.agentId)
         self.response.headers['Cache-Control'] = 'Cache-Control: no-cache, must-revalidate'
         self.response.headers['Content-Type'] = 'Content-Type: plain/text'
         self.response.out.write("Order Not Deliverable")
 def PostContext(self):
             
     tNewOrder = ManualPaOrder()
     tAgent = Agent()
     tPromo = Promo()
     
     tUserEmail = self.GetUser().email()
     
     tStockAccount = StockAccount()
     tStockManager = StockManager()
     tStockManager.LoadAccounts()
     
     tAgent = Agent().GetAgentByEmail(tUserEmail)
     logging.debug('Agent ' + str(tAgent.agentNickName))
             
     tPromoCode = self.request.get('promocode').lower().lstrip().rstrip()
     tPromoCode = tPromoCode.lower().lstrip().rstrip()
     
     tGoldType = str(self.request.get('type')).lower().lstrip().rstrip()
     tGoldAmountWeb = str(self.request.get('amount')).lower()
     tGoldAmountPretty = re.sub(r'[^0-9kmb]*','', tGoldAmountWeb)
     tGoldMatches = re.match(r'^[0-9]*(k|m|b{1})$', tGoldAmountPretty)
     if tGoldMatches is None:
         return {'error' : str(tGoldAmountWeb) + ' is an invalid gold amount'}
     
     tGoldValue = str(self.request.get('value')).lower()
     tGoldValue = float(re.sub(r'[^0-9\.*]*', '', tGoldValue))
     
     tPaId = self.request.get('paid').lower().lstrip().rstrip()
     
     if (tGoldType in ('eoc', '07')) is not True:
         return {'error' : str(tGoldType) + ' is an invalid gold type' }
             
     if not tGoldValue >= 0.0:
         return {'error' : str(tGoldValue) + ' is an invalid gold value'}
     
     tStringOffset = self.request.get('offset')
     if (len(tStringOffset) > 0):
         tOffset = int(tStringOffset)
     else:
         tOffset = 0        
             
     tNewOrder.orderOwner = tUserEmail
     
     tGoldAmount = NumberToGp.ConvertBetToInt(tGoldAmountPretty)
     
     tUsedBonus = []
     try:
         #logging.debug("Promo Code: " + str(tPromoCode))
         tPromo = Promo.GetPromoByCode(tPromoCode)
         #logging.debug("Promo: " + str(tPromo))
         #logging.debug("Gold Amount: " + str(tGoldAmount))
         #logging.debug("Promo is active: " + str(tPromo.promoIsActive))
         
         if ((tPromo.promoIsActive) and (tPromo.promoUses <= tPromo.promoLimit)):
             if (tPromo.promoLimit != 0):
                 tPromo.promoUses = tPromo.promoUses + 1
             
             if((tPromoCode in tUsedBonus) == True):
                 tPercentBonus = 0.0
             else:
                 tPercentBonus = tGoldAmount * tPromo.promoPercentage
                 #tUsedBonus.append(tPromoCode)
 
             tGoldAmount = tGoldAmount + tPercentBonus
             tGoldAmount = tGoldAmount + tPromo.promoGoldAmount
             tTotalBonusFloat = tPercentBonus + tPromo.promoGoldAmount
             #logging.debug("Bonus float: " + str(tTotalBonusFloat))
             tPromoGoldAmount = int(tTotalBonusFloat)
                 
             #logging.debug("Total Bonus Float " + str(tTotalBonusFloat))
             #logging.debug("Promo Gold Amount " + str(tPromo.promoGoldAmount))
             #logging.debug("Promo Percentage " + str(tPercentBonus))
     except:
         tPromoGoldAmount = 0        
     
     tOrderTotalAmount = int(tGoldAmount) + int(tPromoGoldAmount)
     #logging.debug('Order gold ' + str(tOrderTotalAmount))
     
     logging.debug("{}".format(tOrderTotalAmount))
     logging.debug("{}".format(tGoldType))
     tStockManager.PlaceOrder(tOrderTotalAmount * -1, tGoldType)
     
     #if tGoldType == '07':
         ##logging.debug('07 detected')
         #tStockManager.PlaceOrder(aGoldQua
         #tStockAccountManager.Set07Stock(int(tOrderTotalAmount * -1))
         ##tAgent.agentGoldSupply07 = int(tAgent.agentGoldSupply07) - tOrderTotalAmount
     #elif tGoldType == 'eoc':
         ##logging.debug('eoc detected')
         ##tStockAccountManager.SetEOCStock(int(tOrderTotalAmount * -1))
         ##tAgent.agentGoldSupplyEoc = int(tAgent.agentGoldSupplyEoc) - tOrderTotalAmount
         
     #logging.debug('Agent 07 ' + str(tAgent.agentGoldSupply07))
     #logging.debug('Agent eoc ' + str(tAgent.agentGoldSupplyEoc))        
         
     tCommission = float(tGoldValue) * 0.05 + 0.50
     
     if tCommission >= 10.0:
         tCommission = 10.0
     
     tNewOrder.orderCashValue = float(tGoldValue)
     tNewOrder.orderOwner = tUserEmail
     tNewOrder.orderGoldAmount = int(tGoldAmount)
     tNewOrder.orderGoldAmountPretty = tGoldAmountPretty
     tNewOrder.orderGoldType = tGoldType
     tNewOrder.orderPaId = tPaId
     tNewOrder.orderPromoCode = tPromoCode
     tNewOrder.orderPromoGoldAmount = tPromoGoldAmount
     tNewOrderGuid = tNewOrder.put()
     
     tAgent.agentCurrentCommission = float(tAgent.agentCurrentCommission + tCommission)
     tAgent.agentTotalCommission = float(tAgent.agentTotalCommission + tCommission)
     tAgent.agentManualPaOrders = tAgent.agentManualPaOrders + [str(tNewOrderGuid)]
     tAgent.put()
     
     if int(tOffset) > 0:
         self.LOCATION = '/palist?offset=' + str(tOffset)
     else:
         self.LOCATION = '/palist'
         
     self.REDIRECT = True
     return {} 
     
     
     
     
     
     
     
     
     
     
     
Exemplo n.º 42
0
 def GetContext(self):
     tContext = {}
     if (self.IsUserAdmin()):
         tAgentsQuery = Agent().all()
         tAgentsQuery.order("agentNickName")
         tAgentsQuery.filter("agentIsEnabled", True)
         tAgents = tAgentsQuery.fetch(100)
         
         tAgent = Agent()
         for tAgent in tAgents:
             tAgent.__setattr__('agentGoldSupplyEocString', NumberToGp.ConvertIntToBet(tAgent.agentGoldSupplyEoc))
             tAgent.__setattr__('agentGoldSupply07String', NumberToGp.ConvertIntToBet(tAgent.agentGoldSupply07))
         
         tContext['agents'] = tAgents
         return tContext
     else:
         self.redirect("/")
Exemplo n.º 43
0
 def GetContext(self):
     tUser = self.GetUser()
     
     tCustomerOrders = []
     tOrderData = {}
     tContext = {}
     
     tOrder = Order()
     tCustomer = Customer()
     tIpHandler = IpLookup()
     tIpInfo = IpInfo()
     
     tDeliveryAgent = Agent()
     tRefundAgent = Agent()
     tAssignedAgent = Agent()
     
     tPriceDic = PriceContainer.GetCurrentPriceDic()
     tCountryDic = CountryContainer.GetCurrentCountryCodes()
     tOrderKey = str(urllib.unquote(self.request.get('key')))
     
     if(tOrderKey != None and len(tOrderKey) > 0):
         tOrder = Order.get(tOrderKey)
     if(tOrder):
         tOrderHandler = OrderHandler()
         
         tResultDictionary = {}
         tPaypalPayload = {}        
         tPayload = {}
         
         tUrl = "https://api-3t.paypal.com/nvp"
         tOperation = "GetTransactionDetails"            
         tCustomer = Customer.get(tOrder.orderCustomer)
                     
         # disabled to try to trace the "empty order" bug
         #if tOrder.orderVerificationCode is None:
             #tOrder.orderVerificationCode = str(uuid.uuid4())
             #tOrder.put()                    
         
         try:
             tIpInfo = tIpHandler.GetIp(tOrder.orderIp)[0]
         except:
             tIpInfo.ipCountry = "Loading"
             tIpInfo.ipState = "Loading"
             tIpInfo.ipHost = "Loading"
             tIpInfo.ipProxy = "Loading"
             tIpInfo.ipIsp = "Loading"
             tIpInfo.ipType = "Loading"
         
         if (tIpInfo.ipProxy == ""):
             tIpInfo.ipProxy = 'No Proxy'
         tContext['tDisplayDeliver'] = 'True'
                     
         #Get Paypal Information
         tPaypalPayload['METHOD'] = tOperation
         tPaypalPayload['TRANSACTIONID'] = tOrder.orderTransactionId
         
         #logging.debug("Order Paypal Email: " + tOrder.orderPaypalEmail)
         
         try:
             tPayloadEncoded = tOrderHandler.GeneratePayload(tPaypalPayload)
             request_cookies = mechanize.CookieJar()
             request_opener = mechanize.build_opener(mechanize.HTTPCookieProcessor(request_cookies))
             request_opener.addheaders = [('Content-Type', 'application/x-www-form-urlencoded')]
             mechanize.install_opener(request_opener)
             tResponse = mechanize.urlopen(url = tUrl, timeout = 25.0, data = tPayloadEncoded)
         except: 
             tContext['error'] = 'Unable to Connect to Paypal, Try Refreshing'
             tContext['showerror'] = 'True'
             #tmpl = os.path.join(os.path.dirname(__file__), '../views/order.html')
             #self.response.out.write(render(tmpl, tContext))
             return tContext
             
         tResult = str(urllib.unquote(tResponse.read()))
         tResultSplit = tResult.split('&')
         
         for tPair in tResultSplit:
             tSplitPair = tPair.split("=")
             try:
                 tResultDictionary[tSplitPair[0]] = tSplitPair[1]
                 #logging.debug(tSplitPair[0] + "    " + tSplitPair[1])
             except:
                 logging.error("Error splitting item: " + str(tPair))
         
         if('COUNTRYCODE' in tResultDictionary.keys()):
             tCountryCode = tResultDictionary['COUNTRYCODE']
             tPaypalCountry = tCountryDic[tCountryCode]
         else:
             tPaypalCountry = 'UNKNOWN'
             
         tOrderData['paypalcountry'] = tPaypalCountry                    
         
         if 'PROTECTIONELIGIBILITYTYPE' in tResultDictionary.keys():
             tProtectionEligibility = tResultDictionary['PROTECTIONELIGIBILITYTYPE']
             
             if tProtectionEligibility == 'ItemNotReceivedEligible,UnauthorizedPaymentEligible':
                 tProtectionEligibility = 'Eligible'
                 
             if tProtectionEligibility != 'Eligible':
                 tProtectionEligibility = 'Not Eligible'
                 
             tContext['PROTECTIONELIGIBILITYTYPE'] = tProtectionEligibility
         else:
             tProtectionEligibility = 'UNKNOWN'
             
         #Display address fields
         if 'ADDRESSSTATUS' in tResultDictionary.keys():
             tContext['ADDRESSSTATUS'] = tResultDictionary['ADDRESSSTATUS']
         else:
             tContext['ADDRESSSTATUS'] = 'UNKNOWN'
         
         if 'SHIPTONAME' in tResultDictionary.keys():
             tContext['SHIPTONAME'] = tResultDictionary['SHIPTONAME']
         else:
             tContext['SHIPTONAME'] = 'UNKNOWN'
             
         if 'SHIPTOSTREET' in tResultDictionary.keys():
             tContext['SHIPTOSTREET'] = tResultDictionary['SHIPTOSTREET']
         else:
             tContext['SHIPTOSTREET'] = 'UNKNOWN'
             
         if 'SHIPTOSTREET2' in tResultDictionary.keys():
             tContext['SHIPTOSTREET2'] = tResultDictionary['SHIPTOSTREET2']
         else:
             tContext['SHIPTOSTREET2'] = 'UNKNOWN'
             
         if 'SHIPTOCITY' in tResultDictionary.keys():
             tContext['SHIPTOCITY'] = tResultDictionary['SHIPTOCITY']
         else:
             tContext['SHIPTOCITY'] = 'UNKNOWN'
             
         if 'SHIPTOSTATE' in tResultDictionary.keys():
             tContext['SHIPTOSTATE'] = tResultDictionary['SHIPTOSTATE']
         else:
             tContext['SHIPTOSTATE'] = 'UNKNOWN'
                         
         if 'SHIPTOZIP' in tResultDictionary.keys():
             tContext['SHIPTOZIP'] = tResultDictionary['SHIPTOZIP']
         else:
             tContext['SHIPTOZIP'] = 'UNKNOWN'
             
         if 'SHIPTOCOUNTRYCODE' in tResultDictionary.keys():
             tContext['SHIPTOCOUNTRYCODE'] = tResultDictionary['SHIPTOCOUNTRYCODE']
         else:
             tContext['SHIPTOCOUNTRYCODE'] = 'UNKNOWN'
             
         if 'SHIPTOPHONENUM' in tResultDictionary.keys():
             tContext['SHIPTOPHONENUM'] = tResultDictionary['SHIPTOPHONENUM']
         else:
             tContext['SHIPTOPHONENUM'] = 'UNKNOWN'
             
         
         #Get order amount to add to dated totals
         tCurrentCost = float(tOrder.orderCost)
         
         #Get date 30 days ago
         tStartDate = tOrder.orderCreated
         tIncrement = datetime.timedelta(days = -30)
         tEndDate = tStartDate + tIncrement
         tCustomerOrderQuery = Order.all()
         tCustomerOrderQuery.filter("orderCreated >", tEndDate)
         tCustomerOrderQuery.filter("orderCustomer", tOrder.orderCustomer)
         tCustomerOrderQuery.filter("orderDeliver", 'True')
         tCustomerOrders = tCustomerOrderQuery.fetch(1000)
         #logging.debug("30 day date: " + str(tEndDate))
         #logging.debug("30 day orders: " + str(len(tCustomerOrders)))
         tCustomerOrderTotal = 0.0
         for tCustomerOrder in tCustomerOrders:
             tCustomerOrderTotal += float(tCustomerOrder.orderCost)
         if (tOrder.orderDeliver == 'False'):
             tCustomerOrderTotal += tCurrentCost
         tOrderData['orderTotal'] = str("%.2f"% tCustomerOrderTotal)
         
         #Get date 24 hours ago
         tStartDate = tOrder.orderCreated
         tIncrement = datetime.timedelta(days = -1)
         tEndDate = tStartDate + tIncrement
         tCustomerOrderQuery = Order.all().filter("orderCreated >", tEndDate)
         tCustomerOrderQuery.filter("orderCustomer", tOrder.orderCustomer)
         tCustomerOrderQuery.filter("orderDeliver", 'True')
         tCustomerOrders = tCustomerOrderQuery.fetch(1000)
         #logging.debug("24 hour date: " + str(tEndDate))
         #logging.debug("24 hour orders: " + str(len(tCustomerOrders)))
         tCustomerOrderTotal24 = 0.0
         for tCustomerOrder in tCustomerOrders:
             tCustomerOrderTotal24 += float(tCustomerOrder.orderCost)
             
         if (tOrder.orderDeliver == 'False'):
             tCustomerOrderTotal24 += tCurrentCost
         tOrderData['orderTotal24'] = str("%.2f" % tCustomerOrderTotal24)
         
         #Get date 15 days ago
         tStartDate = tOrder.orderCreated
         tIncrement = datetime.timedelta(days = -15)
         tEndDate = tStartDate + tIncrement
         tCustomerOrderQuery = Order.all().filter("orderCreated >", tEndDate)
         tCustomerOrderQuery.filter("orderCustomer", tOrder.orderCustomer)
         tCustomerOrderQuery.filter("orderDeliver", 'True')
         tCustomerOrders = tCustomerOrderQuery.fetch(1000)
         #logging.debug("15 day date: " + str(tEndDate))
         #logging.debug("15 day orders: " + str(len(tCustomerOrders)))
         tCustomerOrderTotal15 = 0.0
         for tCustomerOrder in tCustomerOrders:
             tCustomerOrderTotal15 += float(tCustomerOrder.orderCost)
             
         if (tOrder.orderDeliver == 'False'):
             tCustomerOrderTotal15 += tCurrentCost
         tOrderData['orderTotal15'] = str("%.2f" % tCustomerOrderTotal15)
         
         #===== Begin Location Matching =====
         try:
             tPhoneHandler = PhoneLookup()
             tPhoneInfo = tPhoneHandler.GetPhone(tOrder.orderCustomer)[0]
         except:
             tPhoneInfo = Phone()
             tPhoneInfo.phoneState = "Unknown"
             tPhoneInfo.phoneCountry = "Unknown"
         
         #logging.debug("Ip country: " + str(tIpInfo.ipCountry))
         #logging.debug("Paypal country: " + str(tPaypalCountry))
         
         if (str(tIpInfo.ipCountry) == str(tPaypalCountry)):
             tOrderData['locationmatch'] = 'True'
         else:
             tOrderData['locationmatch'] = 'False'
             
         if (str(tIpInfo.ipCountry) == "United Kingdom" and str(tPaypalCountry) == "Great Britain (UK)"):
             tOrderData['locationmatch'] = 'True'
             
         #Agent Instructions
         #logging.debug("Order Total 24: " + str(tCustomerOrderTotal24))
         #logging.debug("Order Total: " + str(tCustomerOrderTotal))
         #logging.debug("Customer email verified: " + str(tCustomer.customerEmailVerified))
         #logging.debug("Customer phone verified: " + str(tCustomer.customerPhoneVerified))
         #logging.debug("Customer id verified: " + str(tCustomer.customerIdVerified))
         
         #Protection Eligibility Filter 
         tCountryEligibilityCode = tContext['SHIPTOCOUNTRYCODE']
         tOrderData['instructions'] = "No verification required" # default value
         if tCountryEligibilityCode in ('US', 'UK', 'CA', 'GB'):  
             if tOrder.orderCost > 10:              
                 if tProtectionEligibility == 'Eligible':
                     if tCustomerOrderTotal24 > 1000.0 or tCustomerOrderTotal > 4000.0:
                         tOrderData['instructions'] = "<span style='color:red'>$$$ Call Corowns $$$</span>"   
                 else: # not payment eligible
                     tOrderData['instructions'] = "<span style='color:red'>Refund - No Seller Protection</span>"
                     tContext['tDisplayDeliver'] = 'False'
         else: # international customer
             #if( tCustomerOrderTotal24 < 30.0 and tCustomerOrderTotal < 60.0):
             
             if tIpInfo.ipType == "Corporate":
                 tOrderData['instructions'] = tOrderData['instructions'] + "<br /><span style='color:red'>Refer to PA - Corporate IP</span>"
                 tOrderData['tDisplayDeliver'] = 'False'
                 
             if (tIpInfo.ipProxy):
                 if ("Confirmed proxy server" == tIpInfo.ipProxy):
                     tOrderData['instructions'] = tOrderData['instructions'] + "<br /><span style='color:red'>Refer to PA - Proxy</span>"
                     tContext['tDisplaydeliver'] = 'False'
             
             if tCustomerOrderTotal24 > 200.0 or tCustomerOrderTotal > 400.0:
                 tOrderData['instructions'] = "<span style='color:red'>Refer to PA - Limit Exceeded</span>"
                 tOrderData['tDisplayDeliver'] = 'False'                   
             elif tCustomerOrderTotal24 > 90.0 or tCustomerOrderTotal > 180.0:
                 if tCustomer.customerIdVerified != True:
                     tOrderData['instructions'] = "<span style='color:red'>Verify Photo ID</span>"        
             elif tCustomerOrderTotal24 > 30.0 or tCustomerOrderTotal > 60.0:
                 if tCustomer.customerPhoneVerified != True:
                     tOrderData['instructions'] = "<span style='color:red'>Verify Phone Number</span>"
             
         if(tOrderData['locationmatch'] != 'True'):
             tOrderData['instructions'] = tOrderData['instructions'] + "<br /><span style='color:red'>Verify Country Match</span>"
                             
         #logging.debug("Order Data Instructions: " + str(tOrderData['instructions']))
         #logging.debug("Location Match" + str(tOrderData['locationmatch']))
         
         tCustomerOrderQuery = db.GqlQuery("SELECT * FROM Order WHERE orderCustomer = '" + tOrder.orderCustomer + "'")
         tTotalCustomerOrders = []
         tTotalCustomerOrders = tCustomerOrderQuery.fetch(50)
         for tCustomerOrder in tTotalCustomerOrders:
             if (tCustomerOrder.orderChargeback == True):
                 tChargeBack = True
             else:
                 tChargeBack = False
                 
         tOrderData['chargeback'] = tChargeBack if (tChargeBack) else False
         tOrderData['chargeback'] = str(tOrderData['chargeback'])
         
         tIpChargebacks = tIpHandler.GetChargebacks(tOrder.orderIp)
         tOrderData['ipchargeback'] = len(tIpChargebacks)
                         
         try:
             tTotalBonusString = NumberToGp.ConvertIntToBet(int(tOrder.orderBonusQuantity))
             #logging.debug("Total Bonus String " + tTotalBonusString)
         except:
             tTotalBonusString = ""
             
         if (tCustomer.customerIsPaBlacklisted == True):
             tOrderData['instructions'] = tOrderData['instructions'] + "<br /><span style='color:red'>Refer to PA - Blacklist</span>"
             tContext['tDisplayDeliver'] = 'False'
             
         if (tCustomer.customerIsGlobalBlacklisted == True):
             tOrderData['instructions'] = tOrderData['instructions'] + "<br /><span style='color:red'>Do Not Deliver - Blacklist</span>"
             tContext['tDisplayDeliver'] = 'False'
         
         #normalize unicode
         try:
             tSimpleGold = unicodedata.normalize("NFC", tOrder.orderSimpleGoldAmount).encode("ascii", "ignore")
         except:
             tSimpleGold = tOrder.orderSimpleGoldAmount
         
         #logging.debug(str(tPriceDic[tSimpleGold]))
         #logging.debug(str(tOrder.orderCost))
         tCurrentEocPrices = PriceContainer.GetCurrentPriceDic()
         tCurrent07Prices = PriceContainer.GetCurrentPriceDic07()
                     
         #logging.debug(str(tCurrent07Prices))
         #logging.debug(str(tCurrentEocPrices))
         
         tSkip07 = False
         tValidOrder = False
         if tOrder.orderSimpleGoldAmount in tCurrentEocPrices.keys():
             if str(tOrder.orderCost) == str(tCurrentEocPrices[tOrder.orderSimpleGoldAmount]):
                 tOrder.orderGoldType = 'eoc'
                 tSkip07 = True
                 tValidOrder = True
         
         if not tSkip07:
             if tOrder.orderSimpleGoldAmount in tCurrent07Prices.keys():
                 if str(tOrder.orderCost) == str(tCurrent07Prices[tOrder.orderSimpleGoldAmount]):
                     tOrder.orderGoldType = '07'
                     tValidOrder = True
         
         #logging.debug("skip07 {}".format(tSkip07))
         #logging.debug("valid {}".format(tValidOrder))
         #logging.debug("order simple gold amount {}".format(tOrder.orderSimpleGoldAmount))
         #logging.debug("order value {}".format(tOrderData['orderTotal']))
         #logging.debug("gold type {}".format(tContext['gold_type']))
                     
         if not tValidOrder:
             tOrderData['instructions'] = tOrderData['instructions'] + '<br /><span style="color:red">Do Not Deliver - Bad Payment</span>'
             #tOrderData['tDisplayDeliver'] = 'False'
             #tOrder.orderLocked = 'True'
             #tOrder.put()
         
         #logging.debug(str(tOrder.orderIsGenerated))
         if(tOrder.orderIsGenerated == True):
             tOrder.orderLocked = 'False'
             tOrder.orderIsRefunded = 'False'
             tOrder.orderDeliver = 'False'
             tOrderData['tDisplayDeliver'] = 'True'
             
         try:
             tDeliveryAgent = Agent.GetAgentByEmail(tOrder.orderDeliveryAgent)
             tContext['tDeliveryAgent'] = tDeliveryAgent
         except:
             pass
         
         try:
             tAssignedAgent = Agent.GetAgentByEmail(tOrder.orderAssignedAgent)
             tContext['tAssignedAgent'] = tAssignedAgent
         except:
             pass
         
         try:
             tRefundAgent = Agent.GetAgentByEmail(tOrder.orderRefundAgent)
             tContext['tRefundAgent'] = tRefundAgent
         except:
             pass            
         tOrderData['bonus'] = tTotalBonusString
         
         tOrderData['phoneverified'] = str(tCustomer.customerPhoneVerified)
         tOrderData['emailverified'] = str(tCustomer.customerEmailVerified)
         tOrderData['idverified'] = str(tCustomer.customerIdVerified)
         
         tContext['tOrder'] = tOrder
         tContext['tOrderData'] = tOrderData
         tContext['tCustomer'] = tCustomer
         tContext['tIpInfo'] = tIpInfo
         tContext['tPhoneInfo'] = tPhoneInfo
     
     
     if ((tOrder.orderDeliveryAgent == "" or tOrder.orderDeliveryAgent == None) and tOrder.orderDeliver == 'True'):
         tAgentKey = tOrder.orderAgent
         tAgentId = Agent()
         tAgentId = Agent.get(tAgentKey)
         tOrder.orderDeliveryAgent = str(tAgentId.agentId)
                     
     #logging.debug(str(tOrderData))
     return tContext
Exemplo n.º 44
0
def run(jobs_file, job_id=None, plot=False, echo_symlink_to=None, job_date=None):
    # pr.enable()
    with open(jobs_file) as jfile:
        jobs = json.load(jfile)
    if isinstance(jobs, dict):
        # ToDo: make this more explicit, but basically, you can give me a json of SINGLE param dict, aka rerun a
        #       single job that was spit out (ex: echo/experiments/gradient_passing/QPSK_neural_and_neural/results/0.json)
        jobs = [jobs]
    elif job_id is not None:  # 0 = False you dummy
        plot = plot
        jobs = [jobs[job_id]]
    else:
        # NO PLOTTING IF YOU ARE RUNNING A BUNCH OF JOBS...NO!
        plot = False
    for params in jobs:
        params_copy = deepcopy(params)
        keys = params.keys()
        agent_keys = [key for key in keys if 'agent' in key]
        meta = params.pop('__meta__')
        verbose = meta['verbose']
        job_id = meta['job_id']
        trial_num = meta['trial_num']
        protocol = meta['protocol']
        experiment_name = meta['experiment_name']
        experiment_dir = os.path.abspath(os.path.join(ECHO_DIR, 'experiments', protocol, experiment_name))
        results_dir = os.path.abspath(os.path.join(experiment_dir, 'results'))
        # DEAL WITH SYMLINKING FOR RUNNING ON BRC
        if echo_symlink_to is not None:
            assert os.path.isdir(echo_symlink_to), "Invalid symlink path"
            if os.path.isdir(results_dir) and not os.path.islink(results_dir):
                old_results_dir = os.path.abspath(os.path.join(experiment_dir, 'old_results'))
                os.makedirs(old_results_dir, exist_ok=True)
                n = len(os.listdir(old_results_dir))
                os.rename(results_dir, os.path.abspath(os.path.join(old_results_dir, '%i' % n)))
            _experiment_dir = os.path.abspath(os.path.join(echo_symlink_to, 'experiments', protocol, experiment_name))
            job_date = "results" + (job_date if job_date is not None else "")
            _results_dir = os.path.abspath(os.path.join(_experiment_dir, job_date))
            os.makedirs(_results_dir, exist_ok=True)
            if os.path.islink(results_dir) and os.readlink(results_dir) != _results_dir:
                try:
                    os.remove(results_dir)
                except OSError:
                    pass

            if not os.path.islink(results_dir):
                try:
                    os.symlink(_results_dir, results_dir)
                except OSError as e:
                    if e.errno == errno.EEXIST:
                        assert os.readlink(results_dir) == _results_dir
                    else:
                        raise e

        else:
            os.makedirs(results_dir, exist_ok=True)

        results_file = '%s/%i.npy' % (results_dir, job_id)
        if os.path.isfile(results_file) and plot:
            print("result already found")
        else:
            params_file = '%s/%i.json' % (results_dir, job_id)
            with open(params_file, 'w') as pf:
                pf.write(json.dumps(params_copy, indent=4))

            if verbose:
                print("...running run_experiment.py with:", protocol, experiment_name)
            prepare_environment(meta)

            # Load Agents Based on Model
            agents = []
            for agent_key in agent_keys:
                agent_params = params.pop(agent_key)
                agents += [Agent(agent_dict=agent_params, name=agent_key, verbose=verbose)]
            params['agents'] = agents

            # Load Protocol and Train (Results callback will collect results)
            module_name = 'protocols.%s.train' % (protocol)
            train = getattr(import_module(module_name), 'train')

            info, results = train(**params,
                                  verbose=verbose,
                                  plot_callback=lambda **kwargs: None)

            # AFTER DONE TRAINING SAVE RESULTS FILE
            results.insert(0, {'protocol': protocol,
                               'trial_num': trial_num,
                               'experiment_name': experiment_name,
                               **info})
            np.save(results_file, results)
            if verbose:
                print("...params for this job have been saved into:", params_file)
                print("...results for this job have been saved into:", results_file)
        # pr.disable()
        # pr.dump_stats('%s%i.pstat'% (experiment_name,job_id) )
        if plot:
            from importlib import util
            if util.find_spec('matplotlib') is not None:
                from plot_experiment import animated_plot
                animated_plot(results=results)
            else:
                print("Cannot plot; matplotlib not found")
    return ()
Exemplo n.º 45
0
    def GetContext(self):
        tOrder = Order()
        tOrderList = []
        tOrderAgentPairs = {}
        tOrderDataDict = {}
        tPaypalOrder = PaypalOrder()
        tStringOffset = self.request.get('offset')
        if (len(tStringOffset) > 0):
            tOffset = int(tStringOffset)
        else:
            tOffset = 0

        tOrderQuery = Order.all()
        tOrderQuery.filter("orderIsGenerated", False)
        tOrderQuery.order('-orderCreated')
        tOrderList = tOrderQuery.fetch(10, offset=tOffset)

        tCurrentEocPrices = PriceContainer.GetCurrentPriceDic()
        tCurrent07Prices = PriceContainer.GetCurrentPriceDic07()

        tSkip07 = False

        if tOrder.orderGoldType != None:
            if tOrder.orderGoldType in ('eoc', '07') is not True:
                tOrder.orderGoldType = 'UNKNOWN'
        else:
            tOrder.orderGoldType = 'UNKNOWN'

        for tOrder in tOrderList:

            if tOrder.orderSimpleGoldAmount in tCurrentEocPrices.keys():
                if str(tOrder.orderCost) == str(
                        tCurrentEocPrices[tOrder.orderSimpleGoldAmount]):
                    tOrder.orderGoldType = 'eoc'
                    tSkip07 = True

            if not tSkip07:
                if tOrder.orderSimpleGoldAmount in tCurrent07Prices.keys():
                    if str(tOrder.orderCost) == str(
                            tCurrent07Prices[tOrder.orderSimpleGoldAmount]):
                        tOrder.orderGoldType = '07'
            #tOrder.orderSimpleGoldAmount = tOrder.orderSimpleGoldAmount + ' ' + str(tOrder.orderGoldType)

            tOrderAgentPairs[str(
                tOrder.orderAssignedAgent)] = Agent.GetAgentByEmail(
                    tOrder.orderAssignedAgent).agentNickName

        if (tOffset == 0):
            tPrev = tOffset
        else:
            tPrev = tOffset - 10
        tOffset = tOffset + 10
        tNext = tOffset

        tOffset = str(tOffset)
        tNext = str(tNext)
        tPrev = str(tPrev)

        tAgent = tPaypalOrder.GetAssignedAgent()

        if (tAgent != "No Agent Online"):
            tAgent = Agent.GetAgentByEmail(tAgent).agentNickName

        tContext = {
            'orders': tOrderList,
            'agents': tOrderAgentPairs,
            'next': tNext,
            'prev': tPrev,
            'offset': tOffset,
            'agent': tAgent,
        }
        return tContext
Exemplo n.º 46
0
    def post(self):
        tUser = self.GetUser()
        locale.setlocale(locale.LC_ALL, "")
        tContext = {}
        tContext['login'] = users.create_login_url(self.request.uri)
        tContext['logout'] = users.create_logout_url(self.request.uri)
        tContext['error'] = ''
        tContext['TIME'] = str(datetime.datetime.now())
        
        if (tUser == None and self.REQUIRE_AUTH_POST == True):
            if (self.GetLocation() != "../views/index.html"):
                self.redirect("/")
            else:
                tTemplate = os.path.join(os.path.dirname(__file__), "../views/index.html")
                self.response.out.write(render(tTemplate, tContext))
            return
        else:
            self.USER = tUser
            tContext['user'] = tUser
            tPostContext = self.PostContext()
            
            tContext.update(tPostContext)
            tLocation = self.GetLocation()
            tRedirect = self.GetRedirect()
            
            #logging.debug("User:"******"Context: " + str(tContext))
            #logging.debug("Location: " + str(tLocation))
            #logging.debug("Redirect: " + str(tRedirect))

            #if(tContext.has_key('agent')):
                #tAgent = tContext['agent']
            #else:
            try:
                tAgent = Agent().GetAgentByEmail(str(tUser.email()))
            except:
                tAgent = Agent()          
                    
            if(tAgent.agentSoundDelay == None or tAgent.agentSoundDelay == ""):
                tAgent.agentSoundDelay = 10000
                
            if(tAgent.agentSoundSelection == None or tAgent.agentSoundSelection == ""):
                tAgent.agentSoundSelection = "beep"
            
            if(tAgent.agentSoundRepeat == None or tAgent.agentSoundRepeat == ""):
                tAgent.agentSoundRepeat = 1
                        
            #logging.debug("Sound delay: " + str(tAgent.agentSoundDelay))
            #logging.debug("Sound selection: " + str(tAgent.agentSoundSelection))
            #logging.debug("Sound repeat: " + str(tAgent.agentSoundRepeat))            
            tContext['agent'] = tAgent            
            
            if(tContext.has_key('nowrite')):
                if(tContext['nowrite'] == True):
                    return
            else:
                if(tRedirect == False):
                    tTemplate = os.path.join(os.path.dirname(__file__), tLocation)
                    self.response.out.write(render(tTemplate, tContext))
                else:
                    self.redirect(tLocation)