mirror of
https://github.com/jellyfin/jellyfin-plugin-reports.git
synced 2024-11-23 05:39:45 +00:00
Performance improvements
This commit is contained in:
parent
0c0a27abdb
commit
0bdc2d680a
@ -42,15 +42,7 @@ namespace Jellyfin.Plugin.Reports.Api.Common
|
||||
/// <param name="options"> Options for controlling the operation. </param>
|
||||
/// <returns> The active headers. </returns>
|
||||
protected List<ReportHeader> GetActiveHeaders<T>(List<ReportOptions<T>> options, ReportDisplayType displayType)
|
||||
{
|
||||
List<ReportHeader> headers = new List<ReportHeader>();
|
||||
foreach (ReportOptions<T> option in options.Where(x => this.DisplayTypeVisible(x.Header.DisplayType, displayType)))
|
||||
{
|
||||
headers.Add(option.Header);
|
||||
}
|
||||
|
||||
return headers;
|
||||
}
|
||||
=> options.Where(x => this.DisplayTypeVisible(x.Header.DisplayType, displayType)).Select(x => x.Header).ToList();
|
||||
|
||||
/// <summary> Gets audio stream. </summary>
|
||||
/// <param name="item"> The item. </param>
|
||||
@ -73,11 +65,13 @@ namespace Jellyfin.Plugin.Reports.Api.Common
|
||||
/// <returns> The episode. </returns>
|
||||
protected string GetEpisode(BaseItem item)
|
||||
{
|
||||
|
||||
if (item.GetClientTypeName() == ChannelMediaContentType.Episode.ToString() && item.ParentIndexNumber != null)
|
||||
if (string.Equals(item.GetClientTypeName(), ChannelMediaContentType.Episode.ToString(), StringComparison.Ordinal)
|
||||
&& item.ParentIndexNumber != null)
|
||||
{
|
||||
return "Season " + item.ParentIndexNumber;
|
||||
else
|
||||
return item.Name;
|
||||
}
|
||||
|
||||
return item.Name;
|
||||
}
|
||||
|
||||
/// <summary> Gets a genre. </summary>
|
||||
@ -105,15 +99,7 @@ namespace Jellyfin.Plugin.Reports.Api.Common
|
||||
/// <param name="options"> Options for controlling the operation. </param>
|
||||
/// <returns> The headers. </returns>
|
||||
protected List<ReportHeader> GetHeaders<T>(List<ReportOptions<T>> options)
|
||||
{
|
||||
List<ReportHeader> headers = new List<ReportHeader>();
|
||||
foreach (ReportOptions<T> option in options)
|
||||
{
|
||||
headers.Add(option.Header);
|
||||
}
|
||||
|
||||
return headers;
|
||||
}
|
||||
=> options.ConvertAll(x => x.Header);
|
||||
|
||||
/// <summary> Gets the headers. </summary>
|
||||
/// <typeparam name="T"> Generic type parameter. </typeparam>
|
||||
@ -132,7 +118,7 @@ namespace Jellyfin.Plugin.Reports.Api.Common
|
||||
/// <returns> The list as string. </returns>
|
||||
protected string GetListAsString(List<string> items)
|
||||
{
|
||||
return String.Join("; ", items);
|
||||
return string.Join("; ", items);
|
||||
}
|
||||
|
||||
/// <summary> Gets localized header. </summary>
|
||||
|
@ -1,6 +1,6 @@
|
||||
#nullable disable
|
||||
|
||||
using System.Globalization;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Jellyfin.Plugin.Reports.Api.Model;
|
||||
@ -8,30 +8,35 @@ using Jellyfin.Plugin.Reports.Api.Model;
|
||||
namespace Jellyfin.Plugin.Reports.Api.Data
|
||||
{
|
||||
/// <summary> A report export. </summary>
|
||||
public class ReportExport
|
||||
public static class ReportExport
|
||||
{
|
||||
/// <summary> Export to CSV. </summary>
|
||||
/// <param name="reportResult"> The report result. </param>
|
||||
/// <returns> A string. </returns>
|
||||
public string ExportToCsv(ReportResult reportResult)
|
||||
public static string ExportToCsv(ReportResult reportResult)
|
||||
{
|
||||
StringBuilder returnValue = new StringBuilder();
|
||||
static void AppendRows(StringBuilder builder, List<ReportRow> rows)
|
||||
{
|
||||
foreach (ReportRow row in rows)
|
||||
{
|
||||
builder.AppendJoin(';', row.Columns.Select(s => s.Name.Replace(',', ' '))).AppendLine();
|
||||
}
|
||||
}
|
||||
|
||||
returnValue.AppendLine(string.Join(';', reportResult.Headers.Select(s => s.Name.Replace(',', ' '))));
|
||||
StringBuilder returnValue = new StringBuilder();
|
||||
returnValue.AppendJoin(';', reportResult.Headers.Select(s => s.Name.Replace(',', ' '))).AppendLine();
|
||||
|
||||
if (reportResult.IsGrouped)
|
||||
{
|
||||
foreach (ReportGroup group in reportResult.Groups)
|
||||
{
|
||||
foreach (ReportRow row in reportResult.Rows)
|
||||
{
|
||||
returnValue.AppendLine(string.Join(';', row.Columns.Select(s => s.Name.Replace(',', ' '))));
|
||||
}
|
||||
AppendRows(returnValue, group.Rows);
|
||||
}
|
||||
}
|
||||
else
|
||||
foreach (ReportRow row in reportResult.Rows)
|
||||
{
|
||||
returnValue.AppendLine(string.Join(';', row.Columns.Select(s => s.Name.Replace(',', ' '))));
|
||||
}
|
||||
{
|
||||
AppendRows(returnValue, reportResult.Rows);
|
||||
}
|
||||
|
||||
return returnValue.ToString();
|
||||
}
|
||||
@ -40,10 +45,9 @@ namespace Jellyfin.Plugin.Reports.Api.Data
|
||||
/// <summary> Export to excel. </summary>
|
||||
/// <param name="reportResult"> The report result. </param>
|
||||
/// <returns> A string. </returns>
|
||||
public string ExportToExcel(ReportResult reportResult)
|
||||
public static string ExportToExcel(ReportResult reportResult)
|
||||
{
|
||||
|
||||
string style = @"<style type='text/css'>
|
||||
const string Style = @"<style type='text/css'>
|
||||
BODY {
|
||||
font-family: Arial;
|
||||
font-size: 12px;
|
||||
@ -164,35 +168,46 @@ namespace Jellyfin.Plugin.Reports.Api.Data
|
||||
<meta http-equiv='X-UA-Compatible' content='IE=8, IE=9, IE=10' />
|
||||
<meta charset='utf-8'>
|
||||
<title>Jellyfin Reports Export</title>";
|
||||
Html += "\n" + style + "\n";
|
||||
Html += "\n" + Style + "\n";
|
||||
Html += "</head>\n";
|
||||
Html += "<body>\n";
|
||||
|
||||
StringBuilder returnValue = new StringBuilder();
|
||||
returnValue.AppendLine("<table class='gridtable'>");
|
||||
returnValue.AppendLine("<tr>");
|
||||
returnValue.AppendLine(string.Join(string.Empty, reportResult.Headers.Select(s => string.Format(CultureInfo.InvariantCulture, "<th>{0}</th>", s.Name))));
|
||||
foreach (var x in reportResult.Headers)
|
||||
{
|
||||
returnValue.Append("<th>")
|
||||
.Append(x.Name)
|
||||
.AppendLine("</th>");
|
||||
}
|
||||
|
||||
returnValue.AppendLine("</tr>");
|
||||
|
||||
if (reportResult.IsGrouped)
|
||||
{
|
||||
foreach (ReportGroup group in reportResult.Groups)
|
||||
{
|
||||
returnValue.AppendLine("<tr>");
|
||||
returnValue.AppendLine("<th scope='rowgroup' colspan='" + reportResult.Headers.Count + "'>" + (string.IsNullOrEmpty(group.Name) ? " " : group.Name) + "</th>");
|
||||
returnValue.Append("<th scope='rowgroup' colspan='")
|
||||
.Append(reportResult.Headers.Count)
|
||||
.Append("'>")
|
||||
.Append(string.IsNullOrEmpty(group.Name) ? " " : group.Name)
|
||||
.AppendLine("</th>");
|
||||
returnValue.AppendLine("</tr>");
|
||||
foreach (ReportRow row in group.Rows)
|
||||
{
|
||||
ExportToExcelRow(reportResult, returnValue, row);
|
||||
}
|
||||
ExportToExcelRows(returnValue, group.Rows);
|
||||
returnValue.AppendLine("<tr>");
|
||||
returnValue.AppendLine("<th style='background-color: #ffffff;' scope='rowgroup' colspan='" + reportResult.Headers.Count + "'>" + " " + "</th>");
|
||||
returnValue.Append("<th style='background-color: #ffffff;' scope='rowgroup' colspan='")
|
||||
.Append(reportResult.Headers.Count)
|
||||
.AppendLine("'>" + " " + "</th>");
|
||||
returnValue.AppendLine("</tr>");
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
foreach (ReportRow row in reportResult.Rows)
|
||||
{
|
||||
ExportToExcelRow(reportResult, returnValue, row);
|
||||
}
|
||||
{
|
||||
ExportToExcelRows(returnValue, reportResult.Rows);
|
||||
}
|
||||
|
||||
returnValue.AppendLine("</table>");
|
||||
|
||||
Html += returnValue.ToString();
|
||||
@ -200,13 +215,23 @@ namespace Jellyfin.Plugin.Reports.Api.Data
|
||||
Html += "</html>";
|
||||
return Html;
|
||||
}
|
||||
private static void ExportToExcelRow(ReportResult reportResult,
|
||||
|
||||
private static void ExportToExcelRows(
|
||||
StringBuilder returnValue,
|
||||
ReportRow row)
|
||||
List<ReportRow> rows)
|
||||
{
|
||||
returnValue.AppendLine("<tr>");
|
||||
returnValue.AppendLine(string.Join(string.Empty, row.Columns.Select(s => string.Format(CultureInfo.InvariantCulture, "<td>{0}</td>", s.Name))));
|
||||
returnValue.AppendLine("</tr>");
|
||||
foreach (var row in rows)
|
||||
{
|
||||
returnValue.AppendLine("<tr>");
|
||||
foreach (var x in row.Columns)
|
||||
{
|
||||
returnValue.Append("<td>")
|
||||
.Append(x.Name)
|
||||
.AppendLine("</td>");
|
||||
}
|
||||
|
||||
returnValue.AppendLine("</tr>");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
@ -69,18 +70,12 @@ namespace Jellyfin.Plugin.Reports.Api
|
||||
request.DisplayType = "Screen";
|
||||
ReportViewType reportViewType = ReportHelper.GetReportViewType(request.ReportView);
|
||||
|
||||
List<ReportHeader> result = new List<ReportHeader>();
|
||||
switch (reportViewType)
|
||||
List<ReportHeader> result = reportViewType switch
|
||||
{
|
||||
case ReportViewType.ReportData:
|
||||
ReportBuilder dataBuilder = new ReportBuilder(_libraryManager);
|
||||
result = dataBuilder.GetHeaders(request);
|
||||
break;
|
||||
case ReportViewType.ReportActivities:
|
||||
ReportActivitiesBuilder activityBuilder = new ReportActivitiesBuilder(_libraryManager, _userManager);
|
||||
result = activityBuilder.GetHeaders(request);
|
||||
break;
|
||||
}
|
||||
ReportViewType.ReportData => new ReportBuilder(_libraryManager).GetHeaders(request),
|
||||
ReportViewType.ReportActivities => new ReportActivitiesBuilder(_libraryManager, _userManager).GetHeaders(request),
|
||||
_ => throw new InvalidEnumArgumentException()
|
||||
};
|
||||
|
||||
return result;
|
||||
}
|
||||
@ -148,10 +143,10 @@ namespace Jellyfin.Plugin.Reports.Api
|
||||
switch (request.ExportType)
|
||||
{
|
||||
case ReportExportType.CSV:
|
||||
returnResult = new ReportExport().ExportToCsv(result);
|
||||
returnResult = ReportExport.ExportToCsv(result);
|
||||
break;
|
||||
case ReportExportType.Excel:
|
||||
returnResult = new ReportExport().ExportToExcel(result);
|
||||
returnResult = ReportExport.ExportToExcel(result);
|
||||
break;
|
||||
}
|
||||
|
||||
@ -222,11 +217,11 @@ namespace Jellyfin.Plugin.Reports.Api
|
||||
}
|
||||
|
||||
query.IsFavorite = null;
|
||||
if(request.IsFavorite == true)
|
||||
if (request.IsFavorite)
|
||||
{
|
||||
query.IsFavorite = true;
|
||||
}
|
||||
else if (request.IsNotFavorite == true)
|
||||
else if (request.IsNotFavorite)
|
||||
{
|
||||
query.IsFavorite = false;
|
||||
}
|
||||
@ -275,13 +270,13 @@ namespace Jellyfin.Plugin.Reports.Api
|
||||
// Filter by Series Status
|
||||
if (!string.IsNullOrEmpty(request.SeriesStatus))
|
||||
{
|
||||
query.SeriesStatuses = request.SeriesStatus.Split(',').Select(d => (SeriesStatus)Enum.Parse(typeof(SeriesStatus), d, true)).ToArray();
|
||||
query.SeriesStatuses = request.SeriesStatus.Split(',').Select(d => Enum.Parse<SeriesStatus>(d, true)).ToArray();
|
||||
}
|
||||
|
||||
// ExcludeLocationTypes
|
||||
if (!string.IsNullOrEmpty(request.ExcludeLocationTypes))
|
||||
{
|
||||
var excludeLocationTypes = request.ExcludeLocationTypes.Split(',').Select(d => (LocationType)Enum.Parse(typeof(LocationType), d, true)).ToArray();
|
||||
var excludeLocationTypes = request.ExcludeLocationTypes.Split(',').Select(d => Enum.Parse<LocationType>(d, true)).ToArray();
|
||||
if (excludeLocationTypes.Contains(LocationType.Virtual))
|
||||
{
|
||||
query.IsVirtualItem = false;
|
||||
|
Loading…
Reference in New Issue
Block a user