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
63d2556d
Commit
63d2556d
authored
5 years ago
by
morkolai
Browse files
Options
Downloads
Patches
Plain Diff
#52 Fikset QTimer og fikset add_code_to med mye dokumentasjon
parent
8139cd30
No related branches found
Branches containing commit
No related tags found
1 merge request
!27
#52 Automatisk oppdatering av kodebok basert på tid
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
soitool/database.py
+19
-7
19 additions, 7 deletions
soitool/database.py
soitool/main_window.py
+3
-3
3 additions, 3 deletions
soitool/main_window.py
with
22 additions
and
10 deletions
soitool/database.py
+
19
−
7
View file @
63d2556d
...
...
@@ -33,6 +33,7 @@ class Database:
If db is created, tables are created and filled.
Runs a thread that upadtes Code in CodeBook every 24h since last update.
"""
def
__init__
(
self
):
...
...
@@ -51,10 +52,11 @@ class Database:
self
.
fill_tables
()
print
(
"
Tables filled with data.
"
)
# Initiate
s
timer that triggers CodeBook update
# Initiate timer that triggers CodeBook update
self
.
timer
=
QTimer
()
self
.
timer
.
setInterval
(
self
.
seconds_to_next_update
())
self
.
timer
.
timeout
.
connect
(
self
.
update_codebook_auto
)
self
.
timer
.
timeout
.
connect
(
lambda
:
self
.
update_codebook_auto
())
self
.
timer
.
start
()
self
.
conn
.
row_factory
=
sqlite3
.
Row
# Enables row['columnName']
...
...
@@ -247,6 +249,14 @@ class Database:
"""
Generate and insert a code for the new word in DB-table CodeBook.
This function is espescially designed for when a single word is added
to the CodeBook table. A unique code is generate and inserted in
Code which for the parameter word from before were NULL. Dependent on
the number of entries in the table various actions are performed. If
the new word makes the number of entries pass 26^x and the length of
the codes does not have he capacity, all the codes are updatet to an
appropriate length.
Parameters
----------
word : string
...
...
@@ -260,10 +270,15 @@ class Database:
stmt
=
"
SELECT COUNT(*) FROM CodeBook
"
number_of_entries
=
self
.
conn
.
execute
(
stmt
).
fetchall
()[
0
][
0
]
stmt
=
"
SELECT Code FROM CodeBook
"
# Incase db is approximate empty, min code lenght is 2
# In special case where table is empty or has a single word, the
# minimal length of codes will be applied
if
number_of_entries
<
2
:
actual_code_len
=
soitool
.
coder
.
get_code_length_needed
(
0
)
actual_code_len
=
soitool
.
coder
.
get_code_length_needed
(
number_of_entries
)
else
:
# Since the newly added word's code is NULL and at [0][0],
# get [1][0] to get code length from an actual code
actual_code_len
=
len
(
self
.
conn
.
execute
(
stmt
).
fetchall
()[
1
][
0
])
needed_code_len
=
soitool
.
coder
.
get_code_length_needed
(
...
...
@@ -283,6 +298,3 @@ class Database:
# Insert code to the param word in db
stmt
=
"
UPDATE CodeBook SET Code = ? WHERE Word = ?
"
self
.
conn
.
execute
(
stmt
,
(
code
,
word
))
DB
=
Database
()
This diff is collapsed.
Click to expand it.
soitool/main_window.py
+
3
−
3
View file @
63d2556d
...
...
@@ -9,7 +9,7 @@ from enum import Enum
from
PySide2.QtWidgets
import
QMainWindow
,
QApplication
,
QTabWidget
,
QAction
from
PySide2.QtGui
import
QIcon
from
soitool.soi_workspace_widget
import
SOIWorkspaceWidget
from
soitool.database
import
D
B
from
soitool.database
import
D
atabase
class
ModuleType
(
Enum
):
...
...
@@ -28,8 +28,8 @@ class MainWindow(QMainWindow):
self
.
setWindowTitle
(
"
SOI-tool
"
)
self
.
statusBar
()
#
Start Qtimer that triggers db updat
e
D
B
.
timer
.
start
()
#
Database instanc
e
D
atabase
()
# flytt ut til egen funksjon, for setup av menubar
menu
=
self
.
menuBar
()
...
...
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