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 } }; })); }
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() } }; })); }