public ActionResult Index(
            long[] matterIds,
            short[] characteristicLinkIds,
            int length,
            int step,
            bool delta,
            bool fourier,
            bool growingWindow,
            bool autocorrelation,
            Notation notation,
            Language?language,
            Translator?translator,
            PauseTreatment?pauseTreatment,
            bool?sequentialTransfer,
            ImageOrderExtractor?trajectory)
        {
            return(CreateTask(() =>
            {
                var characteristicNames = new string[characteristicLinkIds.Length];
                var partNames = new List <string> [matterIds.Length];
                var starts = new List <int> [matterIds.Length];
                var lengthes = new List <int> [matterIds.Length];
                var chains = new Chain[matterIds.Length];
                var mattersCharacteristics = new object[matterIds.Length];

                var calculators = new IFullCalculator[characteristicLinkIds.Length];
                var links = new Link[characteristicLinkIds.Length];
                matterIds = matterIds.OrderBy(m => m).ToArray();
                Dictionary <long, Matter> matters = Cache.GetInstance().Matters.Where(m => matterIds.Contains(m.Id)).ToDictionary(m => m.Id);

                for (int k = 0; k < matterIds.Length; k++)
                {
                    long matterId = matterIds[k];
                    Nature nature = Cache.GetInstance().Matters.Single(m => m.Id == matterId).Nature;

                    long sequenceId = commonSequenceRepository.GetSequenceIds(new[] { matterId },
                                                                              notation,
                                                                              language,
                                                                              translator,
                                                                              pauseTreatment,
                                                                              sequentialTransfer,
                                                                              trajectory).Single();

                    chains[k] = commonSequenceRepository.GetLibiadaChain(sequenceId);
                }

                for (var i = 0; i < characteristicLinkIds.Length; i++)
                {
                    int characteristicLinkId = characteristicLinkIds[i];
                    FullCharacteristic characteristic = characteristicTypeLinkRepository.GetCharacteristic(characteristicLinkId);
                    calculators[i] = FullCalculatorsFactory.CreateCalculator(characteristic);
                    links[i] = characteristicTypeLinkRepository.GetLinkForCharacteristic(characteristicLinkId);
                }

                for (int i = 0; i < chains.Length; i++)
                {
                    CutRule cutRule = growingWindow
                            ? (CutRule) new CutRuleWithFixedStart(chains[i].Length, step)
                            : new SimpleCutRule(chains[i].Length, step, length);

                    CutRuleIterator iterator = cutRule.GetIterator();

                    var fragments = new List <Chain>();
                    partNames[i] = new List <string>();
                    starts[i] = new List <int>();
                    lengthes[i] = new List <int>();

                    while (iterator.Next())
                    {
                        int start = iterator.GetStartPosition();
                        int end = iterator.GetEndPosition();

                        var fragment = new List <IBaseObject>();
                        for (int k = 0; start + k < end; k++)
                        {
                            fragment.Add(chains[i][start + k]);
                        }

                        fragments.Add(new Chain(fragment));

                        partNames[i].Add(fragment.ToString());
                        starts[i].Add(iterator.GetStartPosition());
                        lengthes[i].Add(fragment.Count);
                    }

                    var fragmentsData = new FragmentData[fragments.Count];
                    for (int k = 0; k < fragments.Count; k++)
                    {
                        var characteristics = new double[calculators.Length];
                        for (int j = 0; j < calculators.Length; j++)
                        {
                            characteristics[j] = calculators[j].Calculate(fragments[k], links[j]);
                        }

                        fragmentsData[k] = new FragmentData(characteristics, fragments[k].ToString(), starts[i][k], fragments[k].Length);
                    }

                    double[][] differenceData = null;
                    double[][] fourierData = null;
                    double[][] autocorrelationData = null;

                    if (delta)
                    {
                        differenceData = CalculateDifference(fragmentsData.Select(f => f.Characteristics).ToArray());
                    }

                    if (fourier)
                    {
                        fourierData = FastFourierTransform.CalculateFastFourierTransform(fragmentsData.Select(f => f.Characteristics).ToArray());
                    }

                    if (autocorrelation)
                    {
                        autocorrelationData = AutoCorrelation.CalculateAutocorrelation(fragmentsData.Select(f => f.Characteristics).ToArray());
                    }

                    mattersCharacteristics[i] = new LocalCharacteristicsData(matters[matterIds[i]].Name,
                                                                             fragmentsData,
                                                                             differenceData,
                                                                             fourierData,
                                                                             autocorrelationData);
                }

                for (int l = 0; l < characteristicLinkIds.Length; l++)
                {
                    characteristicNames[l] = characteristicTypeLinkRepository.GetCharacteristicName(characteristicLinkIds[l]);
                }

                var characteristicsList = new SelectListItem[characteristicLinkIds.Length];
                for (int k = 0; k < characteristicLinkIds.Length; k++)
                {
                    characteristicNames[k] = characteristicTypeLinkRepository.GetCharacteristicName(characteristicLinkIds[k], notation);
                    characteristicsList[k] = new SelectListItem
                    {
                        Value = k.ToString(),
                        Text = characteristicNames[k],
                        Selected = false
                    };
                }

                var result = new Dictionary <string, object>
                {
                    { "characteristics", mattersCharacteristics },
                    { "notationName", notation.GetDisplayValue() },
                    { "starts", starts },
                    { "partNames", partNames },
                    { "lengthes", lengthes },
                    { "characteristicNames", characteristicNames },
                    { "matterIds", matterIds },
                    { "characteristicsList", characteristicsList },
                    { "aligners", EnumHelper.GetSelectList(typeof(Aligner)) },
                    { "distanceCalculators", EnumHelper.GetSelectList(typeof(DistanceCalculator)) },
                    { "aggregators", EnumHelper.GetSelectList(typeof(Aggregator)) }
                };

                return new Dictionary <string, string> {
                    { "data", JsonConvert.SerializeObject(result) }
                };
            }));
        }
Exemple #2
0
 public void NotationHasDisplayValueTest([Values] Notation notation) => Assert.That(notation.GetDisplayValue(), Is.Not.Null.And.Not.Empty);
 /// <summary>
 /// The get binary characteristic name.
 /// </summary>
 /// <param name="characteristicLinkId">
 /// The characteristic link id.
 /// </param>
 /// <param name="notation">
 /// The notation.
 /// </param>
 /// <returns>
 /// The <see cref="string"/>.
 /// </returns>
 public string GetCharacteristicName(int characteristicLinkId, Notation notation)
 {
     return(string.Join("  ", GetCharacteristicName(characteristicLinkId), notation.GetDisplayValue()));
 }