<commit_before># -*- coding: utf-8 -*-
from __future__ import print_function
from __future__ import unicode_literals
from __future__ import division

import csv

from django.conf import settings

from treemap.util import get_csv_response
from treemap.models import User

from models import OTM1UserRelic

# assumptions:
# * there are n userrelics and m users, such that n >= m
# * the user that exists in otm2 is the one with the latest last_login
# * this csv will have one record per userrelic,
#   for relics that have email occurrences greater than one,
#   not including the relic that matches the username that was chosen.

_EMAIL_TEMPLATE = """
Hi %(addressee)s,

Thanks for using %(site_name)s! \
We recently upgraded to the newest version \
of the OpenTreeMap software that powers the \
site ("OTM2"). We noticed there were multiple \
accounts created in the old site for your email, \
"%(email)s". This is not permitted in OTM2, so we \
have merged the activity of your multiple accounts \
onto one, "%(otm2_username)s". If you have any difficulty \
signing in, please contact us at %(contact_email)s.
"""


def render_email_body(user, instance):
    site_name = instance.name
    addressee = user.first_name or "%s user" % site_name
    return _EMAIL_TEMPLATE % {
        'addressee': addressee,
        'site_name': site_name,
        'email': user.email,
        'otm2_username': user.username,
        'contact_email': settings.SUPPORT_EMAIL_ADDRESS
    }


def user_csv(request, instance):
    duplicate_ids_query = """
    SELECT *<commit_msg>Give duplicate user csv view a better name<commit_after># -*- coding: utf-8 -*-
from __future__ import print_function
from __future__ import unicode_literals
from __future__ import division

import csv

from django.conf import settings

from treemap.util import get_csv_response
from treemap.models import User

from models import OTM1UserRelic

# assumptions:
# * there are n userrelics and m users, such that n >= m
# * the user that exists in otm2 is the one with the latest last_login
# * this csv will have one record per userrelic,
#   for relics that have email occurrences greater than one,
#   not including the relic that matches the username that was chosen.

_EMAIL_TEMPLATE = """
Hi %(addressee)s,

Thanks for using %(site_name)s! \
We recently upgraded to the newest version \
of the OpenTreeMap software that powers the \
site ("OTM2"). We noticed there were multiple \
accounts created in the old site for your email, \
"%(email)s". This is not permitted in OTM2, so we \
have merged the activity of your multiple accounts \
onto one, "%(otm2_username)s". If you have any difficulty \
signing in, please contact us at %(contact_email)s.
"""


def render_email_body(user, instance):
    site_name = instance.name
    addressee = user.first_name or "%s user" % site_name
    return _EMAIL_TEMPLATE % {
        'addressee': addressee,
        'site_name': site_name,
        'email': user.email,
        'otm2_username': user.username,
        'contact_email': settings.SUPPORT_EMAIL_ADDRESS
    }


def dupl_user_csv(request, instance):
    duplicate_ids_query = """
    SELECT *
{'fraction_non_alphanumeric': 0.07931472081218274, 'fraction_numerical': 0.004441624365482234, 'mean_word_length': 3.8808049535603715, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '1192537', 'n_tokens_mistral': 963, 'n_tokens_neox': 940, 'n_words': 373}