Refine type
This commit is contained in:
@@ -19,7 +19,7 @@ def get_source(name: str, node: str) -> dict[str, Any]:
|
||||
return {}
|
||||
d = {}
|
||||
d['node'] = str(s['node'])
|
||||
d['s_type'] = str(s['type'])
|
||||
d['s_type'] = str(s['s_type'])
|
||||
d['strength'] = float(s['strength'])
|
||||
d['pattern'] = str(s['pattern']) if s['pattern'] != None else None
|
||||
return d
|
||||
@@ -57,8 +57,8 @@ def _set_source(name: str, cs: ChangeSet) -> DbChangeSet:
|
||||
raw_new[key] = new_dict[key]
|
||||
new = Source(raw_new)
|
||||
|
||||
redo_sql = f"update sources set type = {new.f_s_type}, strength = {new.f_strength}, pattern = {new.f_pattern} where node = {new.f_node};"
|
||||
undo_sql = f"update sources set type = {old.f_s_type}, strength = {old.f_strength}, pattern = {old.f_pattern} where node = {old.f_node};"
|
||||
redo_sql = f"update sources set s_type = {new.f_s_type}, strength = {new.f_strength}, pattern = {new.f_pattern} where node = {new.f_node};"
|
||||
undo_sql = f"update sources set s_type = {old.f_s_type}, strength = {old.f_strength}, pattern = {old.f_pattern} where node = {old.f_node};"
|
||||
|
||||
redo_cs = g_update_prefix | new.as_dict()
|
||||
undo_cs = g_update_prefix | old.as_dict()
|
||||
@@ -73,7 +73,7 @@ def set_source(name: str, cs: ChangeSet) -> ChangeSet:
|
||||
def _add_source(name: str, cs: ChangeSet) -> DbChangeSet:
|
||||
new = Source(cs.operations[0])
|
||||
|
||||
redo_sql = f"insert into sources (node, type, strength, pattern) values ({new.f_node}, {new.f_s_type}, {new.f_strength}, {new.f_pattern});"
|
||||
redo_sql = f"insert into sources (node, s_type, strength, pattern) values ({new.f_node}, {new.f_s_type}, {new.f_strength}, {new.f_pattern});"
|
||||
undo_sql = f"delete from sources where node = {new.f_node};"
|
||||
|
||||
redo_cs = g_add_prefix | new.as_dict()
|
||||
@@ -90,7 +90,7 @@ def _delete_source(name: str, cs: ChangeSet) -> DbChangeSet:
|
||||
old = Source(get_source(name, cs.operations[0]['node']))
|
||||
|
||||
redo_sql = f"delete from sources where node = {old.f_node};"
|
||||
undo_sql = f"insert into sources (node, type, strength, pattern) values ({old.f_node}, {old.f_s_type}, {old.f_strength}, {old.f_pattern});"
|
||||
undo_sql = f"insert into sources (node, s_type, strength, pattern) values ({old.f_node}, {old.f_s_type}, {old.f_strength}, {old.f_pattern});"
|
||||
|
||||
redo_cs = g_delete_prefix | old.as_id_dict()
|
||||
undo_cs = g_add_prefix | old.as_dict()
|
||||
@@ -121,7 +121,7 @@ def inp_in_source(line: str) -> str:
|
||||
pattern = str(tokens[3]) if num_without_desc >= 4 else None
|
||||
pattern = f"'{pattern}'" if pattern != None else 'null'
|
||||
|
||||
return f"insert into sources (node, type, strength, pattern) values ('{node}', '{s_type}', {strength}, {pattern});"
|
||||
return f"insert into sources (node, s_type, strength, pattern) values ('{node}', '{s_type}', {strength}, {pattern});"
|
||||
|
||||
|
||||
|
||||
@@ -130,7 +130,7 @@ def inp_out_source(name: str) -> list[str]:
|
||||
objs = read_all(name, 'select * from sources')
|
||||
for obj in objs:
|
||||
node = obj['node']
|
||||
s_type = obj['type']
|
||||
s_type = obj['s_type']
|
||||
strength = obj['strength']
|
||||
pattern = obj['pattern'] if obj['pattern'] != None else ''
|
||||
lines.append(f'{node} {s_type} {strength} {pattern}')
|
||||
|
||||
Reference in New Issue
Block a user