Пример #1
0
    def get(self):
        self.response.headers['Content-Type'] = 'text/plain'
        """
        for i in np.arange(250,6001,250):
            list_of_entities = Forecast.query(ndb.AND(Forecast.rank >= i-250,Forecast.rank < i))#Forecast.rank < 6000)
            list_of_keys = ndb.put_multi(list_of_entities)
            #list_of_entities = ndb.get_multi(list_of_keys)
            ndb.delete_multi(list_of_keys)

            list_of_entities = StockList.query(ndb.AND(StockList.rank >= i-250,StockList.rank < i))#Forecast.rank < 6000)
            list_of_keys = ndb.put_multi(list_of_entities)
            #list_of_entities = ndb.get_multi(list_of_keys)
            ndb.delete_multi(list_of_keys)
        """
        for i in np.arange(1, 6001, 500):
            list_of_keys = Forecast.query().fetch(500, keys_only=True)
            #list_of_keys = ndb.put_multi(list_of_entities)
            #list_of_entities = ndb.get_multi(list_of_keys)
            ndb.delete_multi(list_of_keys)

        list_of_keys = StockList.query().fetch(25, keys_only=True)
        #list_of_keys = ndb.put_multi(list_of_entities)
        #list_of_entities = ndb.get_multi(list_of_keys)
        ndb.delete_multi(list_of_keys)

        self.response.out.write('All Forecasts Deleted')
        self.redirect('./')
Пример #2
0
    def get(self):
        self.response.headers['Content-Type'] = 'text/plain'
        """
        for i in np.arange(250,6001,250):
            list_of_entities = Forecast.query(ndb.AND(Forecast.rank >= i-250,Forecast.rank < i))#Forecast.rank < 6000)
            list_of_keys = ndb.put_multi(list_of_entities)
            #list_of_entities = ndb.get_multi(list_of_keys)
            ndb.delete_multi(list_of_keys)

            list_of_entities = StockList.query(ndb.AND(StockList.rank >= i-250,StockList.rank < i))#Forecast.rank < 6000)
            list_of_keys = ndb.put_multi(list_of_entities)
            #list_of_entities = ndb.get_multi(list_of_keys)
            ndb.delete_multi(list_of_keys)
        """
        for i in np.arange(1,6001,500):
            list_of_keys = Forecast.query().fetch(500, keys_only=True)
            #list_of_keys = ndb.put_multi(list_of_entities)
            #list_of_entities = ndb.get_multi(list_of_keys)
            ndb.delete_multi(list_of_keys)

        list_of_keys = StockList.query().fetch(25, keys_only=True)
        #list_of_keys = ndb.put_multi(list_of_entities)
        #list_of_entities = ndb.get_multi(list_of_keys)
        ndb.delete_multi(list_of_keys)
        

        self.response.out.write('All Forecasts Deleted')
        self.redirect('./')
Пример #3
0
def InjectTestData():
    #init a new forecast object, fill it with anything
    Forecast(
        rank                     = 1,
        symbol                   = "GOOG",
        company                  = "Google, Inc.",
        exchange                 = "NASDAQ",
        industry                 = "Technology",

        #predictions
        openPredPrice            = list(550.0+5.0*(np.random.ranf(11)-0.5)),
        closePredPrice           = list(550.0+5.0*(np.random.ranf(11)-0.5)),
        highPredPrice            = list(555.0+10.0*(np.random.ranf(11)-0.5)),
        lowPredPrice             = list(545.0+10.0*(np.random.ranf(11)-0.5)),
        volumePred               = list(np.random.randint(1850000,2150000, 11)),
        dayOfPred                = ['M','Tu','W','Th','F',
                                    'M','Tu','W','Th', 'F',
                                    'M','Tu','W','Th', 'F',
                                    'M','Tu','W','Th', 'F',
                                    'M','Tu','W','Th', 'F',
                                    'M','Tu','W','Th', 'F',
                                    'M'],

        #History lists
        openPriceHistory         = list(550.0+5.0*(np.random.ranf(10)-0.5)),
        closePriceHistory        = list(550.0+5.0*(np.random.ranf(10)-0.5)),
        highPriceHistory         = list(560.0+10.0*(np.random.ranf(10)-0.5)),
        lowPriceHistory          = list(540.0+10.0*(np.random.ranf(10)-0.5)),
        volumeHistory            = list(np.random.randint(1850000,2150000, 10)),

        #prediction validation value, R2
        openPredR2               = 1.0 + (np.random.ranf(1)[0] - 0.5)/10.0,
        closePredR2              = 1.0 + (np.random.ranf(1)[0] - 0.5)/10.0,
        highPredR2               = 1.0 + (np.random.ranf(1)[0] - 0.5)/10.0,
        lowPredR2                = 1.0 + (np.random.ranf(1)[0] - 0.5)/10.0,
        volumePredR2             = 1.0 + (np.random.ranf(1)[0] - 0.5)/10.0,

        openPredSlope            = 1.0 + (np.random.ranf(1)[0] - 0.5)/10.0,
        closePredSlope           = 1.0 + (np.random.ranf(1)[0] - 0.5)/10.0,
        highPredSlope            = 1.0 + (np.random.ranf(1)[0] - 0.5)/10.0,
        lowPredSlope             = 1.0 + (np.random.ranf(1)[0] - 0.5)/10.0,
        volumePredSlope          = 1.0 + (np.random.ranf(1)[0] - 0.5)/10.0,

        openModelAccuracy        = 1,
        closeModelAccuracy       = 2,
        highModelAccuracy        = 2,
        lowModelAccuracy         = 3
    ).put()
    
    StockList(
        rank                     = 1,
        symbol                   = "GOOG",
        company                  = "Google, Inc.",
        exchange                 = "NASDAQ",
        currentPrice             = 550.0+5.0*(np.random.ranf(1)[0]-0.5),
        forecastedPrice          = 550.0+5.0*(np.random.ranf(1)[0]-0.5),
        modelAccuracy            = np.random.randint(1,4,1)[0]
    ).put()
    def get(self):

        #Get total nubmer of predictions
        #global_stat = stats.GlobalStat.query().get()
        #forecastCount = global_stat.count

        #Get the time, make a string of format:
        #Tue, Jan 6, 2014, 12:00AM EST - US MARKETS CLOSED
        now = datetime.now(tz=timezone('US/Eastern'))
        #Construct the EST time for the top of page
        if ((now.time() >= time(9, 30) and now.time() <= time(16, 30))
                and (now.weekday() <= 4)):
            timeString = "{0:s} EST  - US Markets Are Open".format(
                now.strftime("%a, %b %d %Y, %I:%M%p"))
        else:
            timeString = "{0:s} EST  - US Markets Are Closed".format(
                now.strftime("%a, %b %d %Y, %I:%M%p"))
        #

        stockList = StockList.query(StockList.rank.IN([1]))

        #Init items using info from forecast, just use the first item
        dayOfForecast = now.strftime("%A, %B %d %Y")
        dof = now
        for forecast in stockList:
            dayOfForecast = forecast.date.strftime("%A, %B %d %Y")
            dof = forecast.date
            break

        if users.get_current_user():
            url = users.create_logout_url(self.request.uri)
            url_linktext = 'Logout'
        else:
            url = users.create_login_url(self.request.uri)
            url_linktext = 'Sign Up for Updates'

        template_values = {
            #'stock_list':stockList,
            #'forecast_data':forecastPlotData,
            #'validation_data':validationPlotData,
            #'computed_values':computedValued,
            #'forecast_count':forecastCount,
            'timeStr': timeString,
            'dayOfForecast': dayOfForecast,
            'url': url,
            'url_linktext': url_linktext,
        }

        template = JINJA_ENVIRONMENT.get_template('markets.html')
        self.response.write(template.render(template_values))
Пример #5
0
    def get(self):
        
        #Get total nubmer of predictions
        #global_stat = stats.GlobalStat.query().get()
        #forecastCount = global_stat.count

        #Get the time, make a string of format:
        #Tue, Jan 6, 2014, 12:00AM EST - US MARKETS CLOSED
        now = datetime.now(tz=timezone('US/Eastern'))
        #Construct the EST time for the top of page
        if( (now.time() >= time(9,30) and now.time() <= time(16,30)) and (now.weekday() <= 4 ) ):
            timeString = "{0:s} EST  - US Markets Are Open".format(now.strftime("%a, %b %d %Y, %I:%M%p"))
        else:
            timeString = "{0:s} EST  - US Markets Are Closed".format(now.strftime("%a, %b %d %Y, %I:%M%p"))
        #

        stockList = StockList.query(StockList.rank.IN([1]))
        
        #Init items using info from forecast, just use the first item
        dayOfForecast = now.strftime("%A, %B %d %Y")
        dof = now
        for forecast in stockList:
            dayOfForecast = forecast.date.strftime("%A, %B %d %Y")
            dof = forecast.date
            break
        
        if users.get_current_user():
            url = users.create_logout_url(self.request.uri)
            url_linktext = 'Logout'
        else:
            url = users.create_login_url(self.request.uri)
            url_linktext = 'Sign Up for Updates'

        template_values = {
            #'stock_list':stockList,
            #'forecast_data':forecastPlotData,
            #'validation_data':validationPlotData,
            #'computed_values':computedValued,
            #'forecast_count':forecastCount,
            'timeStr':timeString,
            'dayOfForecast':dayOfForecast,
            'url': url,
            'url_linktext': url_linktext,
        }

        template = JINJA_ENVIRONMENT.get_template('markets.html')
        self.response.write(template.render(template_values))
