def finalize(self, errors): osti_record = OstiRecord(n=self.nmats, doicoll=self.doi_qe.collection, matcoll=self.mat_qe.collection) osti_record.submit() with open(backupfile, 'w') as outfile: l = list( self.doi_qe.collection.find(fields={ 'created_at': True, 'doi': True })) json.dump(l, outfile, indent=2) # push results to plotly streaming graph counts = [ self.mat_qe.collection.count(), self.doi_qe.collection.count(), len(osti_record.matad.get_all_dois()) ] for idx, stream_id in enumerate(stream_ids): s = py.Stream(stream_id) s.open() s.write(dict(x=now, y=counts[idx])) s.close() return True
matad.matcoll.count()) elif args.plotly: import os, datetime import plotly.plotly as py from plotly.graph_objs import * stream_ids = ['645h22ynck', '96howh4ip8', 'nnqpv5ra02'] py.sign_in(os.environ.get('MP_PLOTLY_USER'), os.environ.get('MP_PLOTLY_APIKEY'), stream_ids=stream_ids) today = datetime.date.today() counts = [ matad.matcoll.count(), matad.doicoll.count(), len(matad.get_all_dois()) ] names = ['materials', 'requested DOIs', 'validated DOIs'] data = Data([ Scatter(x=[today], y=[counts[idx]], name=names[idx], stream=dict(token=stream_ids[idx], maxpoints=10000)) for idx, count in enumerate(counts) ]) filename = 'dois_{}'.format(today) print py.plot(data, filename=filename, auto_open=False) else: # generate records for either n or all (n=0) not-yet-submitted materials # OR generate records for specific materials (submitted or not) osti = OstiRecord(l=args.l, n=args.n, db_yaml=db_yaml) osti.submit()