-
Notifications
You must be signed in to change notification settings - Fork 1
/
datastores.py
68 lines (48 loc) · 1.38 KB
/
datastores.py
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
"""Data persistence layer for rightload."""
from flask import g
from os.path import basename
import shove
def _get_shove_db(path):
"""Get or create a sqlite-backed shove db.
Parameters
----------
path : string
Path to sqlite db, opened or created as needed.
Returns
-------
Shove object
A dict-like object backed by the db at path, attached to flask context.
"""
attr_name = "_" + basename(path)
db = getattr(g, attr_name, None)
if db is None:
db = shove.Shove("lite://" + path)
setattr(g, attr_name, db)
return db
def feed_db():
"""Access feed db.
This is just a cache for feed processing, only for performance and to be nice on the web servers.
Returns
-------
Shove object
A Shove object with feed urls as keys and feed content as values.
"""
return _get_shove_db("feed.sqlite")
def training_db():
"""Access training db.
This has the user feedback as (url, feedback) pairs.
Returns
-------
Shove object
Shove object with urls as keys and feedback info as values.
"""
return _get_shove_db("training.sqlite")
def model_db():
"""Access for model db.
This stores the learning model.
Returns
-------
Shove object
Shove object with a single key and value a sklearn model.
"""
return _get_shove_db("model.sqlite")