/// <summary> /// データ件数を取得する /// </summary> private int GetTotalCount(InferenceSearchInputModel filter) { IQueryable <InferenceHistory> histories; if (string.IsNullOrEmpty(filter.DataSet)) { histories = inferenceHistoryRepository.GetAll(); } else { //データセット名のフィルターがかかっている場合、データセットも併せて取得しないといけない histories = inferenceHistoryRepository.GetAllIncludeDataSet(); } histories = Search(histories, filter); return(histories.Count()); }
public IActionResult GetAll([FromQuery] InferenceSearchInputModel filter, [FromQuery] int?perPage, [FromQuery] int page = 1, bool withTotal = false) { var data = inferenceHistoryRepository.GetAllIncludeDataSetWithOrdering(); data = Search(data, filter); //未指定、あるいは1000件以上であれば、1000件に指定 int pageCount = (perPage.HasValue && perPage.Value < 1000) ? perPage.Value : 1000; data = data.Paging(page, pageCount); if (withTotal) { int total = GetTotalCount(filter); SetTotalCountToHeader(total); } //SQLが多重実行されることを防ぐため、ToListで即時発行させたうえで、結果を生成 return(JsonOK(data.ToList().Select(history => GetUpdatedIndexOutputModelAsync(history).Result))); }
/// <summary> /// 検索条件の追加 /// </summary> private static IQueryable <InferenceHistory> Search(IQueryable <InferenceHistory> sourceData, InferenceSearchInputModel filter) { IQueryable <InferenceHistory> data = sourceData; data = data .SearchLong(d => d.Id, filter.Id) .SearchString(d => d.Name, filter.Name) .SearchTime(d => d.CreatedAt, filter.StartedAt) .SearchString(d => d.Memo, filter.Memo) .SearchString(d => d.EntryPoint, filter.EntryPoint) .SearchString(d => d.GetStatus().ToString(), filter.Status); if (string.IsNullOrEmpty(filter.DataSet) == false) { if (filter.DataSet.StartsWith("!")) { data = data.Where(d => d.DataSet != null && d.DataSet.Name != null && d.DataSet.Name.Contains(filter.DataSet.Substring(1)) == false); } else { data = data.Where(d => d.DataSet != null && d.DataSet.Name != null && d.DataSet.Name.Contains(filter.DataSet)); } } if (string.IsNullOrEmpty(filter.ParentName) == false) { if (filter.ParentName.StartsWith("!")) { data = data.Where(d => string.IsNullOrEmpty(d.Parent.Name) || d.Parent.Name.Contains(filter.ParentName.Substring(1)) == false); } else { data = data.Where(d => d.Parent != null && d.Parent.Name != null && d.Parent.Name.Contains(filter.ParentName)); } } return(data); }
/// <summary> /// 検索条件の追加 /// </summary> /// <param name="sourceData">加工前の検索結果</param> /// <param name="filter">検索条件</param> private static IQueryable <InferenceHistory> Search(IQueryable <InferenceHistory> sourceData, InferenceSearchInputModel filter) { IQueryable <InferenceHistory> data = sourceData; data = data .SearchLong(d => d.Id, filter.Id) .SearchString(d => d.Name, filter.Name) .SearchTime(d => d.CreatedAt, filter.StartedAt) .SearchString(d => d.CreatedBy, filter.StartedBy) .SearchString(d => d.Memo, filter.Memo) .SearchString(d => d.EntryPoint, filter.EntryPoint) .SearchString(d => d.GetStatus().ToString(), filter.Status); // データセット名の検索 if (string.IsNullOrEmpty(filter.DataSet) == false) { if (filter.DataSet.StartsWith("!", StringComparison.CurrentCulture)) { data = data.Where(d => d.DataSet != null && d.DataSet.Name != null && d.DataSet.Name.Contains(filter.DataSet.Substring(1), StringComparison.CurrentCulture) == false); } else { data = data.Where(d => d.DataSet != null && d.DataSet.Name != null && d.DataSet.Name.Contains(filter.DataSet, StringComparison.CurrentCulture)); } } // マウントした学習IDの検索 if (string.IsNullOrEmpty(filter.ParentId) == false) { if (filter.ParentId.StartsWith(">=", StringComparison.CurrentCulture)) { if (long.TryParse(filter.ParentId.Substring(2), out long target)) { data = data.Where(d => d.ParentMaps != null && d.ParentMaps.Any(m => m.ParentId >= target)); } } else if (filter.ParentId.StartsWith(">", StringComparison.CurrentCulture)) { if (long.TryParse(filter.ParentId.Substring(1), out long target)) { data = data.Where(d => d.ParentMaps != null && d.ParentMaps.Any(m => m.ParentId > target)); } } else if (filter.ParentId.StartsWith("<=", StringComparison.CurrentCulture)) { if (long.TryParse(filter.ParentId.Substring(2), out long target)) { data = data.Where(d => d.ParentMaps != null && d.ParentMaps.Any(m => m.ParentId <= target)); } } else if (filter.ParentId.StartsWith("<", StringComparison.CurrentCulture)) { if (long.TryParse(filter.ParentId.Substring(1), out long target)) { data = data.Where(d => d.ParentMaps != null && d.ParentMaps.Any(m => m.ParentId < target)); } } else if (filter.ParentId.StartsWith("=", StringComparison.CurrentCulture)) { if (long.TryParse(filter.ParentId.Substring(1), out long target)) { data = data.Where(d => d.ParentMaps != null && d.ParentMaps.Any(m => m.ParentId == target)); } } else { if (long.TryParse(filter.ParentId, out long target)) { data = data.Where(d => d.ParentMaps != null && d.ParentMaps.Any(m => m.ParentId == target)); } } } // マウントした推論IDの検索 if (string.IsNullOrEmpty(filter.ParentInferenceId) == false) { if (filter.ParentInferenceId.StartsWith(">=", StringComparison.CurrentCulture)) { if (long.TryParse(filter.ParentInferenceId.Substring(2), out long target)) { data = data.Where(d => d.ParentInferenceMaps != null && d.ParentInferenceMaps.Any(m => m.ParentId >= target)); } } else if (filter.ParentInferenceId.StartsWith(">", StringComparison.CurrentCulture)) { if (long.TryParse(filter.ParentInferenceId.Substring(1), out long target)) { data = data.Where(d => d.ParentInferenceMaps != null && d.ParentInferenceMaps.Any(m => m.ParentId > target)); } } else if (filter.ParentInferenceId.StartsWith("<=", StringComparison.CurrentCulture)) { if (long.TryParse(filter.ParentInferenceId.Substring(2), out long target)) { data = data.Where(d => d.ParentInferenceMaps != null && d.ParentInferenceMaps.Any(m => m.ParentId <= target)); } } else if (filter.ParentInferenceId.StartsWith("<", StringComparison.CurrentCulture)) { if (long.TryParse(filter.ParentInferenceId.Substring(1), out long target)) { data = data.Where(d => d.ParentInferenceMaps != null && d.ParentInferenceMaps.Any(m => m.ParentId < target)); } } else if (filter.ParentInferenceId.StartsWith("=", StringComparison.CurrentCulture)) { if (long.TryParse(filter.ParentInferenceId.Substring(1), out long target)) { data = data.Where(d => d.ParentInferenceMaps != null && d.ParentInferenceMaps.Any(m => m.ParentId == target)); } } else { if (long.TryParse(filter.ParentInferenceId, out long target)) { data = data.Where(d => d.ParentMaps != null && d.ParentMaps.Any(m => m.ParentId == target)); } } } // マウントした学習名の検索 if (string.IsNullOrEmpty(filter.ParentName) == false) { if (filter.ParentName.StartsWith("!", StringComparison.CurrentCulture)) { data = data.Where(d => d.ParentMaps == null || d.ParentMaps.Count == 0 || d.ParentMaps.All(m => m.Parent.Name.Contains(filter.ParentName.Substring(1), StringComparison.CurrentCulture) == false)); } else { data = data.Where(d => d.ParentMaps != null && d.ParentMaps.Any(m => m.Parent.Name.Contains(filter.ParentName, StringComparison.CurrentCulture))); } } // マウントした推論名の検索 if (string.IsNullOrEmpty(filter.ParentInferenceName) == false) { if (filter.ParentInferenceName.StartsWith("!", StringComparison.CurrentCulture)) { data = data.Where(d => d.ParentInferenceMaps == null || d.ParentInferenceMaps.Count == 0 || d.ParentInferenceMaps.All(m => m.Parent.Name.Contains(filter.ParentInferenceName.Substring(1), StringComparison.CurrentCulture) == false)); } else { data = data.Where(d => d.ParentInferenceMaps != null && d.ParentInferenceMaps.Any(m => m.Parent.Name.Contains(filter.ParentInferenceName, StringComparison.CurrentCulture))); } } return(data); }