Exemplo n.º 1
0
        public void setRelativeEfficiencyMeasurement(RelativeEfficiencyMeasurement measurement, Metric metric)
        {
            if (this.EffectivenessMeasurement == null)
            {
                bool   successful   = measurement.RecomputedEfficiency.Mean > 0;
                double helpFraction = 0;
                if (successful)
                {
                    helpFraction = 1 - measurement.RecomputedEfficiency.Mean;
                }

                this.EffectivenessMeasurement = new CompletionEfficiencyMeasurement(metric, successful, helpFraction);
            }
            this.EffectivenessMeasurement.Computation = measurement;
        }
        private void simulate(Engine engine, StatList <DateTime, double> efficiencies)
        {
            for (int i = 0; i < efficiencies.NumItems; i++)
            {
                DateTime when = efficiencies.GetValueAtIndex(i).Key;
                if (engine.Test_ChooseExperimentOption().HasError)
                {
                    break; // not enough data to run more experiments
                }
                // make a list of experiment options
                List <SuggestedMetric> experimentOptions = engine.ChooseExperimentOptions(when);
                // Skip setting difficulties for now.
                // Task difficulties could be set via something like:
                //   experimentOptions[0].PlannedMetric.DifficultyEstimate.NumEasiers++;
                // Make an experiment
                ExperimentSuggestion suggestion = engine.Experiment(experimentOptions, when);
                if (!suggestion.Experiment.Started)
                {
                    engine.PutExperimentInMemory(suggestion.Experiment);
                }
                // Do the suggestion
                double             efficiency         = efficiencies.FindPreviousItem(when, false).Value;
                double             duration           = 1.0 / efficiency;
                ActivityDescriptor activityDescriptor = suggestion.ActivitySuggestion.ActivityDescriptor;
                Activity           activity           = engine.ActivityDatabase.ResolveDescriptor(activityDescriptor);
                Metric             metric             = activity.DefaultMetric;
                Participation      participation      = new Participation(when, when.AddDays(duration), activityDescriptor);

                participation.EffectivenessMeasurement = new CompletionEfficiencyMeasurement(metric, true, 0);
                participation.EffectivenessMeasurement.DismissedActivity = true;
                RelativeEfficiencyMeasurement measurement = engine.Make_CompletionEfficiencyMeasurement(participation);
                participation.EffectivenessMeasurement.Computation = measurement;

                engine.PutParticipationInMemory(participation);
            }
            engine.FullUpdate();
            DateTime lastDay = efficiencies.GetLastValue().Key;

            for (int i = 1; i < efficiencies.NumItems; i++)
            {
                ListItemStats <DateTime, double> item     = efficiencies.GetValueAtIndex(i - 1);
                ListItemStats <DateTime, double> nextItem = efficiencies.GetValueAtIndex(i);
                Distribution estimatedEfficiency          = engine.EfficiencySummarizer.GetValueDistributionForDates(item.Key, nextItem.Key, true, false);
                System.Diagnostics.Debug.WriteLine("True efficiency at " + item.Key + " = " + item.Value + ", estimated efficiency = " + estimatedEfficiency.Mean);
            }
            System.Diagnostics.Debug.WriteLine("Test done");
        }
        public Participation GetParticipation(Engine engine)
        {
            Activity activity = this.nameBox.Activity;

            if (activity == null)
            {
                return(null);
            }
            ActivityDescriptor descriptor = activity.MakeDescriptor();

            if (descriptor.ActivityName == null || descriptor.ActivityName.Length == 0)
            {
                return(null);
            }

            if (!this.startDateBox.IsDateValid())
            {
                return(null);
            }
            if (!this.endDateBox.IsDateValid())
            {
                return(null);
            }
            // If the user is trying to submit a participation with misordered dates, then point the out to them
            // Although we could've highlighted this to the user sooner, in most cases this would just distract them and they wouldn't want to think about it
            if (this.EndDate.CompareTo(this.StartDate) <= 0)
            {
                this.startDateBox.appearInvalid();
                this.endDateBox.appearInvalid();
                return(null);
            }
            // If the user tries to record having done someting in the future, that's a mistake because it hasn't happened yet
            DateTime now = DateTime.Now;

            if (this.StartDate.CompareTo(now) > 0 || this.EndDate.CompareTo(now) > 0)
            {
                return(null);
            }
            Participation participation = new Participation(this.StartDate, this.EndDate, descriptor);

            if (this.CommentText != "" && this.CommentText != null)
            {
                participation.Comment = this.CommentText;
            }

            try
            {
                Rating rating = this.ratingBox.GetRelativeRating(engine, participation);
                participation.Rating = rating;
            }
            catch (Exception)
            {
                // If the rating is invalid, then we can ignore that
            }

            Metric metric = this.Metric;

            if (metric != null)
            {
                // Record the success/failure status of the participation
                string status       = this.todoCompletionStatusPicker.SelectedItem.ToString();
                bool   successful   = (status == this.TaskCompleted_Text || status == this.ProblemComplete_Text);
                bool   closed       = (status != this.TaskIncomplete_Text && status != this.ProblemIncomplete_Text);
                double helpFraction = this.helpStatusPicker.GetHelpFraction(participation.Duration);
                participation.EffectivenessMeasurement = new CompletionEfficiencyMeasurement(metric, successful, helpFraction);
                participation.EffectivenessMeasurement.DismissedActivity = closed;
                // Notice that the Engine doesn't need us to pass in a Metric for computing the efficiency of this participation, because computing efficiency requires an experiment, and the
                // experiment already knows which metric we're using
                RelativeEfficiencyMeasurement measurement = engine.Make_CompletionEfficiencyMeasurement(participation);
                participation.EffectivenessMeasurement.Computation = measurement;
            }

            participation.Suggested = this.get_wasSuggested(participation.ActivityDescriptor);

            return(participation);
        }
        public ExperimentResultsView(Participation participation)
        {
            HelpWindowBuilder builder = new HelpWindowBuilder();

            PlannedExperiment             experiment = participation.RelativeEfficiencyMeasurement.Experiment;
            RelativeEfficiencyMeasurement earlier    = experiment.FirstParticipation.RelativeEfficiencyMeasurement;
            RelativeEfficiencyMeasurement later      = experiment.SecondParticipation.RelativeEfficiencyMeasurement;
            string earlierName = earlier.ActivityDescriptor.ActivityName;
            string laterName   = later.ActivityDescriptor.ActivityName;

            builder.AddMessage("In your experiment at " + earlier.StartDate + ", you agreed to several choices, including:");
            builder.AddMessage("A: " + earlierName);
            builder.AddMessage("B: " + laterName);

            double difficultyRatio = experiment.Earlier.DifficultyEstimate.EstimatedSuccessesPerSecond / experiment.Later.DifficultyEstimate.EstimatedSuccessesPerSecond;

            builder.AddMessage("You predicted that B would be " + this.round(difficultyRatio) + " times as difficult as A.");

            TimeSpan earlierDuration = earlier.EndDate.Subtract(earlier.StartDate);
            double   earlierMinutes  = earlierDuration.TotalMinutes;
            TimeSpan laterDuration   = later.EndDate.Subtract(later.StartDate);
            double   laterMinutes    = laterDuration.TotalMinutes;

            double earlierHelpFraction    = experiment.FirstParticipation.HelpFraction;
            string earlierHelpDescription = "";

            if (earlierHelpFraction > 0)
            {
                earlierHelpDescription = " with help, and you personally completed " + this.round(1 - earlierHelpFraction) + " of it";
            }
            builder.AddMessage("Then, you spent " + this.round(earlierDuration.TotalMinutes) + "m on A" + earlierHelpDescription);

            double laterHelpFraction    = experiment.SecondParticipation.HelpFraction;
            string laterHelpDescription = "";

            if (laterHelpFraction > 0)
            {
                laterHelpDescription = " with help, and you personally completed " + this.round(1 - laterHelpFraction) + " of it";
            }
            builder.AddMessage("Later, you spent " + this.round(laterDuration.TotalMinutes) + "m on B at " + later.StartDate + laterHelpDescription);

            double earlierTotalEffectiveness = earlier.RecomputedEfficiency.Mean * earlierMinutes / (1 - earlierHelpFraction);
            double laterTotalEffectiveness   = later.RecomputedEfficiency.Mean * laterMinutes / (1 - laterHelpFraction);

            string earlierHelpDivision = "";

            if (earlierHelpFraction > 0)
            {
                earlierHelpDivision = " / " + this.round(1 - earlierHelpFraction);
            }
            builder.AddMessage("I estimated that your efficiency on A would be about " + this.round(earlier.RecomputedEfficiency.Mean) +
                               ", making the difficulty of A be " + this.round(earlier.RecomputedEfficiency.Mean) + " * " + this.round(earlierMinutes) + "m" + earlierHelpDivision + " = " +
                               this.round(earlierTotalEffectiveness) + "m");

            builder.AddMessage("So, the difficulty of B should be " + this.round(earlierTotalEffectiveness) + "m * "
                               + this.round(difficultyRatio) + " = " + this.round(laterTotalEffectiveness) + "m");

            string laterHelpDivision = "";

            if (laterHelpFraction > 0)
            {
                laterHelpDivision = " / " + this.round(1 - laterHelpFraction);
            }
            builder.AddMessage("And your efficiency on B should be " + this.round(laterTotalEffectiveness) + "m / " +
                               this.round(laterMinutes) + "m" + laterHelpDivision + " = " + this.round(later.RecomputedEfficiency.Mean));

            builder.AddMessage("Isn't that interesting?");

            this.SubLayout = builder.Build();
        }