Skip to content
This repository was archived by the owner on Sep 17, 2025. It is now read-only.

Commit f814904

Browse files
authored
Value type lint fixes (#516)
1 parent 85b4620 commit f814904

File tree

5 files changed

+37
-72
lines changed

5 files changed

+37
-72
lines changed

opencensus/metrics/export/point.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,14 @@
1616
class Point(object):
1717
"""A timestamped measurement of a TimeSeries.
1818
19-
:type value: Value
20-
:param value: the Value of the Point.
19+
:type value: :class:`opencensus.metrics.export.value.ValueDouble` or
20+
:class:`opencensus.metrics.export.value.ValueLong` or
21+
:class:`opencensus.metrics.export.value.ValueSummary` or
22+
:class:`opencensus.metrics.export.value.ValueDistribution`
23+
:param value: the point value.
2124
2225
:type timestamp: time
23-
:param timestamp: the Timestamp when the Point was recorded.
26+
:param timestamp: the timestamp when the `Point` was recorded.
2427
"""
2528

2629
def __init__(self, value, timestamp):
@@ -29,12 +32,10 @@ def __init__(self, value, timestamp):
2932

3033
@property
3134
def value(self):
32-
"""Returns the Value"""
3335
return self._value
3436

3537
@property
3638
def timestamp(self):
37-
"""Returns the Timestamp when this Point was recorded."""
3839
return self._timestamp
3940

4041
def __repr__(self):

opencensus/metrics/export/value.py

Lines changed: 19 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -21,63 +21,15 @@
2121
from copy import copy
2222

2323

24-
class Value(object):
25-
"""The actual point value for a Point.
26-
Currently there are four types of Value:
27-
<ul>
28-
<li>double
29-
<li>long
30-
<li>Summary
31-
<li>Distribution (TODO(mayurkale): add Distribution class)
32-
</ul>
33-
Each Point contains exactly one of the four Value types.
34-
"""
35-
36-
def __init__(self, value):
37-
self._value = value
38-
39-
@staticmethod
40-
def double_value(value):
41-
"""Returns a double Value
42-
43-
:type value: float
44-
:param value: value in double
45-
"""
46-
return ValueDouble(value)
47-
48-
@staticmethod
49-
def long_value(value):
50-
"""Returns a long Value
51-
52-
:type value: long
53-
:param value: value in long
54-
"""
55-
return ValueLong(value)
56-
57-
@staticmethod
58-
def summary_value(value):
59-
"""Returns a summary Value
60-
61-
:type value: Summary
62-
:param value: value in Summary
63-
"""
64-
return ValueSummary(value)
65-
66-
@property
67-
def value(self):
68-
"""Returns the value."""
69-
return self._value
70-
71-
72-
class ValueDouble(Value):
24+
class ValueDouble(object):
7325
"""A 64-bit double-precision floating-point number.
7426
7527
:type value: float
7628
:param value: the value in float.
7729
"""
7830

7931
def __init__(self, value):
80-
super(ValueDouble, self).__init__(value)
32+
self._value = value
8133

8234
def __repr__(self):
8335
return ("{}({})"
@@ -86,16 +38,20 @@ def __repr__(self):
8638
self.value,
8739
))
8840

41+
@property
42+
def value(self):
43+
return self._value
44+
8945

90-
class ValueLong(Value):
46+
class ValueLong(object):
9147
"""A 64-bit integer.
9248
9349
:type value: long
9450
:param value: the value in long.
9551
"""
9652

9753
def __init__(self, value):
98-
super(ValueLong, self).__init__(value)
54+
self._value = value
9955

10056
def __repr__(self):
10157
return ("{}({})"
@@ -104,16 +60,20 @@ def __repr__(self):
10460
self.value,
10561
))
10662

63+
@property
64+
def value(self):
65+
return self._value
66+
10767

108-
class ValueSummary(Value):
68+
class ValueSummary(object):
10969
"""Represents a snapshot values calculated over an arbitrary time window.
11070
11171
:type value: summary
11272
:param value: the value in summary.
11373
"""
11474

11575
def __init__(self, value):
116-
super(ValueSummary, self).__init__(value)
76+
self._value = value
11777

11878
def __repr__(self):
11979
return ("{}({})"
@@ -122,6 +82,10 @@ def __repr__(self):
12282
self.value,
12383
))
12484

85+
@property
86+
def value(self):
87+
return self._value
88+
12589

