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
b0aa994d
Commit
b0aa994d
authored
5 years ago
by
morkolai
Browse files
Options
Downloads
Patches
Plain Diff
#52 modus for auto oppdatering i db-klasse og optimalisering av test_update_codebook + div
parent
022e7a5c
No related branches found
Branches containing commit
No related tags found
1 merge request
!27
#52 Automatisk oppdatering av kodebok basert på tid
Pipeline
#74996
failed
5 years ago
Stage: lint
Stage: test
Stage: deploy
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
soitool/database.py
+13
-12
13 additions, 12 deletions
soitool/database.py
test/test_database.py
+8
-9
8 additions, 9 deletions
test/test_database.py
with
21 additions
and
21 deletions
soitool/database.py
+
13
−
12
View file @
b0aa994d
...
...
@@ -38,7 +38,7 @@ class Database:
Holds a QTimer that requests an update of CodeBook on every timeout.
"""
def
__init__
(
self
):
def
__init__
(
self
,
auto_update
=
True
):
db_exists
=
os
.
path
.
exists
(
DBPATH
)
if
db_exists
:
...
...
@@ -55,12 +55,13 @@ class Database:
print
(
"
Tables filled with data.
"
)
# Initiate timer that triggers CodeBook update
# self.timer = QTimer()
# self.timer.setInterval(
# self.seconds_to_next_update(SECONDS_IN_24H * 1000)
# )
# self.timer.timeout.connect(lambda: self.update_codebook_auto())
# self.timer.start()
if
auto_update
:
self
.
timer
=
QTimer
()
self
.
timer
.
setInterval
(
self
.
seconds_to_next_update
(
SECONDS_IN_24H
*
1000
)
)
self
.
timer
.
timeout
.
connect
(
lambda
:
self
.
update_codebook_auto
())
self
.
timer
.
start
()
self
.
conn
.
row_factory
=
sqlite3
.
Row
# Enables row['columnName']
...
...
@@ -247,16 +248,16 @@ class Database:
# Since QTimer does not handle negative values
if
seconds_to_update
<=
0
:
return
0
else
:
return
seconds_to_update
return
seconds_to_update
def
update_codebook_auto
(
self
):
"""
Update Codebook if needed and set new time for timer.
"""
if
self
.
seconds_to_next_update
(
SECONDS_IN_24H
)
<
10
:
self
.
update_codebook
()
#
self.timer.setInterval(
#
self.seconds_to_next_update(SECONDS_IN_24H * 1000)
#
)
self
.
timer
.
setInterval
(
self
.
seconds_to_next_update
(
SECONDS_IN_24H
*
1000
)
)
def
add_code_to
(
self
,
word
,
mode
=
"
ascii
"
):
"""
...
...
This diff is collapsed.
Click to expand it.
test/test_database.py
+
8
−
9
View file @
b0aa994d
...
...
@@ -16,7 +16,7 @@ class DatabaseTest(unittest.TestCase):
def
setUp
(
self
):
"""
Connect to/create database.
"""
self
.
database
=
Database
()
self
.
database
=
Database
(
auto_update
=
False
)
def
test_connection
(
self
):
"""
Assert connection is not None.
"""
...
...
@@ -203,18 +203,17 @@ class DatabaseTest(unittest.TestCase):
def
test_update_codebook
(
self
):
"""
Test that the codes get updated.
"""
# Get number of entries
stmt
=
"
SELECT COUNT(*) FROM CodeBook
"
number_of_entries
=
self
.
database
.
conn
.
execute
(
stmt
).
fetchall
()[
0
][
0
]
# Get old and updated word-code combinations
# Get entries before and after update
stmt
=
"
SELECT Word, Code FROM CodeBook ORDER BY Word
"
old
=
self
.
database
.
conn
.
execute
(
stmt
).
fetchall
()
old
_entries
=
self
.
database
.
conn
.
execute
(
stmt
).
fetchall
()
self
.
database
.
update_codebook
()
updated
=
self
.
database
.
conn
.
execute
(
stmt
).
fetchall
()
# Collect approximately score of not updated pairs
new_entries
=
self
.
database
.
conn
.
execute
(
stmt
).
fetchall
()
# Collect approximately score of not updated pairs since there is a
# chance for a word to get the same code again
pairs
=
0
number_of_entries
=
len
(
old_entries
)
for
i
in
range
(
0
,
number_of_entries
,
2
):
if
old
[
i
][
"
Code
"
]
==
updated
[
i
][
"
Code
"
]:
if
old
_entries
[
i
][
"
Code
"
]
==
new_entries
[
i
][
"
Code
"
]:
pairs
=
pairs
+
1
# Test that at least some of the test are new
self
.
assertTrue
(
pairs
<
number_of_entries
)
...
...
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