当前位置: 首页>>代码示例>>Python>>正文


Python DB.fetchone方法代码示例

本文整理汇总了Python中Data.DB.fetchone方法的典型用法代码示例。如果您正苦于以下问题:Python DB.fetchone方法的具体用法?Python DB.fetchone怎么用?Python DB.fetchone使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Data.DB的用法示例。


在下文中一共展示了DB.fetchone方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: nextText

# 需要导入模块: from Data import DB [as 别名]
# 或者: from Data.DB import fetchone [as 别名]
    def nextText(self):

        type = Settings.get('select_method')

        if type != 1:
            # Not in order
            v = DB.execute("select id,source,text from text where disabled is null order by random() limit %d" % Settings.get('num_rand')).fetchall()
            if len(v) == 0:
                v = None
            elif type == 2:
                v = min(v, key=self.diff_eval)
            elif type == 3:
                v = max(v, key=self.diff_eval)
            else:
                v = v[0] # random, just pick the first
        else:
            # Fetch in order
            lastid = (0,)
            g = DB.fetchone("""select r.text_id
                from result as r left join source as s on (r.source = s.rowid)
                where (s.discount is null) or (s.discount = 1) order by r.w desc limit 1""", None)
            if g is not None:
                lastid = DB.fetchone("select rowid from text where id = ?", lastid, g)
            v = DB.fetchone("select id,source,text from text where rowid > ? and disabled is null order by rowid asc limit 1", None, lastid)

        if v is None:
            v = self.defaultText

        self.emit(SIGNAL("setText"), v)
开发者ID:fredizzimo,项目名称:amphetype,代码行数:31,代码来源:TextManager.py

示例2: update

# 需要导入模块: from Data import DB [as 别名]
# 或者: from Data.DB import fetchone [as 别名]
    def update(self):
        self.progress_.show()
        n_text = DB.fetchone("""select count(*) from text""", (0,))[0]
        self.progress_.inc(2)
        n_res = DB.fetchone("""select count(*) from result""", (0,))[0]
        self.progress_.inc(2)
        n_words = DB.fetchall(
            """select count(*),sum(count) from statistic
            group by type order by type"""
        )
        self.progress_.inc(2)
        if len(n_words) != 3:
            n_words = [(0, 0), (0, 0), (0, 0)]
        n_first = DB.fetchone("""select w from result order by w asc limit 1""", (time.time(),))[0]
        self.progress_.hide()

        self.stats_.setText(
            locale.format_string(
                """Texts: %d
Results: %d
Analysis data: %d (%d keys, %d trigrams, %d words)
  %d characters and %d words typed total\n"""
                + ("First result was %.2f days ago.\n" % ((time.time() - n_first) / 86400.0)),
                tuple(
                    [n_text, n_res, sum(map(lambda x: x[0], n_words))]
                    + map(lambda x: x[0], n_words)
                    + [n_words[0][1], n_words[2][1]]
                ),
                True,
            )
        )
开发者ID:rmissaoui,项目名称:amphetype,代码行数:33,代码来源:Database.py

示例3: newReview

# 需要导入模块: from Data import DB [as 别名]
# 或者: from Data.DB import fetchone [as 别名]
 def newReview(self, review):
     q = self.addTexts("<Reviews>", [review], lesson=2, update=False)
     if q:
         v = DB.fetchone("select id,source,text from text where id = ?", self.defaultText, q)
         self.emit(SIGNAL("setText"), v)
     else:
         self.nextText()
开发者ID:fredizzimo,项目名称:amphetype,代码行数:9,代码来源:TextManager.py

示例4: getStats

