Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
soitool
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
bachelor-paa-bittet
soitool
Commits
864c1006
Commit
864c1006
authored
5 years ago
by
Anders H. Rebner
Browse files
Options
Downloads
Patches
Plain Diff
#58 get_codebook sorterer på Word eller Code
parent
685c5d4b
No related branches found
Branches containing commit
No related tags found
1 merge request
!33
#58 Lag PDF med kode- og dekodebok
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
soitool/database.py
+19
-4
19 additions, 4 deletions
soitool/database.py
with
19 additions
and
4 deletions
soitool/database.py
+
19
−
4
View file @
864c1006
...
...
@@ -2,6 +2,7 @@
import
os
import
sqlite3
import
json
from
enum
import
Enum
import
soitool.coder
# Set name and path to (future) database
...
...
@@ -21,6 +22,12 @@ CATEGORYWORDS = (
BYHEART
=
"
CREATE TABLE ByHeart(Word VARCHAR PRIMARY KEY)
"
class
CodebookSort
(
Enum
):
"""
Enumerate with ways to sort codebook.
"""
WORD
=
0
CODE
=
1
class
Database
:
"""
Holds database-connection and related functions.
...
...
@@ -137,7 +144,7 @@ class Database:
return
categories
def
get_codebook
(
self
,
small
=
False
):
def
get_codebook
(
self
,
small
=
False
,
sort
=
CodebookSort
.
WORD
):
"""
Retrieve the entries belonging to the full or small codebook.
...
...
@@ -145,16 +152,24 @@ class Database:
----------
small : Bool
Full or small codebook to be returned
sort : int, optional
0 or 1 (enumerate value from
'
CodebookSort
'
)
Data is sorted by Word if 0 (default), by Code if 1
Returns
-------
codebook : list (of dicts)
[{
'
word
'
: str,
'
type
'
: str,
'
category
'
: str,
'
code
'
: str}]
"""
stmt
=
"
SELECT * FROM (SELECT * FROM CodeBook
"
if
sort
==
CodebookSort
.
WORD
:
stmt
=
stmt
+
"
ORDER BY Word)
"
elif
sort
==
CodebookSort
.
CODE
:
stmt
=
stmt
+
"
ORDER BY Code)
"
# Get either full or small codebook
stmt
=
"
SELECT * FROM CodeBook
"
if
small
:
stmt
=
stmt
+
"
WHERE Type = ?
"
stmt
=
stmt
+
"
WHERE Type = ?
"
# T?
queried
=
self
.
conn
.
execute
(
stmt
,
(
1
,)).
fetchall
()
else
:
queried
=
self
.
conn
.
execute
(
stmt
).
fetchall
()
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment