示例#1
0
        public ActionResult Index(
            long matterId,
            short characteristicLinkId,
            Notation notation,
            Language?language,
            Translator?translator,
            PauseTreatment?pauseTreatment,
            bool?sequentialTransfer,
            int filterSize,
            bool filter,
            bool frequencyFilter,
            int frequencyCount)
        {
            return(CreateTask(() =>
            {
                var characteristics = new Dictionary <long, Dictionary <long, double> >();
                Element[] elements = null;
                List <BinaryCharacteristicValue> filteredResult = null;
                var firstElements = new List <Element>();
                var secondElements = new List <Element>();

                Matter matter = db.Matter.Single(m => m.Id == matterId);
                long sequenceId;
                switch (matter.Nature)
                {
                case Nature.Literature:
                    sequenceId = db.LiteratureSequence.Single(l => l.MatterId == matterId &&
                                                              l.Notation == notation &&
                                                              l.Language == language &&
                                                              l.Translator == translator).Id;
                    break;

                case Nature.Music:
                    sequenceId = db.MusicSequence.Single(m => m.MatterId == matterId &&
                                                         m.Notation == notation &&
                                                         m.PauseTreatment == pauseTreatment &&
                                                         m.SequentialTransfer == sequentialTransfer).Id;
                    break;

                default:
                    sequenceId = db.CommonSequence.Single(c => c.MatterId == matterId && c.Notation == notation).Id;
                    break;
                }

                Chain currentChain = commonSequenceRepository.GetLibiadaChain(sequenceId);
                BinaryCharacteristic binaryCharacteristic = characteristicTypeLinkRepository.GetCharacteristic(characteristicLinkId);

                IBinaryCalculator calculator = BinaryCalculatorsFactory.CreateCalculator(binaryCharacteristic);
                Link link = characteristicTypeLinkRepository.GetLinkForCharacteristic(characteristicLinkId);

                if (frequencyFilter)
                {
                    FrequencyCharacteristic(characteristicLinkId, frequencyCount, currentChain, sequenceId, calculator, link);
                }
                else
                {
                    NotFrequencyCharacteristic(characteristicLinkId, sequenceId, currentChain, calculator, link);
                }

                if (filter)
                {
                    filteredResult = db.BinaryCharacteristicValue.Where(b => b.SequenceId == sequenceId && b.CharacteristicLinkId == characteristicLinkId)
                                     .OrderByDescending(b => b.Value)
                                     .Take(filterSize).ToList();

                    for (int l = 0; l < filterSize; l++)
                    {
                        long firstElementId = filteredResult[l].FirstElementId;
                        firstElements.Add(db.Element.Single(e => e.Id == firstElementId));
                    }

                    for (int m = 0; m < filterSize; m++)
                    {
                        long secondElementId = filteredResult[m].SecondElementId;
                        secondElements.Add(db.Element.Single(e => e.Id == secondElementId));
                    }
                }
                else
                {
                    characteristics = db.BinaryCharacteristicValue
                                      .Where(b => b.SequenceId == sequenceId && b.CharacteristicLinkId == characteristicLinkId)
                                      .GroupBy(b => b.FirstElementId)
                                      .ToDictionary(b => b.Key, b => b.ToDictionary(bb => bb.SecondElementId, bb => bb.Value));
                    var elementsIds = db.GetAlphabetElementIds(sequenceId);
                    elements = db.Element.Where(e => elementsIds.Contains(e.Id)).OrderBy(e => e.Id).ToArray();
                }

                string characteristicName = characteristicTypeLinkRepository.GetCharacteristicName(characteristicLinkId, notation);

                return new Dictionary <string, object>
                {
                    { "characteristics", characteristics },
                    { "isFilter", filter },
                    { "filteredResult", filteredResult },
                    { "firstElements", firstElements },
                    { "secondElements", secondElements },
                    { "filterSize", filterSize },
                    { "elements", elements },
                    { "characteristicName", characteristicName },
                    { "matterName", db.CommonSequence.Single(m => m.Id == sequenceId).Matter.Name },
                    { "notationName", db.CommonSequence.Single(c => c.Id == sequenceId).Notation.GetDisplayValue() }
                };
            }));
        }
        public ActionResult Index(
            long matterId,
            short characteristicLinkId,
            Notation notation,
            Language?language,
            Translator?translator,
            PauseTreatment?pauseTreatment,
            bool?sequentialTransfer,
            ImageOrderExtractor?trajectory,
            int filterSize,
            bool filter,
            bool frequencyFilter,
            int frequencyCount)
        {
            return(CreateTask(() =>
            {
                string characteristicName = characteristicTypeLinkRepository.GetCharacteristicName(characteristicLinkId, notation);
                Matter matter = Cache.GetInstance().Matters.Single(m => m.Id == matterId);
                long sequenceId = commonSequenceRepository.GetSequenceIds(new[] { matterId },
                                                                          notation,
                                                                          language,
                                                                          translator,
                                                                          pauseTreatment,
                                                                          sequentialTransfer,
                                                                          trajectory).Single();

                Chain currentChain = commonSequenceRepository.GetLibiadaChain(sequenceId);
                var sequence = db.CommonSequence.Single(m => m.Id == sequenceId);

                var result = new Dictionary <string, object>
                {
                    { "isFilter", filter },
                    { "matterName", sequence.Matter.Name },
                    { "notationName", sequence.Notation.GetDisplayValue() },
                    { "characteristicName", characteristicName }
                };

                BinaryCharacteristic binaryCharacteristic = characteristicTypeLinkRepository.GetCharacteristic(characteristicLinkId);
                IBinaryCalculator calculator = BinaryCalculatorsFactory.CreateCalculator(binaryCharacteristic);
                Link link = characteristicTypeLinkRepository.GetLinkForCharacteristic(characteristicLinkId);

                if (frequencyFilter)
                {
                    FrequencyCharacteristic(characteristicLinkId, frequencyCount, currentChain, sequenceId, calculator, link);
                }
                else
                {
                    NotFrequencyCharacteristic(characteristicLinkId, sequenceId, currentChain, calculator, link);
                }

                if (filter)
                {
                    var filteredResult = db.BinaryCharacteristicValue
                                         .Where(b => b.SequenceId == sequenceId && b.CharacteristicLinkId == characteristicLinkId)
                                         .OrderByDescending(b => b.Value)
                                         .Take(filterSize)
                                         .Select(rc => new
                    {
                        FirstElementId = rc.FirstElementId,
                        SecondElementId = rc.SecondElementId,
                        Value = rc.Value
                    })
                                         .ToArray();

                    var firstElements = new List <string>();
                    var secondElements = new List <string>();
                    for (int i = 0; i < filterSize; i++)
                    {
                        long firstElementId = filteredResult[i].FirstElementId;
                        var firstElement = db.Element.Single(e => e.Id == firstElementId);
                        firstElements.Add(firstElement.Name ?? firstElement.Value);

                        long secondElementId = filteredResult[i].SecondElementId;
                        var secondElement = db.Element.Single(e => e.Id == secondElementId);
                        secondElements.Add(secondElement.Name ?? secondElement.Value);
                    }

                    result.Add("filteredResult", filteredResult);
                    result.Add("filterSize", filterSize);
                    result.Add("firstElements", firstElements);
                    result.Add("secondElements", secondElements);
                }
                else
                {
                    var characteristics = db.BinaryCharacteristicValue
                                          .Where(b => b.SequenceId == sequenceId && b.CharacteristicLinkId == characteristicLinkId)
                                          .GroupBy(b => b.FirstElementId)
                                          .ToDictionary(b => b.Key, b => b.ToDictionary(bb => bb.SecondElementId, bb => bb.Value));
                    var elementsIds = db.GetAlphabetElementIds(sequenceId);
                    var elements = db.Element
                                   .Where(e => elementsIds.Contains(e.Id))
                                   .OrderBy(e => e.Id)
                                   .Select(e => new { Name = e.Name ?? e.Value, e.Id })
                                   .ToArray();

                    result.Add("characteristics", characteristics);
                    result.Add("elements", elements);
                }

                string json = JsonConvert.SerializeObject(result);

                return new Dictionary <string, string> {
                    { "data", json }
                };
            }));
        }
