예제 #1
0
    def get_stock_details(self, id=None):
        self.id = id

        data_rows = None
        stock_dictionary = {}
        stock_list = []

        with DatabaseConnect() as cursor:
            if self.id is None:
                sql_select_query = """select stock_symbol, stock_name, last_price from stock_master"""
                cursor.execute(sql_select_query)
            else:
                sql_select_query = """select stock_symbol, stock_name, last_price from stock_master where stock_symbol = %s"""
                cursor.execute(sql_select_query, (self.id, ))

            data_rows = cursor.fetchall()
            print("Total number of rows: ", cursor.rowcount)

            for each_record in data_rows:
                stock_object = Stock()
                stock_object.stock_symbol = each_record[0]
                stock_object.stock_name = each_record[1]
                stock_object.last_price = SerializeObject.serialize_object(
                    each_record[2])

                stock_dictionary = ConvertToDictionary.convert_to_dictionary(
                    stock_object)
                stock_list.append(stock_dictionary)
            return stock_list
    def semple_data(self):
        self.list_data.append(Stock('TEA', 'Common', 0, '', 100), )
        self.list_data.append(Stock('POP', 'Common', 8, '', 100), )
        self.list_data.append(Stock('ALE', 'Common', 23, '', 60), )

        self.list_data.append(Stock('GIN', 'Preferred', 8, '2%', 100), )
        self.list_data.append(Stock('JOE', 'Common', 13, '', 250), )
        return self.list_data
예제 #3
0
    def get_tables(self):
        cnds = self.navb.conditions()
        cnds.update({
            "(created_at) >= '%s'" % (self.navb.start): '',
            "(created_at) <= '%s'" % (self.navb.finish): ''
        })
        exts = {}
        cnds, markup, cols = self.navb.neater_tables(
            cnds=cnds,
            extras=[('province_pk', 'Province'), ('district_pk', 'District'),
                    ('referral_facility_pk', 'Hospital'),
                    ('facility_pk', 'Health Centre'), ('sector_pk', 'Sector'),
                    ('cell_pk', 'Cell'), ('village_pk', 'Village'),
                    ('user_phone', 'Reporter Phone'),
                    ('created_at', 'Submission Datetime'),
                    ('indexcol', 'Message')])

        markup.update({
            'drugs':
            lambda x, _, __: '%s' % (Stock.get_report_drugs(x))
        })
        markup.update({
            'message':
            lambda x, _, __: '%s' % (Stock.get_report_details(x))
        })
        markup.update({
            'indexcol':
            lambda x, _, __:
            '<a href="/dashboards/report?tbl=so&id=%s">View</a>' % (x),
        })

        DESCRI = []
        STOCKDICT = makedict(queries.STOCK_DATA['attrs'])
        INDICS = []
        attrs = []
        group = "Stock"
        title = "Stock Notifications"
        sc = self.navb.kw.get('subcat')
        if self.navb.kw.get('subcat') and self.navb.kw.get('subcat') in [
                makecol(x[0]) for x in queries.STOCK_DATA['attrs']
        ]:
            cnds.update({queries.STOCK_DATA['query_str']: ''})
            cnds.update({STOCKDICT[self.navb.kw.get('subcat')][0]: ''})
            INDICS = [STOCKDICT[self.navb.kw.get('subcat')]]

        dcols = [x[0] for x in cols]
        nat = Stock.fetch_log_stock(cnds, dcols)
        #DESCRI.append((group, title))
        desc = 'Stock-out cases%s' % (' (%s)' % (self.navb.find_descr(
            DESCRI + [(makecol(x[0]), x[1])
                      for x in INDICS], sc or self.navb.kw.get('subcat'))))
        #print title, group, attrs, "NAT: ", nat[0].__dict__
        return (title, desc, group, attrs, markup, cols, nat)
