Skip to content
Snippets Groups Projects
Commit edec9511 authored by Jorrit Schaap's avatar Jorrit Schaap
Browse files

Task #8291: moved humanreadablesize method to module utils. added monthRanges...

Task #8291: moved humanreadablesize method to module utils. added monthRanges method. use utils methods in report.
parent 722c4b0b
Branches
Tags
No related merge requests found
......@@ -2834,6 +2834,7 @@ LTA/ltastorageoverview/lib/create_db_ltastorageoverview.sql -text
LTA/ltastorageoverview/lib/report.py -text
LTA/ltastorageoverview/lib/scraper.py -text
LTA/ltastorageoverview/lib/store.py -text
LTA/ltastorageoverview/lib/utils.py -text
LTA/ltastorageoverview/lib/webservice/__init__.py -text
LTA/ltastorageoverview/lib/webservice/templates/index.html -text
LTA/ltastorageoverview/lib/webservice/webservice.py -text
......
......@@ -6,6 +6,7 @@ python_install(
store.py
create_db_ltastorageoverview.sql
report.py
utils.py
webservice/webservice.py
webservice/__init__.py
DESTINATION ltastorageoverview)
......
......@@ -19,29 +19,36 @@
import logging
import time
import datetime
from datetime import datetime, timedelta
import sys
import os
import os.path
from ltastorageoverview import store
def humanreadablesize(num, suffix='B', base=1000):
""" converts the given size (number) to a human readable string in powers of 'base'"""
try:
for unit in ['', 'K', 'M', 'G', 'T', 'P', 'E', 'Z']:
if abs(num) < float(base):
return "%3.1f%s%s" % (num, unit, suffix)
num /= float(base)
return "%.2f%s%s" % (num, 'Y', suffix)
except TypeError:
return str(num)
from ltastorageoverview.utils import humanreadablesize
from ltastorageoverview.utils import monthRanges
def main(argv):
db = store.LTAStorageDb('ltastorageoverview.sqlite')
sites = db.sites()
min_date, max_date = db.datetimeRangeOfFilesInTree()
month_ranges = monthRanges(min_date, max_date)
for site in sites:
print '\n--- %s ---' % site[1]
for month_range in month_ranges:
numFilesInSite = db.numFilesInSite(site[0], month_range[0], month_range[1])
totalFileSizeInSite = db.totalFileSizeInSite(site[0], month_range[0], month_range[1])
print " %s %s %s #files=%d total_size=%s" % (site[1], month_range[0], month_range[1], numFilesInSite, humanreadablesize(totalFileSizeInSite))
sys.exit(0)
print '\n*** TOTALS ***'
for site in sites:
......
#!/usr/bin/python
# Copyright (C) 2012-2015 ASTRON (Netherlands Institute for Radio Astronomy)
# P.O. Box 2, 7990 AA Dwingeloo, The Netherlands
#
# This file is part of the LOFAR software suite.
# The LOFAR software suite is free software: you can redistribute it and/or
# modify it under the terms of the GNU General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# The LOFAR software suite is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with the LOFAR software suite. If not, see <http://www.gnu.org/licenses/>.
from datetime import datetime, timedelta
import sys
import os
def humanreadablesize(num, suffix='B', base=1000):
""" converts the given size (number) to a human readable string in powers of 'base'"""
try:
for unit in ['', 'K', 'M', 'G', 'T', 'P', 'E', 'Z']:
if abs(num) < float(base):
return "%3.1f%s%s" % (num, unit, suffix)
num /= float(base)
return "%.2f%s%s" % (num, 'Y', suffix)
except TypeError:
return str(num)
def monthRanges(min_date, max_date):
ranges = []
min_month_start = datetime(min_date.year, min_date.month, 1, tzinfo=min_date.tzinfo)
month_start = min_month_start
while month_start < max_date:
if month_start.month < 12:
month_end = datetime(month_start.year, month_start.month+1, 1, tzinfo=month_start.tzinfo) - timedelta(milliseconds=1)
else:
month_end = datetime(month_start.year+1, month_start.month-11, 1, tzinfo=month_start.tzinfo) - timedelta(milliseconds=1)
ranges.append((month_start, month_end))
if month_start.month < 12:
month_start = datetime(month_start.year, month_start.month+1, 1, tzinfo=min_date.tzinfo)
else:
month_start = datetime(month_start.year+1, month_start.month-11, 1, tzinfo=min_date.tzinfo)
return ranges
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment