Ejemplo n.º 1
0
  def test_metrics_update(self):
    self._create_data()

    with FakeClock(TIME):
      PublicMetricsExport.export('123')
    aggs1 = [a.asdict() for a in AggregateMetricsDao().get_all()]

    with FakeClock(TIME2):
      PublicMetricsExport.export('123')
    aggs2 = [a.asdict() for a in AggregateMetricsDao().get_all()]

    self.assertEquals(TIME2, MetricSetDao().get('123').lastModified)
    self.assertEquals(aggs1, aggs2)
Ejemplo n.º 2
0
  def test_metrics_redaction(self):
    self._create_data()

    with FakeClock(TIME):
      PublicMetricsExport.export('123')

      # Withdraw particpant.
      pdao = ParticipantDao()
      p1 = pdao.get(1)
      p1.withdrawalStatus = WithdrawalStatus.NO_USE
      pdao.update(p1)

      PublicMetricsExport.export('123')
      self.assert_total_count_per_key(2) # now, 2 qualified participants
Ejemplo n.º 3
0
def recalculate_public_metrics():
    logging.info('generating public metrics')
    aggs = PublicMetricsExport.export(LIVE_METRIC_SET_ID)
    client_aggs = AggregateMetricsDao.to_client_json(aggs)

    # summing all counts for one metric yields a total qualified participant count
    participant_count = 0
    if len(client_aggs) > 0:
        participant_count = sum([a['count'] for a in client_aggs[0]['values']])
    logging.info('persisted public metrics: {} aggregations over '
                 '{} participants'.format(len(client_aggs), participant_count))

    # Same format returned by the metric sets API.
    return json.dumps({'metrics': client_aggs})
Ejemplo n.º 4
0
  def test_metrics_export(self):
    self._create_data()

    with FakeClock(TIME):
      PublicMetricsExport.export('123')
      self.assert_total_count_per_key(3) # 3 qualified participants