forked from bibby/ankishow
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodels.py
More file actions
174 lines (123 loc) · 4.38 KB
/
models.py
File metadata and controls
174 lines (123 loc) · 4.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
import os
import json
from peewee import *
ANKI_DB = os.environ.get("ANKI_DB", 'collection.anki2')
db = SqliteDatabase(ANKI_DB)
class JSONField(Field):
def coerce(self, value):
if isinstance(value, dict):
return value
return json.loads(value)
class UnitField(Field):
def coerce(self, value):
if isinstance(value, list):
return value
return value.split(chr(0x1f))
class Collection(Model):
# arbitrary number since there is only one row
id = IntegerField()
# created timestamp
crt = IntegerField()
# last modified in milliseconds
mod = IntegerField()
# schema mod time: time when "schema" was modified.
# If server scm is different from the client scm a full-sync is required
scm = IntegerField()
# version
ver = IntegerField()
# dirty: unused, set to 0
dty = IntegerField()
# update sequence number: used for finding diffs when syncing.
# See usn in cards table for more details.
usn = IntegerField()
# "last sync time"
ls = IntegerField()
# json object containing configuration options that are synced
conf = JSONField()
# json array of json objects containing the models (aka Note types)
models = JSONField()
# json array of json objects containing the deck
decks = JSONField()
# json array of json objects containing the deck options
dconf = JSONField()
# space separated string?
tags = CharField()
class Meta:
database = db
db_table = 'col'
class Note(Model):
# epoch seconds of when the note was created
id = IntegerField()
# globally unique id, almost certainly used for syncing
guid = CharField()
# model id
mid = IntegerField()
# modification timestamp, epoch seconds
mod = IntegerField()
# update sequence number: for finding diffs when syncing.
# See the description in the cards table for more info
usn = IntegerField()
# space-separated string of tags.
# includes space at the beginning and end, for LIKE "% tag %" queries
tags = CharField()
# the values of the fields in this note. separated by 0x1f (31) character.
flds = UnitField()
# sort field: used for quick sorting and duplicate check
sfld = CharField()
# field checksum used for duplicate check.
# integer representation of first 8 digits of sha1 hash of the first field
csum = IntegerField()
# unused
flags = IntegerField()
# unused
data = CharField()
class Meta:
database = db
db_table = 'notes'
class Card(Model):
# the epoch milliseconds of when the card was created
id = IntegerField()
# notes.id
nid = IntegerField()
# deck id (available in col table)
did = IntegerField()
# ordinal : identifies which of the card templates it corresponds to
# valid values are from 0 to num templates - 1
ord = IntegerField()
# modificaton time as epoch seconds
mod = IntegerField()
# update sequence number : used to figure out diffs when syncing.
# value of -1 indicates changes that need to be pushed to server.
# usn < server usn indicates changes that need to be pulled from server.
usn = IntegerField()
# 0=new, 1=learning, 2=due
type = IntegerField()
# Same as type, but -1=suspended, -2=user buried, -3=sched buried
queue = IntegerField()
# Due is used differently for different card types:
# new: note id or random int
# due: integer day, relative to the collection's creation time
# learning: integer timestamp
due = IntegerField()
# interval (used in SRS algorithm). Negative = seconds, possitive = days
ivl = IntegerField()
# factor (used in SRS algorithm)
factor = IntegerField()
# number of reviews
reps = IntegerField()
# the number of times the card went from a "was answered correctly"
# to "was answered incorrectly" state
lapses = IntegerField()
# reps left till graduation
left = IntegerField()
# original due: only used when the card is currently in filtered deck
odue = IntegerField()
# original did: only used when the card is currently in filtered deck
odid = IntegerField()
# currently unused
flags = IntegerField()
# currently unused
data = CharField()
class Meta:
database = db
db_table = 'cards'