示例#1
0
def StoreVocabInMetaTable(session: sqlutil.Session,
                          vocabulary: typing.Dict[str, int]):
  """Store a vocabulary dictionary in the 'Meta' table of a database."""
  q = session.query(encoded.Meta).filter(encoded.Meta.key.like('vocab_%'))
  q.delete(synchronize_session=False)

  session.add(encoded.Meta(key='vocab_size', value=str(len(vocabulary))))
  session.add_all(
      [encoded.Meta(key=f'vocab_{v}', value=k) for k, v in vocabulary.items()])
示例#2
0
文件: me_db.py 项目: SpringRi/phd
 def AddSeriesCollection(session: sqlutil.Session,
                         series_collection: me_pb2.SeriesCollection) -> int:
     """Import the given series_collections to database."""
     num_measurements = 0
     for series in series_collection.series:
         num_measurements += len(series.measurement)
         logging.info('Importing %s %s:%s measurements',
                      humanize.intcomma(len(series.measurement)),
                      series.family, series.name)
         session.add_all(MeasurementsFromSeries(series))
     return num_measurements