12690
class Exemplar(object):
12791
"""An example point to annotate a given value in a bucket.
@@ -227,7 +191,7 @@ def type_(self):
227191
return self._type
228192

229193

230-
class ValueDistribution(Value):
194+
class ValueDistribution(object):
231195
"""Summary statistics for a population of values.
232196
233197
Distribution contains summary statistics for a population of values. It

tests/unit/metrics/export/test_point.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@
2020

2121
class TestPoint(unittest.TestCase):
2222
def setUp(self):
23-
self.double_value = value_module.Value.double_value(55.5)
24-
self.long_value = value_module.Value.long_value(9876543210)
23+
self.double_value = value_module.ValueDouble(55.5)
24+
self.long_value = value_module.ValueLong(9876543210)
2525
self.timestamp = '2018-10-06T17:57:57.936475Z'
2626

2727
value_at_percentile = [summary_module.ValueAtPercentile(99.5, 10.2)]
2828
snapshot = summary_module.Snapshot(10, 87.07, value_at_percentile)
2929
self.summary = summary_module.Summary(10, 6.6, snapshot)
30-
self.summary_value = value_module.Value.summary_value(self.summary)
30+
self.summary_value = value_module.ValueSummary(self.summary)
3131
self.distribution_value = value_module.ValueDistribution(
3232
100,
3333
1000.0,

tests/unit/metrics/export/test_time_series.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,15 @@
2626
LABEL_VALUE2 = label_value.LabelValue('价值二')
2727
LABEL_VALUES = (LABEL_VALUE1, LABEL_VALUE2)
2828
POINTS = (point.Point(
29-
value.Value.long_value(1), "2018-10-09T23:33:44.012345Z"),
29+
value.ValueLong(1), "2018-10-09T23:33:44.012345Z"),
3030
point.Point(
31-
value.Value.long_value(2), "2018-10-10T00:33:44.012345Z"),
31+
value.ValueLong(2), "2018-10-10T00:33:44.012345Z"),
3232
point.Point(
33-
value.Value.long_value(3), "2018-10-10T01:33:44.012345Z"),
33+
value.ValueLong(3), "2018-10-10T01:33:44.012345Z"),
3434
point.Point(
35-
value.Value.long_value(4), "2018-10-10T02:33:44.012345Z"),
35+
value.ValueLong(4), "2018-10-10T02:33:44.012345Z"),
3636
point.Point(
37-
value.Value.long_value(5), "2018-10-10T03:33:44.012345Z"))
37+
value.ValueLong(5), "2018-10-10T03:33:44.012345Z"))
3838

3939

4040
class TestTimeSeries(unittest.TestCase):
@@ -61,7 +61,7 @@ def test_check_points_type(self):
6161
self.assertTrue(ts.check_points_type(value.ValueLong))
6262

6363
bad_points = POINTS + (point.Point(
64-
value.Value.double_value(6.0), "2018-10-10T04:33:44.012345Z"), )
64+
value.ValueDouble(6.0), "2018-10-10T04:33:44.012345Z"), )
6565
bad_time_series = time_series.TimeSeries(LABEL_VALUES, bad_points,
6666
START_TIMESTAMP)
6767

tests/unit/metrics/export/test_value.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@
2020

2121
class TestValue(unittest.TestCase):
2222
def test_create_double_value(self):
23-
double_value = value_module.Value.double_value(-34.56)
23+
double_value = value_module.ValueDouble(-34.56)
2424

2525
self.assertIsNotNone(double_value)
2626
self.assertIsInstance(double_value, value_module.ValueDouble)
2727
self.assertEqual(double_value.value, -34.56)
2828

2929
def test_create_long_value(self):
30-
long_value = value_module.Value.long_value(123456789)
30+
long_value = value_module.ValueLong(123456789)
3131

3232
self.assertIsNotNone(long_value)
3333
self.assertIsInstance(long_value, value_module.ValueLong)
@@ -38,7 +38,7 @@ def test_create_summary_value(self):
3838
snapshot = summary_module.Snapshot(10, 87.07, value_at_percentile)
3939
summary = summary_module.Summary(10, 6.6, snapshot)
4040

41-
summary_value = value_module.Value.summary_value(summary)
41+
summary_value = value_module.ValueSummary(summary)
4242

4343
self.assertIsNotNone(summary_value)
4444
self.assertIsInstance(summary_value, value_module.ValueSummary)

0 commit comments

Comments
 (0)