コード例 #1
0
    def cleanup(self):
        day = 24 * 60 * 60
        now = time.time()
        q = []

        self.progress_.show()
        for grp, lim in [(30.0, Settings.get('group_month')),
                         (7.0, Settings.get('group_week')),
                         (1.0, Settings.get('group_day'))]:

            w = now - day * lim
            g = grp * day
            q.extend(
                DB.fetchall('''
                select avg(w), data, type, agg_mean(time, count), sum(count), sum(mistakes), agg_median(viscosity)
                from statistic where w <= %f
                group by data, type, cast(w/%f as int)''' % (w, g)))
            self.progress_.inc()

            DB.execute('''delete from statistic where w <= ?''', (w, ))
            self.progress_.inc()

        DB.executemany(
            '''insert into statistic (w, data, type, time, count, mistakes, viscosity)
            VALUES (?, ?, ?, ?, ?, ?, ?)''', q)
        self.progress_.inc()
        DB.commit()
        DB.execute('vacuum')
        self.progress_.inc()
        self.progress_.hide()
コード例 #2
0
ファイル: Database.py プロジェクト: maxme/amphetype
    def cleanup(self):
        day = 24*60*60
        now = time.time()
        q = []

        self.progress_.show()
        for grp, lim in [(30.0, Settings.get('group_month')),
                (7.0, Settings.get('group_week')),
                (1.0, Settings.get('group_day'))]:

            w = now - day*lim
            g = grp * day
            q.extend(DB.fetchall('''
                select avg(w), data, type, agg_mean(time, count), sum(count), sum(mistakes), agg_median(viscosity)
                from statistic where w <= %f
                group by data, type, cast(w/%f as int)''' % (w, g)))
            self.progress_.inc()

            DB.execute('''delete from statistic where w <= ?''', (w, ))
            self.progress_.inc()

        DB.executemany('''insert into statistic (w, data, type, time, count, mistakes, viscosity)
            VALUES (?, ?, ?, ?, ?, ?, ?)''', q)
        self.progress_.inc()
        DB.execute('vacuum')
        self.progress_.inc()
        DB.commit()
        self.progress_.hide()
コード例 #3
0
    def cleanup(self):
        s_in_day = 24*60*60
        now = time.time()
        pending = []

        for idx, grp, lim in [
                (1, 30, Settings.get("group_month")),
                (2, 7, Settings.get("group_week")),
                (3, 1, Settings.get("group_day")),
            ]:

            minimum = now - s_in_day * lim
            binsize = s_in_day * grp

            pending.extend(DB.fetchall(f"""
                select avg(w), data, type, agg_mean(time, count), sum(count), sum(mistakes),
                    agg_median(viscosity)
                from statistic where w <= {minimum}
                group by data, type, cast(w/{binsize} as int)"""))
            self.progressbar.set_fraction(idx/5)

        DB.executemany("""insert into statistic (w, data, type, time, count, mistakes, viscosity)
            values (?,?,?,?,?,?,?)""", pending)
        self.progressbar.set_fraction(4/5)
        # FIXME vacuum not supported
        # DB.execute("vacuum")
        self.progressbar.set_fraction(5/5)
        DB.commit()
        self.progressbar.set_fraction(0)
コード例 #4
0
ファイル: TextManager.py プロジェクト: fredizzimo/amphetype
 def removeSelected(self):
     cats, texts = self.getSelected()
     DB.executemany("delete from text where rowid = ?",
                    map(lambda x:(x, ), texts))
     self.removeUnused()
     self.update()
     DB.commit()
コード例 #5
0
 def removeSelected(self):
     cats, texts = self.getSelected()
     DB.executemany("delete from text where rowid = ?",
                    map(lambda x: (x, ), texts))
     self.removeUnused()
     self.update()
     DB.commit()
コード例 #6
0
    def toggle_selected(self):
        model, paths = self.tree.get_selection().get_selected_rows()
        for path in paths:
            if model.iter_depth(model.get_iter(path)) == 0:
                continue

            row = Gtk.TreeModelRow(model, path)
            DB.execute("update text set disabled = 1 where rowid=?",
                       (row[0], ))
        self.update()
        DB.commit()
コード例 #7
0
ファイル: TextManager.py プロジェクト: vaicys/amphetype
    def setImpList(self, files):
        self.sender().hide()
        self.progress.show()
        for x in map(unicode, files):
            self.progress.setValue(0)
            fname = path.basename(x)
            lm = LessonMiner(x)
            self.connect(lm, SIGNAL("progress(int)"), self.progress.setValue)
            self.addTexts(fname, lm, update=False)

        self.progress.hide()
        self.update()
        DB.commit()
