Esempio n. 1
0
def sync():
	cs = CollectionStats(mw.col)
	cs.wholeCollection = True
	lims = []
	num = 365
	chunk = 1
	if num is not None:
		lims.append("id > %d" % (
			(cs.col.sched.dayCutoff-(num*chunk*86400))*1000))
	lim = cs._revlogLimit()
	if lim:
		lims.append(lim)
	if lims:
		lim = "where " + " and ".join(lims)
	else:
		lim = ""
	if cs.type == 0:
		tf = 60.0 # minutes
	else:
		tf = 3600.0 # hours
	revlog = cs.col.db.all("""
	select
	(cast((id/1000.0 - :cut) / 86400.0 as int))/:chunk as day,
	sum(time)/1000,
	sum(case when type = 0 then 1 else 0 end), -- lrn count
	sum(case when type = 1 and lastIvl < 21 then 1 else 0 end), -- yng count
	sum(case when type = 1 and lastIvl >= 21 then 1 else 0 end), -- mtr count
	sum(case when type = 2 then 1 else 0 end), -- lapse count
	sum(case when type = 3 then 1 else 0 end), -- cram count
	sum(case when type = 0 then time/1000.0 else 0 end)/:tf, -- lrn time
	-- yng + mtr time
	sum(case when type = 1 and lastIvl < 21 then time/1000.0 else 0 end)/:tf,
	sum(case when type = 1 and lastIvl >= 21 then time/1000.0 else 0 end)/:tf,
	sum(case when type = 2 then time/1000.0 else 0 end)/:tf, -- lapse time
	sum(case when type = 3 then time/1000.0 else 0 end)/:tf -- cram time
	from revlog %s
	group by day order by day""" % lim,
						cut=cs.col.sched.dayCutoff,
						tf=tf,
						chunk=chunk)
	

	values = {'data': revlog, 'email': mw.pm.profile.get('syncUser')} 
	html = http_post(values)
	
	showInfo(html)
Esempio n. 2
0
    def _create_revision_count_graph(self):
        stats = CollectionStats(self.col)

        categories_labels = list(range(-30, 1, 1))
        data = stats.revision_count_stats()
        data = self._transform_first_column_to_key(data)
        data = self._add_default_value_for_missing_keys(
            data, [0, 0, 0, 0, 0], categories_labels)

        series = QStackedBarSeries(self)
        setLearning = QBarSet("Learning", self)
        [setLearning.append(row[0]) for row in data]
        setYoung = QBarSet("Young", self)
        [setYoung.append(row[1]) for row in data]
        setMature = QBarSet("Mature", self)
        [setMature.append(row[2]) for row in data]
        setLapse = QBarSet("Lapse", self)
        [setLapse.append(row[3]) for row in data]
        setEarly = QBarSet("Early", self)
        [setEarly.append(row[4]) for row in data]

        categories = QBarCategoryAxis()
        categories.setCategories([str(-i) for i in categories_labels])

        series.append(setLearning)
        series.append(setYoung)
        series.append(setMature)
        series.append(setLapse)
        series.append(setEarly)

        chart = QChart()
        chart.addSeries(series)
        chart.createDefaultAxes()
        chart.setAxisX(categories, series)

        chart.setAnimationOptions(QChart.SeriesAnimations)
        chart.setTitle("Number of cards reviewed recently")

        chart.legend().setVisible(True)
        chart.legend().setAlignment(Qt.AlignBottom)

        chartview = QChartView(chart)
        chartview.setRenderHint(QPainter.Antialiasing)

        self.layout.addWidget(chartview)
Esempio n. 3
0
    def _create_reviews_due_chart(self):
        ## TODO: later replace by date selector
        start, end, chunk = 0, 31, 1
        stats = CollectionStats(self.col)

        ## TODO: refactor stats._due
        categories_labels = list(range(0, 31, 1))
        data = stats.due(start, end, chunk)
        data = self._transform_first_column_to_key(data)
        data = self._add_default_value_for_missing_keys(
            data, [0, 0, 0, 0], categories_labels)

        series = QStackedBarSeries(self)
        setYoung = QBarSet("Young", self)
        [setYoung.append(row[0]) for row in data]
        setAdolescent = QBarSet("Adolescent", self)
        [setAdolescent.append(row[1]) for row in data]
        setMature = QBarSet("Mature", self)
        [setMature.append(row[2]) for row in data]
        setOld = QBarSet("Old", self)
        [setOld.append(row[3]) for row in data]

        categories = QBarCategoryAxis()
        categories.setCategories([str(i) for i in categories_labels])

        series.append(setOld)
        series.append(setMature)
        series.append(setAdolescent)
        series.append(setYoung)

        chart = QChart()
        chart.addSeries(series)
        chart.createDefaultAxes()
        chart.setAxisX(categories, series)

        chart.setAnimationOptions(QChart.SeriesAnimations)
        chart.setTitle("Forecast: the number of reviews due in the future")

        chart.legend().setVisible(True)
        chart.legend().setAlignment(Qt.AlignBottom)

        chartview = QChartView(chart)
        chartview.setRenderHint(QPainter.Antialiasing)

        self.layout.addWidget(chartview)
