def _get_source_id_source_element_dict(self, source_ids, targeted_fields_dict): source_id_source_element_dict = defaultdict() source_table_name = targeted_fields_dict['source']['table_name'] source_table_id = targeted_fields_dict['source']['id'] elements = self._db.get_table_elements_by_where_cluases(source_table_name, []) author_guid_author_dict = self._db.get_author_dictionary() id_set = set(source_ids) for temp_author in elements: source_id = getattr(temp_author, source_table_id) if source_id not in id_set or source_id is None: continue if isinstance(temp_author, Author): author = author_guid_author_dict[temp_author.author_guid] elif source_table_id == u"author_guid": author = author_guid_author_dict[source_id] elif hasattr(temp_author, u"author_guid"): author = author_guid_author_dict[getattr(temp_author, u"author_guid")] else: author = Author() author.author_guid = source_id author.statuses_count = len(targeted_fields_dict) if hasattr(temp_author, 'created_at'): author.created_at = temp_author.created_at source = author source_id_source_element_dict[source_id] = source return source_id_source_element_dict
def _create_defult_author(self, source_id, targeted_fields_dict, temp_author): author = Author() author.author_guid = source_id author.statuses_count = len(targeted_fields_dict) if hasattr(temp_author, 'date'): author.created_at = getattr(temp_author, 'date') return author
def _add_author(self, author_guid): author = Author() author.author_guid = author_guid author.author_full_name = u'test author' author.name = u'test' author.domain = u'tests' author.statuses_count = 0 self._db.add_author(author) self._author = author
def _add_author(self, author_guid): author = Author() author.author_guid = author_guid author.author_full_name = u'test author' author.author_screen_name = author_guid author.name = u'test' author.domain = u'tests' author.statuses_count = 0 author.created_at = u"2017-06-14 05:00:00" # self._db.add_author(author) self._author = author
def setUp(self): self._db = DB() self._db.setUp() self.author_guid = u"author_guid" author = Author() author.author_guid = self.author_guid author.author_full_name = u'author' author.name = u'author_name' author.author_screen_name = u'author_screen_name' author.domain = u'Microblog' author.statuses_count = 10 author.friends_count = 5 author.followers_count = 6 author.favourites_count = 8 author.author_sub_type = u"bot" author.author_type = u"bad" author.created_at = u"2017-06-17 05:00:00" author.default_profile = True author.default_profile_image = True author.verified = True self._db.add_author(author) post = Post() post.author = self.author_guid post.author_guid = self.author_guid post.content = u"content" post.title = u"title" post.domain = u"domain" post.post_id = u"post_id" post.guid = post.post_id post.date = convert_str_to_unicode_datetime("2017-06-14 05:00:00") post.created_at = post.date self._db.addPost(post) self._db.session.commit() self.feature_prefix = u"AccountPropertiesFeatureGenerator_" self.account_properties_feature_generator = AccountPropertiesFeatureGenerator( self._db, **{ 'authors': [author], 'posts': { self.author_guid: [post] } }) self.account_properties_feature_generator.execute()
def _convert_source_to_author(self, source_id, targeted_fields_dict): source_table_name = targeted_fields_dict['source']['table_name'] source_table_id = targeted_fields_dict['source']['id'] elements = self._db.get_table_elements_by_ids(source_table_name, source_table_id, [source_id]) temp_author = elements[0] if isinstance(temp_author, Author): author = temp_author elif source_table_id == u"author_guid": author = self._db.get_author_by_author_guid(source_id) elif hasattr(temp_author, u"author_guid"): author = self._db.get_author_by_author_guid(getattr(temp_author, u"author_guid")) else: author = Author() author.author_guid = source_id author.statuses_count = len(targeted_fields_dict) if hasattr(temp_author, 'created_at'): author.created_at = temp_author.created_at return author