Skip to content

Commit

Permalink
Update main (#11)
Browse files Browse the repository at this point in the history
* added new average calculation for the values

* add everage

* changed formular

* updaed

* fixed spelling and some other errors

* added todo

* Switched to poetry and venv

* some linting

* added pre-commit

* reformatted with black

* change code from index to new file

* added the config menue / modal

* added vscode

* mocked spidev in dev mode

* fixed some spelling ??

* Added blinking

* updated blinking to invisable

* added comment

* deleted unused png

* added legend bottom right

* run pre-commit on all files

* change to config instead of global variables

* changed the AFR calculation

* added error check

* added pyinstaller

* fixed exception if ENV not set

* fixed know issue in package eventlet/eventlet#702

* fixed exception if ENV not set

* changed config and can change correction from web interface

* added devcontainer

* some code fixes (#7)

* nachkomastellen default zu 2 (#8)

* Set blinking and removed error warning (#10)

* blinking is in settings

* removed error checking

Co-authored-by: Glaser <florian.glaser@ifm.com>
  • Loading branch information
Floskinner and Floskinner committed Dec 29, 2022
1 parent f861c91 commit 3bb6877
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 37 deletions.
30 changes: 30 additions & 0 deletions .devcontainer/devcontainer.json
@@ -0,0 +1,30 @@
{
"image": "python:3.7.3",
"forwardPorts": [8080],
"customizations": {
// Configure properties specific to VS Code.
"vscode": {
// Add the IDs of extensions you want installed when the container is created.
"extensions": [
"ms-python.python",
"njpwerner.autodocstring",
"naumovs.color-highlight",
"GitHub.copilot",
"donjayamanne.githistory",
"mhutchie.git-graph",
"oderwat.indent-rainbow",
"ms-python.vscode-pylance",
"Gruntfuggly.todo-tree",
"yzhang.markdown-all-in-one"
]
}
},
"features": {
"ghcr.io/devcontainers/features/git:1": {},
"ghcr.io/devcontainers-contrib/features/poetry:1": {}
},
"remoteEnv": {
"FLASK_ENV": "development"
},
"postCreateCommand": "poetry config virtualenvs.in-project true && poetry install"
}
11 changes: 6 additions & 5 deletions starter.py
Expand Up @@ -98,6 +98,9 @@ def update_data(update_interval: float, messure_interval: float):

socketio.emit("newValues", data, broadcast=True)

# Ohne warten wird emit nicht zuverlässig durchgeführt
socketio.sleep(0.01)

if IS_RECORDING:
record_thread = Thread(target=write_to_db, args=(data,), daemon=True)
record_thread.start()
Expand Down Expand Up @@ -255,11 +258,6 @@ def recording(json: dict):
IS_RECORDING = False
write_to_systemd("stoppe Aufnahme")


if __name__ == "__main__":
socketio.run(app, debug=True, port=8080, host="0.0.0.0")


# Clean data from DB older than 6 Months
if os.environ.get("FLASK_ENV") != "development":
db_delete_time_string = (datetime.datetime.now() - datetime.timedelta(days=config.DB_DELETE_AELTER_ALS)).strftime(
Expand All @@ -268,3 +266,6 @@ def recording(json: dict):
query = "DELETE WHERE time < '" + db_delete_time_string + "'"
write_to_systemd(f"Delete Data older than {db_delete_time_string}")
result = client.query(query)

if __name__ == "__main__":
socketio.run(app, debug=True, port=8080, host="0.0.0.0")
48 changes: 18 additions & 30 deletions static/javascript/mySockets.js
Expand Up @@ -10,6 +10,8 @@ const MAX_ABOVE_RED = 1.20;
const MAX_BELOW_ORANGE = 0.86;
const MAX_BELOW_RED = 0.80;

let blinking = false;

socket.on('connect', function () {
let browserTime = new Date().toISOString();

Expand All @@ -19,13 +21,26 @@ socket.on('connect', function () {

});

socket.on("connect_error", (error) => {
console.log("Error connecting to server: " + error);
});

socket.on("disconnect", (reason) => {
console.log("Disconnected from server: " + reason);
if (reason === "io server disconnect") {
// the disconnection was initiated by the server, you need to reconnect manually
socket.connect();
}
// else the socket will automatically try to reconnect
});

socket.on('disconnect', function () {
socket.emit('disconnect', {
data: 'User Disconnected'
});

});


socket.on('newValues', function (values) {
// console.log(JSON.stringify(values));

Expand All @@ -41,13 +56,10 @@ socket.on('newValues', function (values) {
applyWarningColors($("#lamda1"), lamda1);
applyWarningColors($("#lamda2"), lamda2);

checkErrors($('#bank1Label'), $('#lamda1'), $('#afr1'), voltage1);
checkErrors($('#bank2Label'), $('#lamda2'), $('#afr2'), voltage2);

if (lamda1 >= MAX_ABOVE_RED || lamda1 <= MAX_BELOW_RED) {
if ((lamda1 >= MAX_ABOVE_RED || lamda1 <= MAX_BELOW_RED) && blinking) {
applyRedBlinking($("#lamda1"));
}
if (lamda2 >= MAX_ABOVE_RED || lamda2 <= MAX_BELOW_RED) {
if ((lamda2 >= MAX_ABOVE_RED || lamda2 <= MAX_BELOW_RED) && blinking) {
applyRedBlinking($("#lamda2"));
}
});
Expand All @@ -62,30 +74,6 @@ function updateValuesOnScreen(lamda1, lamda2, afr1, afr2) {
$('#afr2').html(afr2.toFixed(2) + " AFR");
}

function checkErrors(htmlBankLabel, htmlLamda, htmlAFR, voltage) {
label = htmlBankLabel.html();
color = "#000000";
lamda = htmlLamda.html();
afr = htmlAFR.html();

if (Math.abs(voltage) <= 0.15) {
// label += " - Fehler";
color= "#b30000";
lamda = "Fehler";
afr = "--------";
} else if (Math.abs(voltage) <= 0.2) {
// label += " - Heizphase";
color= "#b30000";
lamda = "Heizphase";
afr = "--------";
}

htmlBankLabel.html(label);
htmlBankLabel.css("color", color);
htmlLamda.html(lamda);
htmlAFR.html(afr);
}

function applyWarningColors(htmlElement, lamdaValue) {
// Sind die Werte von Lamda entsprechend, wird der Text erst Orange und dann Rot
if (lamdaValue >= MAX_ABOVE_ORANGE || lamdaValue <= MAX_BELOW_ORANGE) {
Expand Down
12 changes: 10 additions & 2 deletions templates/index.html
Expand Up @@ -77,13 +77,17 @@ <h4>Anzuzeigende Banken:</h4>
<label>Bank 2 &#128308</label><br>

<h4>Anzuzeigende Nachkommastellen:</h4>
<input class="w3-radio" type="radio" name="nachkommastellen" value="1" checked>
<input class="w3-radio" type="radio" name="nachkommastellen" value="1">
<label>1</label><br>
<input class="w3-radio" type="radio" name="nachkommastellen" value="2" checked>
<label>2</label><br>
<input class="w3-radio" type="radio" name="nachkommastellen" value="3" checked>
<input class="w3-radio" type="radio" name="nachkommastellen" value="3">
<label>3</label><br>

<h4>Blinken der Werte im roten Bereich:</h4>
<input class="w3-check" type="checkbox" onchange=toggle_blinking(this)>
<label>Blinken</label><br>

<hr>

<h4>Korrekturfaktor für Lamdaberechnung:</h4>
Expand Down Expand Up @@ -208,6 +212,10 @@ <h4>Korrekturfaktor für Lamdaberechnung:</h4>
$('#warning').toggle();
}

function toggle_blinking(checkbox) {
blinking = checkbox.checked;
}

</script>

</html>

0 comments on commit 3bb6877

Please sign in to comment.