private LayoutChoice_Set makeSublayout()
        {
            Correlator correlator = this.efficiencyCorrelator.Correlator;

            if (correlator.HasCorrelation)
            {
                double slope = correlator.Slope;
                if (slope != 0)
                {
                    double numYearsPerDouble = 1.0 / slope;
                    double roundedNumYears   = Math.Round(Math.Abs(numYearsPerDouble), 2);
                    string result;
                    if (numYearsPerDouble > 0)
                    {
                        result = "Your data indicates that your efficiency doubles every " + roundedNumYears + " years. Nice!";
                    }
                    else
                    {
                        result = "Your data indicates that your efficiency halves every " + roundedNumYears + " years. Keep trying anyway!";
                    }
                    result += "\n";
                    result += "\nTo see a graph of your efficiency over time, go back to Visualize one Activity.";
                    result += "\nTo find your most and least efficient participations, go back to Search Participations.";
                    return(new TextblockLayout(result));
                }
                else
                {
                    return(new TextblockLayout("Your efficiency has not changed yet. Collect more data by running more experiments!"));
                }
            }
            else
            {
                return(new TextblockLayout("We don't have enough efficiency data yet. Collect more data by running more experiments!"));
            }
        }
Ejemplo n.º 2
0
        private DataPair doCorrelation(DataIdentifier identifier, DataItem item)
        {
            if (this.correlator == null)
            {
                this.correlator = new Correlator();
            }

            return(this.correlator.Correlate(identifier, item));
        }
        public async Task CorrelateMoveFileAsync()
        {
            var context   = BuildXLContext.CreateInstanceForTesting();
            var pathTable = context.PathTable;

            using (var tempFiles = new TempFileStorage(canGetFileNames: true, rootPath: TemporaryDirectory))
            {
                AbsolutePath sourceDirectory = tempFiles.GetDirectory(pathTable, "Source");
                AbsolutePath sourceFile      = sourceDirectory.Combine(pathTable, "SourceFile.txt");
                var          destinationFile = tempFiles.GetFileName(pathTable, "DestinationFile.txt");
                WriteFile(pathTable, sourceFile, "content");

                var process = CreateDetourProcess(
                    context,
                    pathTable,
                    tempFiles,
                    argumentStr: "CorrelateMoveFile",
                    inputFiles: ReadOnlyArray <FileArtifact> .Empty,
                    inputDirectories: ReadOnlyArray <DirectoryArtifact> .Empty,
                    outputFiles: ReadOnlyArray <FileArtifactWithAttributes> .FromWithoutCopy(
                        FileArtifactWithAttributes.Create(
                            FileArtifact.CreateOutputFile(destinationFile), FileExistence.Required)),
                    outputDirectories: ReadOnlyArray <DirectoryArtifact> .Empty,
                    untrackedScopes: ReadOnlyArray <AbsolutePath> .FromWithoutCopy(sourceDirectory));

                var correlator = new Correlator(pathTable);
                SandboxedProcessPipExecutionResult result = await RunProcessAsync(
                    pathTable : pathTable,
                    ignoreSetFileInformationByHandle : false,
                    ignoreZwRenameFileInformation : false,
                    monitorNtCreate : true,
                    ignoreReparsePoints : false,
                    ignoreNonCreateFileReparsePoints : false,
                    monitorZwCreateOpenQueryFile : false,
                    context : context,
                    pip : process,
                    detoursListener : correlator,
                    errorString : out _);

                VerifyNormalSuccess(context, result);

                XAssert.IsTrue(File.Exists(destinationFile.ToString(pathTable)));

                var toVerify = new List <(AbsolutePath, RequestedAccess, FileAccessStatus)>
                {
                    (sourceFile, RequestedAccess.ReadWrite, FileAccessStatus.Allowed),
                    (destinationFile, RequestedAccess.Write, FileAccessStatus.Allowed)
                };

                VerifyFileAccesses(context, result.AllReportedFileAccesses, toVerify.ToArray());
                correlator.VerifyCorrelation(new Correlator.VerifiedCorrelation(
                                                 destinationFile.ToString(pathTable),
                                                 ReportedFileOperation.MoveFileWithProgressDest,
                                                 sourceFile.ToString(pathTable),
                                                 ReportedFileOperation.MoveFileWithProgressSource));
            }
        }
