示例#1
0
            public override SpellerExperiment Create(IReadonlyContext context)
            {
                var config = new Configuration
                {
                    Gui = new Configuration.GuiConfig
                    {
                        ColumnsOverridden     = ColumnsOverridden.Get(context),
                        BackgroundColor       = BackgroundColor.Get(context, ColorUtils.ToUIntArgb),
                        ForegroundColor       = ForegroundColor.Get(context, ColorUtils.ToUIntArgb),
                        CorrectTextColor      = CorrectTextColor.Get(context, ColorUtils.ToUIntArgb),
                        WrongTextColor        = WrongTextColor.Get(context, ColorUtils.ToUIntArgb),
                        InputTextFontSize     = InputTextFontSize.Get(context),
                        InputBarVisibility    = InputBarVisibility.Get(context),
                        ButtonFontSize        = ButtonFontSize.Get(context),
                        ButtonSize            = ButtonSize.Get(context),
                        ButtonMargin          = ButtonMargin.Get(context),
                        ButtonBorder          = ButtonBorder.Get(context),
                        ButtonNormalColor     = ButtonNormalColor.Get(context, ColorUtils.ToUIntArgb),
                        ButtonFlashingColor   = ButtonFlashingColor.Get(context, ColorUtils.ToUIntArgb),
                        ButtonHintColor       = ButtonHintColor.Get(context, ColorUtils.ToUIntArgb),
                        ButtonFlashingMargins = ButtonFlashingMargins.Get(context),
                        ButtonFixationPoint   = ButtonFixationPoint.Get(context)
                    },
                    Test = new Configuration.TestConfig
                    {
                        Debug                   = Debug.Get(context),
                        Layout                  = Layout.Get(context),
                        Paradigm                = Paradigm.Get(context),
                        ActivationMode          = ActivationMode.Get(context),
                        DynamicInterval         = DynamicInterval.Get(context),
                        CursorMovementTolerance = CursorMovementTolerance.Get(context),
                        SelectionDelay          = SelectionDelay.Get(context),
                        CopySpelling            = CopySpelling.Get(context),
                        AlwaysCorrectFeedback   = AlwaysCorrectFeedback.Get(context),
                        Baseline                = Baseline.Get(context),
                        Channels                = Channels.Get(context),
                        TargetRate              = TargetRate.Get(context),
                        SubTrialCount           = SubTrialCount.Get(context),
                        ComputeParallelLevel    = ComputeParallelLevel.Get(context),
                        StimulationPatterns     = StimulationPatterns.Get(context, ParseMultiple),
                        FilterBank              = FilterBank.Get(context, Configuration.TestConfig.BandpassFilter.Parse),
                        SubBandMixingParams     = SubBandMixingParams.Get(context),
                        HarmonicsCount          = HarmonicsCount.Get(context),
                        SsvepDelay              = SsvepDelay.Get(context),
                        CcaThreshold            = CcaThreshold.Get(context),
                        Trial                   = Trial.Get(context),
                        TrialCancellable        = TrialCancellable.Get(context),
                    }
                };

                if (config.Test.Paradigm == SpellerParadigm.EyeTracking)
                {
                    config.Test.ActivationMode = SpellerActivationMode.Single;
                }
                return(new SpellerExperiment(config));
            }
示例#2
0
            public override SerialPortMarkerSource Create(IReadonlyContext context)
            {
                var serialPort = SerialPortParam.Get(context);

                if (serialPort == null)
                {
                    throw new UserException("Serial Port must set.");
                }
                return(new SerialPortMarkerSource(serialPort, BaudRateParam.Get(context), DataBitsParam.Get(context), StopBitsParam.Get(context), ParityParam.Get(context)));
            }
示例#3
0
            public override OpenBCISampler Create(IReadonlyContext context)
            {
                var serialPort = SerialPortParam.Get(context);

                if (serialPort == AutoSearchPort)
                {
                    serialPort = null;
                }
                return(new OpenBCISampler(serialPort, DaisyModuleParam.Get(context)));
            }
示例#4
0
            public override DataFileReader Create(IReadonlyContext context)
            {
                var filePath = DataFileParam.Get(context) ?? throw new ArgumentException("file must be specified");

                if (!filePath.Exists)
                {
                    throw new FileNotFoundException("data file not found", filePath.Value);
                }
                return(new DataFileReader(filePath.Value, FrequencyParam.Get(context)));
            }
