當前位置: 首頁>>代碼示例>>Python>>正文


Python Drive.create_sheet方法代碼示例

本文整理匯總了Python中drive.Drive.create_sheet方法的典型用法代碼示例。如果您正苦於以下問題:Python Drive.create_sheet方法的具體用法?Python Drive.create_sheet怎麽用?Python Drive.create_sheet使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在drive.Drive的用法示例。


在下文中一共展示了Drive.create_sheet方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: FantasyDB

# 需要導入模塊: from drive import Drive [as 別名]
# 或者: from drive.Drive import create_sheet [as 別名]

#.........這裏部分代碼省略.........
                W integer, SV integer, K integer, ERA real, WHIP real);
        """ % (table_name, table_name))

    def insert(self, sql, data=None):
        if data is None:
            self.c.execute(sql)
        else:
            for line in data:
                self.c.execute(sql, line)
        self.con.commit()

    def add_teams(self, teams):
        self.insert("INSERT INTO team VALUES (?, ?, ?, ?)", teams)

    def add_matchups(self, matchups):
        self.insert("INSERT INTO matchup VALUES(?, ?, ?)", matchups)

    def add_stats(self, stats):
        sql = "INSERT INTO week_stats ("
        sql += ", ".join(stats.keys())
        sql += ") VALUES("
        sql += ", ".join(["?"] * len(stats)) + ")"
        self.insert(sql, [tuple(stats.values())])

    def save_data(self, data, name):
        # Save to file
        f = open("export/" + name + ".txt", "w", encoding="utf-8")
        f.write(data)
        f.close()

        # Save to Google Drive
        if self.drive is not None:
            self.drive.login()
            self.drive.create_sheet(name, data)

    def nb_weeks(self):
        sql = "SELECT DISTINCT COUNT(*) FROM week_stats GROUP BY team_id"
        return self.c.execute(sql).fetchone()[0]

    def get_select(self, aggregate="AVG", real_only=True, use_alias=True,
                   use_round=True, as_string=True, table_alias=""):
        columns = OrderedDict({})
        if len(table_alias):
            table_alias += "."
        for cat, conf in self.cats_conf.items():
            if real_only and not conf["real"]:
                continue
            expr = "$(" + cat + ")" if "expr" not in conf else conf["expr"]
            col = expr.replace("$(", aggregate + "(" + table_alias)
            if use_round:
                col = self.apply_round(cat, col)
            if use_alias:
                col = self.apply_alias(cat, col)

            columns[cat] = col

        return ", ".join(columns.values()) if as_string else columns

    def apply_round(self, cat, expr):
        precision = str(self.cats_conf[cat]["precision"])
        return "round(" + expr + "," + precision + ")"

    def apply_alias(self, cat, expr):
        return expr + " AS " + cat

    def stats_avg_query(self):
開發者ID:donplei,項目名稱:fantasyDB,代碼行數:70,代碼來源:db.py


注:本文中的drive.Drive.create_sheet方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。