Ejemplo n.º 4
0
        // Notes:
        // - Strategies should be resume-able, i.e on start they should look for
        //   existing positions associated with the strategy and continue using them.
        //   This is so startup/shutdown have very little effect on the running of the bot.

        public Strategy(Rylobot bot, string label, double risk)
        {
            Bot         = bot;
            Label       = label;
            Suitability = new List <Vec2d>();
            Correlator  = new Correlator(label);
            Risk        = risk;

            Debugging.DumpInstrument += Dump;
        }
        public void AndItShouldNotDoThat()
        {
            var newGuid    = Guid.NewGuid();
            var correlator = new Correlator <TheSagaData, TheMessage>(
                x => x.Id,
                new TheSaga
            {
                Data = new TheSagaData
                {
                    Id = newGuid
                }
            });

            var fieldFromMessage = correlator.FieldFromMessage(new TheMessage {
                Id = newGuid
            });

            Assert.AreEqual(newGuid, fieldFromMessage);
        }
Ejemplo n.º 6
0
        public ParticipationCorrelationView(Engine engine, IEnumerable <Activity> activitiesToPredictFrom, Activity activityToPredict, TimeSpan windowSize)
        {
            DateTime now = DateTime.Now;

            engine.EnsureRatingsAreAssociated();

            LinearProgression progressionToPredict = activityToPredict.ParticipationsSmoothed((new TimeSpan()).Subtract(windowSize));

            StatList <double, Activity> results = new StatList <double, Activity>(new DoubleComparer(), new NoopCombiner <Activity>());

            foreach (Activity activity in activitiesToPredictFrom)
            {
                System.Diagnostics.Debug.WriteLine("comparing " + activity + " and " + activityToPredict.Name);
                List <Datapoint> datapoints = activity.compareParticipations(windowSize, progressionToPredict, now.Subtract(windowSize));

                // now compute the value of the formula
                Correlator correlator = new Correlator();
                foreach (Datapoint datapoint in datapoints)
                {
                    correlator.Add(datapoint);
                }

                double outputIncreasePerInputIncrease = correlator.Slope;
                if (!double.IsNaN(outputIncreasePerInputIncrease))
                {
                    results.Add(outputIncreasePerInputIncrease, activity);
                }
            }

            IEnumerable <ListItemStats <double, Activity> > resultList = results.AllItems;

            GridLayout_Builder layoutBuilder = new Vertical_GridLayout_Builder().Uniform();
            List <ListItemStats <double, Activity> > mostPositivelyCorrelated = new List <ListItemStats <double, Activity> >();
            List <ListItemStats <double, Activity> > mostNegativelyCorrelated = new List <ListItemStats <double, Activity> >();
            int i            = 0;
            int numPositives = Math.Min(4, resultList.Count());

            foreach (ListItemStats <double, Activity> result in resultList.Reverse())
            {
                mostPositivelyCorrelated.Add(result);
                i++;
                if (i > numPositives)
                {
                    break;
                }
            }
            i = 0;
            int numNegatives = Math.Min(4, resultList.Count() - numPositives);

            foreach (ListItemStats <double, Activity> result in resultList)
            {
                mostNegativelyCorrelated.Add(result);
                i++;
                if (i > numNegatives)
                {
                    break;
                }
            }

            if (resultList.Count() <= 0)
            {
                // This shouldn't be able to happen unless we disallow predicting the activity from itself
                this.SubLayout = new TextblockLayout("No activities found!");
            }
            else
            {
                string title = "Things you do that are correlated with doing more or less of " + activityToPredict.Name + " over the following " +
                               Math.Round(windowSize.TotalDays, 0) + " days";
                layoutBuilder.AddLayout(new TextblockLayout(title));

                if (numPositives > 0)
                {
                    if (numPositives > 1)
                    {
                        layoutBuilder.AddLayout(new TextblockLayout("Doing one minute of these activities adds this many minutes:"));
                    }
                    else
                    {
                        layoutBuilder.AddLayout(new TextblockLayout("Doing one minute of this activity adds this many minutes:"));
                    }
                    foreach (ListItemStats <double, Activity> result in mostPositivelyCorrelated)
                    {
                        double   correlation = result.Key;
                        Activity activity    = result.Value;
                        String   message     = activity.Name + ": " + Math.Round(correlation, 5);
                        layoutBuilder.AddLayout(new TextblockLayout(message));
                    }
                }

                if (numNegatives > 0)
                {
                    if (numNegatives > 1)
                    {
                        layoutBuilder.AddLayout(new TextblockLayout("Doing one minute of these activities subtracts this many minutes:"));
                    }
                    else
                    {
                        layoutBuilder.AddLayout(new TextblockLayout("Doing one minute of this activity subtracts this many minutes:"));
                    }
                    foreach (ListItemStats <double, Activity> result in mostNegativelyCorrelated)
                    {
                        double   correlation = result.Key;
                        Activity activity    = result.Value;
                        String   message     = activity.Name + ": " + Math.Round(correlation, 5);
                        layoutBuilder.AddLayout(new TextblockLayout(message));
                    }
                }

                this.SubLayout = layoutBuilder.Build();
            }
        }