예제 #4
0
class TestStockPile(unittest.TestCase):
    """
    
    Tests the functionality of a Stock pile.
    
    """

    def setUp(self):
        """Initializes a Stock pile."""
        self.pile = Stock()

    def tearDown(self):
        """Does nothing."""
        print ""
    
    def test_init(self):
        """Tests the Stock init() function"""
        print "stock: test_init ",
        self.assertEqual(self.pile.name, "Stock", 
                         "The name of the Stock pile was incorrect.")
        self.assertEqual(len(self.pile), 0, 
                         "The Stock pile was not empty initially.")
    
    def test_maxlen(self):
        """Tests that the maximum size of a Stock pile is 24."""
        print "stock: test_maximumSize ",
        self.assertEqual(self.pile.maxlen, 24,
                         "The maximum size of the Stock pile was incorrect.")
    
    def test_pushCard(self):
        """
        Tests that Cards are not allowed to be pushed to a
        Stock pile.
        """
        print "stock: test_pushCard ",
        card = Card(Suit.CLUB, 4)
        self.pile.push_card(card)
        self.assertEqual(len(self.pile), 0, 
                         "The Stock pile wasn't empty after the push.")
        self.assertNotIn(card, self.pile, 
                         "The card was pushed to the Stock pile.")
예제 #5
0
 def get_stats(self):
     cnds = self.navb.conditions()
     cnds.update({
         "(created_at) >= '%s'" % (self.navb.start): '',
         "(created_at) <= '%s'" % (self.navb.finish): ''
     })
     exts = {}
     attrs = [(makecol(x[0]), x[1]) for x in queries.STOCK_DATA['attrs']]
     exts.update(
         dict([(makecol(x[0]), ('COUNT(*)', x[0]))
               for x in queries.STOCK_DATA['attrs']]))  #;print exts
     cols = ['COUNT(*) AS total']
     nat = Stock.fetch_stock(cnds, cols, exts)
     #print attrs, "NAT: ", nat[0].__dict__
     return [attrs, nat]
예제 #6
0
def get_all_stocks_from_config():
    """

    :return:
    """
    for key, value in STOCK_CONFIG.items():
        new_stock = Stock()
        new_stock.stock_symbol = key
        new_stock.last_dividend = value.get(LAST_DIVIDEND)
        new_stock.fixed_dividend = value.get(FIXED_DIVIDEND)
        new_stock.par_value = value.get(PAR_VALUE)
        new_stock.stock_type = value.get(STOCK_TYPE)
        stock_list.append(new_stock)
    return stock_list
예제 #7
0
def get_stock_by_symbol(stock_symbol):
    """

    :param stock_symbol:
    :return:
    """
    new_stock = None
    for key, value in STOCK_CONFIG.items():
        if stock_symbol == key:
            new_stock = Stock()
            new_stock.stock_symbol = key
            new_stock.last_dividend = value.get(LAST_DIVIDEND)
            new_stock.fixed_dividend = value.get(FIXED_DIVIDEND)
            new_stock.par_value = value.get(PAR_VALUE)
            new_stock.stock_type = value.get(STOCK_TYPE)
            break
    return new_stock
예제 #8
0
def getNYSEsymbols():
    try:
        with open('data/nysecompanylist.csv') as csvfile:
            csv_reader = csv.reader(csvfile, delimiter=',')
            line = 0
            for row in csv_reader:
                if line > 0:
                    Cache.stocks[row[0]]=Stock(symbol=row[0],
                        name=row[1],
                        lastsale=row[2],
                        marketcap=row[3],
                        ipoyear=row[4],
                        sector=row[5],
                        industry=row[6],
                        summary=row[7]
                          )

                line += 1
    except Exception as ex:
        logging.error(str(ex))
예제 #9
0
 def setUp(self):
     self.stock = Stock('TEA', 'Common', 3, '', 100)
     self.stock = Stock('GIN', 'Preferred', 8, '2%', 100)
예제 #10
0
 def test_stock(self):
     stock = Stock("Nokia")
     self.assertEqual("Nokia", stock.name)
예제 #11
0
 def setUp(self):
     """Initializes a Stock pile."""
     self.pile = Stock()
 def __get_current_price(self, ticker_symbl):
     stk = Stock()
     stk.get_info(ticker_symbl)
     return stk.current_price
 def search_stock(self, ticker_symbl):
     stock = Stock()
     stock.get_info(ticker_symbl)
     return stock
