# Path: stackalytics/processor/user_processor.py
# LOG = logging.getLogger(__name__)
# def make_user_id(emails=None, launchpad_id=None, gerrit_id=None,
#                  member_id=None, github_id=None, ldap_id=None, ci_id=None,
#                  zanata_id=None):
# def store_user(runtime_storage_inst, user):
# def load_user(runtime_storage_inst, seq=None, user_id=None, email=None,
#               launchpad_id=None, gerrit_id=None, member_id=None,
#               github_id=None, ldap_id=None, zanata_id=None):
# def delete_user(runtime_storage_inst, user):
# def update_user_profile(stored_user, user):
# 
# Path: stackalytics/processor/utils.py
# LOG = logging.getLogger(__name__)
# BAD_NAME_SUFFIXES = ['Ltd', 'Pvt', 'Inc', 'GmbH', 'AG', 'Corporation', 'Corp',
#                      'Company', 'Co', 'Group', 'Srl', 'Limited', 'LLC', 'IT']
# BAD_NAME_SUFFIXES_WITH_STOPS = ['S.p.A.', 's.r.o.', 'L.P.', 'B.V.', 'K.K.',
#                                 'd.o.o.']
# def init_config_and_logging(opts):
# def date_to_timestamp(d):
# def date_to_timestamp_ext(d):
# def member_date_to_timestamp(d):
# def iso8601_to_timestamp(s):
# def timestamp_to_date(timestamp):
# def timestamp_to_week(timestamp):
# def week_to_date(week):
# def timestamp_to_day(timestamp):
# def timestamp_to_utc_date(timestamp):
# def round_timestamp_to_day(timestamp):
# def check_email_validity(email):
# def _session_request(session, uri, method):
# def do_request(uri, method='get', session=None):
# def read_uri(uri, session=None):
# def read_json_from_uri(uri, session=None):
# def read_yaml_from_uri(uri):
# def _gzip_decompress(content):
# def read_gzip_from_uri(uri):
# def get_uri_last_modified(uri):
# def cmp_to_key(mycmp):  # ported from python 3
#         def __init__(self, obj):
#         def __lt__(self, other):
#         def __gt__(self, other):
#         def __eq__(self, other):
#         def __le__(self, other):
#         def __ge__(self, other):
#         def __ne__(self, other):
# def make_range(start, stop, step):
# def load_repos(runtime_storage_inst):
# def unwrap_text(text):
# def format_text(s):
#     def replace_dots(match_obj):
# def make_age_string(seconds):
# def merge_records(original, new):
# def get_blueprint_id(module, name):
# def make_bug_id(bug_id, module, release=None):
# def get_patch_id(review_id, patch_number):
# def add_index(sequence, start=1, item_filter=lambda x: True):
# def safe_encode(s):
# def keep_safe_chars(s):
# def make_module_group(module_group_id, name=None, modules=None, tag='module'):
# def normalize_company_name(name):
# def normalize_company_draft(name):
# def validate_lp_display_name(lp_profile):
# def make_pipeline_processor(processors):
#     def get_passes(_processors):
#     def pipeline_processor(record_generator):
#     class K(object):


from oslo_log import log as logging
from stackalytics.processor import user_processor
from stackalytics.processor import utils
import six
# You may obtain a copy of the License at
#
#   http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.




LOG = logging.getLogger(__name__)


def _normalize_user(user):
    for c in user['companies']:
        c['end_date'] = utils.date_to_timestamp(c['end_date'])

    # sort companies by end_date
    def end_date_comparator(x, y):
        if x["end_date"] == 0:
            return 1
        elif y["end_date"] == 0:
            return -1
        else:
            return x["end_date"] - y["end_date"]


# Path: stackalytics/processor/user_processor.py
# LOG = logging.getLogger(__name__)
# def make_user_id(emails=None, launchpad_id=None, gerrit_id=None,
#                  member_id=None, github_id=None, ldap_id=None, ci_id=None,
#                  zanata_id=None):
# def store_user(runtime_storage_inst, user):
# def load_user(runtime_storage_inst, seq=None, user_id=None, email=None,
#               launchpad_id=None, gerrit_id=None, member_id=None,
#               github_id=None, ldap_id=None, zanata_id=None):
# def delete_user(runtime_storage_inst, user):
# def update_user_profile(stored_user, user):
# 
# Path: stackalytics/processor/utils.py
# LOG = logging.getLogger(__name__)
# BAD_NAME_SUFFIXES = ['Ltd', 'Pvt', 'Inc', 'GmbH', 'AG', 'Corporation', 'Corp',
#                      'Company', 'Co', 'Group', 'Srl', 'Limited', 'LLC', 'IT']
# BAD_NAME_SUFFIXES_WITH_STOPS = ['S.p.A.', 's.r.o.', 'L.P.', 'B.V.', 'K.K.',
#                                 'd.o.o.']
# def init_config_and_logging(opts):
# def date_to_timestamp(d):
# def date_to_timestamp_ext(d):
# def member_date_to_timestamp(d):
# def iso8601_to_timestamp(s):
# def timestamp_to_date(timestamp):
# def timestamp_to_week(timestamp):
# def week_to_date(week):
# def timestamp_to_day(timestamp):
# def timestamp_to_utc_date(timestamp):
# def round_timestamp_to_day(timestamp):
# def check_email_validity(email):
# def _session_request(session, uri, method):
# def do_request(uri, method='get', session=None):
# def read_uri(uri, session=None):
# def read_json_from_uri(uri, session=None):
# def read_yaml_from_uri(uri):
# def _gzip_decompress(content):
# def read_gzip_from_uri(uri):
# def get_uri_last_modified(uri):
# def cmp_to_key(mycmp):  # ported from python 3
#         def __init__(self, obj):
#         def __lt__(self, other):
#         def __gt__(self, other):
#         def __eq__(self, other):
#         def __le__(self, other):
#         def __ge__(self, other):
#         def __ne__(self, other):
# def make_range(start, stop, step):
# def load_repos(runtime_storage_inst):
# def unwrap_text(text):
# def format_text(s):
#     def replace_dots(match_obj):
# def make_age_string(seconds):
# def merge_records(original, new):
# def get_blueprint_id(module, name):
# def make_bug_id(bug_id, module, release=None):
# def get_patch_id(review_id, patch_number):
# def add_index(sequence, start=1, item_filter=lambda x: True):
# def safe_encode(s):
# def keep_safe_chars(s):
# def make_module_group(module_group_id, name=None, modules=None, tag='module'):
# def normalize_company_name(name):
# def normalize_company_draft(name):
# def validate_lp_display_name(lp_profile):
# def make_pipeline_processor(processors):
#     def get_passes(_processors):
#     def pipeline_processor(record_generator):
#     class K(object):


# Path: stackalytics/processor/normalizer.py
from oslo_log import log as logging
from stackalytics.processor import user_processor
from stackalytics.processor import utils
import six

# You may obtain a copy of the License at
#
#   http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.




LOG = logging.getLogger(__name__)


def _normalize_user(user):
    for c in user['companies']:
        c['end_date'] = utils.date_to_timestamp(c['end_date'])

    # sort companies by end_date
    def end_date_comparator(x, y):
        if x["end_date"] == 0:
            return 1
        elif y["end_date"] == 0:
            return -1
        else:
            return x["end_date"] - y["end_date"]


    user['companies'].sort(key=utils.cmp_to_key(end_date_comparator))