Code Cleanup
This commit is contained in:
		
							
								
								
									
										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,26 +7,29 @@ | |||||||
| # oder unter z. B. Ubuntu: apt install python3-xlrd python3-sqlite3 | # oder unter z. B. Ubuntu: apt install python3-xlrd python3-sqlite3 | ||||||
| # | # | ||||||
|  |  | ||||||
| import xlrd |  | ||||||
| import sqlite3 | import sqlite3 | ||||||
|  | import xlrd | ||||||
|  |  | ||||||
| SQLITE_FILE = "database.db" | SQLITE_FILE = "database.db" | ||||||
| con = sqlite3.connect(SQLITE_FILE) | 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.execute("create table pruefungsergebnis (pruefung_id int not null, "\ | ||||||
|  | #    + "mtknr int not null, note decimal(3,1), primary key(pruefung_id, mtknr))") | ||||||
| #con.commit() | #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 | PRUEFUNG_ID = 3 | ||||||
|  |  | ||||||
| def read_file(filename): | def read_file(filename): | ||||||
|     # alle Validierungsschritte zugunsten eines übersichtlichen Beispiels eingespart |     # alle Validierungsschritte zugunsten eines übersichtlichen Beispiels eingespart | ||||||
|     xlfile = xlrd.open_workbook(filename)  |     xlfile = xlrd.open_workbook(filename) | ||||||
|     xlsheet = xlfile.sheet_by_index(0)   |     xlsheet = xlfile.sheet_by_index(0) | ||||||
|     print(f"Importiere aus {filename} - {xlsheet.name}") |     print(f"Importiere aus {filename} - {xlsheet.name}") | ||||||
|  |  | ||||||
|     data = { |     data = { | ||||||
|         int(xlsheet.cell(rx, 0).value): xlsheet.cell(rx, 1).value |         int(xlsheet.cell(rx, 0).value): xlsheet.cell(rx, 1).value | ||||||
|         for rx in range(1, xlsheet.nrows)         |         for rx in range(1, xlsheet.nrows) | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     return data |     return data | ||||||
| @@ -42,11 +45,14 @@ def is_already_set(con, pruefung_id, mtknr): | |||||||
|  |  | ||||||
| def is_valid_value(pruefung_id, note): | def is_valid_value(pruefung_id, note): | ||||||
|     # Im realen System z. B. auf der Basis der Notengebungsart etc. prüfen |     # 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): | 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 = con.cursor() | ||||||
|     cur.execute(sql, (pruefung_id, mtknr, note)) |     cur.execute(sql, (pruefung_id, mtknr, note)) | ||||||
|     result = cur.fetchone()[0] |     result = cur.fetchone()[0] | ||||||
| @@ -56,19 +62,21 @@ def is_modified(con, pruefung_id, mtknr, note): | |||||||
| def merge_data(pruefung_id, new_data): | def merge_data(pruefung_id, new_data): | ||||||
|     update_sql = "update pruefungsergebnis set note = ? where pruefung_id = ? and mtknr = ?" |     update_sql = "update pruefungsergebnis set note = ? where pruefung_id = ? and mtknr = ?" | ||||||
|     insert_sql = "insert into pruefungsergebnis (pruefung_id, mtknr, note) values (?, ?, ?)" |     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(): |         for mtknr in new_data.keys(): | ||||||
|             note = new_data[mtknr] |             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_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)") |                         print(f"Wollen Sie die Note zu {mtknr} auf {note} aktualisieren? (j/n)") | ||||||
|                         answer = input() |                         answer = input() | ||||||
|                         if answer == 'j': |                         if answer == 'j': | ||||||
|                             con.execute(update_sql, (note, pruefung_id, mtknr)) |                             connection.execute(update_sql, (note, pruefung_id, mtknr)) | ||||||
|                             print(f"angepasst") |                             print("angepasst") | ||||||
|                         else: |                         else: | ||||||
|                             print(f"unverändert") |                             print("unverändert") | ||||||
|                     else: |                     else: | ||||||
|                         print(f"Note zu {mtknr} wird nicht geändert, Notenwert unverändert") |                         print(f"Note zu {mtknr} wird nicht geändert, Notenwert unverändert") | ||||||
|                 else: |                 else: | ||||||
| @@ -77,7 +85,7 @@ def merge_data(pruefung_id, new_data): | |||||||
|                 print(f"Mtknr: {mtknr} Note: {note} hinzufügen") |                 print(f"Mtknr: {mtknr} Note: {note} hinzufügen") | ||||||
|                 # im Falle von HISinOne wegen bereits bestehendem Anmeldesatz auch Update, so aber |                 # im Falle von HISinOne wegen bereits bestehendem Anmeldesatz auch Update, so aber | ||||||
|                 # einfacher im Beispiel darzustellen... |                 # einfacher im Beispiel darzustellen... | ||||||
|                 con.execute(insert_sql, (pruefung_id, mtknr, note))                 |                 connection.execute(insert_sql, (pruefung_id, mtknr, note)) | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Wolfgang Wiedermann
					Wolfgang Wiedermann