Skip to content
This repository was archived by the owner on Jun 30, 2022. It is now read-only.

Commit 2bbd273

Browse files
gildeasilviulica
authored andcommitted
Add class Accumulator
An Accumulator is an internal Counter that sums. ----Release Notes---- [] ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=119882525
1 parent e0f1df8 commit 2bbd273

1 file changed

Lines changed: 21 additions & 1 deletion

File tree

google/cloud/dataflow/utils/counters.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ class Counter(object):
2929
3030
(The aggregated value will be reported to the Dataflow service.)
3131
32+
Do not create directly; call CounterFactory.get_counter instead.
33+
3234
Attributes:
3335
name: the name of the counter, a string
3436
aggregation_kind: one of the aggregation kinds defined by this class.
@@ -101,9 +103,27 @@ def _str_internal(self):
101103
class AggregatorCounter(Counter):
102104
"""A Counter that represents a step-specific instance of an Aggregator.
103105
104-
Do not create directly, call CounterFactory.get_aggregator_counter instead.
106+
Do not create directly; call CounterFactory.get_aggregator_counter instead.
107+
"""
108+
109+
110+
class Accumulator(Counter):
111+
"""An internal Counter that sums.
112+
113+
Because this class is used only internally (not reported to the
114+
Dataflow service), its name is not important. It is not necessary
115+
to supply a name when creating one.
105116
"""
106117

118+
def __init__(self, name='unnamed'):
119+
"""Creates an Accumulator object.
120+
121+
Args:
122+
name: a suggested name-part. Optional.
123+
"""
124+
super(Accumulator, self).__init__('internal-%s-%x' % (name, id(self)),
125+
Counter.SUM)
126+
107127

108128
class CounterFactory(object):
109129
"""Keeps track of unique counters."""

0 commit comments

Comments
 (0)