コード例 #8
0
ファイル: TextManager.py プロジェクト: gordonfierce/amphetype
    def setImpList(self, files):
        self.sender().hide()
        self.progress.show()
        for x in map(unicode, files):
            self.progress.setValue(0)
            fname = path.basename(x)
            lm = LessonMiner(x)
            self.connect(lm, SIGNAL("progress(int)"), self.progress.setValue)
            self.addTexts(fname, lm, update=False)

        self.progress.hide()
        self.update()
        DB.commit()
コード例 #9
0
    def add_files(self):
        filepicker = Gtk.FileChooserDialog()
        filepicker.add_button(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL)
        filepicker.add_button(Gtk.STOCK_OPEN, Gtk.ResponseType.ACCEPT)
        result = filepicker.run()
        fname = filepicker.get_filename()
        filepicker.destroy()
        if result == Gtk.ResponseType.CANCEL or fname is None:
            return

        lminer = LessonMiner(fname)
        lminer.connect("progress",
                       lambda p: self.progress.set_fraction(p / 100))
        self.add_texts(fname, lminer, update=False)
        self.progress.set_fraction(0)

        self.update()
        DB.commit()
コード例 #10
0
 def addTexts(self, source, texts, lesson=None, update=True):
     id = DB.getSource(source, lesson)
     r = []
     for x in texts:
         h = hashlib.sha1()
         h.update(x.encode('utf-8'))
         txt_id = h.hexdigest()
         dis = 1 if lesson == 2 else None
         try:
             DB.execute("insert into text (id,text,source,disabled) values (?,?,?,?)",
                        (txt_id, x, id, dis))
             r.append(txt_id)
         except Exception as e:
             pass # silently skip ...
     if update:
         self.update()
     if lesson:
         DB.commit()
     return r
コード例 #11
0
ファイル: TextManager.py プロジェクト: maxme/amphetype
    def addTexts(self, source, texts, lesson=None, update=True):
        id = DB.getSource(source, lesson)

        r = []
        for x in texts:
            x = re.sub(Settings.get('sentence_strip'), ' ', x)
            h = hashlib.sha1()
            h.update(x.encode('utf-8'))
            txt_id = h.hexdigest()
            dis = 1 if lesson == 2 else None
            try:
                DB.execute("insert into text (id, text, source, disabled) values (?, ?, ?, ?)", (txt_id, x, id, dis))
            except Exception:
                pass # silently skip ...
        r.append(txt_id)
        if update:
            self.update()
        if lesson:
            DB.commit()
        return r
コード例 #12
0
 def delete_disabled(self):
     DB.execute('delete from text where disabled is not null')
     DB.execute("""
         delete from source where rowid in (
             select s.rowid from source as s
                 left join result as r on (s.rowid=r.source)
                 left join text as t on (t.source=s.rowid)
             group by s.rowid
             having count(r.rowid) = 0 and count(t.rowid) = 0
         )""")
     DB.execute("""
         update source set disabled = 1 where rowid in (
             select s.rowid from source as s
                 left join result as r on (s.rowid=r.source)
                 left join text as t on (t.source=s.rowid)
             group by s.rowid
             having count(r.rowid) > 0 and count(t.rowid) = 0
         )""")
     self.emit("refresh-sources")
     self.update()
     DB.commit()
コード例 #13
0
 def add_texts(self, source, texts, lesson=None, update=True):
     idx = DB.get_source(source, lesson)
     out = []
     for text in texts:
         hasher = hashlib.sha1()
         hasher.update(text.encode("utf-8"))
         text_hash = hasher.hexdigest()
         dis = 1 if lesson == 2 else None
         try:
             DB.execute(
                 "insert into text (id,text,source,disabled) values (?,?,?,?)",
                 (text_hash, text, idx, dis))
             out.append(text_hash)
         except Exception:
             # TODO properly handle exception
             pass  # silently skip ...
     if update:
         self.update()
     if lesson:
         DB.commit()
     return out
コード例 #14
0
ファイル: TextManager.py プロジェクト: gordonfierce/amphetype
 def addTexts(self, source, texts, lesson=None, update=True):
     id = DB.getSource(source, lesson)
     r = []
     for x in texts:
         h = hashlib.sha1()
         h.update(x.encode("utf-8"))
         txt_id = h.hexdigest()
         dis = 1 if lesson == 2 else None
         try:
             DB.execute(
                 "insert into text (id,text,source,disabled) values (?,?,?,?)",
                 (txt_id, x, id, dis),
             )
             r.append(txt_id)
         except Exception as e:
             pass  # silently skip ...
     if update:
         self.update()
     if lesson:
         DB.commit()
     return r
