allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brond...@apache.org
Subject git commit: Remove dead code (since [2356145])
Date Thu, 01 May 2014 20:36:09 GMT
Repository: allura
Updated Branches:
  refs/heads/master a0c83eabc -> 7eec72050


Remove dead code (since [2356145])


Project: http://git-wip-us.apache.org/repos/asf/allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/allura/commit/7eec7205
Tree: http://git-wip-us.apache.org/repos/asf/allura/tree/7eec7205
Diff: http://git-wip-us.apache.org/repos/asf/allura/diff/7eec7205

Branch: refs/heads/master
Commit: 7eec720501d8432b2d938404e75963a21bd00dff
Parents: a0c83ea
Author: Dave Brondsema <dbrondsema@slashdotmedia.com>
Authored: Thu May 1 20:23:41 2014 +0000
Committer: Dave Brondsema <dbrondsema@slashdotmedia.com>
Committed: Thu May 1 20:35:53 2014 +0000

----------------------------------------------------------------------
 Allura/allura/lib/zarkov_helpers.py        | 75 ------------------------
 Allura/allura/tests/test_zarkov_helpers.py | 77 -------------------------
 2 files changed, 152 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/7eec7205/Allura/allura/lib/zarkov_helpers.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/zarkov_helpers.py b/Allura/allura/lib/zarkov_helpers.py
index 15d0b96..2f136f2 100644
--- a/Allura/allura/lib/zarkov_helpers.py
+++ b/Allura/allura/lib/zarkov_helpers.py
@@ -37,78 +37,3 @@ class ZarkovClient(object):
             type=type, context=context, extra=extra)
         self._sock.send(bson.BSON.encode(obj))
 
-
-def zero_fill_zarkov_result(zarkov_data, period, start_date, end_date):
-    """Return a new copy of zarkov_data (a dict returned from a zarkov
-    query) with the timeseries data zero-filled for missing dates.
-
-    Args:
-        zarkov_data (dict): A Zarkov query result.
-        period (str): 'month' or 'date' for monthly or daily timestamps
-        start_date (datetime or str): Start of the date range. If a str is
-            passed, it must be in %Y-%m-%d format.
-        end_date (datetime or str): End of the date range. If a str is
-            passed, it must be in %Y-%m-%d format.
-
-    Returns:
-        dict. A new copy of zarkov_data, zero-filled.
-
-    """
-    d = zarkov_data.copy()
-    if isinstance(start_date, basestring):
-        start_date = datetime.strptime(start_date, '%Y-%m-%d')
-    if isinstance(end_date, basestring):
-        end_date = datetime.strptime(end_date, '%Y-%m-%d')
-    for query in zarkov_data.iterkeys():
-        for series in zarkov_data[query].iterkeys():
-            d[query][series] = zero_fill_time_series(d[query][series],
-                                                     period, start_date, end_date)
-    return d
-
-
-def zero_fill_time_series(time_series, period, start_date, end_date):
-    """Return a copy of time_series after adding [timestamp, 0] pairs for
-    each missing timestamp in the given date range.
-
-    Args:
-        time_series (list): A list of [timestamp, value] pairs, e.g.:
-            [[1306886400000.0, 1], [1309478400000.0, 0]]
-        period (str): 'month' or 'date' for monthly or daily timestamps
-        start_date (datetime): Start of the date range.
-        end_date (datetime or str): End of the date range.
-
-    Returns:
-        list. A new copy of time_series, zero-filled.
-
-    If you want to zero-fill an entire zarkov result, you should use
-    :func:`zero_fill_zarkov_result` instead, which will call this function
-    for each timeseries list in the zarkov result.
-
-    """
-    new_series = dict(time_series)
-    if period == 'month':
-        date = start_date
-        while date <= end_date:
-            ts = to_utc_timestamp(date)
-            if ts not in new_series:
-                new_series[ts] = 0
-            # next month
-            if date.month == 12:
-                date = date.replace(year=date.year + 1, month=1)
-            else:
-                date = date.replace(month=date.month + 1)
-    else:  # daily
-        days = (end_date - start_date).days + 1
-        periods = range(0, days)
-        for dayoffset in periods:
-            date = start_date + timedelta(days=dayoffset)
-            ts = to_utc_timestamp(date)
-            if ts not in new_series:
-                new_series[ts] = 0
-    return sorted([[k, v] for k, v in new_series.items()])
-
-
-def to_utc_timestamp(d):
-    """Return UTC unix timestamp representation of d (datetime)."""
-    # http://stackoverflow.com/questions/1077285/how-to-specify-time-zone-utc-when-converting-to-unix-time-python
-    return calendar.timegm(d.utctimetuple()) * 1000.0