Пример #6
0
    def get(self):
        
        #Get total nubmer of predictions
        #global_stat = stats.GlobalStat.query().get()
        #forecastCount = global_stat.count

        #Get the time, make a string of format:
        #Tue, Jan 6, 2014, 12:00AM EST - US MARKETS CLOSED
        now = datetime.now(tz=timezone('US/Eastern'))
        #Construct the EST time for the top of page
        if( (now.time() >= time(9,30) and now.time() <= time(16,30)) and (now.weekday() <= 4 ) ):
            timeString = "{0:s} EST  - US Markets Are Open".format(now.strftime("%a, %b %d %Y, %I:%M%p"))
        else:
            timeString = "{0:s} EST  - US Markets Are Closed".format(now.strftime("%a, %b %d %Y, %I:%M%p"))
        #

        stockList = StockList.query(StockList.rank.IN(list(np.arange(1,26))))

        computedCloseValues = np.zeros((stockList.count(), 3), float)

        #createa  binary list of stock list vs user favorite list
        user = users.get_current_user()
        if user:
            up = UserProfile.query(UserProfile.user_id == str(user.user_id()))            
            favBinary = []
            for u in up:
                for stock in stockList:
                    if stock.symbol in u.favorite_list:
                        favBinary.append(1)
                    else:
                        favBinary.append(0)
                break
            #case where user exists(like admin) but no profile yet
            if stockList.count() != len(favBinary):
                favBinary = np.zeros((stockList.count(),))
        else:
            favBinary = np.zeros((stockList.count(),))
        #

        i = 0
        for stock in stockList:
            computedCloseValues[i][0] = stock.forecastedPrice-stock.currentPrice
            computedCloseValues[i][1] = (stock.forecastedPrice-stock.currentPrice)/abs(stock.currentPrice)*100.0
            computedCloseValues[i][2] = favBinary[i]
            i += 1

        #Init items using info from forecast, just use the first item
        dayOfForecast = now.strftime("%A, %B %d %Y")
        dof = now
        for stock in stockList:
            dayOfForecast = stock.date.strftime("%A, %B %d %Y")
            #dof = forecast.date
            break
        
        if users.get_current_user():
            url = users.create_logout_url(self.request.uri)
            url_linktext = 'Logout'
        else:
            url = users.create_login_url(self.request.uri)
            url_linktext = 'Sign Up for Updates'

        template_values = {
            'stock_list':stockList,
            'computed_values':computedCloseValues,
            #'forecast_count':forecastCount,
            'timeStr':timeString,
            'dayOfForecast':dayOfForecast,
            'url': url,
            'url_linktext': url_linktext,
        }

        template = JINJA_ENVIRONMENT.get_template('index.html')
        self.response.write(template.render(template_values))
    def get(self):

        #Get total nubmer of predictions
        #global_stat = stats.GlobalStat.query().get()
        #forecastCount = global_stat.count

        #Get the time, make a string of format:
        #Tue, Jan 6, 2014, 12:00AM EST - US MARKETS CLOSED
        now = datetime.now(tz=timezone('US/Eastern'))
        #Construct the EST time for the top of page
        if ((now.time() >= time(9, 30) and now.time() <= time(16, 30))
                and (now.weekday() <= 4)):
            timeString = "{0:s} EST  - US Markets Are Open".format(
                now.strftime("%a, %b %d %Y, %I:%M%p"))
        else:
            timeString = "{0:s} EST  - US Markets Are Closed".format(
                now.strftime("%a, %b %d %Y, %I:%M%p"))
        #

        stockList = StockList.query(StockList.rank.IN(list(np.arange(1, 26))))

        computedCloseValues = np.zeros((stockList.count(), 3), float)

        #createa  binary list of stock list vs user favorite list
        user = users.get_current_user()
        if user:
            up = UserProfile.query(UserProfile.user_id == str(user.user_id()))
            favBinary = []
            for u in up:
                for stock in stockList:
                    if stock.symbol in u.favorite_list:
                        favBinary.append(1)
                    else:
                        favBinary.append(0)
                break
            #case where user exists(like admin) but no profile yet
            if stockList.count() != len(favBinary):
                favBinary = np.zeros((stockList.count(), ))
        else:
            favBinary = np.zeros((stockList.count(), ))
        #

        i = 0
        for stock in stockList:
            computedCloseValues[i][
                0] = stock.forecastedPrice - stock.currentPrice
            computedCloseValues[i][1] = (stock.forecastedPrice -
                                         stock.currentPrice) / abs(
                                             stock.currentPrice) * 100.0
            computedCloseValues[i][2] = favBinary[i]
            i += 1

        #Init items using info from forecast, just use the first item
        dayOfForecast = now.strftime("%A, %B %d %Y")
        dof = now
        for stock in stockList:
            dayOfForecast = stock.date.strftime("%A, %B %d %Y")
            #dof = forecast.date
            break

        if users.get_current_user():
            url = users.create_logout_url(self.request.uri)
            url_linktext = 'Logout'
        else:
            url = users.create_login_url(self.request.uri)
            url_linktext = 'Sign Up for Updates'

        template_values = {
            'stock_list': stockList,
            'computed_values': computedCloseValues,
            #'forecast_count':forecastCount,
            'timeStr': timeString,
            'dayOfForecast': dayOfForecast,
            'url': url,
            'url_linktext': url_linktext,
        }

        template = JINJA_ENVIRONMENT.get_template('index.html')
        self.response.write(template.render(template_values))