Package eu.scape_project.planning.model

Examples of eu.scape_project.planning.model.PlanState


    private void analyseChangelogs(PlanStatistics statistics, Plan plan) {
        long[] minChangeLogs = new long[PlanStatistics.MAX_STATE + 1];
        long[] maxChangeLogs = new long[PlanStatistics.MAX_STATE + 1];

        PlanState maxState = plan.getPlanProperties().getState();

        long createdAt = plan.getChangeLog().getCreated();

        // 0 CREATED
        minChangeLogs[0] = createdAt;
        maxChangeLogs[0] = createdAt;
        // 1 INITIALISED
        minChangeLogs[1] = createdAt;
        maxChangeLogs[1] = createdAt;

        // 2 Define Basis - BASIS_DEFINED(2)
        // - ProjectBasis
        minChangeLogs[2] = plan.getProjectBasis().getChangeLog().getChanged();
        maxChangeLogs[2] = minChangeLogs[2];

        // 3. Define Sample Objects - RECORDS_CHOSEN(3)
        // - SampleRecordsDefinition
        // - samples (also created here)
        long minCL = plan.getSampleRecordsDefinition().getChangeLog().getChanged();
        long maxCL = minCL;
        if (minCL <= createdAt) {
            minCL = Long.MAX_VALUE;
        }

        for (SampleObject sample : plan.getSampleRecordsDefinition().getRecords()) {
            ChangeLog sampleCL = sample.getChangeLog();
            if (sampleCL.getChanged() > maxCL) {
                maxCL = sampleCL.getChanged();
            }
            if (sampleCL.getCreated() < minCL) {
                minCL = sampleCL.getCreated();
            }
        }
        minChangeLogs[3] = minCL;
        maxChangeLogs[3] = maxCL;

        // 4. Identify requirements - TREE_DEFINED(4, "Tree Defined"),
        // - nodes/leaves (also created!)
        // - scales
        // - RequirementsDefinition
        minCL = plan.getRequirementsDefinition().getChangeLog().getChanged();
        maxCL = minCL;
        if (minCL <= createdAt) {
            minCL = Long.MAX_VALUE;
        }

        List<TreeNode> nodes = plan.getTree().getRoot().getAllChildren();
        for (TreeNode treeNode : nodes) {
            ChangeLog nodeCL = treeNode.getChangeLog();
            // we can only consider the creation time stamp, as changed is used
            // to confirm values
            if (minCL > nodeCL.getCreated()) {
                minCL = nodeCL.getCreated();
            }
            if (maxCL < nodeCL.getCreated()) {
                maxCL = nodeCL.getCreated();
            }
            // we can only use the scales of leaves, as
            // - nodes can be changed when weighting is changed
            // - leaves are "changed" when evaluated, aggregation mode is
            // changed
            if (treeNode instanceof Leaf) {
                Scale scale = ((Leaf) treeNode).getScale();
                if (scale != null) {
                    ChangeLog scaleCL = scale.getChangeLog();
                    if (maxCL < scaleCL.getChanged()) {
                        maxCL = scaleCL.getChanged();
                    }
                }
            }
        }
        minChangeLogs[4] = minCL;
        maxChangeLogs[4] = maxCL;

        // 5. Define alternatives - ALTERNATIVES_DEFINED(5,
        // "Alternatives Defined")
        // - AlternativesDefinition
        // - Alternative - only created, "changed" can be overwritten in
        // GoDecision)
        minCL = plan.getAlternativesDefinition().getChangeLog().getChanged();
        maxCL = minCL;
        if (minCL <= createdAt) {
            minCL = Long.MAX_VALUE;
        }
        for (Alternative alternative : plan.getAlternativesDefinition().getAlternatives()) {
            ChangeLog altCL = alternative.getChangeLog();
            if (minCL > altCL.getCreated()) {
                minCL = altCL.getCreated();
            }
            if (maxCL < altCL.getCreated()) {
                maxCL = altCL.getCreated();
            }
            // we cannot check for the changed(), as the alternative is also
            // changed in GoDecision
        }
        minChangeLogs[5] = minCL;
        maxChangeLogs[5] = maxCL;

        // 6. Take go decision - GO_CHOSEN(6, "Go Decision Taken")
        // - no: Alternative (! - if discarded)
        // - GoDecision
        minCL = plan.getDecision().getChangeLog().getChanged();
        maxCL = minCL;
        if (minCL <= createdAt) {
            minCL = Long.MAX_VALUE;
        }
        // for (Alternative alternative :
        // plan.getAlternativesDefinition().getAlternatives()) {
        // ChangeLog altCL = alternative.getChangeLog();
        // if (maxCL < altCL.getChanged()) {
        // maxCL = altCL.getChanged();
        // }
        // }
        minChangeLogs[6] = minCL;
        maxChangeLogs[6] = maxCL;
        // 7. Develop Experiments - EXPERIMENT_DEFINED(7, "Experiments Defined")
        // Alternative.Experiment
        minCL = Long.MAX_VALUE;
        maxCL = Long.MIN_VALUE;
        // as the experiment is created together with the alternative, this
        // might result in the same timestamps
        for (Alternative alternative : plan.getAlternativesDefinition().getAlternatives()) {
            ChangeLog expCL = alternative.getExperiment().getChangeLog();
            if (maxCL < expCL.getChanged()) {
                maxCL = expCL.getChanged();
            }
            if (minCL > expCL.getChanged()) {
                minCL = expCL.getChanged();
            }
        }
        minChangeLogs[7] = minCL;
        maxChangeLogs[7] = maxCL;
        // 8. Run Experiments - EXPERIMENT_PERFORMED(8, "Experiments Performed")
        // - detailedExperimentInfo
        // - result files (alternative.experiment.results)
        // - initValues on save
        minCL = Long.MAX_VALUE;
        maxCL = Long.MIN_VALUE;
        // as the experiment is created together with the alternative, this
        // might result in the same timestamps
        for (Alternative alternative : plan.getAlternativesDefinition().getAlternatives()) {
            Experiment experiment = alternative.getExperiment();
            // - detailedExperimentInfo
            // for (DetailedExperimentInfo detailedInfo :
            // experiment.getDetailedInfo().values()) {
            // ChangeLog diCL = detailedInfo.getChangeLog();
            // if (maxCL < diCL.getChanged()) {
            // maxCL = diCL.getChanged();
            // }
            // if (minCL > diCL.getChanged()) {
            // minCL = diCL.getChanged();
            // }
            // }
            // - result files (alternative.experiment.results)
            for (DigitalObject result : experiment.getResults().values()) {
                ChangeLog resultCL = result.getChangeLog();
                if (maxCL < resultCL.getChanged()) {
                    maxCL = resultCL.getChanged();
                }
                if (minCL > resultCL.getChanged()) {
                    minCL = resultCL.getChanged();
                }
            }
            // - initValues on save
            // cannot be used, as automatic evaluators replace the value objects
            // for (TreeNode treeNode : nodes) {
            // ChangeLog nodeCL = treeNode.getChangeLog();
            // if (treeNode instanceof Leaf) {
            // Leaf leaf = (Leaf)treeNode;
            // for (Values values : leaf.getValueMap().values()) {
            // for (Value value : values.getList()) {
            // ChangeLog valueCL = value.getChangeLog();
            // // only the creation time of the value is relevant!
            // if (maxCL.getChanged() < valueCL.getCreated()) {
            // maxCL = valueCL;
            // }
            // }
            // }
            // }
            // }
        }

        minChangeLogs[8] = minCL;
        maxChangeLogs[8] = maxCL;

        // 9. Evaluate Experiments - RESULTS_CAPTURED(9, "Results Captured")
        // - Evaluation
        // - ValueMap-Values
        minCL = plan.getEvaluation().getChangeLog().getChanged();
        maxCL = minCL;
        if (minCL <= createdAt) {
            minCL = Long.MAX_VALUE;
        }
        for (TreeNode treeNode : nodes) {
            if (treeNode instanceof Leaf) {
                Leaf leaf = (Leaf) treeNode;
                // ValueMap-Values
                for (Values values : leaf.getValueMap().values()) {
                    for (Value value : values.getList()) {
                        ChangeLog valueCL = value.getChangeLog();
                        if (maxCL < valueCL.getChanged()) {
                            maxCL = valueCL.getChanged();
                        }
                    }
                }
                // values are created in a previous step, therefore the min
                // values cannot be set regarding the created timestamp
            }
        }
        minChangeLogs[9] = minCL;
        maxChangeLogs[9] = maxCL;

        // 10. Transform measured values - TRANSFORMATION_DEFINED(10,
        // "Transformations Defined")
        // - leaf.transformer
        // - Transformation
        // - leaf (!! - leaf.aggregationMode )
        minCL = plan.getTransformation().getChangeLog().getChanged();
        maxCL = minCL;
        if (minCL <= createdAt) {
            minCL = Long.MAX_VALUE;
        }
        for (TreeNode treeNode : nodes) {
            if (treeNode instanceof Leaf) {
                Leaf leaf = (Leaf) treeNode;
                if (leaf.getTransformer() != null) {
                    ChangeLog tCL = leaf.getTransformer().getChangeLog();
                    if (maxCL < tCL.getChanged()) {
                        maxCL = tCL.getChanged();
                    }
                    if (minCL > tCL.getChanged()) {
                        minCL = tCL.getChanged();
                    }
                }
            }
        }
        minChangeLogs[10] = minCL;
        maxChangeLogs[10] = maxCL;

        // 11. Set importance factors - WEIGHTS_SET(11, "Weights Set")
        // - no: node (! - lock )
        // - ImportanceWeighting
        minCL = plan.getImportanceWeighting().getChangeLog().getChanged();
        maxCL = minCL;
        if (minCL <= createdAt) {
            minCL = Long.MAX_VALUE;
        }

        minChangeLogs[11] = minCL;
        maxChangeLogs[11] = maxCL;

        // 12. Analyse results - ANALYSED(12, "Analyzed")
        // - Recommendation
        minCL = plan.getRecommendation().getChangeLog().getChanged();
        maxCL = minCL;
        if (minCL <= createdAt) {
            minCL = Long.MAX_VALUE;
        }
        minChangeLogs[12] = minCL;
        maxChangeLogs[12] = maxCL;
        //
        // 13. Create Executable plan - EXECUTEABLE_PLAN_CREATED(13,
        // "Executable Plan Created")
        // - ExecutablePlanDefinition
        minCL = plan.getExecutablePlanDefinition().getChangeLog().getChanged();
        maxCL = minCL;
        if (minCL <= createdAt) {
            minCL = Long.MAX_VALUE;
        }
        minChangeLogs[13] = minCL;
        maxChangeLogs[13] = maxCL;

        //
        // 14. Define Plan - PLAN_DEFINED(14, "Plan Defined")
        // - PlanDefinition
        minCL = plan.getPlanDefinition().getChangeLog().getChanged();
        maxCL = minCL;
        if (minCL <= createdAt) {
            minCL = Long.MAX_VALUE;
        }
        minChangeLogs[14] = minCL;
        maxChangeLogs[14] = maxCL;

        // 15. Validate Plan
        if (plan.getPlanProperties().getState() == PlanState.PLAN_VALIDATED) {
            minCL = plan.getPlanProperties().getChangeLog().getChanged();
        } else {
            minCL = Long.MAX_VALUE;
        }

        minChangeLogs[15] = minCL;
        maxChangeLogs[15] = minCL;

        // for (int i =0; i <= PlanStatistics.MAX_STATE; i ++) {
        // if (minChangeLogs[i] == Long.MAX_VALUE) {
        // minChangeLogs[i] = 0L;
        // }
        // if (maxChangeLogs[i] == Long.MIN_VALUE) {
        // maxChangeLogs[i] = 0L;
        // }
        // }
        // calculate durations of each step
        for (int stage = 1; stage < PlanStatistics.MAX_STATE; stage++) {
            long enter = minChangeLogs[stage];
            long exit = minChangeLogs[stage + 1];
            if (LUndef.isDefined(enter) && LUndef.isDefined(exit)) {
                // in minutes, not milliseconds!
                // long duration = exit - enter;
                // from plan creation to exit - in hours
                long duration = exit - createdAt;
                statistics.getPhaseDurations()[stage] = duration / (60 * 60 * 1000);
            } else {
                statistics.getPhaseDurations()[stage] = Long.MAX_VALUE;
            }
        }

        minCL = minChangeLogs[PlanState.GO_CHOSEN.getValue()];
        if (LUndef.isDefined(minCL)) {
            statistics.setToDecision((minCL - createdAt) / (60 * 60 * 1000));
        } else {
            statistics.setToDecision(Long.MIN_VALUE);
        }

        minCL = minChangeLogs[PlanState.PLAN_VALIDATED.getValue()];
        if (LUndef.isDefined(minCL)) {
            statistics.setToCompletion((minCL - createdAt) / (60 * 60 * 1000));
        } else {
            statistics.setToCompletion(Long.MIN_VALUE);
        }

        if (maxState != PlanState.PLAN_VALIDATED) {
            for (int i = PlanStatistics.MAX_STATE - 1; i >= 1; i--) {
                if (LUndef.isDefined(maxChangeLogs[i]) && (maxChangeLogs[i] > createdAt) && (i > maxState.getValue())) {
                    maxState = PlanState.valueOf(i);
                }
            }
        }
        statistics.setHighestStateAchieved(maxState.getValue());
    }
View Full Code Here

TOP

Related Classes of eu.scape_project.planning.model.PlanState

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.