Skip to content

Revise quota table#836

Open
g7gpr wants to merge 15 commits intoCroatianMeteorNetwork:prereleasefrom
g7gpr:feature/DeleteOldObservations/QuotaTable
Open

Revise quota table#836
g7gpr wants to merge 15 commits intoCroatianMeteorNetwork:prereleasefrom
g7gpr:feature/DeleteOldObservations/QuotaTable

Conversation

@g7gpr
Copy link
Copy Markdown
Contributor

@g7gpr g7gpr commented Mar 5, 2026

Issue #835 identifies that the quota management table is not very easy to interpret. This PR modifies the table so that the usage, and the associated quota are all on the same line.

Directory quotas before management
--------------------------------------------------------------
Usage and quotas

                                           Used     Quota
                       frames files :    0.88GB
                         time files :    0.08GB
                        video files :   33.82GB
                                        ----------------------
       total for continuous capture :   34.77GB   30.00GB 116%

                          bz2 files :    0.27GB    3.00GB   9%
               archived directories :    0.52GB    3.00GB  17%
                                        ----------------------
 bz2 files and archived directories :    0.79GB    6.00GB  13%

               captured directories :   31.39GB   63.00GB  50%
                          log files :    0.05GB    1.00GB   5%
                                        ----------------------
                 total for RMS_data :   67.01GB  100.00GB  67%

 logical partition information
      partition containing RMS_data :  325.36GB  869.79GB  37%
--------------------------------------------------------------

It adds a percentage used indication, with divide by zero protection, and information about the logical partition containing the RMS_data folder.

@g7gpr g7gpr requested a review from markmac99 March 5, 2026 13:03
Copy link
Copy Markdown
Contributor

@markmac99 markmac99 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all seems ok.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses issue #835 by revising the quota management report table in DeleteOldObservations.py. Instead of showing space usage and quotas in separate sections, it presents used space and quota side-by-side on the same line, along with a percentage indicator and divide-by-zero protection. It also adds a new row showing disk usage of the logical partition containing the RMS_data folder.

Changes:

  • Refactored quotaReport() to display usage, quota, and percentage on the same line for each category.
  • Added divide-by-zero protection for all percentage calculations.
  • Added a logical partition information section using shutil.disk_usage().

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread RMS/DeleteOldObservations.py Outdated
Comment on lines +122 to +127
rep += (" bz2 files and archived directories : {:7.02f}GB {:7.02f}GB {:3.0f}%\n".format(usedSpace(archived_dir), config.arch_dir_quota + config.bz2_files_quota, total_arch_pc))
rep += ("\n")
rep += (" captured directories : {:7.02f}GB {:7.02f}GB {:3.0f}%\n".format(usedSpace(captured_dir), capt_dir_quota, captured_dir_pc))
rep += (" log files : {:7.02f}GB {:7.02f}GB {:3.0f}%\n".format(usedSpace(log_dir),config.log_files_quota, log_files_pc))
rep += (" ----------------------\n")
rep += (" total for RMS_data : {:7.02f}GB {:7.02f}GB {:3.0f}%\n".format(usedSpace(config.data_dir), config.rms_data_quota, total_rms_data_pc))
Copy link

Copilot AI Mar 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Several usedSpace() calls are made twice — once in the percentage calculation block and again in the format string for display. Specifically: usedSpace(archived_dir) (lines 85 and 122), usedSpace(captured_dir) (lines 95 and 124), usedSpace(log_dir) (lines 65 and 125), and usedSpace(config.data_dir) (lines 90 and 127). Since usedSpace() calls usedSpaceNoRecursion() which walks the filesystem, these redundant calls are expensive. Each value should be computed once and stored in a local variable, similar to continuous_capture_used_space.

Copilot uses AI. Check for mistakes.
Comment thread RMS/DeleteOldObservations.py Outdated
else:
total_arch_pc = 0

if config.arch_dir_quota + config.bz2_files_quota != 0:
Copy link

Copilot AI Mar 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The guard condition on lines 89-92 checks config.arch_dir_quota + config.bz2_files_quota != 0 to protect against division by zero, but the actual division on line 90 divides by config.rms_data_quota, which is a completely different variable. This means:

  1. If config.rms_data_quota is zero but config.arch_dir_quota + config.bz2_files_quota is non-zero, a ZeroDivisionError will be raised.
  2. If config.arch_dir_quota + config.bz2_files_quota is zero but config.rms_data_quota is non-zero, the percentage will be incorrectly set to 0 instead of being calculated.

The condition should be if config.rms_data_quota != 0: to properly guard the division by config.rms_data_quota.

Suggested change
if config.arch_dir_quota + config.bz2_files_quota != 0:
if config.rms_data_quota != 0:

Copilot uses AI. Check for mistakes.
Comment thread RMS/DeleteOldObservations.py Outdated
rep += (" Available space on drive : {:7.02f}GB\n".format(availableSpace(config.data_dir) / (1024 ** 3)))
rep += ("-----------------------------------------------\n")
rep += (" logical partition information\n")
rep += (" partition containing RMS_data : {:7.02f}GB {:7.02f}GB {:3.0f}%\n".format(usage.used / (1024 ** 3), usage.total / (1024 ** 3) , 100 * usage.used / usage.total))
Copy link

Copilot AI Mar 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On line 130, usage.total is used as a divisor in 100 * usage.used / usage.total without any zero-division protection. While a disk with total == 0 is an unlikely edge case, all other percentage calculations in this function explicitly guard against division by zero. For consistency and robustness, this calculation should also be protected, e.g., by only computing the percentage if usage.total != 0.

Copilot uses AI. Check for mistakes.
Comment thread RMS/DeleteOldObservations.py Outdated
from RMS.ConfigReader import loadConfigFromDirectory
from RMS.Logger import LoggingManager, getLogger
from RMS.Misc import RmsDateTime, UTCFromTimestamp
from pathlib import Path
Copy link

Copilot AI Mar 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

from pathlib import Path is imported on line 21 but Path is never used anywhere in the file. This is an unused import that was likely added by mistake. It should be removed to keep the imports clean.

Suggested change
from pathlib import Path

Copilot uses AI. Check for mistakes.
Comment thread RMS/DeleteOldObservations.py Outdated
Comment on lines +119 to +120
rep += (" bz2 files : {:7.02f}GB {:7.02f}GB {:3.0f}%\n".format(sizeBz2Files(config), config.bz2_files_quota, bz2_files_pc))
rep += (" archived directories : {:7.02f}GB {:7.02f}GB {:3.0f}%\n".format(sizeArchivedDirs(config), config.arch_dir_quota, arch_dir_pc))
Copy link

Copilot AI Mar 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The functions sizeBz2Files(config) and sizeArchivedDirs(config) are each called twice in the updated code: once during the percentage calculation block (lines 75 and 80) and again within the format string for the report (lines 119 and 120). Both functions iterate over the filesystem, making them potentially expensive. The values should be computed once and stored in local variables (similar to how continuous_capture_used_space is pre-computed), then reused in the format strings.

Copilot uses AI. Check for mistakes.
@g7gpr
Copy link
Copy Markdown
Contributor Author

g7gpr commented Mar 7, 2026

OK. I'll fix this up.

@g7gpr g7gpr marked this pull request as draft March 7, 2026 06:48
@g7gpr g7gpr marked this pull request as ready for review March 14, 2026 23:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants