Style
This commit is contained in:
parent
474bea6ff5
commit
0dd2ef2f1d
@ -95,7 +95,7 @@ class UserInterface (object):
|
|||||||
as bytes.
|
as bytes.
|
||||||
'''
|
'''
|
||||||
if filename:
|
if filename:
|
||||||
with open(filename,'w') as f:
|
with open(filename, 'w') as f:
|
||||||
pickle.dump(self.relations, f)
|
pickle.dump(self.relations, f)
|
||||||
return None
|
return None
|
||||||
return pickle.dumps(self.relations)
|
return pickle.dumps(self.relations)
|
||||||
|
@ -508,6 +508,7 @@ def select_union_intersect_subtract(n):
|
|||||||
|
|
||||||
return changes + recoursive_scan(select_union_intersect_subtract, n)
|
return changes + recoursive_scan(select_union_intersect_subtract, n)
|
||||||
|
|
||||||
|
|
||||||
def union_and_product(n):
|
def union_and_product(n):
|
||||||
'''
|
'''
|
||||||
A * B ∪ A * C = A * (B ∪ C)
|
A * B ∪ A * C = A * (B ∪ C)
|
||||||
|
@ -341,11 +341,12 @@ def tokenize(expression):
|
|||||||
expression = expression[
|
expression = expression[
|
||||||
par:].strip() # Removing parameter from the expression
|
par:].strip() # Removing parameter from the expression
|
||||||
else: # Relation (hopefully)
|
else: # Relation (hopefully)
|
||||||
expression+=' ' #To avoid the special case of the ending
|
expression += ' ' # To avoid the special case of the ending
|
||||||
|
|
||||||
#Initial part is a relation, stop when the name of the relation is over
|
# Initial part is a relation, stop when the name of the relation is
|
||||||
for r in range(1,len(expression)):
|
# over
|
||||||
if rtypes.RELATION_NAME_REGEXP.match(expression[:r+1]) is None:
|
for r in range(1, len(expression)):
|
||||||
|
if rtypes.RELATION_NAME_REGEXP.match(expression[:r + 1]) is None:
|
||||||
break
|
break
|
||||||
items.append(expression[:r])
|
items.append(expression[:r])
|
||||||
expression = expression[r:].strip()
|
expression = expression[r:].strip()
|
||||||
@ -371,5 +372,5 @@ if __name__ == "__main__":
|
|||||||
e = input("Expression: ")
|
e = input("Expression: ")
|
||||||
print (parse(e))
|
print (parse(e))
|
||||||
|
|
||||||
#Backwards compatibility
|
# Backwards compatibility
|
||||||
node = Node
|
node = Node
|
||||||
|
@ -64,6 +64,7 @@ class Relation (object):
|
|||||||
self.header = Header(next(reader)) # read 1st line
|
self.header = Header(next(reader)) # read 1st line
|
||||||
iterator = ((self.insert(i) for i in reader))
|
iterator = ((self.insert(i) for i in reader))
|
||||||
deque(iterator, maxlen=0)
|
deque(iterator, maxlen=0)
|
||||||
|
|
||||||
def _make_duplicate(self, copy):
|
def _make_duplicate(self, copy):
|
||||||
'''Flag that the relation "copy" is pointing
|
'''Flag that the relation "copy" is pointing
|
||||||
to the same set as this relation.'''
|
to the same set as this relation.'''
|
||||||
@ -393,7 +394,7 @@ class Relation (object):
|
|||||||
m_len = [len(i) for i in self.header] # Maximum lenght string
|
m_len = [len(i) for i in self.header] # Maximum lenght string
|
||||||
|
|
||||||
for f in self.content:
|
for f in self.content:
|
||||||
for col,i in enumerate(f):
|
for col, i in enumerate(f):
|
||||||
if len(i) > m_len[col]:
|
if len(i) > m_len[col]:
|
||||||
m_len[col] = len(i)
|
m_len[col] = len(i)
|
||||||
|
|
||||||
@ -403,7 +404,7 @@ class Relation (object):
|
|||||||
|
|
||||||
for r in self.content:
|
for r in self.content:
|
||||||
res += "\n"
|
res += "\n"
|
||||||
for col,i in enumerate(r):
|
for col, i in enumerate(r):
|
||||||
res += "%s" % (i.ljust(2 + m_len[col]))
|
res += "%s" % (i.ljust(2 + m_len[col]))
|
||||||
|
|
||||||
return res
|
return res
|
||||||
@ -426,12 +427,14 @@ class Relation (object):
|
|||||||
affected = self.selection(expr)
|
affected = self.selection(expr)
|
||||||
not_affected = self.difference(affected)
|
not_affected = self.difference(affected)
|
||||||
|
|
||||||
new_values = tuple(zip(self.header.getAttributesId(dic.keys()), dic.values()))
|
new_values = tuple(
|
||||||
|
zip(self.header.getAttributesId(dic.keys()), dic.values())
|
||||||
|
)
|
||||||
|
|
||||||
for i in set(affected.content):
|
for i in set(affected.content):
|
||||||
i = list(i)
|
i = list(i)
|
||||||
|
|
||||||
for column,value in new_values:
|
for column, value in new_values:
|
||||||
i[column] = value
|
i[column] = value
|
||||||
not_affected.insert(i)
|
not_affected.insert(i)
|
||||||
|
|
||||||
@ -530,6 +533,6 @@ class Header(tuple):
|
|||||||
'''Returns a list with numeric index corresponding to field's name'''
|
'''Returns a list with numeric index corresponding to field's name'''
|
||||||
return [self.index(i) for i in param]
|
return [self.index(i) for i in param]
|
||||||
|
|
||||||
#Backwards compatibility
|
# Backwards compatibility
|
||||||
relation = Relation
|
relation = Relation
|
||||||
header = Header
|
header = Header
|
||||||
|
@ -32,7 +32,9 @@ class Rstring (str):
|
|||||||
|
|
||||||
int_regexp = re.compile(r'^[\+\-]{0,1}[0-9]+$')
|
int_regexp = re.compile(r'^[\+\-]{0,1}[0-9]+$')
|
||||||
float_regexp = re.compile(r'^[\+\-]{0,1}[0-9]+(\.([0-9])+)?$')
|
float_regexp = re.compile(r'^[\+\-]{0,1}[0-9]+(\.([0-9])+)?$')
|
||||||
date_regexp = re.compile(r'^([0-9]{1,4})(\\|-|/)([0-9]{1,2})(\\|-|/)([0-9]{1,2})$')
|
date_regexp = re.compile(
|
||||||
|
r'^([0-9]{1,4})(\\|-|/)([0-9]{1,2})(\\|-|/)([0-9]{1,2})$'
|
||||||
|
)
|
||||||
|
|
||||||
def autocast(self):
|
def autocast(self):
|
||||||
'''
|
'''
|
||||||
@ -155,11 +157,12 @@ class Rdate (object):
|
|||||||
def __sub__(self, other):
|
def __sub__(self, other):
|
||||||
return (self.intdate - other.intdate).days
|
return (self.intdate - other.intdate).days
|
||||||
|
|
||||||
|
|
||||||
def is_valid_relation_name(name):
|
def is_valid_relation_name(name):
|
||||||
'''Checks if a name is valid for a relation.
|
'''Checks if a name is valid for a relation.
|
||||||
Returns boolean'''
|
Returns boolean'''
|
||||||
return re.match(RELATION_NAME_REGEXP, name) != None
|
return re.match(RELATION_NAME_REGEXP, name) != None
|
||||||
|
|
||||||
#Backwards compatibility
|
# Backwards compatibility
|
||||||
rdate = Rdate
|
rdate = Rdate
|
||||||
rstring = Rstring
|
rstring = Rstring
|
||||||
|
@ -43,7 +43,7 @@ class relForm(QtWidgets.QMainWindow):
|
|||||||
# Creates the UI
|
# Creates the UI
|
||||||
self.ui.setupUi(self)
|
self.ui.setupUi(self)
|
||||||
|
|
||||||
#Setting fonts for symbols
|
# Setting fonts for symbols
|
||||||
f = QtGui.QFont()
|
f = QtGui.QFont()
|
||||||
size = f.pointSize()
|
size = f.pointSize()
|
||||||
if sys.platform.startswith('win'):
|
if sys.platform.startswith('win'):
|
||||||
@ -106,7 +106,6 @@ class relForm(QtWidgets.QMainWindow):
|
|||||||
action.setShortcutContext(0)
|
action.setShortcutContext(0)
|
||||||
widget.addAction(action)
|
widget.addAction(action)
|
||||||
|
|
||||||
|
|
||||||
def checkVersion(self):
|
def checkVersion(self):
|
||||||
from relational import maintenance
|
from relational import maintenance
|
||||||
online = maintenance.check_latest_version()
|
online = maintenance.check_latest_version()
|
||||||
@ -250,8 +249,11 @@ class relForm(QtWidgets.QMainWindow):
|
|||||||
self, QtWidgets.QApplication.translate("Form", "Error"), r
|
self, QtWidgets.QApplication.translate("Form", "Error"), r
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
filename = QtWidgets.QFileDialog.getSaveFileName(self, QtWidgets.QApplication.translate(
|
filename = QtWidgets.QFileDialog.getSaveFileName(
|
||||||
"Form", "Save Relation"), "", QtWidgets.QApplication.translate("Form", "Relations (*.csv)"))[0]
|
self, QtWidgets.QApplication.translate("Form", "Save Relation"),
|
||||||
|
"",
|
||||||
|
QtWidgets.QApplication.translate("Form", "Relations (*.csv)")
|
||||||
|
)[0]
|
||||||
if (len(filename) == 0): # Returns if no file was selected
|
if (len(filename) == 0): # Returns if no file was selected
|
||||||
return
|
return
|
||||||
self.selectedRelation.save(filename)
|
self.selectedRelation.save(filename)
|
||||||
@ -366,8 +368,15 @@ class relForm(QtWidgets.QMainWindow):
|
|||||||
It shouldn't be called giving filename but not giving name.'''
|
It shouldn't be called giving filename but not giving name.'''
|
||||||
# Asking for file to load
|
# Asking for file to load
|
||||||
if not filenames:
|
if not filenames:
|
||||||
f = QtWidgets.QFileDialog.getOpenFileNames(self, QtWidgets.QApplication.translate(
|
f = QtWidgets.QFileDialog.getOpenFileNames(
|
||||||
"Form", "Load Relation"), "", QtWidgets.QApplication.translate("Form", "Relations (*.csv);;Text Files (*.txt);;All Files (*)"))
|
self,
|
||||||
|
QtWidgets.QApplication.translate("Form", "Load Relation"),
|
||||||
|
"",
|
||||||
|
QtWidgets.QApplication.translate(
|
||||||
|
"Form",
|
||||||
|
"Relations (*.csv);;Text Files (*.txt);;All Files (*)"
|
||||||
|
)
|
||||||
|
)
|
||||||
filenames = f[0]
|
filenames = f[0]
|
||||||
|
|
||||||
for f in filenames:
|
for f in filenames:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user