Skip to content

Commit

Permalink
replace CleanedPost class structure with named tuple
Browse files Browse the repository at this point in the history
  • Loading branch information
Sieboldianus committed Jan 11, 2019
1 parent b2a7fb0 commit 7cbd4d4
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 18 deletions.
29 changes: 14 additions & 15 deletions tagmaps/classes/load_data.py
Expand Up @@ -298,21 +298,20 @@ def get_cleaned_location(self, first_post, locid_userid,
post_latlng -- tuple with lat/lng coordinates
user_key -- user_guid
"""
cleaned_post = CleanedPost() # named tuple structure
cleaned_post.origin_id = first_post.origin_id
cleaned_post.lat = float(post_latlng[0])
cleaned_post.long = float(post_latlng[1])
cleaned_post.guid = first_post.guid
cleaned_post.user_guid = user_key
cleaned_post.post_body = \
self.userlocation_wordlist_dict.get(
locid_userid, ("",)) # ("",) = substitute default
cleaned_post.post_create_date = first_post.post_create_date
cleaned_post.post_publish_date = first_post.post_publish_date
cleaned_post.post_views_count = first_post.post_views_count
cleaned_post.hashtags = \
self.userlocation_taglist_dict.get(locid_userid, ("",))
cleaned_post.loc_id = first_post.loc_id
cleaned_post = CleanedPost(
origin_id=first_post.origin_id,
lat=float(post_latlng[0]),
long=float(post_latlng[1]),
guid=first_post.guid,
user_guid=user_key,
post_body=self.userlocation_wordlist_dict.get(
locid_userid, ("",)), # ("",)=substitute default
post_create_date=first_post.post_create_date,
post_publish_date=first_post.post_publish_date,
post_views_count=first_post.post_views_count,
hashtags=self.userlocation_taglist_dict.get(locid_userid, ("",)),
loc_id=first_post.loc_id
) # named tuple structure
return cleaned_post

@staticmethod
Expand Down
13 changes: 10 additions & 3 deletions tagmaps/classes/shared_structure.py
Expand Up @@ -49,11 +49,18 @@ def __init__(self):
self.loc_id = None


"""This auto-class provides a structure for fast handling
of essential post attributes for use in tag maps clustering
"""This auto-class generated from named structure
provides access for fast handling
of essential post attributes
for use in tag maps clustering
- namedtuple instances are just as memory
efficient as regular tuples because they
do not have per-instance dictionaries.
"""
CleanedPost = namedtuple(
'cleanedPostLocation_tuple',
'CleanedPost',
'origin_id lat lng guid user_guid '
'post_create_date post_publish_date '
'post_body hashtags emoji '
Expand Down

0 comments on commit 7cbd4d4

Please sign in to comment.