<commit_before>package com.box.l10n.mojito.entity;

import com.box.l10n.mojito.entity.security.user.User;
import com.box.l10n.mojito.rest.View;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonManagedReference;
import com.fasterxml.jackson.annotation.JsonView;
import java.util.HashSet;
import java.util.Set;
import javax.persistence.ColumnResult;
import javax.persistence.ConstructorResult;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.ForeignKey;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import javax.persistence.SqlResultSetMapping;
import javax.persistence.Table;
import org.hibernate.annotations.NamedNativeQueries;
import org.hibernate.annotations.NamedNativeQuery;
import org.springframework.data.annotation.CreatedBy;

/**
 * Entity that contains statistics (word count, translated count, etc) of a
 * {@link Repository}
 *
 * @author jaurambault
 */
@Entity
@Table(name = "repository_statistic")
@SqlResultSetMapping(
        name = "RepositoryStatistic.computeBaseStatistics",
        classes = {
            @ConstructorResult(
                    targetClass = RepositoryStatistic.class,
                    columns = {
                        @ColumnResult(name = "usedTextUnitCount", type = Long.class),
                        @ColumnResult(name = "usedTextUnitWordCount", type = Long.class),
                        @ColumnResult(name = "unusedTextUnitCount", type = Long.class),
                        @ColumnResult(name = "unusedTextUnitWordCount", type = Long.class),
                        @ColumnResult(name = "uncommentedTextUnitCount", type = Long.class),
                        @ColumnResult(name = "pluralTextUnitCount", type = Long.class),
                        @ColumnResult(name = "pluralTextUnitWordCount", type = Long.class)
                    }
            )
        }
)
@NamedNativeQueries(
        @NamedNativeQuery(name = "RepositoryStatistic.computeBaseStatistics",
                query
                = "select "
                + "   coalesce(sum(case when map.id is not null and a.deleted = false then 1 else 0 end), 0) as usedTextUnitCount, "
                + "   coalesce(sum(case when map.id is not null and a.deleted = false then tu.word_count else 0 end), 0) as usedTextUnitWordCount, "
                + "   coalesce(sum(case when map.id is null or a.deleted = true then 1 else 0 end), 0) as unusedTextUnitCount, "
                + "   coalesce(sum(case when map.id is null or a.deleted = true then tu.word_count else 0 end), 0) as unusedTextUnitWordCount, "
                + "   coalesce(sum(case when (map.id is not null and tu.comment is null) then 1 else 0 end), 0) as uncommentedTextUnitCount, "
                + "   coalesce(sum(case when (map.id is not null and tu.plural_form_id is not null) then 1 else 0 end), 0) / 6 as pluralTextUnitCount, "
                + "   coalesce(sum(case when (map.id is not null and tu.plural_form_id is not null) then tu.word_count else 0 end), 0) / 6 as pluralTextUnitWordCount "
                + " "
                + "from tm_text_unit tu "
                + "   inner join asset a on a.id = tu.asset_id "
                + "   left outer join asset_text_unit_to_tm_text_unit map on tu.id = map.tm_text_unit_id and map.asset_extraction_id = a.last_successful_asset_extraction_id "
                + "where "
                + "   a.repository_id = ?1",
                resultSetMapping = "RepositoryStatistic.computeBaseStatistics"
        )
)
public class RepositoryStatistic extends AuditableEntity {

    /**
     * The number of used text units in the repository
     */
    @JsonView(View.RepositorySummary.class)
    private Long usedTextUnitCount = 0L;

    /**
     * The word count of used text units
     */
    @JsonView(View.RepositorySummary.class)<commit_msg>Should look only at used text unit for plural information and comments<commit_after>package com.box.l10n.mojito.entity;

import com.box.l10n.mojito.entity.security.user.User;
import com.box.l10n.mojito.rest.View;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonManagedReference;
import com.fasterxml.jackson.annotation.JsonView;
import java.util.HashSet;
import java.util.Set;
import javax.persistence.ColumnResult;
import javax.persistence.ConstructorResult;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.ForeignKey;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import javax.persistence.SqlResultSetMapping;
import javax.persistence.Table;
import org.hibernate.annotations.NamedNativeQueries;
import org.hibernate.annotations.NamedNativeQuery;
import org.springframework.data.annotation.CreatedBy;

/**
 * Entity that contains statistics (word count, translated count, etc) of a
 * {@link Repository}
 *
 * @author jaurambault
 */
@Entity
@Table(name = "repository_statistic")
@SqlResultSetMapping(
        name = "RepositoryStatistic.computeBaseStatistics",
        classes = {
            @ConstructorResult(
                    targetClass = RepositoryStatistic.class,
                    columns = {
                        @ColumnResult(name = "usedTextUnitCount", type = Long.class),
                        @ColumnResult(name = "usedTextUnitWordCount", type = Long.class),
                        @ColumnResult(name = "unusedTextUnitCount", type = Long.class),
                        @ColumnResult(name = "unusedTextUnitWordCount", type = Long.class),
                        @ColumnResult(name = "uncommentedTextUnitCount", type = Long.class),
                        @ColumnResult(name = "pluralTextUnitCount", type = Long.class),
                        @ColumnResult(name = "pluralTextUnitWordCount", type = Long.class)
                    }
            )
        }
)
@NamedNativeQueries(
        @NamedNativeQuery(name = "RepositoryStatistic.computeBaseStatistics",
                query
                = "select "
                + "   coalesce(sum(case when map.id is not null and a.deleted = false then 1 else 0 end), 0) as usedTextUnitCount, "
                + "   coalesce(sum(case when map.id is not null and a.deleted = false then tu.word_count else 0 end), 0) as usedTextUnitWordCount, "
                + "   coalesce(sum(case when map.id is null or a.deleted = true then 1 else 0 end), 0) as unusedTextUnitCount, "
                + "   coalesce(sum(case when map.id is null or a.deleted = true then tu.word_count else 0 end), 0) as unusedTextUnitWordCount, "
                + "   coalesce(sum(case when (map.id is not null and a.deleted = false and tu.comment is null) then 1 else 0 end), 0) as uncommentedTextUnitCount, "
                + "   coalesce(sum(case when (map.id is not null and a.deleted = false and tu.plural_form_id is not null) then 1 else 0 end), 0) as pluralTextUnitCount, "
                + "   coalesce(sum(case when (map.id is not null and a.deleted = false and tu.plural_form_id is not null) then tu.word_count else 0 end), 0) as pluralTextUnitWordCount "
                + " "
                + "from tm_text_unit tu "
                + "   inner join asset a on a.id = tu.asset_id "
                + "   left outer join asset_text_unit_to_tm_text_unit map on tu.id = map.tm_text_unit_id and map.asset_extraction_id = a.last_successful_asset_extraction_id "
                + "where "
                + "   a.repository_id = ?1",
                resultSetMapping = "RepositoryStatistic.computeBaseStatistics"
        )
)
public class RepositoryStatistic extends AuditableEntity {

    /**
     * The number of used text units in the repository
     */
    @JsonView(View.RepositorySummary.class)
    private Long usedTextUnitCount = 0L;

    /**
     * The word count of used text units
     */
    @JsonView(View.RepositorySummary.class)
{'fraction_non_alphanumeric': 0.09159736874767282, 'fraction_numerical': 0.006702246493732159, 'mean_word_length': 2.634641407307172, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 6}, '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': '4334657', 'n_tokens_mistral': 2334, 'n_tokens_neox': 2245, 'n_words': 577}