Skip to content

Commit

Permalink
[file_size_metrics] v0.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] committed Mar 13, 2024
1 parent 8ae43d9 commit f82b92d
Show file tree
Hide file tree
Showing 8 changed files with 142 additions and 81 deletions.
12 changes: 12 additions & 0 deletions source/file_size_metrics/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
root = true

[*]
charset = utf-8
end_of_line = lf
indent_size = 2
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true

[{info.json,*.py}]
indent_size = 4
3 changes: 3 additions & 0 deletions source/file_size_metrics/changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
**<span style="color:#56adda">0.1.1</span>**
- When viewing on mobile, show individual file metrics in a dialog popup

**<span style="color:#56adda">0.1.0</span>**
- New layout to try and make better use of space

Expand Down
26 changes: 13 additions & 13 deletions source/file_size_metrics/info.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{
"author": "Josh.5, EspadaV8",
"compatibility": [1, 2],
"description": "Aggregate changes in file size metrics for processed files and add a data panel for displaying the results.",
"icon": "https://raw.githubusercontent.com/Josh5/unmanic.plugin.file_size_metrics/master/icon.png",
"id": "file_size_metrics",
"name": "File Size Metrics Data Panel",
"platform": ["all"],
"priorities": {
"on_worker_process": 1,
"on_postprocessor_task_results": 0
},
"tags": "data panel",
"version": "0.1.0"
"author": "Josh.5, EspadaV8",
"compatibility": [1, 2],
"description": "Aggregate changes in file size metrics for processed files and add a data panel for displaying the results.",
"icon": "https://raw.githubusercontent.com/Josh5/unmanic.plugin.file_size_metrics/master/icon.png",
"id": "file_size_metrics",
"name": "File Size Metrics Data Panel",
"platform": ["all"],
"priorities": {
"on_worker_process": 1,
"on_postprocessor_task_results": 0
},
"tags": "data panel",
"version": "0.1.1"
}
19 changes: 14 additions & 5 deletions source/file_size_metrics/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,12 +317,12 @@ def prepare_filtered_historic_tasks(self, request_dict):
self.db_stop()
return return_data

def save_source_item(self, abspath, size, task_success=False):
def save_source_item(self, abspath, size, start_time=None, task_success=False):
self.db_start()

basename = os.path.basename(abspath)
task_label = basename
start_time = datetime.datetime.now()
start_time = start_time if start_time is not None else datetime.datetime.now()
finish_time = None
try:
new_historic_task = HistoricTasks.create(
Expand Down Expand Up @@ -412,10 +412,10 @@ def get_total_size_change_data_details(data):
return json.dumps(results, indent=2)


def save_source_size(abspath, size):
def save_source_details(abspath, size, start_time=None):
# Return a list of historical tasks based on the request JSON body
data = Data()
task_id = data.save_source_item(abspath, size)
task_id = data.save_source_item(abspath, size, start_time)

return task_id

Expand Down Expand Up @@ -458,7 +458,10 @@ def on_worker_process(data):

with open(plugin_data_file, 'w') as f:
required_data = {
'file_in': data.get('file_in'),
'original_file_path': data.get('original_file_path'),
'source_size': source_size,
'start_time': datetime.datetime.now().isoformat(),
}
json.dump(required_data, f, indent=4)

Expand Down Expand Up @@ -491,11 +494,15 @@ def on_postprocessor_task_results(data):
# Get the file out and store (if it exists)
src_file_hash = hashlib.md5(original_source_path.encode('utf8')).hexdigest()
plugin_data_file = os.path.join(profile_directory, '{}.json'.format(src_file_hash))
start_time = None

if os.path.exists(plugin_data_file):
# The store exists
with open(plugin_data_file) as infile:
task_metadata = json.load(infile)

source_size = task_metadata.get('source_size')
start_time = datetime.datetime.fromisoformat(task_metadata.get('start_time')) if 'start_time' in task_metadata else datetime.datetime.now()
else:
# The store did not exist, resort to fetching the data from the original source file (hopefully unchanged)
logger.warning("Plugin data file is missing. Fetching source size direct from source path.")
Expand All @@ -504,7 +511,9 @@ def on_postprocessor_task_results(data):
if not source_size:
logger.error("Plugin data file is missing 'source_size'.")
return data
task_id = save_source_size(original_source_path, source_size)

task_id = save_source_details(original_source_path, source_size, start_time)

if task_id is None:
logger.error("Failed to create source size entry for this file")
return data
Expand Down
39 changes: 37 additions & 2 deletions source/file_size_metrics/static/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,8 @@ html {
background-color: var(--q-card-head-hover);
}

.content {
.card-content {
background-color: var(--q-card);
display: none;
overflow: hidden;
padding: 0 18px;
}
Expand Down Expand Up @@ -126,7 +125,10 @@ html {
}

#individual_file_size_chart {
display: block;
order: 2;
overflow: hidden;
padding: 0 3px;
}

#individual_file_size_chart .card {
Expand Down Expand Up @@ -195,6 +197,7 @@ html {

#individual_file_size_chart {
order: 1;
display: none;
}

#individual_file_size_chart .card {
Expand All @@ -210,3 +213,35 @@ html {
padding-top: 20px;
}
}

dialog {
color: var(--q-text);
border: none;
background-color: var(--q-card);
width: 100%;
padding: 0;
}

