Exemplo n.º 1
0
def get_data():
    database = DB()

    q = "SELECT first_name, last_name, rguru_id FROM player_ids WHERE rguru_id IS NOT NULL"
    ids = database.query(q)

    results = []
    for (fname, lname, id_) in ids:
        q = "SELECT dk_pts FROM rguru_hitters WHERE id=%s"
        scores = [
            float(x[0]) for x in database.query(q, (str(id_), ))
            if x[0] is not None
        ]
        # dont count if not enough sample size.
        if len(scores) < 30:
            continue
        mean = np.mean(scores)
        # only look at players w/ avg score > 4
        if mean < 4:
            continue
        stdev = np.std(scores)
        results.append((fname, lname, id_, round(mean, 2), round(stdev, 2),
                        round((mean / stdev), 2)))

    return sorted(results, key=lambda x: x[5], reverse=True)
Exemplo n.º 2
0
def get_data():
    database = DB()

    q = "SELECT first_name, last_name, rguru_id FROM player_ids WHERE rguru_id IS NOT NULL"
    ids = database.query(q)

    results = []
    for (fname, lname, id_) in ids:
        q = "SELECT dk_pts FROM rguru_hitters WHERE id=%s"
        scores = [float(x[0]) for x in database.query(q, (str(id_),)) if x[0] is not None]
        # dont count if not enough sample size.
        if len(scores) < 30:
            continue
        mean = np.mean(scores)
        # only look at players w/ avg score > 4
        if mean < 4:
            continue
        stdev = np.std(scores)
        results.append((
            fname,
            lname,
            id_,
            round(mean, 2),
            round(stdev, 2),
            round((mean/stdev), 2)
        ))

    return sorted(results, key=lambda x: x[5], reverse=True)
Exemplo n.º 3
0
class GetHist:
    def __init__(self, player_id, site='dk'):
        self.db = DB()
        self.id_ = player_id

        self.points = self.get_points(player_id, site)

    def get_mean(self):
        return np.mean(self.points)

    def get_name(self):
        return get_player.name_from_id(self.id_)

    def get_stdev(self):
        return np.std(self.points)

    def plot_hist(self, bins=20):
        self.fig = plt.figure()
        self.ax = self.fig.add_subplot(111)
        self.ax.hist(self.points, bins=bins, normed=True)
        self.ax.axvline(self.get_mean(), color='red', linestyle='--', linewidth=1.5,
                        label='Avg. Points: {0:.2f}\nSt. Dev. Points: {1:.2f}'.format(
                            self.get_mean(), self.get_stdev()))
        self.ax.legend(loc='upper right')
        self.ax.set_title(self.get_name())
        self.ax.set_ylabel('%')
        self.ax.set_xlabel('Points Scored')

    def get_points(self, id_, site):
        q = "SELECT {}_pts FROM rguru_hitters WHERE id={}".format(site, id_)
        return [float(x[0]) for x in self.db.query(q)]
Exemplo n.º 4
0
 def query_data(self):
     """Fetches all records for player id"""
     db = DB()
     q = "SELECT bat_order, AB, BB, HBP FROM rguru_hitters where id=%s"
     res = db.query(q, (self.id_,))
     db.finish()
     return res
Exemplo n.º 5
0
def fetch_data(site, pos):
    db = DB()
    q = "SELECT {0}_pts, {0}_salary FROM rguru_{1}".format(site, pos)
    points = []
    salaries = []
    for pts, sal in db.query(q):
        if pts is None or pts < 0 or sal is None or sal == 0:
            continue
        points.append(float(pts))
        salaries.append(float(sal)/1000)

    return salaries, points
Exemplo n.º 6
0
 def get_team_abs(self, date, team):
     db = DB()
     q = "SELECT name, AB, BB, HBP FROM rguru_hitters WHERE date=%s and team=%s"
     res = db.query(q, (date, team))
     db.finish()
     return res
Exemplo n.º 7
0
 def get_dates(self):
     db = DB()
     q = "SELECT date FROM rguru_hitters WHERE team = %s"
     res = db.query(q, (self.team,))
     db.finish()
     return set([x[0] for x in res])
Exemplo n.º 8
0
            if count == 10:
                count = 0
                logger.info("insert result: %s", db.excutemany(SQLMgr.insert_stock_xg_many(), write_list))
                write_list = []
            count += 1
            write_list.append(data)
        except Exception as e:
            logger.info("db break %s", e)
            break
    #result_queue.task_done()

if __name__ == "__main__":
    Log("test.log")
    try:
        db = DB()
        all_data = db.query(SQLMgr.get_all_kline_info(Tools.get_today_str()))
        if all_data:
            for row in all_data:
                task_queue.put(row)
        print all_data
        worker_thread_num = 4
        worker_thread_list = []
        for i in range(worker_thread_num):
            t = threading.Thread(target=worker, args=(task_queue, result_queue))
            worker_thread_list.append(t)
            
        database_thread = threading.Thread(target=db_writer, args=(result_queue, db))
        database_thread.setDaemon(True)
        database_thread.start()
        #
        for t in worker_thread_list: