From 4fdbf579afa8d095ffcafda5464da2853f15deb4 Mon Sep 17 00:00:00 2001
From: 42loop <ulf.freyhoff@gmx.net>
Date: Sun, 2 Sep 2018 16:56:15 +0200
Subject: [PATCH] first (late) commit

---
 showstats.py | 23 +++++++++++++++++++++--
 1 file changed, 21 insertions(+), 2 deletions(-)

diff --git a/showstats.py b/showstats.py
index 4bbaf5c..8a10840 100644
--- a/showstats.py
+++ b/showstats.py
@@ -44,11 +44,30 @@ def db_dump():
         cur.execute("SELECT * FROM trains")
 
         rows = cur.fetchall()
+        train_time=0
+        last_et_stamp=0
+        last_st_stamp=0
 
         for row in rows:
             #print(row[1])
-            st = datetime.datetime.fromtimestamp(float(row[1])-7200.0) #.strftime('%Y-%m-%d %H:%M:%S'))
-            print(st,float(row[2])*1000000)
+            st_stamp=float(row[1])-7200.0
+            if st_stamp>last_et_stamp+45:
+                st = datetime.datetime.fromtimestamp(last_st_stamp) #.strftime('%Y-%m-%d %H:%M:%S'))
+                et = datetime.datetime.fromtimestamp(last_et_stamp)
+
+                if train_time>2:
+                    #print(st," to ", et," train_time: ",train_time)
+                    print(str(last_st_stamp)+",%.2f" % train_time) 
+                #print("----------------new train")
+                last_st_stamp=st_stamp
+                train_time=0
+            train_time+=float(row[2])
+            et_stamp=float(row[1])-7200.0+float(row[2])
+            st = datetime.datetime.fromtimestamp(st_stamp) #.strftime('%Y-%m-%d %H:%M:%S'))
+            et = datetime.datetime.fromtimestamp(et_stamp)
+            #print(st,float(row[2]),et)
+
+            last_et_stamp=et_stamp
 
 def db_create():
     global con
-- 
GitLab