dialog::backdrop {
background-color: var(--q-card-head);
opacity: 0.85;
}

dialog .card-content {
padding: 0 10px;
}

dialog .card-footer {
padding: 0 0 10px 0;
}

dialog .q-btn {
background: var(--q-primary);
border: 0;
color: #fff;
font-size: 14px;
font-weight: 500;
outline: 0;
padding: 8px 20px;
text-transform: uppercase;
}
45 changes: 30 additions & 15 deletions source/file_size_metrics/static/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@
</head>
<body id="top-of-page">
<!-- ######## BEGIN PAGE CONTENT -->
<input
id="selected_task_id"
type="hidden"
name="selected_task_id"
value=""
/>

<div class="top-content">
<div class="charts">
Expand Down Expand Up @@ -91,27 +97,36 @@
<div class="card">
<div class="card-header active">Individual File Size Change</div>
<div class="card-content">
<div class="content" style="display: block">
<input
id="selected_task_id"
type="hidden"
name="selected_task_id"
value=""
/>

<div id="task_details">
<div id="file_size_chart">
There was an issue showing this chart
</div>
<div class="task_details">
<div id="file_size_chart">
There was an issue showing this chart
</div>
</div>

<div class="selected_task_name" class="car-header"></div>
</div>
</div>
</div>

<div id="selected_task_name" class="car-header">
(Select a task from the table)
<dialog id="individual_file_size_chart_dialog" data-modal>
<div class="card">
<div class="card-header active">Individual File Size Change</div>
<div class="card-content">
<div class="task_details">
<div id="file_size_chart_dialog">
There was an issue showing this chart
</div>
</div>

<div class="selected_task_name" class="car-header"></div>
</div>
<div class="card-footer">
<form method="dialog">
<button autofocus class="q-btn">Close</button>
</form>
</div>
</div>
</div>
</dialog>
</div>

<a href="#top-of-page" class="top-of-page-link" data-visible="true">
Expand Down
73 changes: 27 additions & 46 deletions source/file_size_metrics/static/js/filesizechart.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const CompletedTasksFileSizeDiffChart = (function () {
let source_total_size = 0;
let destination_total_size = 0;

const individualChart = Highcharts.chart("file_size_chart", {
Highcharts.setOptions({
chart: {
backgroundColor: chart_background,
height: chartHeight,
Expand All @@ -58,6 +58,9 @@ const CompletedTasksFileSizeDiffChart = (function () {
},
},
colors: [default_bar_colour, positive_bar_colour],
legend: {
enabled: false,
},
xAxis: {
type: "category",
labels: {
Expand All @@ -74,62 +77,33 @@ const CompletedTasksFileSizeDiffChart = (function () {
},
},
title: {
text: "Sizes",
text: "Size",
style: {
color: subtext_colour,
},
},
},
legend: {
enabled: false,
},
series: [],
});

const totalChart = Highcharts.chart("total_size_chart", {
const individualChart = new Highcharts.Chart({
chart: {
backgroundColor: chart_background,
height: chartHeight,
renderTo: "file_size_chart",
},
title: {
text: "",
style: {
color: text_colour,
},
});
const individualChart2 = new Highcharts.Chart({
chart: {
renderTo: "file_size_chart_dialog",
},
});

const totalChart = new Highcharts.Chart({
chart: {
renderTo: "total_size_chart",
},
subtitle: {
text: "Displaying the total file size changed on disk by Unmanic processing files",
style: {
color: subtext_colour,
},
},
colors: [default_bar_colour, positive_bar_colour],
xAxis: {
type: "category",
labels: {
style: {
color: text_colour,
},
},
lineColor: text_colour,
},
yAxis: {
labels: {
style: {
color: text_colour,
},
},
title: {
text: "Sizes",
style: {
color: subtext_colour,
},
},
},
legend: {
enabled: false,
},
series: [],
});

const updateIndividualChart = function () {
Expand All @@ -149,7 +123,7 @@ const CompletedTasksFileSizeDiffChart = (function () {
source_file_size = Number(source_file_size);
destination_file_size = Number(destination_file_size);

individualChart.update({
const options = {
chart: {
backgroundColor: chart_background,
type: "bar",
Expand All @@ -173,7 +147,10 @@ const CompletedTasksFileSizeDiffChart = (function () {
File Size: ${formatBytes(Math.abs(this.point.y))}`;
},
},
});
};

individualChart.update(options);
individualChart2.update(options);

const newSeriesData = {
borderWidth: 0,
Expand All @@ -193,10 +170,14 @@ const CompletedTasksFileSizeDiffChart = (function () {

for (let i = individualChart.series.length - 1; i >= 0; i--) {
individualChart.series[i].remove(false);
individualChart2.series[i].remove(false);
}

individualChart.addSeries(newSeriesData, false);
individualChart2.addSeries(newSeriesData, false);

individualChart.redraw();
individualChart2.redraw();
};

const updateTotalChart = function () {
Expand Down Expand Up @@ -303,7 +284,7 @@ const CompletedTasksFileSizeDiffChart = (function () {
</p>`;
}

$("#selected_task_name").html(html);
$(".selected_task_name").html(html);
});
};

Expand Down
Loading

0 comments on commit f82b92d

Please sign in to comment.