Code Cleanup
This commit is contained in:
parent
2e4b7174a9
commit
989e1a7eca
23
.github/workflows/pylint.yml
vendored
23
.github/workflows/pylint.yml
vendored
@ -1,23 +0,0 @@
|
||||
name: Pylint
|
||||
|
||||
on: [push]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
matrix:
|
||||
python-version: ["3.8", "3.9", "3.10"]
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: Set up Python ${{ matrix.python-version }}
|
||||
uses: actions/setup-python@v3
|
||||
with:
|
||||
python-version: ${{ matrix.python-version }}
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
python -m pip install --upgrade pip
|
||||
pip install pylint
|
||||
- name: Analysing the code with pylint
|
||||
run: |
|
||||
pylint $(git ls-files '*.py')
|
@ -7,15 +7,18 @@
|
||||
# oder unter z. B. Ubuntu: apt install python3-xlrd python3-sqlite3
|
||||
#
|
||||
|
||||
import xlrd
|
||||
import sqlite3
|
||||
import xlrd
|
||||
|
||||
SQLITE_FILE = "database.db"
|
||||
con = sqlite3.connect(SQLITE_FILE)
|
||||
#con.execute("create table pruefungsergebnis (pruefung_id int not null, mtknr int not null, note decimal(3,1), primary key(pruefung_id, mtknr))")
|
||||
connection = sqlite3.connect(SQLITE_FILE)
|
||||
|
||||
#con.execute("create table pruefungsergebnis (pruefung_id int not null, "\
|
||||
# + "mtknr int not null, note decimal(3,1), primary key(pruefung_id, mtknr))")
|
||||
#con.commit()
|
||||
|
||||
# Hier als Konstante, da in der Praxis wahrscheinlich aus Kontext in Webanwendung abgeleitet
|
||||
# Hier als Konstante, da in der Praxis wahrscheinlich aus Kontext
|
||||
# in Webanwendung abgeleitet
|
||||
PRUEFUNG_ID = 3
|
||||
|
||||
def read_file(filename):
|
||||
@ -42,11 +45,14 @@ def is_already_set(con, pruefung_id, mtknr):
|
||||
|
||||
def is_valid_value(pruefung_id, note):
|
||||
# Im realen System z. B. auf der Basis der Notengebungsart etc. prüfen
|
||||
return note is not None and note in [1, 1.3, 1.7, 2, 2.3, 2.7, 3, 3.3, 3.7, 4, 5]
|
||||
return note is not None and note in [
|
||||
1, 1.3, 1.7, 2, 2.3, 2.7, 3, 3.3, 3.7, 4, 5
|
||||
]
|
||||
|
||||
|
||||
def is_modified(con, pruefung_id, mtknr, note):
|
||||
sql = "select count(*) as anzahl from pruefungsergebnis where pruefung_id = ? and mtknr = ? and note = ?"
|
||||
sql = "select count(*) as anzahl from pruefungsergebnis" \
|
||||
+ " where pruefung_id = ? and mtknr = ? and note = ?"
|
||||
cur = con.cursor()
|
||||
cur.execute(sql, (pruefung_id, mtknr, note))
|
||||
result = cur.fetchone()[0]
|
||||
@ -56,19 +62,21 @@ def is_modified(con, pruefung_id, mtknr, note):
|
||||
def merge_data(pruefung_id, new_data):
|
||||
update_sql = "update pruefungsergebnis set note = ? where pruefung_id = ? and mtknr = ?"
|
||||
insert_sql = "insert into pruefungsergebnis (pruefung_id, mtknr, note) values (?, ?, ?)"
|
||||
with con: # Transaktionsscope: Fehler führt zuverlässig zum Verwerfen aller Änderungen aus einer Excel-Datei
|
||||
# Transaktionsscope: Fehler führt zuverlässig zum Verwerfen
|
||||
# aller Änderungen aus einer Excel-Datei
|
||||
with connection:
|
||||
for mtknr in new_data.keys():
|
||||
note = new_data[mtknr]
|
||||
if is_already_set(con, pruefung_id, mtknr):
|
||||
if is_already_set(connection, pruefung_id, mtknr):
|
||||
if is_valid_value(pruefung_id, note):
|
||||
if is_modified(con, pruefung_id, mtknr, note):
|
||||
if is_modified(connection, pruefung_id, mtknr, note):
|
||||
print(f"Wollen Sie die Note zu {mtknr} auf {note} aktualisieren? (j/n)")
|
||||
answer = input()
|
||||
if answer == 'j':
|
||||
con.execute(update_sql, (note, pruefung_id, mtknr))
|
||||
print(f"angepasst")
|
||||
connection.execute(update_sql, (note, pruefung_id, mtknr))
|
||||
print("angepasst")
|
||||
else:
|
||||
print(f"unverändert")
|
||||
print("unverändert")
|
||||
else:
|
||||
print(f"Note zu {mtknr} wird nicht geändert, Notenwert unverändert")
|
||||
else:
|
||||
@ -77,7 +85,7 @@ def merge_data(pruefung_id, new_data):
|
||||
print(f"Mtknr: {mtknr} Note: {note} hinzufügen")
|
||||
# im Falle von HISinOne wegen bereits bestehendem Anmeldesatz auch Update, so aber
|
||||
# einfacher im Beispiel darzustellen...
|
||||
con.execute(insert_sql, (pruefung_id, mtknr, note))
|
||||
connection.execute(insert_sql, (pruefung_id, mtknr, note))
|
||||
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user