11import sys
22import string
33from builtins import range
4+ from collections import OrderedDict
45# from tkinter import *
56# from tkinter import ttk
67# import matplotlib.pyplot as plt
@@ -12,7 +13,7 @@ def isOcta(number):
1213 if number == "" :
1314 isValid = False
1415 for char in number :
15- if char .isdigit () and int (char )< base :
16+ if char .isdigit () and int (char )< base :
1617 continue
1718 else :
1819 isValid = False
@@ -163,15 +164,15 @@ def removeNoneArrays(array):
163164 return result
164165
165166def toFormula (subscriptionsAll ):
166- if subscriptions == None or len (subscriptions ) == 0 :
167+ if subscriptionsAll == None or len (subscriptionsAll ) == 0 :
167168 return ""
168169 result = ""
169170
170171 for subscription in subscriptionsAll :
171- # subscription=removeNoneArray (subscription)
172- # if subscription != None and len (subscription) != 0:
173- # result+='*'.join(subscription)+'+'
174- result += '*' . join ( subscription ) + '+'
172+ if isinstance (subscription , list ):
173+ result += '*' . join (subscription )+ '+'
174+ else :
175+ result += subscription + '+'
175176
176177 return result .rstrip ('+' )
177178
@@ -187,11 +188,9 @@ def evalFormula(formula, binaries):
187188 for binary in binaries :
188189 newFormula = formula
189190 i = 0
190-
191191 # newFormula=newFormula.replace("x", str(binary[0]))
192192 # newFormula=newFormula.replace("y", str(binary[1]))
193193 # newFormula=newFormula.replace("z", str(binary[2]))
194-
195194 for alpha in alphas :
196195 newFormula = newFormula .replace (alpha + "'" , str (binary [i ]))
197196 newFormula = newFormula .replace (alpha , str (binary [i ]))
@@ -204,6 +203,7 @@ def evalFormula(formula, binaries):
204203 results .append (binary )
205204 return results
206205
206+
207207def nonSubscribers (subscriptions1 , subscriptions2 ):
208208 results = []
209209 if subscriptions1 == None or len (subscriptions1 ) == 0 :
@@ -241,11 +241,87 @@ def removeDublicateValue(array):
241241 result .append (item )
242242 return result
243243
244+ def commonValues (array ):
245+ # if array != None and len(array) != 0:
246+ # print(array)
247+ for x in array [0 ]:
248+ # print("x", x)
249+ tc = 0
250+ for y in array [1 :]:
251+ # print("y", y)
252+ c = 0
253+ for z in y :
254+ # print("z", z)
255+ if z == x :
256+ c = c + 1
257+
258+ if c > 0 :
259+ # print("yes", c)
260+ tc = tc + 1
261+ # else:
262+ # print("no")
263+
264+ # print()
265+
266+ if tc > 0 :
267+ return x
268+ # print("yes", c)
269+ # else:
270+ # print("no")
271+ # print("----------")
272+
273+ return None
274+
275+ def removeValue (array , values ):
276+ result = []
277+ for item in array :
278+ for x in item :
279+ if isinstance (values , list ):
280+ for i in values :
281+ if x != i :
282+ result .append (x )
283+ else :
284+ if x != values :
285+ result .append (x )
286+ return result
287+
288+ def filterGArray (g ):
289+ # print(g)
290+ if len (g ) >= 2 and isinstance (g [1 ], list ):
291+ # print("i",g[1][0])
292+ # n=0
293+ for x in g [1 ][0 ]:
294+ # m=0
295+ for y in g [1 ][0 ]:
296+ # print(x, y)
297+ if (x == "x" and y == "x'" ) or (x == "x'" and y == "x" ):
298+ # print("del", g[1][0])
299+ g [1 ][0 ].remove (x )
300+ g [1 ][0 ].remove (y )
301+ elif (x == "y" and y == "y'" ) or (x == "y'" and y == "y" ):
302+ g [1 ][0 ].remove (x )
303+ g [1 ][0 ].remove (y )
304+ elif (x == "z" and y == "z'" ) or (x == "z'" and y == "z" ):
305+ g [1 ][0 ].remove (x )
306+ g [1 ][0 ].remove (y )
307+ # m=m+1
308+ # n=n+1
309+ g [1 ]= g [1 ][0 ]
310+ if len (g [1 ]) == 0 :
311+ g .remove (g [1 ])
312+ return g
313+
244314# number="156"
245315# number="0367"
246316# number="45"
247317# number="145"
248- number = "457"
318+ # number="457"
319+
320+ # number="1357"
321+ number = "0246"
322+ number = "0167"
323+ number = "1247"
324+ number = "25"
249325countChild = 3
250326numberLength = len (number )
251327alphas = string .ascii_lowercase
@@ -296,61 +372,107 @@ def removeDublicateValue(array):
296372 subscriptions .append (subscription )
297373
298374print ("Subscriptions: " , subscriptions )
299- subscriptionsAll = subscriptionsFilter (subscriptions )
300- print ("SubscriptionsAll: " , subscriptionsAll )
301- if subscriptionsAll != None and len (subscriptionsAll ) != 0 :
302- subscriptionsAllFormula = toFormula (subscriptionsAll )
303- print ("SubscriptionsAllFormula: " , subscriptionsAllFormula ) #It's $g formula
304-
305- gValues = evalFormula (subscriptionsAllFormula , binaries )
306- gValuesCount = len (gValues )
307-
308- print ("gValues: " , gValues )
309- print ("gValuesCount: " , gValuesCount )
310- print ("Compare gValuesCount with binariesLength: " , gValuesCount , "??" , binariesLength )
311- g = []
312- if gValuesCount == binariesLength :
313- print ("\t They are equal!" )
314- g = subscriptionsAll
315- elif gValuesCount < binariesLength :
316- print ("\t binariesLength is bigger then gValuesCount." )
317- g = subscriptionsAll
318- print ("Diff two array:" )
319- print ("\t subscriptions1: " , binaries )
320- print ("\t subscriptions2: " , gValues )
321- nonSubscribersAll = nonSubscribers (binaries , gValues )
322- print ("NonSubscribers: " , nonSubscribersAll )
323- nonSubscribersAllFormula = binsToFormula (nonSubscribersAll )
324- print ("nonSubscribersAllFormula: " , nonSubscribersAllFormula )
325- g = g + nonSubscribersAllFormula
375+ g = subscriptionsFilter (subscriptions )
376+ print ("g, SubscriptionsAll: " , g )
377+
378+ if g != None and len (g ) != 0 :
379+ commonSubscriptions = commonValues (g )
380+ print ("commonSubscriptions: " , commonSubscriptions )
381+ if commonSubscriptions != None :
382+ newG = [commonSubscriptions , [removeValue (g , commonSubscriptions )]]
326383 else :
327- print ("Error: binariesLength is more then gValuesCount and we not except it!" )
328- sys .exit (- 1 )
329-
330- print ("g: " , g )
331- gFormula = toFormula (g )
332- print ("gFormula: " , gFormula )
333- gNormalize = normalize (g )
334- print ("gNormalize: " , gNormalize )
335- gNormalizeSubscriptions = subscriptionsOfFormulas (gNormalize )
336- print ("gNormalizeSubscriptions: " , gNormalizeSubscriptions )
337- gNormalizeSubscriptionsCount = len (gNormalizeSubscriptions )
338- print ("gNormalizeSubscriptionsCount: " , gNormalizeSubscriptionsCount )
339- gNormalizeSubscriptionsFilter = removeNoneArrays (gNormalizeSubscriptions )
340- print ("gNormalizeSubscriptionsFilter: " , gNormalizeSubscriptionsFilter )
341-
342- gNormalizeSubscriptionsFilterDublicate = removeDublicateValue (gNormalizeSubscriptionsFilter )
343- print ("gNormalizeSubscriptionsFilterDublicate: " , gNormalizeSubscriptionsFilterDublicate )
344-
345- if gNormalizeSubscriptionsCount == 0 :
346- print ("Error: Cannot draw this graph!" )
347- sys .exit (- 1 )
348-
349- g = gNormalizeSubscriptionsFilterDublicate
384+ newG = commonSubscriptions
385+ print ("newG: " , newG )
386+ newG = filterGArray (newG )
387+ print ("newG: " , newG )
388+ if newG != None and len (newG ) != 0 :
389+ gFormula = toFormula (newG )
390+ print ("gFormula: " , gFormula ) #It's $g formula
391+
392+ gValues = evalFormula (gFormula , binaries )
393+ gValuesCount = len (gValues )
394+
395+ print ("gValues: " , gValues )
396+ print ("gValuesCount: " , gValuesCount )
397+ print ("Compare gValuesCount with binariesLength: " , gValuesCount , "??" , binariesLength )
398+
399+ if gValuesCount == binariesLength :
400+ print ("\t They are equal!" )
401+ g = newG
402+ elif gValuesCount < binariesLength :
403+ print ("\t binariesLength is bigger then gValuesCount." )
404+ g = newG
405+ print ("Diff two array:" )
406+ print ("\t subscriptions1: " , binaries )
407+ print ("\t subscriptions2: " , gValues )
408+ nonSubscribersAll = nonSubscribers (binaries , gValues )
409+ print ("NonSubscribers: " , nonSubscribersAll )
410+ nonSubscribersAllFormula = binsToFormula (nonSubscribersAll )
411+ print ("nonSubscribersAllFormula: " , nonSubscribersAllFormula )
412+ g = g + nonSubscribersAllFormula
413+ else :
414+ print ("Error: binariesLength is more then gValuesCount and we not except it!" )
415+ sys .exit (- 1 )
350416
351- else :
352- print ("Not need to calc g formula!" )
353- g = subscriptionsAll
354417
355- graph = g
356- print ("Graph: " , graph )
418+ else :
419+ print ("newG formula is empty!" )
420+ else :
421+ subscriptions
422+ print ("g formula is empty!" )
423+ # if subscriptionsAll != None and len(subscriptionsAll) != 0:
424+ # subscriptionsAllFormula=toFormula(subscriptionsAll)
425+ # print("SubscriptionsAllFormula: ", subscriptionsAllFormula) #It's $g formula
426+
427+ # gValues=evalFormula(subscriptionsAllFormula, binaries)
428+ # gValuesCount=len(gValues)
429+
430+ # print("gValues: ", gValues)
431+ # print("gValuesCount: ", gValuesCount)
432+ # print("Compare gValuesCount with binariesLength: ", gValuesCount, "??", binariesLength)
433+ # g=[]
434+ # if gValuesCount == binariesLength:
435+ # print("\tThey are equal!")
436+ # g=subscriptionsAll
437+ # elif gValuesCount < binariesLength:
438+ # print("\tbinariesLength is bigger then gValuesCount.")
439+ # g=subscriptionsAll
440+ # print("Diff two array:")
441+ # print("\tsubscriptions1: ", binaries)
442+ # print("\tsubscriptions2: ", gValues)
443+ # nonSubscribersAll=nonSubscribers(binaries, gValues)
444+ # print("NonSubscribers: ", nonSubscribersAll)
445+ # nonSubscribersAllFormula=binsToFormula(nonSubscribersAll)
446+ # print("nonSubscribersAllFormula: ", nonSubscribersAllFormula)
447+ # g=g + nonSubscribersAllFormula
448+ # else:
449+ # print("Error: binariesLength is more then gValuesCount and we not except it!")
450+ # sys.exit(-1)
451+
452+ # print("g: ", g)
453+ # gFormula=toFormula(g)
454+ # print("gFormula: ", gFormula)
455+ # gNormalize=normalize(g)
456+ # print("gNormalize: ", gNormalize)
457+ # gNormalizeSubscriptions=subscriptionsOfFormulas(gNormalize)
458+ # print("gNormalizeSubscriptions: ", gNormalizeSubscriptions)
459+ # gNormalizeSubscriptionsCount=len(gNormalizeSubscriptions)
460+ # print("gNormalizeSubscriptionsCount: ", gNormalizeSubscriptionsCount)
461+ # gNormalizeSubscriptionsFilter=removeNoneArrays(gNormalizeSubscriptions)
462+ # print("gNormalizeSubscriptionsFilter: ", gNormalizeSubscriptionsFilter)
463+
464+ # gNormalizeSubscriptionsFilterDublicate=removeDublicateValue(gNormalizeSubscriptionsFilter)
465+ # print("gNormalizeSubscriptionsFilterDublicate: ", gNormalizeSubscriptionsFilterDublicate)
466+
467+ # if gNormalizeSubscriptionsCount == 0:
468+ # print("Error: Cannot draw this graph!")
469+ # sys.exit(-1)
470+
471+ # g=gNormalizeSubscriptionsFilterDublicate
472+
473+ # else:
474+ # print("Not need to calc g formula!")
475+ # g=subscriptionsAll
476+
477+ # graph=g
478+ # print("Graph: ", graph)
0 commit comments