http://git-wip-us.apache.org/repos/asf/allura/blob/7eec7205/Allura/allura/tests/test_zarkov_helpers.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/test_zarkov_helpers.py b/Allura/allura/tests/test_zarkov_helpers.py
index 36a14d4..2a6cb38 100644
--- a/Allura/allura/tests/test_zarkov_helpers.py
+++ b/Allura/allura/tests/test_zarkov_helpers.py
@@ -51,80 +51,3 @@ class TestZarkovClient(unittest.TestCase):
             extra=None))
         self.socket.send.assert_called_once_with(obj)
 
-
-class TestZeroFill(unittest.TestCase):
-
-    def setUp(self):
-        self.dt_begin = datetime(2010, 6, 1)
-        self.dt_end = datetime(2011, 7, 1)
-        ts_begin = timegm(self.dt_begin.timetuple())
-        ts_end = timegm(self.dt_end.timetuple())
-        self.ts_ms_begin = ts_begin * 1000.0
-        self.ts_ms_end = ts_end * 1000.0
-        self.zarkov_data = dict(
-            a=dict(
-                a1=[(self.ts_ms_begin, 1000), (self.ts_ms_end, 1000)],
-                a2=[(self.ts_ms_begin, 1000), (self.ts_ms_end, 1000)]),
-            b=dict(
-                b1=[(self.ts_ms_begin, 2000), (self.ts_ms_end, 2000)],
-                b2=[(self.ts_ms_begin, 2000), (self.ts_ms_end, 2000)]))
-
-    def test_to_utc_timestamp(self):
-        self.assertEqual(
-            zh.to_utc_timestamp(self.dt_begin),
-            self.ts_ms_begin)
-        self.assertEqual(
-            zh.to_utc_timestamp(self.dt_end),
-            self.ts_ms_end)
-
-    def test_zero_fill_time_series_month(self):
-        result = zh.zero_fill_time_series(
-            self.zarkov_data['a']['a1'], 'month',
-            datetime(2010, 5, 1), datetime(2011, 9, 1))
-        self.assertEqual(result[0][1], 0)
-        self.assertEqual(result[-1][1], 0)
-        self.assertEqual(len(result), 17)
-        self.assertEqual(result[1][1], 1000)
-        self.assertEqual(result[-3][1], 1000)
-        days_ms = 24 * 3600 * 1000
-        min_delta = 28 * days_ms
-        max_delta = 31 * days_ms
-        for p1, p2 in zip(result, result[1:]):
-            delta = p2[0] - p1[0]
-            assert min_delta <= delta <= max_delta, delta
-
-    def test_zero_fill_time_series_date(self):
-        result = zh.zero_fill_time_series(
-            self.zarkov_data['a']['a1'], 'date',
-            datetime(2010, 5, 1), datetime(2011, 9, 1))
-        self.assertEqual(len(result), 489)
-        days_ms = 24 * 3600 * 1000
-        for p1, p2 in zip(result, result[1:]):
-            delta = p2[0] - p1[0]
-            assert delta == days_ms
-
-    def test_zero_fill_zarkov_month_dt(self):
-        result = zh.zero_fill_zarkov_result(
-            self.zarkov_data, 'month',
-            datetime(2010, 5, 1), datetime(2011, 9, 1))
-        a_result = result['a']['a1']
-        b_result = result['b']['b2']
-        self.assertEqual(a_result[0][1], 0)
-        self.assertEqual(a_result[-1][1], 0)
-        self.assertEqual(len(a_result), 17)
-        self.assertEqual(a_result[1][1], 1000)
-        self.assertEqual(a_result[-3][1], 1000)
-        self.assertEqual(b_result[0][1], 0)
-        self.assertEqual(b_result[-1][1], 0)
-        self.assertEqual(len(b_result), 17)
-        self.assertEqual(b_result[1][1], 2000)
-        self.assertEqual(b_result[-3][1], 2000)
-
-    def test_zero_fill_zarkov_month_str(self):
-        result0 = zh.zero_fill_zarkov_result(
-            self.zarkov_data, 'month',
-            datetime(2010, 5, 1), datetime(2011, 9, 1))
-        result1 = zh.zero_fill_zarkov_result(
-            self.zarkov_data, 'month',
-            '2010-5-1', '2011-09-1')
-        self.assertEqual(result0, result1)


Mime
View raw message