Skip to content

Commit

Permalink
refactor: use namedtuple for essential structure
Browse files Browse the repository at this point in the history
- intead of extra class
  • Loading branch information
Sieboldianus committed Jan 10, 2019
1 parent e3ea47d commit b2a7fb0
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
13 changes: 10 additions & 3 deletions tagmaps/classes/load_data.py
Expand Up @@ -290,11 +290,18 @@ def get_cleaned_location(self, first_post, locid_userid,
- some information (e.g. hashtags) need merge with removing dupliates:
use prepared dictionaries
- some important information is type-checked (longitude, latitude)
Keyword arguments:
first_post -- first post of a user_guid at a location
locid_userid -- user_guid and loc_id in merged format
(f'{location}::{user_key}')
post_latlng -- tuple with lat/lng coordinates
user_key -- user_guid
"""
cleaned_post = CleanedPost()
cleaned_post = CleanedPost() # named tuple structure
cleaned_post.origin_id = first_post.origin_id
cleaned_post.latitude = float(post_latlng[0])
cleaned_post.longitude = float(post_latlng[1])
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 = \
Expand Down
17 changes: 16 additions & 1 deletion tagmaps/classes/shared_structure.py
Expand Up @@ -4,11 +4,15 @@
Module for shared structural elements
"""

from collections import namedtuple


class PostStructure():
"""Shared structure for Post Attributes
Contains attributes shared among PG DB and LBSN ProtoBuf spec.
- this could also be replaces by protobuf lbsnPost() from
lbsnstructure package
"""

def __init__(self):
Expand Down Expand Up @@ -45,7 +49,18 @@ def __init__(self):
self.loc_id = None


class CleanedPost():
"""This auto-class provides a structure for fast handling
of essential post attributes for use in tag maps clustering
"""
CleanedPost = namedtuple(
'cleanedPostLocation_tuple',
'origin_id lat lng guid user_guid '
'post_create_date post_publish_date '
'post_body hashtags emoji '
'post_views_count loc_id')


class CleanedPost_():
"""Shared structure for Post Attributes
Contains only the attributes needed for tag maps.
Expand Down

0 comments on commit b2a7fb0

Please sign in to comment.