public long[] GetSequenceIds(long[] matterIds, Notation notation, Language?language, Translator?translator, PauseTreatment?pauseTreatment, bool?sequentialTransfer, ImageOrderExtractor?imageOrderExtractor) { var sequenceIds = new long[matterIds.Length]; for (int i = 0; i < matterIds.Length; i++) { switch (notation.GetNature()) { case Nature.Literature: return(Db.LiteratureSequence .Where(l => matterIds.Contains(l.MatterId) && l.Notation == notation && l.Language == language && l.Translator == translator) .ToArray() .OrderBy(s => { return Array.IndexOf(matterIds, s.MatterId); }) .Select(s => s.Id) .ToArray()); case Nature.Music: return(Db.MusicSequence .Where(m => matterIds.Contains(m.MatterId) && m.Notation == notation && m.PauseTreatment == pauseTreatment && m.SequentialTransfer == sequentialTransfer) .ToArray() .OrderBy(s => { return Array.IndexOf(matterIds, s.MatterId); }) .Select(s => s.Id) .ToArray()); case Nature.Image: return(Db.ImageSequences .Where(c => matterIds.Contains(c.MatterId) && c.Notation == notation && c.OrderExtractor == imageOrderExtractor) .ToArray() .OrderBy(s => { return Array.IndexOf(matterIds, s.MatterId); }) .Select(s => s.Id) .ToArray()); default: return(Db.CommonSequence .Where(c => matterIds.Contains(c.MatterId) && c.Notation == notation) .ToArray() .OrderBy(s => { return Array.IndexOf(matterIds, s.MatterId); }) .Select(s => s.Id) .ToArray()); } } return(sequenceIds); }
/// <summary> /// Extracts sequences ids from database. /// </summary> /// <param name="matterIds"> /// The matters ids. /// </param> /// <param name="notations"> /// The notations ids. /// </param> /// <param name="languages"> /// The languages ids. /// </param> /// <param name="translators"> /// The translators ids. /// </param> /// <param name="pauseTreatments"> /// Pause treatment parameters of music sequences. /// </param> /// <param name="sequentialTransfers"> /// Sequential transfer flag used in music sequences. /// </param> /// <returns> /// The sequences ids as <see cref="T:long[][]"/>. /// </returns> public long[][] GetSequenceIds(long[] matterIds, Notation[] notations, Language[] languages, Translator?[] translators, PauseTreatment[] pauseTreatments, bool[] sequentialTransfers) { var sequenceIds = new long[matterIds.Length][]; for (int i = 0; i < matterIds.Length; i++) { var matterId = matterIds[i]; sequenceIds[i] = new long[notations.Length]; for (int j = 0; j < notations.Length; j++) { Notation notation = notations[j]; switch (notation.GetNature()) { case Nature.Literature: Language language = languages[j]; Translator translator = translators[j] ?? Translator.NoneOrManual; sequenceIds[i][j] = Db.LiteratureSequence.Single(l => l.MatterId == matterId && l.Notation == notation && l.Language == language && l.Translator == translator).Id; break; case Nature.Music: PauseTreatment pauseTreatment = pauseTreatments[j]; bool sequentialTransfer = sequentialTransfers[j]; sequenceIds[i][j] = Db.MusicSequence.Single(m => m.MatterId == matterId && m.Notation == notation && m.PauseTreatment == pauseTreatment && m.SequentialTransfer == sequentialTransfer).Id; break; default: sequenceIds[i][j] = Db.CommonSequence.Single(c => c.MatterId == matterId && c.Notation == notation).Id; break; } } } return(sequenceIds); }
public void NotationHasNatureTest([Values] Notation notation) => Assert.True(natures.Contains(notation.GetNature()));
public ActionResult Index( long[] matterIds, int characteristicLinkId, Notation notation, Language?language, Translator?translator, PauseTreatment?pauseTreatment, bool?sequentialTransfer, string calculationType) { return(CreateTask(() => { if (matterIds.Length != 2) { throw new ArgumentException("Number of selected matters must be 2.", nameof(matterIds)); } var characteristics = new List <List <double> >(); string characteristicName = characteristicTypeLinkRepository.GetCharacteristicName(characteristicLinkId, notation); var result = new Dictionary <string, object> { { "characteristics", characteristics }, { "matterNames", db.Matter.Where(m => matterIds.Contains(m.Id)).Select(m => m.Name).ToList() }, { "characteristicName", characteristicName }, { "calculationType", calculationType } }; long firstMatterId = matterIds[0]; long secondMatterId = matterIds[1]; long firstSequenceId; long secondSequenceId; switch (notation.GetNature()) { case Nature.Literature: firstSequenceId = db.LiteratureSequence.Single(l => l.MatterId == firstMatterId && l.Notation == notation && l.Language == language && l.Translator == translator).Id; secondSequenceId = db.LiteratureSequence.Single(l => l.MatterId == secondMatterId && l.Notation == notation && l.Language == language && l.Translator == translator).Id; break; case Nature.Music: firstSequenceId = db.MusicSequence.Single(m => m.MatterId == firstMatterId && m.Notation == notation && m.PauseTreatment == pauseTreatment && m.SequentialTransfer == sequentialTransfer).Id; secondSequenceId = db.MusicSequence.Single(m => m.MatterId == secondMatterId && m.Notation == notation && m.PauseTreatment == pauseTreatment && m.SequentialTransfer == sequentialTransfer).Id; break; default: firstSequenceId = db.CommonSequence.Single(c => c.MatterId == firstMatterId && c.Notation == notation).Id; secondSequenceId = db.CommonSequence.Single(c => c.MatterId == secondMatterId && c.Notation == notation).Id; break; } Chain firstChain = commonSequenceRepository.GetLibiadaChain(firstSequenceId); Chain secondChain = commonSequenceRepository.GetLibiadaChain(secondSequenceId); AccordanceCharacteristic accordanceCharacteristic = characteristicTypeLinkRepository.GetCharacteristic(characteristicLinkId); IAccordanceCalculator calculator = AccordanceCalculatorsFactory.CreateCalculator(accordanceCharacteristic); Link link = characteristicTypeLinkRepository.GetLinkForCharacteristic(characteristicLinkId); Alphabet firstChainAlphabet = firstChain.Alphabet; Alphabet secondChainAlphabet = secondChain.Alphabet; switch (calculationType) { case "Equality": if (!firstChainAlphabet.SetEquals(secondChainAlphabet)) { throw new Exception("Alphabets of sequences are not equal."); } characteristics.Add(new List <double>()); characteristics.Add(new List <double>()); var alphabet = new List <string>(); for (int i = 0; i < firstChainAlphabet.Cardinality; i++) { IBaseObject element = firstChainAlphabet[i]; alphabet.Add(element.ToString()); CongenericChain firstCongenericChain = firstChain.CongenericChain(element); CongenericChain secondCongenericChain = secondChain.CongenericChain(element); double characteristicValue = calculator.Calculate(firstCongenericChain, secondCongenericChain, link); characteristics[0].Add(characteristicValue); characteristicValue = calculator.Calculate(secondCongenericChain, firstCongenericChain, link); characteristics[1].Add(characteristicValue); } result.Add("alphabet", alphabet); break; case "All": var firstAlphabet = new List <string>(); for (int i = 0; i < firstChain.Alphabet.Cardinality; i++) { characteristics.Add(new List <double>()); IBaseObject firstElement = firstChainAlphabet[i]; firstAlphabet.Add(firstElement.ToString()); for (int j = 0; j < secondChainAlphabet.Cardinality; j++) { var secondElement = secondChainAlphabet[j]; var firstCongenericChain = firstChain.CongenericChain(firstElement); var secondCongenericChain = secondChain.CongenericChain(secondElement); var characteristicValue = calculator.Calculate(firstCongenericChain, secondCongenericChain, link); characteristics[i].Add(characteristicValue); } } var secondAlphabet = new List <string>(); for (int j = 0; j < secondChainAlphabet.Cardinality; j++) { secondAlphabet.Add(secondChainAlphabet[j].ToString()); } result.Add("firstAlphabet", firstAlphabet); result.Add("secondAlphabet", secondAlphabet); break; case "Specified": throw new NotImplementedException(); default: throw new ArgumentException("Calculation type is not implemented", nameof(calculationType)); } return result; })); }