# 需要导入模块: from Data import DB [as 别名]
# 或者: from Data.DB import fetchone [as 别名]
 def getStats(self):
     if self.when[0] == -1:
         t = self.times[1:]
         t.sort(reverse=True)
         v = DB.fetchone('select time from statistic where type = 0 and data = ? order by rowid desc limit 1', (t[len(t)//5], ), (self.target[0], ))
         self.times[0] = v[0]
         self.when[0] = self.when[1] - self.times[0]
     return self.when[self.where]-self.when[0], self.where, self.times, self.mistake, self.getMistakes()
开发者ID:fredizzimo,项目名称:amphetype,代码行数:10,代码来源:Quizzer.py

示例5: doubleClicked

# 需要导入模块: from Data import DB [as 别名]
# 或者: from Data.DB import fetchone [as 别名]
    def doubleClicked(self, idx):
        r = self.model.rows[idx.row()]

        v = DB.fetchone('select id,source,text from text where id = ?', None, (r[0], ))
        if v == None:
            return # silently ignore

        self.emit(SIGNAL("setText"), v)
        self.emit(SIGNAL("gotoText"))
开发者ID:Alok,项目名称:amphetype,代码行数:11,代码来源:Performance.py

示例6: getStats

# 需要导入模块: from Data import DB [as 别名]
# 或者: from Data.DB import fetchone [as 别名]
    def getStats(self):
        #TODO: redo when, times to avoid guessing time taken to hit zeroth char from old stat
        if self.when[0] == -1:
            t = self.times[1:]
            t.sort(reverse=True)
            v = DB.fetchone('select time from statistic where type = 0 and data = ? order by rowid desc limit 1', (t[len(t)//5], ), (self.target[0], ))
            self.when[0] = self.when[1] - v[0]

        if not self.when[-1]:
            self.when[-1] = timer()

        self.when = list(linearly_interpolate(self.when))
        
        for i in range(len(self.times)):
            #prevent division by zero when 0 time 
            time = self.when[i+1] - self.when[i]
            self.times[i] = MINIMUM_CHAR_TYPING_TIME if time == 0 else time   

        return self.when[-1]-self.when[0], len(self.target), self.times, self.mistake, self.getMistakes()
开发者ID:eliasdorneles,项目名称:amphetype-backup,代码行数:21,代码来源:Quizzer.py

示例7: done

# 需要导入模块: from Data import DB [as 别名]
# 或者: from Data.DB import fetchone [as 别名]
    def done(self):
        now = time.time()
        elapsed, chars, times, mis, mistakes = self.typer.getStats()

        assert chars == len(self.text[2])

        accuracy = 1.0 - len(filter(None, mis)) / chars
        spc = elapsed / chars
        
        viscosity = sum(map(lambda x: ((x-spc)/spc)**2, times)) / chars

        DB.execute('insert into result (w,text_id,source,wpm,accuracy,viscosity) values (?,?,?,?,?,?)',
                   (now, self.text[0], self.text[1], 12.0/spc, accuracy, viscosity))

        v2 = DB.fetchone("""select agg_median(wpm),agg_median(acc) from
            (select wpm,100.0*accuracy as acc from result order by w desc limit %d)""" % Settings.get('def_group_by'), (0.0, 100.0))
        self.result.setText("Last: %.1fwpm (%.1f%%), last 10 average: %.1fwpm (%.1f%%)"
            % ((12.0/spc, 100.0*accuracy) + v2))

        self.emit(SIGNAL("statsChanged"))

        stats = collections.defaultdict(Statistic)
        visc = collections.defaultdict(Statistic)
        text = self.text[2]

        for c, t, m in zip(text, times, mis):
            stats[c].append(t, m)
            visc[c].append(((t-spc)/spc)**2)

        def gen_tup(s, e):
            perch = sum(times[s:e])/(e-s)
            visc = sum(map(lambda x: ((x-perch)/perch)**2, times[s:e]))/(e-s)
            return (text[s:e], perch, len(filter(None, mis[s:e])), visc)

        for tri, t, m, v in [gen_tup(i, i+3) for i in xrange(0, chars-2)]:
            stats[tri].append(t, m > 0)
            visc[tri].append(v)

        regex = re.compile(r"(\w|'(?![A-Z]))+(-\w(\w|')*)*")

        for w, t, m, v in [gen_tup(*x.span()) for x in regex.finditer(text) if x.end()-x.start() > 3]:
            stats[w].append(t, m > 0)
            visc[w].append(v)

        def type(k):
            if len(k) == 1:
                return 0
            elif len(k) == 3:
                return 1
            return 2

        vals = []
        for k, s in stats.iteritems():
            v = visc[k].median()
            vals.append( (s.median(), v*100.0, now, len(s), s.flawed(), type(k), k) )

        is_lesson = DB.fetchone("select discount from source where rowid=?", (None,), (self.text[1], ))[0]

        if Settings.get('use_lesson_stats') or not is_lesson:
            DB.executemany_('''insert into statistic
                (time,viscosity,w,count,mistakes,type,data) values (?,?,?,?,?,?,?)''', vals)
            DB.executemany_('insert into mistake (w,target,mistake,count) values (?,?,?,?)',
                    [(now, k[0], k[1], v) for k, v in mistakes.iteritems()])

        if is_lesson:
            mins = (Settings.get("min_lesson_wpm"), Settings.get("min_lesson_acc"))
        else:
            mins = (Settings.get("min_wpm"), Settings.get("min_acc"))

        if 12.0/spc < mins[0] or accuracy < mins[1]/100.0:
            self.setText(self.text)
        elif not is_lesson and Settings.get('auto_review'):
            ws = filter(lambda x: x[5] == 2, vals)
            if len(ws) == 0:
                self.emit(SIGNAL("wantText"))
                return
            ws.sort(key=lambda x: (x[4],x[0]), reverse=True)
            i = 0
            while ws[i][4] != 0:
                i += 1
            i += (len(ws) - i) // 4

            self.emit(SIGNAL("wantReview"), map(lambda x:x[6], ws[0:i]))
        else:
            self.emit(SIGNAL("wantText"))
开发者ID:eliasdorneles,项目名称:amphetype-backup,代码行数:87,代码来源:Quizzer.py


注:本文中的Data.DB.fetchone方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。