/// <summary> Gets report statistic. </summary> /// <param name="request"> The request. </param> /// <returns> The report statistic. </returns> private async Task <ReportStatResult> GetReportStatistic(GetReportStatistics request) { ReportIncludeItemTypes reportRowType = ReportHelper.GetRowType(request.IncludeItemTypes); QueryResult <BaseItem> queryResult = await GetQueryResult(request).ConfigureAwait(false); ReportStatBuilder reportBuilder = new ReportStatBuilder(_libraryManager); ReportStatResult reportResult = reportBuilder.GetResult(queryResult.Items, ReportHelper.GetRowType(request.IncludeItemTypes), request.TopItems ?? 5); reportResult.TotalRecordCount = reportResult.Groups.Count(); return(reportResult); }
/// <summary> Gets report stat result. </summary> /// <param name="items"> The items. </param> /// <param name="reportIncludeItemTypes"> List of types of the report include items. </param> /// <param name="topItem"> The top item. </param> /// <returns> The report stat result. </returns> public ReportStatResult GetResult(BaseItem[] items, ReportIncludeItemTypes reportIncludeItemTypes, int topItem = 5) { ReportStatResult result = new ReportStatResult(); result = this.GetResultGenres(result, items, topItem); result = this.GetResultStudios(result, items, topItem); result = this.GetResultPersons(result, items, topItem); result = this.GetResultProductionYears(result, items, topItem); result = this.GetResulProductionLocations(result, items, topItem); result = this.GetResultCommunityRatings(result, items, topItem); result = this.GetResultParentalRatings(result, items, topItem); switch (reportIncludeItemTypes) { case ReportIncludeItemTypes.Season: case ReportIncludeItemTypes.Series: case ReportIncludeItemTypes.MusicAlbum: case ReportIncludeItemTypes.MusicArtist: case ReportIncludeItemTypes.Game: break; case ReportIncludeItemTypes.Movie: case ReportIncludeItemTypes.BoxSet: break; case ReportIncludeItemTypes.Book: case ReportIncludeItemTypes.Episode: case ReportIncludeItemTypes.Video: case ReportIncludeItemTypes.MusicVideo: case ReportIncludeItemTypes.Trailer: case ReportIncludeItemTypes.Audio: case ReportIncludeItemTypes.BaseItem: default: break; } result.Groups = result.Groups.OrderByDescending(n => n.Items.Count()).ToList(); return(result); }
/// <summary> Gets report result. </summary> /// <param name="items"> The items. </param> /// <param name="request"> The request. </param> /// <returns> The report result. </returns> public ReportResult GetResult(BaseItem[] items, IReportsQuery request) { ReportIncludeItemTypes reportRowType = ReportHelper.GetRowType(request.IncludeItemTypes); ReportDisplayType displayType = ReportHelper.GetReportDisplayType(request.DisplayType); List <ReportOptions <BaseItem> > options = this.GetReportOptions <BaseItem>(request, () => this.GetDefaultHeaderMetadata(reportRowType), (hm) => this.GetOption(hm)).Where(x => this.DisplayTypeVisible(x.Header.DisplayType, displayType)).ToList(); var headers = GetHeaders <BaseItem>(options); var rows = GetReportRows(items, options); ReportResult result = new ReportResult { Headers = headers }; HeaderMetadata groupBy = ReportHelper.GetHeaderMetadataType(request.GroupBy); int i = headers.FindIndex(x => x.FieldName == groupBy); if (groupBy != HeaderMetadata.None && i >= 0) { var rowsGroup = rows.SelectMany(x => x.Columns[i].Name.Split(';'), (x, g) => new { Group = g.Trim(), Rows = x }) .GroupBy(x => x.Group) .OrderBy(x => x.Key) .Select(x => new ReportGroup { Name = x.Key, Rows = x.Select(r => r.Rows).ToList() }); result.Groups = rowsGroup.ToList(); result.IsGrouped = true; } else { result.Rows = rows; result.IsGrouped = false; } return(result); }
/// <summary> Gets the given request. </summary> /// <param name="request"> The request. </param> /// <returns> A Task<object> </returns> public async Task <object> Get(GetReportDownload request) { if (string.IsNullOrEmpty(request.IncludeItemTypes)) { return(null); } request.DisplayType = "Export"; ReportViewType reportViewType = ReportHelper.GetReportViewType(request.ReportView); var headers = new Dictionary <string, string>(); string fileExtension = "csv"; string contentType = "text/plain;charset='utf-8'"; switch (request.ExportType) { case ReportExportType.CSV: break; case ReportExportType.Excel: contentType = "application/vnd.ms-excel"; fileExtension = "xls"; break; } var filename = "ReportExport." + fileExtension; headers["Content-Disposition"] = string.Format("attachment; filename=\"{0}\"", filename); headers["Content-Encoding"] = "UTF-8"; ReportResult result = null; switch (reportViewType) { case ReportViewType.ReportStatistics: case ReportViewType.ReportData: ReportIncludeItemTypes reportRowType = ReportHelper.GetRowType(request.IncludeItemTypes); ReportBuilder dataBuilder = new ReportBuilder(_libraryManager); QueryResult <BaseItem> queryResult = await GetQueryResult(request).ConfigureAwait(false); result = dataBuilder.GetResult(queryResult.Items, request); result.TotalRecordCount = queryResult.TotalRecordCount; break; case ReportViewType.ReportActivities: result = await GetReportActivities(request).ConfigureAwait(false); break; } string returnResult = string.Empty; switch (request.ExportType) { case ReportExportType.CSV: returnResult = new ReportExport().ExportToCsv(result); break; case ReportExportType.Excel: returnResult = new ReportExport().ExportToExcel(result); break; } object ro = ResultFactory.GetResult(returnResult, contentType, headers); return(ro); }
/// <summary> Gets default report header metadata. </summary> /// <param name="reportIncludeItemTypes"> Type of the report row. </param> /// <returns> The default report header metadata. </returns> private List <HeaderMetadata> GetDefaultHeaderMetadata(ReportIncludeItemTypes reportIncludeItemTypes) { switch (reportIncludeItemTypes) { case ReportIncludeItemTypes.Season: return(new List <HeaderMetadata> { HeaderMetadata.Status, HeaderMetadata.Locked, HeaderMetadata.ImagePrimary, HeaderMetadata.ImageBackdrop, HeaderMetadata.ImageLogo, HeaderMetadata.Series, HeaderMetadata.Season, HeaderMetadata.SeasonNumber, HeaderMetadata.DateAdded, HeaderMetadata.Year, HeaderMetadata.Genres }); case ReportIncludeItemTypes.Series: return(new List <HeaderMetadata> { HeaderMetadata.Status, HeaderMetadata.Locked, HeaderMetadata.ImagePrimary, HeaderMetadata.ImageBackdrop, HeaderMetadata.ImageLogo, HeaderMetadata.Name, HeaderMetadata.Network, HeaderMetadata.DateAdded, HeaderMetadata.Year, HeaderMetadata.Genres, HeaderMetadata.ParentalRating, HeaderMetadata.CommunityRating, HeaderMetadata.Runtime, HeaderMetadata.Trailers, HeaderMetadata.Specials }); case ReportIncludeItemTypes.MusicAlbum: return(new List <HeaderMetadata> { HeaderMetadata.Status, HeaderMetadata.Locked, HeaderMetadata.ImagePrimary, HeaderMetadata.ImageBackdrop, HeaderMetadata.ImageLogo, HeaderMetadata.Name, HeaderMetadata.AlbumArtist, HeaderMetadata.DateAdded, HeaderMetadata.ReleaseDate, HeaderMetadata.Tracks, HeaderMetadata.Year, HeaderMetadata.Genres }); case ReportIncludeItemTypes.MusicArtist: return(new List <HeaderMetadata> { HeaderMetadata.Status, HeaderMetadata.Locked, HeaderMetadata.ImagePrimary, HeaderMetadata.ImageBackdrop, HeaderMetadata.ImageLogo, HeaderMetadata.MusicArtist, HeaderMetadata.Countries, HeaderMetadata.DateAdded, HeaderMetadata.Year, HeaderMetadata.Genres }); case ReportIncludeItemTypes.Game: return(new List <HeaderMetadata> { HeaderMetadata.Status, HeaderMetadata.Locked, HeaderMetadata.ImagePrimary, HeaderMetadata.ImageBackdrop, HeaderMetadata.ImageLogo, HeaderMetadata.Name, HeaderMetadata.GameSystem, HeaderMetadata.DateAdded, HeaderMetadata.ReleaseDate, HeaderMetadata.ParentalRating, HeaderMetadata.CommunityRating, HeaderMetadata.Players, HeaderMetadata.Year, HeaderMetadata.Genres, HeaderMetadata.Trailers }); case ReportIncludeItemTypes.Movie: return(new List <HeaderMetadata> { HeaderMetadata.Status, HeaderMetadata.Locked, HeaderMetadata.ImagePrimary, HeaderMetadata.ImageBackdrop, HeaderMetadata.ImageLogo, HeaderMetadata.Name, HeaderMetadata.DateAdded, HeaderMetadata.ReleaseDate, HeaderMetadata.Year, HeaderMetadata.Genres, HeaderMetadata.ParentalRating, HeaderMetadata.CommunityRating, HeaderMetadata.Runtime, HeaderMetadata.Video, HeaderMetadata.Resolution, HeaderMetadata.Audio, HeaderMetadata.Subtitles, HeaderMetadata.Trailers, HeaderMetadata.Specials }); case ReportIncludeItemTypes.Book: return(new List <HeaderMetadata> { HeaderMetadata.Status, HeaderMetadata.Locked, HeaderMetadata.ImagePrimary, HeaderMetadata.ImageBackdrop, HeaderMetadata.ImageLogo, HeaderMetadata.Name, HeaderMetadata.DateAdded, HeaderMetadata.ReleaseDate, HeaderMetadata.Year, HeaderMetadata.Genres, HeaderMetadata.ParentalRating, HeaderMetadata.CommunityRating }); case ReportIncludeItemTypes.BoxSet: return(new List <HeaderMetadata> { HeaderMetadata.Status, HeaderMetadata.Locked, HeaderMetadata.ImagePrimary, HeaderMetadata.ImageBackdrop, HeaderMetadata.ImageLogo, HeaderMetadata.Name, HeaderMetadata.DateAdded, HeaderMetadata.ReleaseDate, HeaderMetadata.Year, HeaderMetadata.Genres, HeaderMetadata.ParentalRating, HeaderMetadata.CommunityRating, HeaderMetadata.Trailers }); case ReportIncludeItemTypes.Audio: return(new List <HeaderMetadata> { HeaderMetadata.Status, HeaderMetadata.Locked, HeaderMetadata.ImagePrimary, HeaderMetadata.ImageBackdrop, HeaderMetadata.ImageLogo, HeaderMetadata.Name, HeaderMetadata.AudioAlbumArtist, HeaderMetadata.AudioAlbum, HeaderMetadata.Disc, HeaderMetadata.Track, HeaderMetadata.DateAdded, HeaderMetadata.ReleaseDate, HeaderMetadata.Year, HeaderMetadata.Genres, HeaderMetadata.ParentalRating, HeaderMetadata.CommunityRating, HeaderMetadata.Runtime, HeaderMetadata.Audio }); case ReportIncludeItemTypes.Episode: return(new List <HeaderMetadata> { HeaderMetadata.Status, HeaderMetadata.Locked, HeaderMetadata.ImagePrimary, HeaderMetadata.ImageBackdrop, HeaderMetadata.ImageLogo, HeaderMetadata.Name, HeaderMetadata.EpisodeSeries, HeaderMetadata.Season, HeaderMetadata.EpisodeNumber, HeaderMetadata.DateAdded, HeaderMetadata.ReleaseDate, HeaderMetadata.Year, HeaderMetadata.Genres, HeaderMetadata.ParentalRating, HeaderMetadata.CommunityRating, HeaderMetadata.Runtime, HeaderMetadata.Video, HeaderMetadata.Resolution, HeaderMetadata.Audio, HeaderMetadata.Subtitles, HeaderMetadata.Trailers, HeaderMetadata.Specials }); case ReportIncludeItemTypes.Video: case ReportIncludeItemTypes.MusicVideo: case ReportIncludeItemTypes.Trailer: case ReportIncludeItemTypes.BaseItem: default: return(new List <HeaderMetadata> { HeaderMetadata.Status, HeaderMetadata.Locked, HeaderMetadata.ImagePrimary, HeaderMetadata.ImageBackdrop, HeaderMetadata.ImageLogo, HeaderMetadata.ImagePrimary, HeaderMetadata.ImageBackdrop, HeaderMetadata.ImageLogo, HeaderMetadata.Name, HeaderMetadata.DateAdded, HeaderMetadata.ReleaseDate, HeaderMetadata.Year, HeaderMetadata.Genres, HeaderMetadata.ParentalRating, HeaderMetadata.CommunityRating, HeaderMetadata.Runtime, HeaderMetadata.Video, HeaderMetadata.Resolution, HeaderMetadata.Audio, HeaderMetadata.Subtitles, HeaderMetadata.Trailers, HeaderMetadata.Specials }); } }
/// <summary> Gets the headers. </summary> /// <typeparam name="H"> Type of the header. </typeparam> /// <param name="request"> The request. </param> /// <returns> The headers. </returns> /// <seealso cref="M:MediaBrowser.Api.Reports.ReportBuilderBase.GetHeaders{H}(H)"/> protected internal override List <ReportHeader> GetHeaders <H>(H request) { ReportIncludeItemTypes reportRowType = ReportHelper.GetRowType(request.IncludeItemTypes); return(this.GetHeaders <BaseItem>(request, () => this.GetDefaultHeaderMetadata(reportRowType), (hm) => this.GetOption(hm))); }
/// <summary> Gets the given request. </summary> /// <param name="request"> The request. </param> /// <returns> A Task<object> </returns> public object Get(GetReportDownload request) { if (string.IsNullOrEmpty(request.IncludeItemTypes)) { return(null); } request.DisplayType = "Export"; ReportViewType reportViewType = ReportHelper.GetReportViewType(request.ReportView); var headers = new Dictionary <string, string>(); string fileExtension = "csv"; string contentType = "text/plain;charset='utf-8'"; switch (request.ExportType) { case ReportExportType.CSV: break; case ReportExportType.Excel: contentType = "application/vnd.ms-excel"; fileExtension = "xls"; break; } var filename = "ReportExport." + fileExtension; headers["Content-Disposition"] = string.Format("attachment; filename=\"{0}\"", filename); headers["Content-Encoding"] = "UTF-8"; var user = !string.IsNullOrWhiteSpace(request.UserId) ? _userManager.GetUserById(request.UserId) : null; ReportResult result = null; switch (reportViewType) { case ReportViewType.ReportData: ReportIncludeItemTypes reportRowType = ReportHelper.GetRowType(request.IncludeItemTypes); ReportBuilder dataBuilder = new ReportBuilder(_libraryManager); QueryResult <BaseItem> queryResult = GetQueryResult(request, new DtoOptions(), user); result = dataBuilder.GetResult(queryResult.Items, request); result.TotalRecordCount = queryResult.TotalRecordCount; break; case ReportViewType.ReportActivities: result = GetReportActivities(request); break; } ReadOnlySpan <char> returnResult = default(ReadOnlySpan <char>); switch (request.ExportType) { case ReportExportType.CSV: returnResult = new ReportExport().ExportToCsv(result).AsSpan(); break; case ReportExportType.Excel: returnResult = new ReportExport().ExportToExcel(result).AsSpan(); break; } return(_resultFactory.GetResult(returnResult, contentType, headers)); }