<commit_before># This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

from __future__ import absolute_import

import calendar
import re
import time

import dateutil.parser
import sqlalchemy as sa
import structlog
from flask import Blueprint
from flask import Response
from flask import abort
from flask import g
from flask import jsonify
from flask import request
from sqlalchemy import orm
from sqlalchemy.orm.exc import MultipleResultsFound
from sqlalchemy.orm.exc import NoResultFound

from relengapi.lib import db
from relengapi.lib.permissions import p

logger = structlog.get_logger()
# logging.basicConfig(level=logging.DEBUG)
bp = Blueprint('mapper', __name__)

p.mapper.mapping.insert.doc("Allows new hg-git mappings to be inserted "
                            "into mapper db (hashes table)")
p.mapper.project.insert.doc("Allows new projects to be inserted into "
                            "mapper db (projects table)")

# TODO: replace abort with a custom exception
# - http://flask.pocoo.org/docs/patterns/apierrors/


class Project(db.declarative_base('mapper')):

    """Object-relational mapping between python class Project
    and database table "projects"
    """
    __tablename__ = 'projects'
    id = sa.Column(sa.Integer, primary_key=True)
    name = sa.Column(sa.String(255), nullable=False, unique=True)


class Hash(db.declarative_base('mapper')):

    """Object-relational mapping between python class Hash
    and database table "hashes"
    """
    __tablename__ = 'hashes'
    hg_changeset = sa.Column(sa.String(40), nullable=False)
    git_commit = sa.Column(sa.String(40), nullable=False)
    project_id = sa.Column(
        sa.Integer, sa.ForeignKey('projects.id'), nullable=False)
    project = orm.relationship(Project, primaryjoin=(project_id == Project.id))
    # project = orm.relationship(Project, backref=orm.backref('hashes', order_by=id))
    date_added = sa.Column(sa.Integer, nullable=False)

    project_name = property(lambda self: self.project.name)

    def as_json(self):
        return jsonify(**{n: getattr(self, n)<commit_msg>mapper: renaming tables<commit_after># This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

from __future__ import absolute_import

import calendar
import re
import time

import dateutil.parser
import sqlalchemy as sa
import structlog
from flask import Blueprint
from flask import Response
from flask import abort
from flask import g
from flask import jsonify
from flask import request
from sqlalchemy import orm
from sqlalchemy.orm.exc import MultipleResultsFound
from sqlalchemy.orm.exc import NoResultFound

from relengapi.lib import db
from relengapi.lib.permissions import p

logger = structlog.get_logger()
# logging.basicConfig(level=logging.DEBUG)
bp = Blueprint('mapper', __name__)

p.mapper.mapping.insert.doc("Allows new hg-git mappings to be inserted "
                            "into mapper db (hashes table)")
p.mapper.project.insert.doc("Allows new projects to be inserted into "
                            "mapper db (projects table)")

# TODO: replace abort with a custom exception
# - http://flask.pocoo.org/docs/patterns/apierrors/


class Project(db.declarative_base('mapper')):

    """Object-relational mapping between python class Project
    and database table "projects"
    """
    __tablename__ = 'releng_mapper_projects'
    id = sa.Column(sa.Integer, primary_key=True)
    name = sa.Column(sa.String(255), nullable=False, unique=True)


class Hash(db.declarative_base('mapper')):

    """Object-relational mapping between python class Hash
    and database table "hashes"
    """
    __tablename__ = 'releng_mapper_hashes'
    hg_changeset = sa.Column(sa.String(40), nullable=False)
    git_commit = sa.Column(sa.String(40), nullable=False)
    project_id = sa.Column(
        sa.Integer, sa.ForeignKey('releng_mapper_projects.id'), nullable=False)
    project = orm.relationship(Project, primaryjoin=(project_id == Project.id))
    # project = orm.relationship(Project, backref=orm.backref('hashes', order_by=id))
    date_added = sa.Column(sa.Integer, nullable=False)

    project_name = property(lambda self: self.project.name)

    def as_json(self):
        return jsonify(**{n: getattr(self, n)
{'fraction_non_alphanumeric': 0.09840071079520213, 'fraction_numerical': 0.004886717014660151, 'mean_word_length': 4.008898776418243, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '2875122', 'n_tokens_mistral': 1408, 'n_tokens_neox': 1346, 'n_words': 403}