
"""A module implementing a simple sharded counter."""


import random

from google.appengine.ext import ndb


NUM_SHARDS = 20


class SimpleCounterShard(ndb.Model):
  """Shards for the counter"""
  count = ndb.IntegerProperty(required=True, default=0)


def get_count():
  """Retrieve the value for a given sharded counter."""
  total = 0
  for counter in SimpleCounterShard.query():
    total += counter.count
  return total


@ndb.transactional
def increment():
  """Increment the value for a given sharded counter."""
  shard_index = random.randint(0, NUM_SHARDS - 1)
  counter = SimpleCounterShard.get_by_id(shard_index)
  if counter is None:
    counter = SimpleCounterShard(id=shard_index)
  counter.count += 1
  counter.put()


"""A module implementing a simple sharded counter."""


import random

from google.appengine.ext import ndb


NUM_SHARDS = 20


class SimpleCounterShard(ndb.Model):
    """Shards for the counter"""
    count = ndb.IntegerProperty(required=True, default=0)


def get_count():
    """Retrieve the value for a given sharded counter."""
    total = 0
    for counter in SimpleCounterShard.query():
        total += counter.count
    return total


@ndb.transactional
def increment():
    """Increment the value for a given sharded counter."""
    shard_index = random.randint(0, NUM_SHARDS - 1)
    counter = SimpleCounterShard.get_by_id(shard_index)
    if counter is None:
        counter = SimpleCounterShard(id=shard_index)
    counter.count += 1
    counter.put()

Indent only (PEP8) commit of simple counter.
Indent only (PEP8) commit of simple counter.

  
  """A module implementing a simple sharded counter."""
  
  
  import random
  
  from google.appengine.ext import ndb
  
  
  NUM_SHARDS = 20
  
  
  class SimpleCounterShard(ndb.Model):
-   """Shards for the counter"""
+     """Shards for the counter"""
-   count = ndb.IntegerProperty(required=True, default=0)
+     count = ndb.IntegerProperty(required=True, default=0)
  
  
  def get_count():
-   """Retrieve the value for a given sharded counter."""
+     """Retrieve the value for a given sharded counter."""
-   total = 0
+     total = 0
-   for counter in SimpleCounterShard.query():
+     for counter in SimpleCounterShard.query():
-     total += counter.count
+         total += counter.count
-   return total
+     return total
  
  
  @ndb.transactional
  def increment():
-   """Increment the value for a given sharded counter."""
+     """Increment the value for a given sharded counter."""
-   shard_index = random.randint(0, NUM_SHARDS - 1)
+     shard_index = random.randint(0, NUM_SHARDS - 1)
-   counter = SimpleCounterShard.get_by_id(shard_index)
+     counter = SimpleCounterShard.get_by_id(shard_index)
-   if counter is None:
+     if counter is None:
-     counter = SimpleCounterShard(id=shard_index)
+         counter = SimpleCounterShard(id=shard_index)
-   counter.count += 1
+     counter.count += 1
-   counter.put()
+     counter.put()
  
Indent only (PEP8) commit of simple counter.
## Code Before:

"""A module implementing a simple sharded counter."""


import random

from google.appengine.ext import ndb


NUM_SHARDS = 20


class SimpleCounterShard(ndb.Model):
  """Shards for the counter"""
  count = ndb.IntegerProperty(required=True, default=0)


def get_count():
  """Retrieve the value for a given sharded counter."""
  total = 0
  for counter in SimpleCounterShard.query():
    total += counter.count
  return total


@ndb.transactional
def increment():
  """Increment the value for a given sharded counter."""
  shard_index = random.randint(0, NUM_SHARDS - 1)
  counter = SimpleCounterShard.get_by_id(shard_index)
  if counter is None:
    counter = SimpleCounterShard(id=shard_index)
  counter.count += 1
  counter.put()

## Instruction:
Indent only (PEP8) commit of simple counter.
## Code After:

"""A module implementing a simple sharded counter."""


import random

from google.appengine.ext import ndb


NUM_SHARDS = 20


class SimpleCounterShard(ndb.Model):
    """Shards for the counter"""
    count = ndb.IntegerProperty(required=True, default=0)


def get_count():
    """Retrieve the value for a given sharded counter."""
    total = 0
    for counter in SimpleCounterShard.query():
        total += counter.count
    return total


@ndb.transactional
def increment():
    """Increment the value for a given sharded counter."""
    shard_index = random.randint(0, NUM_SHARDS - 1)
    counter = SimpleCounterShard.get_by_id(shard_index)
    if counter is None:
        counter = SimpleCounterShard(id=shard_index)
    counter.count += 1
    counter.put()
