<commit_before># coding=utf-8

"""This module, entity_owner.py, is a cache abstraction to the server/database hosting of entity owner objects."""

from entities import base_entity as be
from entities import entity_manager as em


class EntityOwner(object):
	"""Represents a single unique EntityOwner."""

	def __init__(self, raw_data):
		self._needs_to_be_saved = False
		self._entity_manager    = em.EntityManager()

		for key in raw_data:
			if key == be.ENTITY_PROPERTY_EMAIL:
				self._email = raw_data[be.ENTITY_PROPERTY_EMAIL]
			elif key == be.ENTITY_PROPERTY_PASSWORD:
				self._password = raw_data[be.ENTITY_PROPERTY_PASSWORD]
			elif key == be.ENTITY_PROPERTY_USERNAME:
				self._username = raw_data[be.ENTITY_PROPERTY_USERNAME]
			elif key == 'entities':
				self._entities = raw_data['entities']

	def create_initial_entities(self):
		"""Creates the initial entities that this EntityOwner needs."""
		owner_entity = be.Entity()
		owner_entity.set_property_and_value(be.ENTITY_DEFAULT_PROPERTY_TYPE, be.ENTITY_TYPE_OWNER)
		owner_entity.set_property_and_value(be.ENTITY_PROPERTY_USERNAME, self._username)
		owner_entity.set_property_and_value(be.ENTITY_PROPERTY_EMAIL, self._email)
		owner_entity.set_property_and_value(be.ENTITY_PROPERTY_PASSWORD, self._password)
		self._entity_manager.add_entity(owner_entity)

	'''__   ___ ___ ___  ___  __   __
	  / _` |__   |   |  |__  |__) /__`
	  \__> |___  |   |  |___ |  \ .__/ '''
	def get_data_for_database(self):
		"""Returns the data in database saveable format."""
		json_data = {be.ENTITY_PROPERTY_EMAIL: self._email,
		             be.ENTITY_PROPERTY_PASSWORD: self._password,
		             be.ENTITY_PROPERTY_USERNAME: self._username}

		entities_data = {}
		all_entities = self._entity_manager.get_all_entities()

		for e in all_entities:
			entities_data[str(e.relative_id)] = e.get_json_data()

		json_data['entities'] = str(entities_data)
		return json_data

	def needs_to_be_saved(self) -> bool:
		"""Returns a boolean indicating if this entity owner needs to be saved on the database."""
		return self._needs_to_be_saved

	@property
	def username(self) -> str:
		"""Returns the username of this EntityOwner."""
		return self._username

	@property<commit_msg>general updating 113<commit_after># coding=utf-8

"""This module, entity_owner.py, is a cache abstraction to the server/database hosting of entity owner objects."""

from entities import base_entity as be
from entities import entity_manager as em


class EntityOwner(object):
	"""Represents a single unique EntityOwner."""

	def __init__(self, raw_data):
		self._needs_to_be_saved = False
		self._entity_manager    = em.EntityManager()

		for key in raw_data:
			if key == be.ENTITY_PROPERTY_EMAIL:
				self._email = raw_data[be.ENTITY_PROPERTY_EMAIL]
			elif key == be.ENTITY_PROPERTY_PASSWORD:
				self._password = raw_data[be.ENTITY_PROPERTY_PASSWORD]
			elif key == be.ENTITY_PROPERTY_USERNAME:
				self._username = raw_data[be.ENTITY_PROPERTY_USERNAME]
			elif key == 'entities':
				self._entities = raw_data['entities']

	def create_initial_entities(self):
		"""Creates the initial entities that this EntityOwner needs."""
		owner_entity = be.Entity()
		owner_entity.set_property_and_value(be.ENTITY_DEFAULT_PROPERTY_TYPE, be.ENTITY_TYPE_OWNER)
		owner_entity.set_property_and_value(be.ENTITY_PROPERTY_USERNAME, self._username)
		owner_entity.set_property_and_value(be.ENTITY_PROPERTY_EMAIL, self._email)
		owner_entity.set_property_and_value(be.ENTITY_PROPERTY_PASSWORD, self._password)
		self._entity_manager.add_entity(owner_entity)

	'''__   ___ ___ ___  ___  __   __
	  / _` |__   |   |  |__  |__) /__`
	  \__> |___  |   |  |___ |  \ .__/ '''
	def get_all_entities(self):
		"""Returns all the entities in this EntityOwner."""
		return self._entity_manager.get_all_entities()

	def get_data_for_database(self):
		"""Returns the data in database saveable format."""
		json_data = {be.ENTITY_PROPERTY_EMAIL: self._email,
		             be.ENTITY_PROPERTY_PASSWORD: <PASSWORD>,
		             be.ENTITY_PROPERTY_USERNAME: self._username}

		entities_data = {}
		all_entities = self._entity_manager.get_all_entities()

		for e in all_entities:
			entities_data[str(e.relative_id)] = e.get_json_data()

		json_data['entities'] = str(entities_data)
		return json_data

	def needs_to_be_saved(self) -> bool:
		"""Returns a boolean indicating if this entity owner needs to be saved on the database."""
		return self._needs_to_be_saved

	@property
	def username(self) -> str:
		"""Returns the username of this EntityOwner."""
		return self._username

	@property
{'fraction_non_alphanumeric': 0.1, 'fraction_numerical': 0.0010893246187363835, 'mean_word_length': 4.571601941747573, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1189055', 'n_tokens_mistral': 1607, 'n_tokens_neox': 1518, 'n_words': 312}