missing_selects.append("case when i{}=1 then NULL ELSE {} END".format(v,v))
elifis_var(v):
missing_selects.append(v)
#### CREATION OF D STAR #####
missing_data_table="{}_star".format(table_prefix)
deletion_sql="DROP TABLE IF EXISTS {};".format(missing_data_table)
cursor.execute(deletion_sql)
missing_selects_text=",".join(missing_selects)
missing_data_sql="CREATE TABLE {} AS SELECT block, {}, md5(CAST(({}) AS text)) AS superblock FROM {}".format(missing_data_table,missing_selects_text,missing_selects_text,table_prefix)
WHERE e.block IN %s AND e.max_occurence = 0 AND tl.tuple = e.tuple
AND tl.occurence = 1 AND tb.block = e.block""".format(equigraph_table,tuple_label_table,block_label_table,equigraph_table,tuple_label_table,block_label_table),[tuple(S),db_size,tuple(S)])
WHERE e.block IN %s
AND e.max_occurence = 0 AND tl.tuple = e.tuple
AND tl.occurence = 1 AND tb.block = e.block""".format(equigraph_table,tuple_label_table,block_label_table,tuple_label_table,equigraph_table,tuple_label_table,block_label_table),[tuple(S),db_size,tuple(S)])
alpha=sys.float_info.max
edges_to_add=[]
forrowincursor.fetchall():
if (row[1],row[2])inT:
continue
a=row[4]+row[5]-row[3]
ifa<alpha:
alpha=a
edges_to_add=[]
ifa==alpha:
edges_to_add.append(row)
# print(alpha, edges_to_add)
cursor.execute("UPDATE {} SET label = label - %s WHERE block in %s".format(block_label_table),[alpha,tuple(S)])
cursor.execute("UPDATE {} SET label = label + %s WHERE (tuple, occurence) in %s".format(tuple_label_table),[alpha,tuple(T)])
iflen(T)>0:
cursor.execute("UPDATE {} SET label = label + %s WHERE (tuple, occurence) in %s".format(tuple_label_table),[alpha,tuple(T)])
cursor.execute("UPDATE {} SET max_occurence = CASE WHEN max_occurence > 0 THEN max_occurence -1 ELSE 0 END WHERE (tuple, max_occurence) in %s AND block NOT IN %s".format(equigraph_table),[tuple(T),tuple(S)])
foredgeinedges_to_add:
cursor.execute("INSERT INTO {} (block, label) VALUES (%s, %s)".format(block_label_table),[row[0],row[4]])
cursor.execute("INSERT INTO {} (tuple, occurence, label, weight) VALUES (%s, %s, %s, %s) ON CONFLICT DO NOTHING".format(tuple_label_table),[row[1],row[2],row[5],row[3]])
cursor.execute("UPDATE {} SET max_occurence = %s WHERE block = %s AND tuple = %s".format(equigraph_table),[row[2],row[0],row[1]])
cursor.execute("INSERT INTO {} (tuple, occurence, label, weight) VALUES (%s, %s, %s, %s) ON CONFLICT DO NOTHING".format(tuple_label_table),[edge[1],edge[2],edge[5],edge[3]])
cursor.execute("UPDATE {} SET max_occurence = %s WHERE block = %s AND tuple = %s".format(equigraph_table),[edge[2],edge[0],edge[1]])
# input("updated labels with S={}, T={} and alpha={} \n with edges {}".format(S,T, alpha, edges_to_add))