Skip to content

Commit 6a749c9

Browse files
committed
fix bug in transitions matrix function
1 parent bc80fdb commit 6a749c9

File tree

2 files changed

+24
-13
lines changed

2 files changed

+24
-13
lines changed

boris.py

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,8 @@
103103
import time_budget_functions
104104

105105

106-
__version__ = "6.2"
107-
__version_date__ = "2018-03-26"
106+
__version__ = "6.2.1"
107+
__version_date__ = "2018-03-28"
108108

109109
if platform.python_version() < "3.5":
110110
logging.critical("BORIS requires Python 3.5+! You are using v. {}")
@@ -9465,11 +9465,19 @@ def export_tabular_events(self):
94659465
def create_behavioral_strings(self, obsId, subj, plot_parameters):
94669466
"""
94679467
return the behavioral string for subject in obsId
9468+
9469+
Args:
9470+
obsId (str): observation id
9471+
subj (str): subject
9472+
plot_parameters (dict): parameters
9473+
9474+
Returns:
9475+
str: behavioral string for selected subject in selected observation
94689476
"""
94699477

94709478
s = ""
94719479
currentStates = []
9472-
eventsWithStatus = project_function.events_start_stop(self.pj[ETHOGRAM], self.pj[OBSERVATIONS][obsId][EVENTS])
9480+
eventsWithStatus = project_functions.events_start_stop(self.pj[ETHOGRAM], self.pj[OBSERVATIONS][obsId][EVENTS])
94739481

94749482
for event in eventsWithStatus:
94759483
if event[EVENT_SUBJECT_FIELD_IDX] == subj or (subj == NO_FOCAL_SUBJECT and event[EVENT_SUBJECT_FIELD_IDX] == ""):
@@ -9511,6 +9519,7 @@ def create_behavioral_strings(self, obsId, subj, plot_parameters):
95119519

95129520
return s
95139521

9522+
95149523
def export_string_events(self):
95159524
"""
95169525
export events from selected observations by subject as behavioral strings (plain text file)
@@ -9576,9 +9585,8 @@ def export_string_events(self):
95769585
outFile.write(out + "\n")
95779586

95789587
except:
9579-
errorMsg = sys.exc_info()[1]
9580-
logging.critical(errorMsg)
9581-
QMessageBox.critical(None, programName, str(errorMsg), QMessageBox.Ok | QMessageBox.Default, QMessageBox.NoButton)
9588+
logging.critical(sys.exc_info()[1])
9589+
QMessageBox.critical(None, programName, str(sys.exc_info()[1]), QMessageBox.Ok | QMessageBox.Default, QMessageBox.NoButton)
95829590

95839591

95849592
def transitions_matrix(self, mode):
@@ -9605,7 +9613,7 @@ def transitions_matrix(self, mode):
96059613

96069614
fn = QFileDialog(self).getSaveFileName(self, "Create matrix of transitions " + mode, "",
96079615
"Transitions matrix files (*.txt *.tsv);;All files (*)")
9608-
fileName = fn[0] if type(fn) is tuple else fn
9616+
fileName = fn[0] if type(fn) is tuple else fn # PyQt4/5
96099617

96109618
else:
96119619
exportDir = QFileDialog(self).getExistingDirectory(self, "Choose a directory to save the transitions matrices",
@@ -9614,6 +9622,7 @@ def transitions_matrix(self, mode):
96149622
return
96159623
flagMulti = True
96169624

9625+
flag_overwrite_all = False
96179626
for subject in plot_parameters["selected subjects"]:
96189627

96199628
logging.debug("subjects: {}".format(subject))
@@ -9643,11 +9652,13 @@ def transitions_matrix(self, mode):
96439652
subject=subject,
96449653
mode=mode)
96459654

9646-
if os.path.isfile(nf):
9647-
if dialog.MessageDialog(programName,
9648-
"A file with same name already exists.<br><b>{}</b>".format(nf),
9649-
["Overwrite", CANCEL]) == CANCEL:
9655+
if os.path.isfile(nf) and not flag_overwrite_all:
9656+
answer = dialog.MessageDialog(programName, "A file with same name already exists.<br><b>{}</b>".format(nf),
9657+
["Overwrite", "Overwrite all", CANCEL])
9658+
if answer == CANCEL:
96509659
continue
9660+
if answer == "Overwrite all":
9661+
flag_overwrite_all = True
96519662

96529663
with open(nf, "w") as outfile:
96539664
outfile.write(observed_matrix)

boris_cli.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@
3434
import plot_events
3535

3636

37-
__version__ = "6.2"
38-
__version_date__ = "2018-03-26"
37+
__version__ = "6.2.1"
38+
__version_date__ = "2018-03-28"
3939

4040
def cleanhtml(raw_html):
4141
raw_html = raw_html.replace("<br>", "\n")

0 commit comments

Comments
 (0)