Esempio n. 4
0
def test_days_studied_works_with_old_logs():
    # ARRANGE
    col = getEmptyCol()
    ivl = 1
    card = create_learning_card(col, ivl)
    hard_answer = 2
    factor = 2500
    time_taken = 10  # seconds

    for day in range(1, 31):
        timestamp = datetime(2020, 4, day, 12, 0, 0, 0).timestamp()
        # days, due were added, so previous logs have 0s
        col.db.execute("insert into revlog values (?,?,?,?,?,?,?,?,?,?,?)",
                       int(timestamp * 1000), card.id, col.usn(), hard_answer,
                       ivl, ivl, factor, time_taken, 1, 0, 0)

    # ACT
    collection_stats = CollectionStats(col)
    collection_stats.type = 2
    return_value = collection_stats._daysStudied()

    # ASSERT
    # number of days should be 30
    assert return_value[0] == 30
Esempio n. 5
0
    def stats(self) -> "anki.stats.CollectionStats":
        from anki.stats import CollectionStats

        return CollectionStats(self)
Esempio n. 6
0
 def stats(self):
     from anki.stats import CollectionStats
     return CollectionStats(self)
Esempio n. 7
0
    def _update(self):
        if not self.dock or not self.dock.isVisible(): return
        if freezeMode and self.type>10: return

        card = mw.reviewer.card
        txt = _("No Current Card")

        if self.type<-10:
            txt = _("No Last Card")
            card = mw.reviewer.lastCard()

        cs = CollectionStats(mw.col)
        cs.wholeCollection=True if self.type<0 else False

        if self.type==0: #review count
            txt = "<center>%s</center>" % mw.reviewer._remaining() if mw.state=="review" else '? + ? + ?'
        elif abs(self.type)==1: #todayStats
            txt = "<center>%s</center>" % cs.todayStats()
        elif abs(self.type)==2: #forecast chart
            #no filtered decks
            did=mw.col.decks.selected()
            dyn=mw.col.decks.get(did)
            if dyn['dyn'] and self.type>0:
                txt="No data for filtered decks"

            elif ANKI21:
                p=mw.mediaServer.getPort()
                txt = """
<script src="http://localhost:%d/_anki/jquery.js"></script>
<script src="http://localhost:%d/_anki/plot.js"></script>
<center>%s</center>
""" % (p,p,self.dueGraph(cs))

            else:
                txt = "<script>%s\n</script><center>%s</center>" % (
                    anki.js.jquery+anki.js.plot, self.dueGraph(cs))

        elif abs(self.type)>=90:
            txt = self.customViews(card)

        elif mw.state!='review' and self.type>10:
            txt = _("No Review Card")

        elif card: #left or right col
            cs = CardStats(mw.col, card)
            if abs(self.type)==12: #card rev log
                txt = self._revlogData(card, cs)
            else: #card stats
                txt = self.deckOptionsInfo(card)
                txt += _("<h3>Card Stats:</h3>")
                txt += self.mini_card_stats(card)
                txt +=  cs.report()

                did = card.odid if card.odid else card.did
                fdid = card.did if card.odid else 0
                deckName = mw.col.decks.get(did)['name'] #in case of filtered decks
                sis=[i for i in mw.col.db.list("select id from cards where nid=?", card.nid)]
                tags=mw.col.getNote(card.nid).stringTags()

                txt += """<table width="100%%"><tr>
<td><b>Deck ID:</b></td> <td>%d</td></tr><tr>
<td><b>Fil DID:</b></td> <td>%d</td></tr><tr>
<td><b>oDeck:</b></td> <td>%s</td></tr><tr>
<td><b>SiblingCnt:</b></td> <td>%d</td></tr><tr>
<td><b>Siblings:</b></td> <td>%s</td></tr><tr>
<td><b>Tags:</b></td> <td>%s</td>
</tr></table>""" % (did, fdid, deckName, len(sis), str(sis), tags)

        style = self._style()
        self.web.setHtml("""
<!doctype html><html><head><style>%s</style></head>
<body class="night_mode">%s</body></html>""" % (style, txt))