<commit_before>/* global require, Project,ResearchItemTypes, ResearchItemProjectCompetitive, ResearchItemProjectIndustrial, ResearchItemProjectAgreement, ResearchItemKinds, Group, GroupTypes, Utils  */
'use strict';

const _ = require('lodash');

const BaseModel = require("../lib/BaseModel.js");

const fields = [
    'kind',
    'type',
    'draftCreator',
    'code',
    'acronym',
    'title',
    'abstract',
    'startDate',
    'endDate',
    'projectType',
    'category',
    'payment',
    'role',
    'status',
    'url',
    'members',
    'researchLines',
    'logos',
    'projectData'
];

module.exports = _.merge({}, BaseModel, {
    DEFAULT_SORTING: {
        start_year: 'desc',
        title: 'asc',
        id: 'desc'
    },
    migrate: 'safe',
    tableName: 'project',
    autoUpdatedAt: false,
    autoCreatedAt: false,
    attributes: {
        kind: 'STRING',
        type: {
            model: 'researchitemtype'
        },
        draftCreator: {
            model: 'researchentity',
            columnName: 'draft_creator'
        },
        group: {
            model: 'group'
        },
        code: 'STRING',
        acronym: 'STRING',
        title: 'STRING',
        abstract: 'STRING',
        startDate: {
            type: 'STRING',
            columnName: 'start_date'
        },
        endDate: {
            type: 'STRING',
            columnName: 'end_date'
        },
        startYear: {
            type: 'STRING',
            columnName: 'start_year'
        },
        endYear: {
            type: 'STRING',
            columnName: 'end_year'
        },
        projectType: {
            type: 'STRING',
            columnName: 'project_type'
        },
        projectType2: {
            type: 'STRING',
            columnName: 'project_type_2'
        },
        category: {
            type: 'STRING',
            columnName: 'category'
        },
        payment: {
            type: 'STRING',
            columnName: 'payment'
        },
        role: 'STRING',
        status: 'STRING',
        url: 'STRING',
        members: 'JSON',
        authorsStr: {
            type: 'STRING',
            columnName: 'authors_str'
        },
        researchLines: {
            type: 'JSON',
            columnName: 'research_lines'
        },
        logos: 'JSON',
        projectData: {
            type: 'JSON',
            columnName: 'project_data'
        },
        typeKey: {
            type: 'STRING',
            columnName: 'key'
        },
        verified: {
            collection: 'projectverify',
            via: 'project'
        },
        verifiedUsers: {
            collection: 'user',
            through: 'projectverifieduser'
        },
        verifiedGroups: {
            collection: 'group',
            through: 'projectverifiedgroup'
        },
        authors: {
            collection: 'projectauthor',
            via: 'project'
        },
        affiliations: {
            collection: 'projectaffiliation',
            via: 'project',
        },
        institutes: {
            collection: 'institute',
            via: 'project',
            through: 'projectaffiliation'
        },
        favorites: {
            collection: 'researchentity',
            via: 'favoriteprojects',
            through: 'projectfavorite'
        },
        async isValid() {
            const ResearchItemModel = Project.getResearchItemModel(this.type);
            const ri = await ResearchItemModel.findOne({researchItem: this.id});
            return ri.isValid();
        },
        toJSON() {
            const project = this.toObject();
            if (project.typeKey === ResearchItemTypes.PROJECT_COMPETITIVE && project.members)
                project.pi = project.members
                    .filter(m => ['pi', 'co_pi'].includes(m.role))
                    .map(m => ({
                        email: m.email,
                        name: m.name,
                        surname: m.surname
                    }));
            if (project.researchLines)<commit_msg>Added contribution totals for industrial projects<commit_after>/* global require, Project,ResearchItemTypes, ResearchItemProjectCompetitive, ResearchItemProjectIndustrial, ResearchItemProjectAgreement, ResearchItemKinds, Group, GroupTypes, Utils  */
'use strict';

const _ = require('lodash');

const BaseModel = require("../lib/BaseModel.js");

const fields = [
    'kind',
    'type',
    'draftCreator',
    'code',
    'acronym',
    'title',
    'abstract',
    'startDate',
    'endDate',
    'projectType',
    'category',
    'payment',
    'role',
    'status',
    'url',
    'members',
    'researchLines',
    'logos',
    'projectData'
];

module.exports = _.merge({}, BaseModel, {
    DEFAULT_SORTING: {
        start_year: 'desc',
        title: 'asc',
        id: 'desc'
    },
    migrate: 'safe',
    tableName: 'project',
    autoUpdatedAt: false,
    autoCreatedAt: false,
    attributes: {
        kind: 'STRING',
        type: {
            model: 'researchitemtype'
        },
        draftCreator: {
            model: 'researchentity',
            columnName: 'draft_creator'
        },
        group: {
            model: 'group'
        },
        code: 'STRING',
        acronym: 'STRING',
        title: 'STRING',
        abstract: 'STRING',
        startDate: {
            type: 'STRING',
            columnName: 'start_date'
        },
        endDate: {
            type: 'STRING',
            columnName: 'end_date'
        },
        startYear: {
            type: 'STRING',
            columnName: 'start_year'
        },
        endYear: {
            type: 'STRING',
            columnName: 'end_year'
        },
        projectType: {
            type: 'STRING',
            columnName: 'project_type'
        },
        projectType2: {
            type: 'STRING',
            columnName: 'project_type_2'
        },
        category: {
            type: 'STRING',
            columnName: 'category'
        },
        payment: {
            type: 'STRING',
            columnName: 'payment'
        },
        role: 'STRING',
        status: 'STRING',
        url: 'STRING',
        members: 'JSON',
        authorsStr: {
            type: 'STRING',
            columnName: 'authors_str'
        },
        researchLines: {
            type: 'JSON',
            columnName: 'research_lines'
        },
        logos: 'JSON',
        projectData: {
            type: 'JSON',
            columnName: 'project_data'
        },
        typeKey: {
            type: 'STRING',
            columnName: 'key'
        },
        verified: {
            collection: 'projectverify',
            via: 'project'
        },
        verifiedUsers: {
            collection: 'user',
            through: 'projectverifieduser'
        },
        verifiedGroups: {
            collection: 'group',
            through: 'projectverifiedgroup'
        },
        authors: {
            collection: 'projectauthor',
            via: 'project'
        },
        affiliations: {
            collection: 'projectaffiliation',
            via: 'project',
        },
        institutes: {
            collection: 'institute',
            via: 'project',
            through: 'projectaffiliation'
        },
        favorites: {
            collection: 'researchentity',
            via: 'favoriteprojects',
            through: 'projectfavorite'
        },
        async isValid() {
            const ResearchItemModel = Project.getResearchItemModel(this.type);
            const ri = await ResearchItemModel.findOne({researchItem: this.id});
            return ri.isValid();
        },
        toJSON() {
            const project = this.toObject();
            if (project.typeKey === ResearchItemTypes.PROJECT_COMPETITIVE && project.members)
                project.pi = project.members
                    .filter(m => ['pi', 'co_pi'].includes(m.role))
                    .map(m => ({
                        email: m.email,
                        name: m.name,
                        surname: m.surname
                    }));
            if (project.typeKey === ResearchItemTypes.PROJECT_INDUSTRIAL && project.researchLines) {
                project.inCashContribution = project.researchLines.reduce(
                    (total, rl) => total + (rl.inCashContribution || 0),
                    0);
                project.inKindContribution = project.researchLines.reduce(
                    (total, rl) => total + (rl.inKindContribution || 0),
                    0);
                project.totalContribution = project.inCashContribution + project.inKindContribution;
            }
            if (project.researchLines)
{'fraction_non_alphanumeric': 0.12109375, 'fraction_numerical': 0.0009191176470588235, 'mean_word_length': 1.4737141233304916, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '1031601', 'n_tokens_mistral': 2385, 'n_tokens_neox': 2350, 'n_words': 471}