/// <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 ActionResult Index( long[] matterIds, OrderTransformation[] transformationsSequence, int iterationsCount, short[] characteristicLinkIds, Notation[] notations, Language[] languages, Translator?[] translators, PauseTreatment[] pauseTreatments, bool[] sequentialTransfers) { return(CreateTask(() => { var db = new LibiadaWebEntities(); var characteristicTypeLinkRepository = FullCharacteristicRepository.Instance; var commonSequenceRepository = new CommonSequenceRepository(db); var mattersCharacteristics = new object[matterIds.Length]; matterIds = matterIds.OrderBy(m => m).ToArray(); Dictionary <long, Matter> matters = db.Matter.Where(m => matterIds.Contains(m.Id)).ToDictionary(m => m.Id); for (int i = 0; i < matterIds.Length; i++) { long matterId = matterIds[i]; var characteristics = new double[characteristicLinkIds.Length]; for (int k = 0; k < characteristicLinkIds.Length; k++) { Notation notation = notations[k]; long sequenceId; switch (matters[matterId].Nature) { case Nature.Literature: Language language = languages[k]; Translator translator = translators[k] ?? Translator.NoneOrManual; sequenceId = db.LiteratureSequence.Single(l => l.MatterId == matterId && l.Notation == notation && l.Language == language && l.Translator == translator).Id; break; case Nature.Music: PauseTreatment pauseTreatment = pauseTreatments[k]; bool sequentialTransfer = sequentialTransfers[k]; 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 sequence = commonSequenceRepository.GetLibiadaChain(sequenceId); for (int l = 0; l < iterationsCount; l++) { for (int j = 0; j < transformationsSequence.Length; j++) { sequence = transformationsSequence[j] == OrderTransformation.Dissimilar ? DissimilarChainFactory.Create(sequence) : HighOrderFactory.Create(sequence, EnumExtensions.GetLink(transformationsSequence[j])); } } int characteristicLinkId = characteristicLinkIds[k]; Link link = characteristicTypeLinkRepository.GetLinkForCharacteristic(characteristicLinkId); FullCharacteristic characteristic = characteristicTypeLinkRepository.GetCharacteristic(characteristicLinkId); IFullCalculator calculator = FullCalculatorsFactory.CreateCalculator(characteristic); characteristics[k] = calculator.Calculate(sequence, link); } mattersCharacteristics[i] = new { matterName = matters[matterId].Name, characteristics }; } var characteristicNames = new string[characteristicLinkIds.Length]; for (int k = 0; k < characteristicLinkIds.Length; k++) { characteristicNames[k] = characteristicTypeLinkRepository.GetCharacteristicName(characteristicLinkIds[k], notations[k]); } var characteristicsList = new SelectListItem[characteristicLinkIds.Length]; for (int i = 0; i < characteristicNames.Length; i++) { characteristicsList[i] = new SelectListItem { Value = i.ToString(), Text = characteristicNames[i], Selected = false }; } var transformations = new Dictionary <int, string>(); for (int i = 0; i < transformationsSequence.Length; i++) { transformations.Add(i, transformationsSequence[i].GetDisplayValue()); } var result = new Dictionary <string, object> { { "characteristics", mattersCharacteristics }, { "characteristicNames", characteristicNames }, { "characteristicsList", characteristicsList }, { "transformationsList", transformations }, { "iterationsCount", iterationsCount } }; return new Dictionary <string, object> { { "data", JsonConvert.SerializeObject(result) } }; })); }
/// <summary> /// The fill parameters. /// </summary> /// <param name="commonSequence"> /// The sequence. /// </param> /// <param name="alphabet"> /// The alphabet. /// </param> /// <param name="building"> /// The building. /// </param> /// <returns> /// The <see cref="List{Object}"/>. /// </returns> private List <NpgsqlParameter> FillParams(CommonSequence commonSequence, long[] alphabet, int[] building, PauseTreatment pauseTreatment, bool sequentialTransfer) { var parameters = FillParams(commonSequence, alphabet, building); parameters.Add(new NpgsqlParameter <byte>("pause_treatment", NpgsqlDbType.Smallint) { TypedValue = (byte)pauseTreatment }); parameters.Add(new NpgsqlParameter <bool>("sequential_transfer", NpgsqlDbType.Boolean) { TypedValue = sequentialTransfer }); return(parameters); }
/// <summary> /// Converts congeneric score track to formal motifs base chain. /// </summary> /// <param name="scoreTrack"> /// The score track. /// </param> /// <returns> /// The <see cref="BaseChain"/>. /// </returns> private BaseChain ConvertCongenericScoreTrackToFormalMotifsBaseChain(CongenericScoreTrack scoreTrack, PauseTreatment pauseTreatment, bool sequentialTransfer) { var borodaDivider = new BorodaDivider(); FmotifChain fmotifChain = borodaDivider.Divide(scoreTrack, pauseTreatment, sequentialTransfer); return(new BaseChain(((IEnumerable <IBaseObject>)fmotifChain.FmotifsList).ToList())); }
/// <summary> /// The insert. /// </summary> /// <param name="commonSequence"> /// The sequence. /// </param> /// <param name="alphabet"> /// The alphabet. /// </param> /// <param name="building"> /// The building. /// </param> public void Create(CommonSequence commonSequence, long[] alphabet, int[] building, PauseTreatment pauseTreatment = PauseTreatment.NotApplicable, bool sequentialTransfer = false) { List <NpgsqlParameter> parameters = FillParams(commonSequence, alphabet, building, pauseTreatment, sequentialTransfer); const string Query = @"INSERT INTO music_chain ( id, notation, matter_id, alphabet, building, remote_id, remote_db, pause_treatment, sequential_transfer ) VALUES ( @id, @notation, @matter_id, @alphabet, @building, @remote_id, @remote_db, @pause_treatment, @sequential_transfer );"; Db.ExecuteCommand(Query, parameters.ToArray()); }