コード例 #15
0
    def addTexts(self, source, texts, lesson=None, update=True):
        source = source +' Length:' + str(Settings.get('min_chars'))
        id = DB.getSource(source, lesson)

        r = []
        for x in texts:
            x = self.cleanText(x)
            h = hashlib.sha1()
            h.update(x.encode('utf-8'))
            txt_id = h.hexdigest()
            dis = 1 if lesson == 2 else None
            try:
                DB.execute("insert into text (id, text, source, disabled) values (?, ?, ?, ?)", (txt_id, x, id, dis))
            except Exception:
                pass # silently skip ...
        r.append(txt_id)
        if update:
            self.update()
        if lesson:
            DB.commit()
        return r
コード例 #16
0
 def enable_all(self):
     DB.execute(
         'update text set disabled = null where disabled is not null')
     self.update()
     DB.commit()
コード例 #17
0
ファイル: TextManager.py プロジェクト: vaicys/amphetype
class TextManager(QWidget):

    defaultText = ("", 0, """Welcome to Amphetype!
A typing program that not only measures your speed and progress, but also gives you detailed statistics about problem keys, words, common mistakes, and so on. This is just a default text since your database is empty. You might import a novel or text of your choosing and text excerpts will be generated for you automatically. There are also some facilities to generate lessons based on your past statistics! But for now, go to the "Sources" tab and try adding some texts from the "txt" directory."""
                   )

    def __init__(self, *args):
        super(TextManager, self).__init__(*args)

        self.diff_eval = lambda x: 1
        self.model = SourceModel()
        tv = AmphTree(self.model)
        tv.resizeColumnToContents(1)
        tv.setColumnWidth(0, 300)
        self.connect(tv, SIGNAL("doubleClicked(QModelIndex)"),
                     self.doubleClicked)
        self.tree = tv

        self.progress = QProgressBar()
        self.progress.setRange(0, 100)
        self.progress.hide()

        self.setLayout(
            AmphBoxLayout(
                [
                    (
                        [
                            "Below you will see the different text sources used. Disabling texts or sources deactivates them so they won't be selected for typing. You can double click a text to do that particular text.\n",
                            (self.tree, 1),
                            self.progress,
                            [
                                AmphButton("Import Texts", self.addFiles),
                                None,
                                AmphButton("Enable All", self.enableAll),
                                AmphButton("Delete Disabled",
                                           self.removeDisabled), None,
                                AmphButton("Update List", self.update)
                            ],
                            [  #AmphButton("Remove", self.removeSelected), "or",
                                AmphButton("Toggle disabled",
                                           self.disableSelected),
                                "on all selected texts that match <a href=\"http://en.wikipedia.org/wiki/Regular_expression\">regular expression</a>",
                                SettingsEdit('text_regex')
                            ]
                        ],
                        1),
                    [[
                        "Selection method for new lessons:",
                        SettingsCombo(
                            'select_method',
                            ['Random', 'In Order', 'Difficult', 'Easy']), None
                    ],
                     "(in order works by selecting the next text after the one you completed last, in the order they were added to the database, easy/difficult works by estimating your WPM for several random texts and choosing the fastest/slowest)\n",
                     20,
                     AmphGridLayout([
                         [("Repeat <i>texts</i> that don't meet the following requirements:\n",
                           (1, 3))],
                         ["WPM:", SettingsEdit("min_wpm")],
                         [
                             "Accuracy:",
                             SettingsEdit("min_acc"), (None, (0, 1))
                         ],
                         [("Repeat <i>lessons</i> that don't meet the following requirements:\n",
                           (1, 3))],
                         ["WPM:", SettingsEdit("min_lesson_wpm")],
                         ["Accuracy:",
                          SettingsEdit("min_lesson_acc")],
                     ]), None]
                ],
                QBoxLayout.LeftToRight))

        self.connect(Settings, SIGNAL("change_select_method"), self.setSelect)
        self.setSelect(Settings.get('select_method'))

    def setSelect(self, v):
        if v == 0 or v == 1:
            self.diff_eval = lambda x: 1
            self.nextText()
            return

        hist = time.time() - 86400.0 * Settings.get('history')
        tri = dict(
            DB.execute(
                """
                    select data,agg_median(time) as wpm from statistic
                    where w >= ? and type = 1
                    group by data""",
                (hist, )).fetchall())  #[(t, (m, c)) for t, m, c in

        g = tri.values()
        if len(g) == 0:
            return lambda x: 1
        g.sort(reverse=True)
        expect = g[len(g) // 4]

        def _func(v):
            text = v[2]
            v = 0
            s = 0.0
            for i in xrange(0, len(text) - 2):
                t = text[i:i + 3]
                if t in tri:
                    s += tri[t]
                else:
                    #print "|", t,
                    s += expect
                    v += 1
            avg = s / (len(text) - 2)
            #print text
            #print " v=%d,s=%f" % (v, 12.0/avg), "ex:", expect
            return 12.0 / avg

        self.diff_eval = _func
        self.nextText()

    def addFiles(self):

        qf = QFileDialog(self, "Import Text From File(s)")
        qf.setFilters(["UTF-8 text files (*.txt)", "All files (*)"])
        qf.setFileMode(QFileDialog.ExistingFiles)
        qf.setAcceptMode(QFileDialog.AcceptOpen)

        self.connect(qf, SIGNAL("filesSelected(QStringList)"), self.setImpList)

        qf.show()

    def setImpList(self, files):
        self.sender().hide()
        self.progress.show()
        for x in map(unicode, files):
            self.progress.setValue(0)
            fname = path.basename(x)
            lm = LessonMiner(x)
            self.connect(lm, SIGNAL("progress(int)"), self.progress.setValue)
            self.addTexts(fname, lm, update=False)

        self.progress.hide()
        self.update()
        DB.commit()

    def addTexts(self, source, texts, lesson=None, update=True):
        id = DB.getSource(source, lesson)
        r = []
        for x in texts:
            h = hashlib.sha1()
            h.update(x.encode('utf-8'))
            txt_id = h.hexdigest()
            dis = 1 if lesson == 2 else None
            try:
                DB.execute(
                    "insert into text (id,text,source,disabled) values (?,?,?,?)",
                    (txt_id, x, id, dis))
                r.append(txt_id)
            except Exception, e:
                pass  # silently skip ...
        if update:
            self.update()
        if lesson:
            DB.commit()
        return r
コード例 #18
0
ファイル: TextManager.py プロジェクト: vaicys/amphetype
 def removeDisabled(self):
     DB.execute('delete from text where disabled is not null')
     self.removeUnused()
     self.update()
     DB.commit()
コード例 #19
0
ファイル: TextManager.py プロジェクト: gordonfierce/amphetype
 def removeDisabled(self):
     DB.execute("delete from text where disabled is not null")
     self.removeUnused()
     self.update()
     DB.commit()
コード例 #20
0
                    "main_text_area_color"),  #most text areas' backgrounds
                Settings.getColor(
                    "main_background_color"
                )  #most backgrounds.  label tab gets part of its color from here. 
            ))


