<commit_before>/*
 * This file is part of NavalPlan
 *
 * Copyright (C) 2009-2010 Fundación para o Fomento da Calidade Industrial e
 *                         Desenvolvemento Tecnolóxico de Galicia
 * Copyright (C) 2010-2011 Igalia, S.L.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package org.navalplanner.business.planner.entities;

import java.math.BigDecimal;
import java.util.List;

import org.navalplanner.business.common.BaseEntity;

/**
 *
 * @author <NAME><<EMAIL>>
 *
 *         This is an object, directly associated with a TaskGroup with no parent
 *         (TaskRoot element), which is used to stored data about the whole
 *         scheduling
 *
 */
public class PlanningData extends BaseEntity {

    public static PlanningData create(TaskGroup rootTask) {
        return new PlanningData(rootTask);
    }

    private TaskGroup rootTask;

    private BigDecimal progressByDuration;

    private BigDecimal progressByNumHours;

    protected PlanningData() {

    }

    public BigDecimal getProgressByDuration() {
        return progressByDuration;
    }

    public BigDecimal getProgressByNumHours() {
        return progressByNumHours;
    }

    private PlanningData(TaskGroup rootTask) {
        this.rootTask = rootTask;
    }

    public void update(List<Task> criticalPath) {
        progressByDuration = calculateByDuration(criticalPath);
        progressByNumHours = calculateByNumHours(criticalPath);
    }

    private BigDecimal calculateByDuration(List<Task> criticalPath) {
        Integer totalDuration = new Integer(0), duration;
        BigDecimal totalProgress = BigDecimal.ZERO, progress;

        for (Task each : criticalPath) {
            duration = each.getWorkableDays();<commit_msg>[Bug #871] The problem is due to receiving an empty list of tasks<commit_after>/*
 * This file is part of NavalPlan
 *
 * Copyright (C) 2009-2010 Fundación para o Fomento da Calidade Industrial e
 *                         Desenvolvemento Tecnolóxico de Galicia
 * Copyright (C) 2010-2011 Igalia, S.L.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package org.navalplanner.business.planner.entities;

import java.math.BigDecimal;
import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.navalplanner.business.common.BaseEntity;

/**
 *
 * @author <NAME><<EMAIL>>
 *
 *         This is an object, directly associated with a TaskGroup with no parent
 *         (TaskRoot element), which is used to stored data about the whole
 *         scheduling
 *
 */
public class PlanningData extends BaseEntity {

    private static Log LOG = LogFactory.getLog(PlanningData.class);

    public static PlanningData create(TaskGroup rootTask) {
        return new PlanningData(rootTask);
    }

    private TaskGroup rootTask;

    private BigDecimal progressByDuration;

    private BigDecimal progressByNumHours;

    protected PlanningData() {

    }

    public BigDecimal getProgressByDuration() {
        return progressByDuration;
    }

    public BigDecimal getProgressByNumHours() {
        return progressByNumHours;
    }

    private PlanningData(TaskGroup rootTask) {
        this.rootTask = rootTask;
    }

    public void update(List<Task> criticalPath) {
        if (criticalPath.isEmpty()) {
            LOG.warn("it can't be updated because the critical path provided is empty");
            return;
        }
        progressByDuration = calculateByDuration(criticalPath);
        progressByNumHours = calculateByNumHours(criticalPath);
    }

    private BigDecimal calculateByDuration(List<Task> criticalPath) {
        Integer totalDuration = new Integer(0), duration;
        BigDecimal totalProgress = BigDecimal.ZERO, progress;

        for (Task each : criticalPath) {
            duration = each.getWorkableDays();
{'fraction_non_alphanumeric': 0.07169588339570612, 'fraction_numerical': 0.0076817017923970846, 'mean_word_length': 3.2176079734219267, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '381803', 'n_tokens_mistral': 1376, 'n_tokens_neox': 1304, 'n_words': 492}