示例#3
0
        /// <summary>
        /// The details.
        /// </summary>
        /// <param name="id">
        /// The music sequence's id.
        /// </param>
        /// <returns>
        /// The <see cref="System.Threading.Tasks.Task"/>.
        /// </returns>
        public async Task <ActionResult> Details(long?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            using (var db = new LibiadaWebEntities())
            {
                MusicSequence musicSequence = db.MusicSequence.Include(m => m.Matter).Single(m => m.Id == id);
                if (musicSequence == null)
                {
                    return(HttpNotFound());
                }

                var musicChainAlphabet = db.GetAlphabetElementIds(musicSequence.Id)
                                         .Select(el => db.Fmotif.Single(f => f.Id == el))
                                         .ToList();
                var musicChainBuilding = db.GetSequenceBuilding(musicSequence.Id);
                var sortedFmotifs      = new Dictionary <LibiadaWeb.Fmotif, int>();
                for (int i = 0; i < musicChainAlphabet.Count; i++)
                {
                    sortedFmotifs.Add(musicChainAlphabet[i], musicChainBuilding.Count(el => el == i + 1));
                }
                sortedFmotifs = sortedFmotifs.OrderByDescending(pair => pair.Value)
                                .ToDictionary(pair => pair.Key, pair => pair.Value);

                var fmotifsChain = new List <Fmotif>();
                foreach (var fmotif in sortedFmotifs.Keys)
                {
                    var newFmotif = new Fmotif(fmotif.FmotifType, musicSequence.PauseTreatment, fmotif.Id);

                    var fmotifAlphabet = db.GetFmotifAlphabet(fmotif.Id);
                    var fmotifBuilding = db.GetFmotifBuilding(fmotif.Id);
                    foreach (var position in fmotifBuilding)
                    {
                        var dbNoteId   = fmotifAlphabet.ElementAt(position - 1);
                        var dbNote     = db.Note.Single(n => n.Id == dbNoteId);
                        var newPitches = new List <Pitch>();
                        foreach (var pitch in dbNote.Pitch)
                        {
                            newPitches.Add(new Pitch(pitch.Midinumber));
                        }

                        var newNote = new ValueNote(newPitches,
                                                    new Duration(dbNote.Numerator, dbNote.Denominator),
                                                    dbNote.Triplet,
                                                    dbNote.Tie);
                        newNote.Id = dbNote.Id;
                        newFmotif.NoteList.Add(newNote);
                    }
                    fmotifsChain.Add(newFmotif);
                }
                var result = new Dictionary <string, object> {
                    { "fmotifs", fmotifsChain },
                    { "sequentialTransfer", musicSequence.SequentialTransfer }
                };
                ViewBag.data = JsonConvert.SerializeObject(new Dictionary <string, object> {
                    { "data", result }
                });
                return(View(musicSequence));
            }
        }