class AboutWidget(QTextBrowser):
    def __init__(self, *args):
        html = "about.html file missing!"
        try:
            html = open("about.html", "r").read()
        except:
            pass
        super(AboutWidget, self).__init__(*args)
        self.setHtml(html)
        self.setOpenExternalLinks(True)
        #self.setMargin(40)
        self.setReadOnly(True)


app = QApplication(sys.argv)

w = TyperWindow()
w.show()

app.exec_()

print "exit"
DB.commit()
コード例 #21
0
ファイル: Amphetype.py プロジェクト: ralismark/amphetype
def main():
    app = App()
    app.show_all()
    app.connect("destroy", Gtk.main_quit)
    Gtk.main()
    DB.commit()
コード例 #22
0
 def removeDisabled(self):
     DB.execute('delete from text where disabled = 1')
     self.removeUnused()
     self.update()
     DB.commit()
コード例 #23
0
ファイル: Amphetype.py プロジェクト: Alok/amphetype
        tm.nextText()

    def sizeHint(self):
        return QSize(650, 400)

class AboutWidget(QTextBrowser):
    def __init__(self, *args):
        html = "about.html file missing!"
        try:
            html = open("about.html", "r").read()
        except:
            pass
        super(AboutWidget, self).__init__(*args)
        self.setHtml(html)
        self.setOpenExternalLinks(True)
        #self.setMargin(40)
        self.setReadOnly(True)

app = QApplication(sys.argv)

w = TyperWindow()
w.show()

app.exec_()

print "exit"
DB.commit()