From c58bea19e09a987bac4a6b17ce146f5871205215 Mon Sep 17 00:00:00 2001
From: Lennard <27106448+SirWalross@users.noreply.github.com>
Date: Tue, 21 Jun 2022 23:10:21 +0200
Subject: [PATCH] Remove debug info and add check for overwriting previous
 commit

---
 .gitignore        |  3 ++-
 main.py           | 25 +++++++------------------
 scripts/push.bash | 20 +++++++++++++-------
 3 files changed, 22 insertions(+), 26 deletions(-)

diff --git a/.gitignore b/.gitignore
index 713dd31..a1f94ae 100644
--- a/.gitignore
+++ b/.gitignore
@@ -3,4 +3,5 @@ out/*
 CHANGELOG.md
 profiling.log
 data/data
-data.zip
\ No newline at end of file
+data.zip
+__pycache__/**
\ No newline at end of file
diff --git a/main.py b/main.py
index 684c1c6..4a48178 100644
--- a/main.py
+++ b/main.py
@@ -152,8 +152,6 @@ def main(config: Any) -> None:
         last_write = time.time()
         data = np.zeros((8,))
         n = 0
-        recv1, recv2 = None, None
-        off1, off2 = None, None
         while datetime.datetime.now() + datetime.timedelta(seconds=delta_time) < end_time:
 
             try:
@@ -162,30 +160,24 @@ def main(config: Any) -> None:
 
                 con1.write(1)
                 # offsets for writing data in correct column
-                off1 = 0 if int(convert(con1.readline())) == 1.0 else 4
+                off = 0 if int(convert(con1.readline())) == 1.0 else 4
 
                 # read data
                 for i in range(4):
-                    recv1 = con1.readline()
-                    new_data[i + off1] += float(convert(recv1))
-                    recv1 = None
-                off1 = None
+                    new_data[i + off] += float(convert(con1.readline()))
 
                 con2.write(1)
                 # offsets for writing data in correct column
-                off2 = 0 if int(convert(con2.readline())) == 1.0 else 4
+                off = 0 if int(convert(con2.readline())) == 1.0 else 4
 
                 for i in range(4):
-                    recv2 = con2.readline()
-                    new_data[i + off2] += float(convert(recv2))
-                    recv2 = None
-                off2 = None
+                    new_data[i + off] += float(convert(con2.readline()))
 
                 n += 1
                 data = new_data
             except (TypeError, ValueError):
-                # may occur if no data was read over serial, but why???
-                logger.info(f"Didn't receive data from arduino, off1: {off1}, off2: {off2}, recv1: {recv1}, recv2: {recv2}", exc_info=True)
+                # may occur if no data was read over serial
+                logger.info("Didnt receive data from arduino", exc_info=True)
 
             if time.time() - last_write > delta_time:
                 # write data
@@ -196,12 +188,9 @@ def main(config: Any) -> None:
                 last_write = time.time()
 
     fh[0].doRollover() # rollover the current data log file
-    
-    
-    Path(f"{Path(__file__).parent}/data/data").unlink(missing_ok=True) # delete old data file
 
     logger.warning("Finished")
 
 
 if __name__ == "__main__":
-    main(yaml.safe_load(open(f"{Path(__file__).parent}/config.yml")))
+    main(yaml.safe_load(open(f"{Path(__file__).parent}/config.yml")))
\ No newline at end of file
diff --git a/scripts/push.bash b/scripts/push.bash
index 8d8dda2..4d4fb21 100755
--- a/scripts/push.bash
+++ b/scripts/push.bash
@@ -6,22 +6,28 @@ while pidof  -x "python3 main.py">/dev/null; do
     echo "python3 main.py is still running, checking in 60 seconds."
     sleep 60
 done
-sleep 10
-
-du -hc --max-depth=1 .
-
-scripts/./write.bash
 
 sleep 10
 
-python3 measure.py
+scripts/./write.bash
 
 sleep 10
 
 echo -e "Starting python script:\n"
-python3 main.py
+if python3 main.py then
+    rm data/data
+fi
 echo -e "\nPython script ended"
 
 git pull
+
+last_commit_name = $(git log -1 --pretty=%B | cat)
+
+if [[ $string == *"New data"* ]]; then
+    # check if the last commit was "New data"
+    # if yes overwrite the commit
+    git reset --soft HEAD~1
+fi
+
 git add .
 git commit -m "New data" && git push --force
\ No newline at end of file
-- 
GitLab