Browse Source

fix: update_memcache_index with active =count_active_dmx_ch(dmx)

micha 6 months ago
parent
commit
c1347ffafd
1 changed files with 23 additions and 26 deletions
  1. 23 26
      ArtNetProcessor.py

+ 23 - 26
ArtNetProcessor.py

@@ -93,7 +93,7 @@ def memcachd_index_clear():
 
 memcachd_index_clear()
 
-def memcachd_index(key,val=""):
+def update_memcachd_index(key,val="",active=-1):
     try:
         _index =  mc.get("index")
         #print("A",_index)
@@ -101,17 +101,25 @@ def memcachd_index(key,val=""):
             _index = {}
         #print("A",_index)
 
-        if key in _index:
-            _index[key] += 1
-        else:
-            _index[key] = 1
+        if key not in _index:
+            _index[key] = [0,-33]
+        _index[key][0] += 1
+        _index[key][1] = active
+
+
         mc.set("index",_index)
     except Exception as e:
         print("memcach exception",e)
 
 
-
-
+def count_active_dmx_ch(dmx):
+    active = 0
+    for i,v in enumerate(dmx):
+        if type(v) is int and v>=1:
+            if active < 0:
+                active = 0
+            active += 1
+    return active
 # ============================================================   
 # Text Grafik Curses =========================================   
 # ============================================================   
@@ -559,7 +567,6 @@ class UniversBuffer():
         dmxframe_old = self.__universes_dmx[host]
 
         self._next_frame(host)
-
         #if len(dmxframe) <= 512: #len(dmxframe_old):
         if cython:# "cython":
             if len(dmxframe) <= 512: #len(dmxframe_old):
@@ -592,6 +599,7 @@ class UniversBuffer():
         #tmp["hosts"] = self.__hosts
         tmp["uni"] = self.__univers_nr 
         tmp["fps"] = self.__universes_fps[host]
+        tmp["active"] = count_active_dmx_ch(dmxframe)
         self.__universes_info[host] = tmp
         if update_flag:
             #print( "UPDATE HOST:",host, update_flag,"UNIV:",self.__univers_nr)
@@ -1055,7 +1063,9 @@ class Main():
                     try:
                         k = "{}:{}".format(x["host"],x["univ"])
                         mc.set(k, x["dmx"])  # "dmx-{}".format(univ), ltp)
-                        memcachd_index(key=k)
+
+                        active = count_active_dmx_ch(x["dmx"])
+                        update_memcachd_index(key=k,active=active)
                     except Exception as e:
                         print("exception:",e)
                         time.sleep(.1)
@@ -1074,10 +1084,6 @@ class Main():
                 screen.sel_univ.data = ohost.univs()
                 screen.sel_host.data = ohost.hosts()
 
-                #if x:
-                #     #screen.exit()
-                #     print( "poll_clean",x)
-
                 if ohost_timer.check():
                     for i in ohost_buf:
                         for j in ohost_buf[i]:
@@ -1090,34 +1096,25 @@ class Main():
 
                     #x=ohost.get(univ=univ2)
                     info=ohost.info()
-                    #print( info)
                     jinfo = ""
+
                     for i in info:
                         univ = i
-                        #print( [ univ])
                         if str(univ) == "54":
                             break
                         xl = json.dumps(univ) + "======= " #XX
                         ltp=ohost.get(univ=i)
                         
-                        #print( xl )
-                        #print( len(ltp) ,ltp[:20])
-                        #print( "univ", univ )
                         try:
                             k="ltp-out:{}".format(univ)
                             mc.set(k,ltp)
-                            memcachd_index(key=k)
+                            active = count_active_dmx_ch(ltp)
+                            update_memcachd_index(key=k,active=active)
                         except Exception as e:
-                            pass#
-                            #print("Exception",e)
+                            print("Exc memcachd_index1 ",e)
 
-                        #ltp[511] = int(univ) # set uni nr to last dmx ... testing only
                         artnet_out.univ=int(univ)
                         artnet_out.send(ltp)
-                        #for j in info[i]:
-                        #    print( str(univ)+" " + json.dumps([j,""]) )
-                        #    for k in info[i][j]:
-                        #        print( str(univ)+ "   "+str(k).ljust(5," ")+": " + json.dumps( info[i][j][k]) )
 
                 if not poll_flag: 
                     time.sleep(.001)