Best Python code snippet using robotframework-pageobjects_python
test.py
Source:test.py  
1from datetime import datetime2import matplotlib.pyplot as plt3from matplotlib import style4import pandas5# My classes for simulating trading6import SmoothAlgo as SAlgo7from StockSim import HistoricalStock8from BrokerSim import Broker9from RobotTrader import TrendRobot10############################11###### BEGIN : CONFIG ######12############################13TICKER = 'aapl'14START = datetime(2015,1,1)15START_WALLET = 5000016BUY_RATE = 1317BUY_MARGIN = 1.0818SELL_RATE = 2119SELL_MARGIN = 0.920SMOOTH_ALGO = SAlgo.MovingAverage(6)21# SMOOTH_ALGO = SAlgo.WeightedMovingAverage(32)22# SMOOTH_ALGO = SAlgo.ExponentialMovingAverage(16)23############################24####### END : CONFIG #######25############################26def simulate_robot_and_graph(in_robot):27    ### Keep track of data in these classes ###28    stocks_held = {}29    total_wallet = {}30    raw_wallet = {}31    raw_stock_price = {}32    smooth_stock_price = {}33    ### While there is still stock data,   ###34    ### Get the robot to go through it and ###35    ### record the data                    ###36    while not in_robot.done():37        # Get robot to buy and sell for the day38        in_robot.simulate_day()39        # Get the current date from the stock class40        date = in_robot.get_broker().get_stock().get_date()41        # Get the amount of stocks held42        stocks_held[date] = in_robot.get_stocks_held() / STOCKS_HELD_SCALE43        # Get the wallet amount with and without stocks in them44        total_wallet[date] = in_robot.get_total_wallet() / WALLET_SCALE45        raw_wallet[date] = in_robot.get_raw_wallet() / WALLET_SCALE46        # get the raw and the stock prices47        raw_stock_price[date] = in_robot.get_stock_price()48        # Check if you should record two smooth values or just one49        smooth_stock_price[date] = in_robot.get_smooth_stock_price()50    # Plot all of the data51    pandas.Series(raw_stock_price).plot(label='Stock Price')52    pandas.Series(smooth_stock_price).plot(label='Smooth Stock Price')53    pandas.Series(total_wallet).plot(label='Total Wallet / ' + str(WALLET_SCALE))54    pandas.Series(raw_wallet).plot(label='Wallet / ' + str(WALLET_SCALE))55    #pandas.Series(stocks_held).plot(label='Stocks Held / ' + str(STOCKS_HELD_SCALE))56    # Show trading information57    plt.legend()58    plt.show()59    return in_robot60# Simulate the robot going through the stocks61def simulate_robot(in_robot):62    while not in_robot.done():63        in_robot.simulate_day()64    return in_robot65### The amount that the data will be scaled on the graph66STOCKS_HELD_SCALE = 1067WALLET_SCALE = 100068### Get the stock data into a class called my_stock ###69my_stock = HistoricalStock(ticker=TICKER, start=START)70### Simulate broker that holds all the money and my stocks ###71my_broker = Broker(stock=my_stock, wallet=START_WALLET)72### Create robot class and give it all the parameters ###73my_robot = TrendRobot(74    broker=my_broker, smoother=SMOOTH_ALGO, 75    buy_rate=BUY_RATE, sell_rate=SELL_RATE,76    buy_margin=BUY_MARGIN, sell_margin=SELL_MARGIN77)78# print(simulate_robot(my_robot).get_total_wallet())...feedbackcontroller.py
Source:feedbackcontroller.py  
1# @author Simon Stepputtis <sstepput@asu.edu>, Interactive Robotics Lab, Arizona State University2import tensorflow as tf3from model_src.basismodel import BasisModel4class FeedbackController(tf.keras.layers.Layer):5    def __init__(self, robot_state_size, rnn_state_size, dimensions, basis_functions, special, **kwargs):6        super(FeedbackController, self).__init__(**kwargs)7        self.robot_state_size = robot_state_size8        self.state_size       = rnn_state_size9        self.dims             = dimensions10        self.n_bfuncs         = basis_functions11    def build(self, input_shape):12        self.robot_gru      = tf.keras.layers.GRUCell(units=self.robot_state_size)13        self.weight_dense_1 = tf.keras.layers.Dense(units=self.dims * self.n_bfuncs, activation=tf.keras.activations.relu)14        self.weight_dense_2 = tf.keras.layers.Dense(units=self.dims * self.n_bfuncs, activation=tf.keras.activations.relu)15        self.weight_dense_3 = tf.keras.layers.Dense(units=self.dims * self.n_bfuncs, activation=tf.keras.activations.linear)16        self.phase_dense_1 = tf.keras.layers.Dense(units=int(self.robot_state_size / 2.0), activation=tf.keras.activations.relu)17        self.phase_dense_2 = tf.keras.layers.Dense(units=1, activation=tf.keras.activations.hard_sigmoid)18        self.basismodel = BasisModel(dimensions=self.dims, nfunctions=self.n_bfuncs, scale=0.012)19    # @tf.function20    def call(self, inputs, states, constants=None, training=False, mask=None, **kwargs):21        # Get data ready22        in_robot       = inputs23        st_robot_last  = states[0]24        st_gru_last    = states[1]25        cn_features    = constants[0]26        cn_delta_t     = constants[1]27        28        # Robot GRU:29        in_robot           = tf.cond(tf.convert_to_tensor(training), lambda: st_robot_last, lambda: in_robot)30        e_robot, gru_state = self.robot_gru(inputs=in_robot, states=[st_gru_last])31        # Internal state:32        x = tf.keras.backend.concatenate((cn_features, e_robot), axis=1)33        # Use x to calcate the weights:34        weights = self.weight_dense_3(self.weight_dense_2(self.weight_dense_1(x)))35        weights = tf.keras.backend.reshape(weights, shape=[-1, self.dims, self.n_bfuncs])36        # Phase estimation, based on x:37        dt    = 1.0 / (500.0 * cn_delta_t) # Calculates the actual dt38        phase = self.phase_dense_2(self.phase_dense_1(x))39        phase = phase + dt40        # Apply basis model:41        action, _ = self.basismodel((weights, tf.zeros_like(weights), phase))42        action = tf.squeeze(action)43        # Rebuild the state:44        new_states = (action, gru_state[0])45        # Return results (and state)...Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!
