Skip to content

Commit

Permalink
Added serializer for metrics record rn_citation_data field (#19)
Browse files Browse the repository at this point in the history
* Values supported include timestamp and hastable/dict

* Added serializer metrics records rn_citation_data is an array of hashtables.  protobuf serializer converts them into a list of citation_record objects.
  • Loading branch information
spacemansteve authored and marblestation committed Jun 21, 2017
1 parent dd6b95a commit 0510f8e
Show file tree
Hide file tree
Showing 4 changed files with 284 additions and 71 deletions.
18 changes: 17 additions & 1 deletion adsmsg/metrics_record.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,23 @@
class MetricsRecord(Msg):

def __init__(self, *args, **kwargs):
super(MetricsRecord, self).__init__(metrics_pb2.MetricsRecord(), args, kwargs)
"""construct protobuf metrics record, ususally from a database dict
value for rn_citation_data needs speical processing
to clearly specify its contents for protobuf. example data:
[{"ref_norm": 0.2, "pubyear": 1954, "auth_norm": 0.25, "bibcode": "1954PhRv...93..257G", "cityear": 1954}, ...]
the citation_records message defines the contents of the json object
"""
instance = metrics_pb2.MetricsRecord()
kwargs.pop('id', None) # local database key field is not serialized
rn_citation_data = kwargs.pop('rn_citation_data', None)
super(MetricsRecord, self).__init__(instance, args, kwargs)
if rn_citation_data:
for current in rn_citation_data:
citation_record = instance.rn_citation_data.add()
for key in current:
setattr(citation_record, key, current[key])



class MetricsRecordList(Msg):
Expand Down
210 changes: 165 additions & 45 deletions adsmsg/protobuf/metrics_pb2.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 0510f8e

Please sign in to comment.