import datetime


class Record(object):

    def __init__(self, data):
        self.data = data
        self.meta = {}
        if "_timestamp" in self.data:
            days_since_week_start = datetime.timedelta(
                days=self.data['_timestamp'].weekday())
            week_start = self.data['_timestamp'] - days_since_week_start
            self.meta['_week_start_at'] = week_start.replace(
                hour=0, minute=0, second=0, microsecond=0)

    def to_mongo(self):
        return dict(
            self.data.items() + self.meta.items()
        )

    def __eq__(self, other):
        if not isinstance(other, Record):
            return False
        if self.data != other.data:
            return False
        if self.meta != other.meta:
            return False
        return True

import datetime


class Record(object):

    def __init__(self, data):
        self.data = data
        self.meta = {}

        if "_timestamp" in self.data:
            day_of_week = self.data['_timestamp'].weekday()
            delta_from_week_start = datetime.timedelta(days=day_of_week)
            week_start = self.data['_timestamp'] - delta_from_week_start
            self.meta['_week_start_at'] = week_start.replace(
                hour=0,
                minute=0,
                second=0,
                microsecond=0
            )

    def to_mongo(self):
        return dict(
            self.data.items() + self.meta.items()
        )

    def __eq__(self, other):
        if not isinstance(other, Record):
            return False
        if self.data != other.data:
            return False
        if self.meta != other.meta:
            return False
        return True

Refactor for clarity around _week_start_at
Refactor for clarity around _week_start_at

  import datetime
  
  
  class Record(object):
  
      def __init__(self, data):
          self.data = data
          self.meta = {}
+ 
          if "_timestamp" in self.data:
-             days_since_week_start = datetime.timedelta(
-                 days=self.data['_timestamp'].weekday())
+             day_of_week = self.data['_timestamp'].weekday()
+             delta_from_week_start = datetime.timedelta(days=day_of_week)
-             week_start = self.data['_timestamp'] - days_since_week_start
+             week_start = self.data['_timestamp'] - delta_from_week_start
              self.meta['_week_start_at'] = week_start.replace(
-                 hour=0, minute=0, second=0, microsecond=0)
+                 hour=0,
+                 minute=0,
+                 second=0,
+                 microsecond=0
+             )
  
      def to_mongo(self):
          return dict(
              self.data.items() + self.meta.items()
          )
  
      def __eq__(self, other):
          if not isinstance(other, Record):
              return False
          if self.data != other.data:
              return False
          if self.meta != other.meta:
              return False
          return True
  
Refactor for clarity around _week_start_at
## Code Before:
import datetime


class Record(object):

    def __init__(self, data):
        self.data = data
        self.meta = {}
        if "_timestamp" in self.data:
            days_since_week_start = datetime.timedelta(
                days=self.data['_timestamp'].weekday())
            week_start = self.data['_timestamp'] - days_since_week_start
            self.meta['_week_start_at'] = week_start.replace(
                hour=0, minute=0, second=0, microsecond=0)

    def to_mongo(self):
        return dict(
            self.data.items() + self.meta.items()
        )

    def __eq__(self, other):
        if not isinstance(other, Record):
            return False
        if self.data != other.data:
            return False
        if self.meta != other.meta:
            return False
        return True

## Instruction:
Refactor for clarity around _week_start_at
## Code After:
import datetime


class Record(object):

    def __init__(self, data):
        self.data = data
        self.meta = {}

        if "_timestamp" in self.data:
            day_of_week = self.data['_timestamp'].weekday()
            delta_from_week_start = datetime.timedelta(days=day_of_week)
            week_start = self.data['_timestamp'] - delta_from_week_start
            self.meta['_week_start_at'] = week_start.replace(
                hour=0,
                minute=0,
                second=0,
                microsecond=0
            )

    def to_mongo(self):
        return dict(
            self.data.items() + self.meta.items()
        )

    def __eq__(self, other):
        if not isinstance(other, Record):
            return False
        if self.data != other.data:
            return False
        if self.meta != other.meta:
            return False
        return True