示例#5
0
        public static string GetFullSessionName(string subject, string sessionDescriptor, SerializedObject serializedParadigm, string time = null)
        {
            IReadonlyContext context = null;

            if (serializedParadigm.Args != null && App.Instance.Registries.Registry <ParadigmTemplate>().LookUp(serializedParadigm.Id, out var paradigmTemplate))
            {
                context = paradigmTemplate.DeserializeArgs(serializedParadigm.Args);
            }
            return(GetFullSessionName(subject, sessionDescriptor, context, time));
        }
示例#6
0
            public override GazeFileReader Create(IReadonlyContext context)
            {
                var filePath = GazeFileParam.Get(context) ?? throw new ArgumentException("file must be specified");

                if (!filePath.Exists)
                {
                    throw new FileNotFoundException("gaze file not found", filePath.Value);
                }
                return(new GazeFileReader(filePath.Value));
            }
            public override UnnamedDeviceSampler Create(IReadonlyContext context)
            {
                var serialPort = SerialPortParam.Get(context);

                if (serialPort == null)
                {
                    throw new UserException("Serial Port must set.");
                }
                return(new UnnamedDeviceSampler(serialPort));
            }
示例#8
0
            public object Get(IReadonlyContext context)
            {
                var result = context.TryGet(_parameter, out var val) ? val : _parameter.DefaultValue;

                _parameter.IsValidOrThrow(result);
                if (!(_adapter?.IsValid(_parameter.Field, result) ?? true))
                {
                    throw new ArgumentException($"Value of field '{_parameter.Field}' is invalid");
                }
                return(result);
            }
示例#9
0
            public override Colors Create(IParameterDescriptor parameter, IReadonlyContext context)
            {
                var colorKeys = ColorKeysProperty.Get(parameter.Metadata);
                var colors    = new uint[colorKeys.Length];

                for (var i = 0; i < colorKeys.Length; i++)
                {
                    colors[i] = GetParameter(colorKeys[i]).Get(context).ToUIntArgb();
                }
                return(new Colors(colorKeys, colors));
            }
        public IParameterizedObject Create(IParameterDescriptor parameter, IReadonlyContext context)
        {
            var meta  = GetMeta(parameter);
            var value = meta.Constructor();

            foreach (var autoParameter in meta.Parameters)
            {
                autoParameter.SetMemberValue(value, context.TryGet(autoParameter, out var pv) ? pv : autoParameter.DefaultValue);
            }
            return(value);
        }
示例#11
0
            public override Dimensions Create(IParameterDescriptor parameter, IReadonlyContext context)
            {
                var dimensionNames = DimensionNamesProperty.Get(parameter.Metadata);
                var dimensions     = new ushort[dimensionNames.Length];

                for (var i = 0; i < dimensionNames.Length; i++)
                {
                    dimensions[i] = GetParameter(dimensionNames[i]).Get(context);
                }
                return(new Dimensions(dimensions, false));
            }
示例#12
0
 public override ValidationResult CheckValid(IReadonlyContext context, IParameterDescriptor parameter)
 {
     if (ReferenceEquals(Patterns, parameter))
     {
         var patterns = ParseMultiple(Patterns.Get(context));
         if ((int)BlockLayout.Get(context).Volume > (patterns?.Length ?? 0))
         {
             return(ValidationResult.Failed("Input number of 'Pattern' value must not less than block count"));
         }
     }
     return(base.CheckValid(context, parameter));
 }
        public bool ShowDialog(out IReadonlyContext @params)
        {
            @params = EmptyContext.Instance;
            var dialogResult = ShowDialog() ?? false;

            if (!dialogResult)
            {
                return(false);
            }
            @params = ConfigurationPanel.Context;
            return(true);
        }
示例#14
0
 public override bool IsVisible(IReadonlyContext context, IDescriptor descriptor)
 {
     if (ReferenceEquals(descriptor, CheckerboardDensity))
     {
         var stimulationType = StimulationType.Get(context);
         return(stimulationType == SsvepStimulationType.SquareCheckerboard || stimulationType == SsvepStimulationType.SquareCheckerboardRadical);
     }
     if (ReferenceEquals(descriptor, BlockTextGroup))
     {
         return(ShowBlockText.Get(context));
     }
     return(base.IsVisible(context, descriptor));
 }
 public override CountdownExperiment Create(IReadonlyContext context) => new CountdownExperiment(new Configuration
 {
     Gui = new Configuration.GuiConfig
     {
         BackgroundColor = BackgroundColor.Get(context, ColorUtils.ToUIntArgb),
         ForegroundColor = ForegroundColor.Get(context, ColorUtils.ToUIntArgb),
         FontSize        = FontSize.Get(context),
     },
     Test = new Configuration.TestConfig
     {
         Seconds = Seconds.Get(context),
     }
 });
