def test_histograms_read_yaml(self):
     values = [
         V1Event(
             timestamp=dt_parser.parse("2018-12-11 10:24:57"),
             histogram=V1EventHistogram(values=[10], counts=[1]),
             step=12,
         ),
         V1Event(
             timestamp=dt_parser.parse("2018-12-11 10:25:57"),
             histogram=V1EventHistogram(values=[10, 1, 1], counts=[1, 1,
                                                                   1]),
             step=13,
         ),
         V1Event(
             timestamp=dt_parser.parse("2018-12-11 10:26:57"),
             histogram=V1EventHistogram(values=[10, 112, 12, 1],
                                        counts=[12, 1, 1, 1]),
             step=14,
         ),
     ]
     events = V1Events.read(
         name="foo",
         kind="histogram",
         data=os.path.abspath(
             "tests/fixtures/polyboard/histogram/histogram_events.plx"),
     )
     assert events.name == "foo"
     assert len(events.df.values) == 3
     for i in range(3):
         assert events.get_event_at(i).to_dict() == values[i].to_dict()
def histogram(values, bins, max_bins=None):
    if not np:
        logger.warning(NUMPY_ERROR_MESSAGE)
        return UNKNOWN

    values = to_np(values).astype(float)

    if values.size == 0:
        raise ValueError("The input has no element.")
    values = values.reshape(-1)
    counts, limits = np.histogram(values, bins=bins)
    num_bins = len(counts)
    if max_bins is not None and num_bins > max_bins:
        subsampling = num_bins // max_bins
        subsampling_remainder = num_bins % subsampling
        if subsampling_remainder != 0:
            counts = np.pad(
                counts,
                pad_width=[[0, subsampling - subsampling_remainder]],
                mode="constant",
                constant_values=0,
            )
        counts = counts.reshape(-1, subsampling).sum(axis=-1)

    if counts.size == 0:
        logger.warning("Tracking an empty histogram")
        return UNKNOWN

    return V1EventHistogram(values=values, counts=counts)
 def test_histogram(self):
     events = LoggedEventListSpec(
         name="foo",
         kind="histogram",
         events=[
             V1Event(
                 timestamp=dt_parser.parse("2018-12-11 10:24:57"),
                 histogram=V1EventHistogram(values=[10], counts=[1]),
                 step=12,
             ),
             V1Event(
                 timestamp=dt_parser.parse("2018-12-11 11:24:57"),
                 histogram=V1EventHistogram(values=[10], counts=[1]),
                 step=13,
             ),
             V1Event(
                 timestamp=dt_parser.parse("2018-12-11 12:24:57"),
                 histogram=V1EventHistogram(values=[10], counts=[1]),
                 step=14,
             ),
         ],
     )
     events_dict = events.to_dict()
     assert events_dict == events.from_dict(events_dict).to_dict()
def np_histogram(values, counts):
    return V1EventHistogram(values=values, counts=counts)