diff --git a/.gitattributes b/.gitattributes index 92e9713390d0d709ec674864c4d0cb84668a5b9d..e0ee661e860746095a25266a24d1eb7f0554c6f2 100644 --- a/.gitattributes +++ b/.gitattributes @@ -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 diff --git a/LTA/ltastorageoverview/lib/CMakeLists.txt b/LTA/ltastorageoverview/lib/CMakeLists.txt index e702da64f53e302b723382f11763b79a37e2f873..e99af80663a872801aca5e9e891b284dea005dfe 100644 --- a/LTA/ltastorageoverview/lib/CMakeLists.txt +++ b/LTA/ltastorageoverview/lib/CMakeLists.txt @@ -6,6 +6,7 @@ python_install( store.py create_db_ltastorageoverview.sql report.py + utils.py webservice/webservice.py webservice/__init__.py DESTINATION ltastorageoverview) diff --git a/LTA/ltastorageoverview/lib/report.py b/LTA/ltastorageoverview/lib/report.py index 987f6c4649b1b51cbf7db5cd5198b10f9cbe8508..95731b27c59c8ddebe442d2b03f2067fa36cdbed 100755 --- a/LTA/ltastorageoverview/lib/report.py +++ b/LTA/ltastorageoverview/lib/report.py @@ -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: diff --git a/LTA/ltastorageoverview/lib/utils.py b/LTA/ltastorageoverview/lib/utils.py new file mode 100644 index 0000000000000000000000000000000000000000..c322876d8e4a32233c3a210bc66e82163e718790 --- /dev/null +++ b/LTA/ltastorageoverview/lib/utils.py @@ -0,0 +1,55 @@ +#!/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