예제 #14
0
 def __init__(self):
     self.stock = Stock(DEFAULT_TICKER)
     self.current_iteration = len(self.stock.price_history) + 1
     self.traders = []
     self.buy_orders = []
     self.sell_orders = []
예제 #15
0
    def get_stats(self):
        cnds = self.navb.conditions()
        cnds.update({"(created_at) <= '%s'" % (self.navb.finish): ''})
        cnds.update({"(created_at) >= '%s'" % (self.navb.start): ''})
        cols = ['COUNT(*) AS total']
        exts = {}
        nat = [
            ("pre", "Pregnancy", Pregnancy.fetch_pregnancies(cnds, cols,
                                                             exts)),
            ("anc", "Antenatal Consultation",
             Ancvisit.fetch_ancvisits(cnds, cols, exts)),
            ("ref", "Refusal", Refusal.fetch_refusals(cnds, cols, exts)),
            ("red", "Red Alert", Redalert.fetch_redalerts(cnds, cols, exts)),
            ("rar", "Red Alert Result",
             Redalert.fetch_redresults(cnds, cols, exts)),
            ("risk", "Risk", Risk.fetch_risks(cnds, cols, exts)),
            ("res", "Risk Result", Risk.fetch_riskresults(cnds, cols, exts)),
            ("dep", "Departure", Departure.fetch_departures(cnds, cols, exts)),
            ("bir", "Birth", Birth.fetch_births(cnds, cols, exts)),
            ("pnc", "Postnatal Care",
             Pncvisit.fetch_pncvisits(cnds, cols, exts)),
            ("nbc", "Newborn Care", Nbcvisit.fetch_nbcvisits(cnds, cols,
                                                             exts)),
            ("chi", "Child Health",
             Childhealth.fetch_childhealths(cnds, cols, exts)),
            ("cbn", "Community Based Nutrition",
             Nutrition.fetch_nutritions(cnds, cols, exts)),
            ("ccm", "Community Case Management",
             CCM.fetch_ccms(cnds, cols, exts)),
            ("cmr", "Case Management Response",
             CCM.fetch_cmrs(cnds, cols, exts)),
            ("dth", "Death", Death.fetch_deaths(cnds, cols, exts)),
            ("smn", "Severe Malaria",
             Malaria.fetch_malaria(
                 self.extra_cnds(cnds, extra={"keyword = 'SMN'": ''}), cols,
                 exts)),
            ("smr", "Severe Malaria Result",
             Malaria.fetch_malaria(
                 self.extra_cnds(cnds, extra={"keyword = 'SMR'": ''}), cols,
                 exts)),
            ("rso", "Risk Of Stock Out",
             Stock.fetch_stock(
                 self.extra_cnds(cnds, extra={"keyword = 'RSO'": ''}), cols,
                 exts)),
            ("so", "Stock out",
             Stock.fetch_stock(
                 self.extra_cnds(cnds, extra={"keyword = 'SO'": ''}), cols,
                 exts)),
            ("ss", "Stock Supplied",
             Stock.fetch_stock(
                 self.extra_cnds(cnds, extra={"keyword = 'SS'": ''}), cols,
                 exts)),
        ]

        data = {}
        attrs = [(x[0], x[1]) for x in nat]
        total = 0
        for an in nat:
            try:
                value = an[2][0].total
                print value, an[0]
                data.update({an[0]: value})
                total += value
            except Exception, e:
                print e
                data.update({an[0]: 0})
                continue
 def __get_current_price(self, ticker_symbl):
     stk = Stock()
     stk.get_info(ticker_symbl)
     return stk.current_price
 def search_stock(self, ticker_symbl):
     stock = Stock()
     stock.get_info(ticker_symbl)
     return stock
예제 #18
0
 def get_total(self):
     cnds = self.navb.conditions()
     exts = {}
     cols = ['COUNT(*) AS total']
     total = Stock.fetch_stock(cnds, cols, exts)[0]
     return total