Skip to content

Commit

Permalink
Report count of pages in sections, notebooks
Browse files Browse the repository at this point in the history
  • Loading branch information
stevencohn authored and weissm committed Dec 28, 2023
1 parent 21bc150 commit 522467a
Showing 1 changed file with 37 additions and 25 deletions.
62 changes: 37 additions & 25 deletions OneMore/Commands/File/AnalyzeCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -297,13 +297,13 @@ private void ReportNotebooks(XElement container, XElement notebooks)
table.Rows.ForEach(r =>
{
if (r[1].Value > 0)
r[1].ShadingColor = $"#{map1.MapToRGB(r[1].Value).ToString("x6")}";
r[1].ShadingColor = $"#{map1.MapToRGB(r[1].Value):x6}";
if (r[2].Value > 0)
r[2].ShadingColor = $"#{map2.MapToRGB(r[2].Value).ToString("x6")}";
r[2].ShadingColor = $"#{map2.MapToRGB(r[2].Value):x6}";
if (r[3].Value > 0)
r[3].ShadingColor = $"#{map3.MapToRGB(r[3].Value).ToString("x6")}";
r[3].ShadingColor = $"#{map3.MapToRGB(r[3].Value):x6}";
});
}

Expand Down Expand Up @@ -390,7 +390,7 @@ private async Task ReportSections(XElement container, XElement notebooks)
new Paragraph($"{book.Attribute("name").Value} Notebook")
.SetQuickStyle(heading2Index));

var table = new Table(ns, 1, 4)
var table = new Table(ns, 1, 5)
{
HasHeaderRow = true,
BordersVisible = true
Expand All @@ -400,39 +400,42 @@ private async Task ReportSections(XElement container, XElement notebooks)
table.SetColumnWidth(1, 70);
table.SetColumnWidth(2, 70);
table.SetColumnWidth(3, 70);
table.SetColumnWidth(4, 70);

var row = table[0];
row.SetShading(HeaderShading);
row[0].SetContent(new Paragraph("Section").SetStyle(HeaderCss));
row[1].SetContent(new Paragraph("Size on Disk").SetStyle(HeaderCss).SetAlignment("center"));
row[2].SetContent(new Paragraph("# of Copies").SetStyle(HeaderCss).SetAlignment("center"));
row[3].SetContent(new Paragraph("Total Size").SetStyle(HeaderCss).SetAlignment("center"));
row[1].SetContent(new Paragraph("# of Pages").SetStyle(HeaderCss).SetAlignment("center"));
row[2].SetContent(new Paragraph("Size on Disk").SetStyle(HeaderCss).SetAlignment("center"));
row[3].SetContent(new Paragraph("# of Copies").SetStyle(HeaderCss).SetAlignment("center"));
row[4].SetContent(new Paragraph("Total Size").SetStyle(HeaderCss).SetAlignment("center"));

var notebook = await one.GetNotebook(book.Attribute("ID").Value);

var total = ReportSections(table, notebook, null);
var (totalPages, totalSize) = ReportSections(table, notebook, null);

row = table.AddRow();
row[3].SetContent(new Paragraph(total.ToBytes(1)).SetAlignment("right"));
row[1].SetContent(new Paragraph(totalPages.ToString()).SetAlignment("right"));
row[4].SetContent(new Paragraph(totalSize.ToBytes(1)).SetAlignment("right"));

// heatmap
var values1 = new List<decimal>();
var values3 = new List<decimal>();
table.Rows.ForEach(r =>
{
if (r[1].Value > 0) values1.Add(r[1].Value);
if (r[3].Value > 0) values3.Add(r[1].Value);
if (r[2].Value > 0) values1.Add(r[2].Value);
if (r[4].Value > 0) values3.Add(r[2].Value);
});

var map1 = new Heatmap(values1);
var map3 = new Heatmap(values3);
table.Rows.ForEach(r =>
{
if (r[1].Value > 0)
r[1].ShadingColor = $"#{map1.MapToRGB(r[1].Value).ToString("x6")}";
if (r[2].Value > 0)
r[2].ShadingColor = $"#{map1.MapToRGB(r[2].Value):x6}";
if (r[3].Value > 0)
r[3].ShadingColor = $"#{map3.MapToRGB(r[3].Value).ToString("x6")}";
if (r[4].Value > 0)
r[4].ShadingColor = $"#{map3.MapToRGB(r[4].Value):x6}";
});

container.Add(
Expand All @@ -442,9 +445,10 @@ private async Task ReportSections(XElement container, XElement notebooks)
}
}

private long ReportSections(Table table, XElement folder, string folderPath)
private (int, long) ReportSections(Table table, XElement folder, string folderPath)
{
long total = 0;
int totalPages = 0;
long totalSize = 0;
var folderName = folder.Attribute("name").Value;

var sections = folder.Elements(ns + "Section")
Expand Down Expand Up @@ -483,6 +487,12 @@ private long ReportSections(Table table, XElement folder, string folderPath)
{
row[0].SetContent(new Paragraph(title));

var expanded = one.GetSection(section.Attribute("ID").Value);
var count = expanded.Elements().Count();
totalPages += count;
row[1].Value = count;
row[1].SetContent(new Paragraph(count.ToString()).SetAlignment("right"));

var filter = remote ? $"{name}.one (On *).one" : $"{name}.one";
var files = Directory.EnumerateFiles(filePath, filter).ToList();
if (files.Count > 0)
Expand All @@ -501,17 +511,17 @@ private long ReportSections(Table table, XElement folder, string folderPath)

if (all > 0)
{
row[1].Value = first;
row[1].SetContent(new Paragraph(first.ToBytes(1)).SetAlignment("right"));
row[2].Value = first;
row[2].SetContent(new Paragraph(first.ToBytes(1)).SetAlignment("right"));

if (remote)
{
row[2].SetContent(new Paragraph(files.Count.ToString()).SetAlignment("right"));
row[3].SetContent(new Paragraph(files.Count.ToString()).SetAlignment("right"));
}

row[3].Value = all;
row[3].SetContent(new Paragraph(all.ToBytes(1)).SetAlignment("right"));
total += all;
row[4].Value = all;
row[4].SetContent(new Paragraph(all.ToBytes(1)).SetAlignment("right"));
totalSize += all;
}
}
else
Expand All @@ -533,10 +543,12 @@ private long ReportSections(Table table, XElement folder, string folderPath)
foreach (var group in groups)
{
var path = folderPath == null ? folderName : Path.Combine(folderPath, folderName);
total += ReportSections(table, group, path);
var (p, s) = ReportSections(table, group, path);
totalPages += p;
totalSize += s;
}

return total;
return (totalPages, totalSize);
}


Expand Down

0 comments on commit 522467a

Please sign in to comment.