示例#16
0
        public static void Apply([CanBeNull] IReadonlyContext context)
        {
            if (context == null)
            {
                return;
            }
            var transaction = Context.CreateTransaction();

            foreach (var property in context.Properties)
            {
                transaction[property] = context[property];
            }
            transaction.Commit();
        }
示例#17
0
            public object Get(IReadonlyContext context)
            {
                var instance = Activator.CreateInstance(_targetType);

                foreach (var pair in _fieldInitializerDict)
                {
                    pair.Key.SetValue(instance, pair.Value.Get(context));
                }
                if (!(_adapter?.IsValid(_field, instance) ?? true))
                {
                    throw new ArgumentException($"Value of field '{_field}' is invalid");
                }
                return(instance);
            }
示例#18
0
 public override RestParadigm Create(IReadonlyContext context) => new RestParadigm(new Configuration
 {
     Gui = new Configuration.GuiConfig
     {
         BackgroundColor = BackgroundColor.Get(context, ColorUtils.ToUIntArgb),
         ForegroundColor = ForegroundColor.Get(context, ColorUtils.ToUIntArgb),
         FontSize        = FontSize.Get(context),
         Cue             = Cue.Get(context)
     },
     Test = new Configuration.TestConfig
     {
         Duration = Duration.Get(context),
     }
 });
示例#19
0
            public override TobiiEyeTracker Create(IReadonlyContext context)
            {
                switch (Host.EyeXAvailability)
                {
                case EyeXAvailability.NotAvailable:
                    throw new StateException("Tobii software is unavailable");

                case EyeXAvailability.NotRunning:
                    throw new StateException("Tobii software is not running");

                default:
                    return(new TobiiEyeTracker(HostNameParam.Get(context)));
                }
            }
示例#20
0
 public override MavepParadigm Create(IReadonlyContext context) => new MavepParadigm(new Configuration
 {
     Gui = new Configuration.GuiConfig
     {
         BackgroundColor = BackgroundColor.Get(context, ColorUtils.ToUIntArgb),
         FixationPoint   = FixationPoint.Get(context),
         Stimulus        = Stimulus.Get(context)
     },
     Test = new Configuration.TestConfig
     {
         Baseline              = Baseline.Get(context),
         TrialCount            = TrialCount.Get(context),
         InterStimulusInterval = InterStimulusInterval.Get(context),
     }
 });
        public bool ShowDialog(out IReadonlyContext deviceParams, out PluginStreamConsumer consumer, out IReadonlyContext consumerParams)
        {
            deviceParams   = EmptyContext.Instance;
            consumer       = null;
            consumerParams = EmptyContext.Instance;
            var dialogResult = ShowDialog() ?? false;

            if (!dialogResult)
            {
                return(false);
            }
            deviceParams   = DeviceConfigurationPanel.Context;
            consumer       = _currentConsumer;
            consumerParams = ConsumerConfigurationPanel.Context;
            return(true);
        }
示例#22
0
            public override ComplexObject Create(IParameterDescriptor parameter, IReadonlyContext context)
            {
                var fields = FieldsProperty.Get(parameter.Metadata);

                if (fields.IsEmpty())
                {
                    return(Empty);
                }
                var values = new object[fields.Length];

                for (var i = 0; i < fields.Length; i++)
                {
                    values[i] = context[fields[i]];
                }
                return(new ComplexObject(fields, values));
            }
示例#23
0
 public override TextDisplayExperiment Create(IReadonlyContext context) => new TextDisplayExperiment(new Configuration
 {
     Gui = new Configuration.GuiConfig
     {
         BackgroundColor = BackgroundColor.Get(context, ColorUtils.ToUIntArgb),
         ForegroundColor = ForegroundColor.Get(context, ColorUtils.ToUIntArgb),
         FontSize        = FontSize.Get(context),
         Text            = Text.Get(context),
     },
     Test = new Configuration.TestConfig
     {
         TrialCount            = TrialCount.Get(context),
         TrialDuration         = TrialDuration.Get(context),
         InterStimulusInterval = InterStimulusInterval.Get(context),
     }
 });
示例#24
0
 public override bool IsVisible(IReadonlyContext context, ISummary summary)
 {
     if (summary == HintSummary)
     {
         return(CopySpelling.Get(context).Enabled);
     }
     if (summary == SsvepSchemesSummary)
     {
         return(ControlParadigm.Get(context) == SpellerControlParadigm.SsvepWithEyeTracking);
     }
     if (summary == EstimatedFlashingCountSummary || summary == SubTrialDurationSummary)
     {
         return(ControlParadigm.Get(context) == SpellerControlParadigm.P300WithEyeTracking);
     }
     return(true);
 }
