Skip to content

Commit 585b10d

Browse files
author
sreeder
committed
Merge branch 'iss305c' into Beta_2.0.1
2 parents ca0e94f + 51fdff1 commit 585b10d

2 files changed

Lines changed: 41 additions & 24 deletions

File tree

odmtools/odmdata/memory_database.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -194,11 +194,11 @@ def chunking(self, data):
194194
def updateFlag(self, ids, value):
195195

196196

197-
flags = pd.DataFrame(columns = ['AnnotationID', 'DateTime', 'ResultID', 'ValueID'])
198-
flags["DateTime"] = ids
199-
flags["AnnotationID"] = value
200-
flags["ResultID"] = self.series.ResultID
201-
flags["ValueID"] = None
197+
flags = pd.DataFrame(columns = ['annotationid', 'valuedatetime', 'resultid', 'valueid'])
198+
flags["valuedatetime"] = ids
199+
flags["annotationid"] = value
200+
flags["resultid"] = self.series.ResultID
201+
flags["valueid"] = None
202202

203203

204204
#what if the column already exists

odmtools/odmservices/edit_service.py

Lines changed: 36 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -498,20 +498,23 @@ def restore(self):
498498
self.reset_filter()
499499

500500
def save(self, result=None):
501-
values = self.memDB.getDataValuesDF()
502-
503-
if not result:
504-
result = self.memDB.series_service.get_series(series_id = values['resultid'][0])
505-
else:
506-
values["resultid"] = result.ResultID
501+
try:
502+
values = self.memDB.getDataValuesDF()
507503

508-
# update result
509-
result.ValueCount = 0
510-
self.updateResult(result)
511-
# upsert values
512-
self.memDB.series_service.upsert_values(values)
513-
# save new annotations
514-
self.add_annotations(self.memDB.annotation_list)
504+
if not result:
505+
result = self.memDB.series_service.get_series(series_id = values['resultid'][0])
506+
else:
507+
values["resultid"] = result.ResultID
508+
509+
# update result
510+
result.ValueCount = 0
511+
self.updateResult(result)
512+
# upsert values
513+
self.memDB.series_service.upsert_values(values)
514+
# save new annotations
515+
self.add_annotations(self.memDB.annotation_list)
516+
except Exception as e:
517+
logger.error("Exception encountered while saving: {}".format(e))
515518
return result
516519

517520
def save_existing(self, result):
@@ -651,8 +654,8 @@ def updateResult(self, result, valuecount = -10):
651654

652655
setSchema(self.memDB.series_service._session_factory.engine)
653656
self.memDB.series_service.update.updateResult(result.ResultID, result.ValueCount)
654-
self.memDB.series_service.update.updateAction(actionID=action.ActionID, begin=action.BeginDateTime, end=action.EndDateTime)
655-
657+
self.memDB.series_service.update.updateAction(actionID=action.ActionID,
658+
begin=action.BeginDateTime, end=action.EndDateTime)
656659
return result
657660

658661
def overlapcalc(self, result, values, overwrite):
@@ -675,16 +678,30 @@ def overlapcalc(self, result, values, overwrite):
675678

676679
def add_annotations(self, annolist):
677680
#match up with existing values and get value id
678-
#get df with only ValueID and AnnotationID
679-
#remove any duplicates
680-
#save df to db
681-
pass
682681

682+
print("ANNOTATIONS ARE ATTEMPTED TO ADD")
683+
engine = self.memDB.series_service._session_factory.engine
684+
685+
q =self.memDB.series_service._session.query(TimeSeriesResultValues) \
686+
.filter(TimeSeriesResultValues.ResultID == int(min(annolist["resultid"])))
683687

688+
query = q.statement.compile(dialect=engine.dialect)
689+
# data = pd.read_sql_query(sql=query, con=self._session_factory.engine,
690+
# params=query.params)
691+
# query = "SELECT ValueID, ResultID, ValueDateTime FROM TimeSeriesResultValues Where ResultID="+annolist["ResultID"][0]
684692

693+
vals = pd.read_sql_query(sql=query, con=engine,params=query.params)
694+
# remove any duplicates
695+
annolist.drop_duplicates(["resultid", "annotationid", "valuedatetime"], keep= 'last', inplace = True)
696+
newdf = pd.merge(annolist, vals, how='left', on= ["resultid", "valuedatetime"], indicator = True)
685697

686698

699+
#get only AnnotationID and ValueID
700+
mynewdf= newdf[["valueid_y","annotationid"]]
701+
mynewdf.columns = ["ValueID", "AnnotationID"]
687702

703+
# save df to db
704+
self.memDB.series_service.add_annotations(mynewdf)
688705

689706

690707

0 commit comments

Comments
 (0)