Skip to content

Commit

Permalink
Merge pull request #542 from HERA-Team/allow_metric_updates
Browse files Browse the repository at this point in the history
Allow for updates to qm metric tables
  • Loading branch information
bhazelton authored Mar 23, 2021
2 parents 698622e + f017291 commit fc114c0
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
10 changes: 6 additions & 4 deletions hera_mc/mc_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -4618,7 +4618,7 @@ def add_antenna_status_from_corrcm(self, ant_status_dict=None,

def add_ant_metric(self, obsid, ant, pol, metric, val):
"""
Add a new antenna metric to the M&C database.
Add a new antenna metric or update an existing metric.
Parameters
----------
Expand All @@ -4636,7 +4636,8 @@ def add_ant_metric(self, obsid, ant, pol, metric, val):
"""
db_time = self.get_current_db_time()

self.add(AntMetrics.create(obsid, ant, pol, metric, db_time, val))
obj_list = [AntMetrics.create(obsid, ant, pol, metric, db_time, val)]
self._insert_ignoring_duplicates(AntMetrics, obj_list, update=True)

def get_ant_metric(self, ant=None, pol=None, metric=None, starttime=None,
stoptime=None):
Expand Down Expand Up @@ -4681,7 +4682,7 @@ def get_ant_metric(self, ant=None, pol=None, metric=None, starttime=None,

def add_array_metric(self, obsid, metric, val):
"""
Add a new array metric to the M&C database.
Add a new array metric or update an existing metric.
Parameters
----------
Expand All @@ -4695,7 +4696,8 @@ def add_array_metric(self, obsid, metric, val):
"""
db_time = self.get_current_db_time()

self.add(ArrayMetrics.create(obsid, metric, db_time, val))
obj_list = [ArrayMetrics.create(obsid, metric, db_time, val)]
self._insert_ignoring_duplicates(ArrayMetrics, obj_list, update=True)

def get_array_metric(self, metric=None, starttime=None, stoptime=None):
"""
Expand Down
18 changes: 18 additions & 0 deletions hera_mc/tests/test_qm.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,22 @@ def test_AntMetrics(mcsession, pol_x, pol_y):

# now the tests
test_session.add_ant_metric(obsid, 0, pol_x, 'test', 4.5)
test_session.commit()
r = test_session.get_ant_metric(metric='test')
assert len(r) == 1
assert r[0].antpol == (0, pol_x)
assert r[0].metric == 'test'
assert r[0].val == 4.5

# test that updating works
test_session.add_ant_metric(obsid, 0, pol_x, 'test', 4.3)
test_session.commit()
r = test_session.get_ant_metric(metric='test')
assert len(r) == 1
assert r[0].antpol == (0, pol_x)
assert r[0].metric == 'test'
assert r[0].val == 4.3

# Test more exciting queries
test_session.add_ant_metric(obsid, 0, pol_y, 'test', 2.5)
test_session.add_ant_metric(obsid, 3, pol_x, 'test', 2.5)
Expand Down Expand Up @@ -152,10 +162,18 @@ def test_ArrayMetrics(mcsession):

# now the tests
test_session.add_array_metric(obsid, 'test', 6.2)
test_session.commit()
r = test_session.get_array_metric()
assert r[0].metric == 'test'
assert r[0].val == 6.2

# test that updating works
test_session.add_array_metric(obsid, 'test', 6.5)
test_session.commit()
r = test_session.get_array_metric()
assert r[0].metric == 'test'
assert r[0].val == 6.5

# Test more exciting queries
test_session.add_array_metric(obsid + 10, 'test', 2.5)
test_session.add_array_metric(obsid - 10, 'test', 2.5)
Expand Down

0 comments on commit fc114c0

Please sign in to comment.