示例#25
0
 /// <summary>
 /// Try initiate experiment experiment under specific context.
 /// </summary>
 public static bool TryInitiateExperiment(PluginExperiment pluginExperiment, IReadonlyContext context, out IExperiment experiment, bool msgBox = true)
 {
     experiment = null;
     try
     {
         experiment = pluginExperiment.Factory.Create(context);
         return(true);
     }
     catch (Exception ex)
     {
         if (msgBox)
         {
             App.ShowErrorMessage(ex);
         }
         return(false);
     }
 }
示例#26
0
 /// <summary>
 /// Try initiate paradigm under specific context.
 /// </summary>
 public static bool TryInitiateParadigm(ParadigmTemplate paradigm, IReadonlyContext context, out IParadigm instance, bool msgBox = true)
 {
     instance = null;
     try
     {
         instance = paradigm.Factory.Create(paradigm.Clz, context);
         return(true);
     }
     catch (Exception ex)
     {
         if (msgBox)
         {
             App.ShowErrorMessage(ex);
         }
         return(false);
     }
 }
示例#27
0
 public override CptParadigm Create(IReadonlyContext context) => new CptParadigm(new Configuration
 {
     Gui = new Configuration.GuiConfig
     {
         BackgroundColor = BackgroundColor.Get(context, ColorUtils.ToUIntArgb),
         FontSize        = FontSize.Get(context),
         FontColor       = FontColor.Get(context, ColorUtils.ToUIntArgb)
     },
     Test = new Configuration.TestConfig
     {
         Still                 = Still.Get(context),
         TargetRate            = TargetRate.Get(context),
         LetterDuration        = LetterDuration.Get(context),
         InterStimulusInterval = InterStimulusInterval.Get(context),
         TotalDuration         = TotalDuration.Get(context) * 60 * 1000,
     }
 });
示例#28
0
 public override CptExperiment Create(IReadonlyContext context) => new CptExperiment(new Configuration
 {
     Gui = new Configuration.GuiConfig
     {
         BackgroundColor = BackgroundColor.Get(context, ColorUtils.ToUIntArgb),
         FontSize        = FontSize.Get(context),
         FontColor       = FontColor.Get(context, ColorUtils.ToUIntArgb)
     },
     Test = new Configuration.TestConfig
     {
         Still                 = Still.Get(context),
         PseudoRandom          = PseudoRandom.Get(context),
         TargetRate            = TargetRate.Get(context) / 100.0F,
         LetterDuration        = LetterDuration.Get(context),
         InterStimulusInterval = InterStimulusInterval.Get(context),
         ExperimentDuration    = ExperimentDuration.Get(context) * 60 * 1000,
     }
 });
示例#29
0
        public MetadataOverridenParameter([NotNull] IParameterDescriptor originalParameter,
                                          [CanBeNull] string name, [CanBeNull] string unit = Keep, [CanBeNull] string description = Keep,
                                          [CanBeNull] IReadonlyContext metadata            = null) : base(originalParameter)
        {
            var context = new Context(4);

            if (name == null || !Equals(unit, Keep))
            {
                context[NameProperty] = name;
            }
            if (!Equals(unit, Keep))
            {
                context[UnitProperty] = unit;
            }
            if (!Equals(description, Keep))
            {
                context[DescriptionProperty] = description;
            }
            Metadata = metadata == null ? (IReadonlyContext)context : new CompositeReadonlyContext(context, metadata);
        }
示例#30
0
 public override WebBrowserAssistantExperiment Create(IReadonlyContext context) => new WebBrowserAssistantExperiment(new Configuration
 {
     System = new Configuration.SystemConfig
     {
         DebugInformation = DebugInformation.Get(context),
         ListeningPort    = ListeningPort.Get(context),
         Channels         = Channels.Get(context),
     },
     User = new Configuration.UserConfig
     {
         HomePage                = HomePage.Get(context),
         WebRootDir              = WebRootDir.Get(context).Value,
         DwellSelectionDelay     = DwellSelectionDelay.Get(context),
         ConfirmationDelay       = ConfirmationDelay.Get(context),
         CursorMovementTolerance = CursorMovementTolerance.Get(context),
         TrialDuration           = TrialDuration.Get(context),
         TrialCancellable        = TrialCancellable.Get(context),
         StimulationSize         = StimulationSize.Get(context)
     }
 });