Skip to content

Commit

Permalink
Merge pull request #96 from spacemansteve/master
Browse files Browse the repository at this point in the history
fix new metrics command options
  • Loading branch information
spacemansteve authored Jun 14, 2019
2 parents a5b02b9 + 5eea723 commit 99fcce3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
19 changes: 15 additions & 4 deletions adsdata/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,22 @@ def update_metrics_changed(self, db_conn, nonbib_conn, row_view_schema='ingest')
self.flush(db_conn)
# need to close?

def update_metrics_bibcode(self, bibcode, nonbib): #, delta_schema='delta'):
def update_metrics_bibcode(self, bibcode, db_conn, nonbib_conn, row_view_schema='nonbib'): #, delta_schema='delta'):
"""changed bibcodes are in sql table, for each we update metrics record"""
row = nonbib.get_by_bibcode(bibcode)
metrics_dict = self.row_view_to_metrics(row, sql_sync)
self.save(metrics_dict)
Metrics_Session = sessionmaker()
metrics_sess = Metrics_Session(bind=db_conn)
metrics_sess.execute('set search_path to {}'.format('metrics'))
sql_sync = nonbib.NonBib(row_view_schema)
row = sql_sync.get_by_bibcode(nonbib_conn, bibcode)
metrics_old = metrics_sess.query(models.MetricsTable).filter(models.MetricsTable.bibcode == bibcode).first()
metrics_new = self.row_view_to_metrics(row, nonbib_conn, row_view_schema, metrics_old)
if metrics_old:
metrics_sess.merge(metrics_new)
else:
metrics_sess.add(metrics_new)
metrics_sess.commit()
metrics_sess.close()
self.flush(db_conn)


# paper from 1988: 1988PASP..100.1134B
Expand Down
2 changes: 1 addition & 1 deletion run.py
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ def main():
for line in f:
bibcode = line.strip()
if bibcode:
m.update_metrics_bibcode(bibcode, nonbib_db_enging)
m.update_metrics_bibcode(bibcode, metrics_db_conn, nonbib_db_conn)

elif args.command == 'populateMetricsTable' and args.rowViewSchemaName and args.metricsSchemaName:
m = metrics.Metrics()
Expand Down

0 comments on commit 99fcce3

Please sign in to comment.