tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

data_points.py (889B)


      1 #!/usr/bin/env vpython3
      2 
      3 # Copyright 2024 The Chromium Authors
      4 # Use of this source code is governed by a BSD-style license that can be
      5 # found in the LICENSE file.
      6 """ A metric implementation to record the raw inputs. """
      7 
      8 from google.protobuf.timestamp_pb2 import Timestamp
      9 from measure import Measure
     10 from test_script_metrics_pb2 import TestScriptMetric
     11 
     12 
     13 class DataPoints(Measure):
     14 
     15  def __init__(self, name: str) -> None:
     16    self._name = name
     17    self._points = []
     18 
     19  def record(self, value: float) -> None:
     20    point = TestScriptMetric.DataPoint()
     21    point.value = value
     22    # The function name is confusing, it updates itself to the current time.
     23    point.timestamp.GetCurrentTime()
     24    self._points.append(point)
     25 
     26  def dump(self) -> TestScriptMetric:
     27    result = TestScriptMetric()
     28    result.name = self._name
     29    result.points.points.extend(self._points)
     30    return result