aboutsummaryrefslogtreecommitdiff
path: root/backend/hist_data
diff options
context:
space:
mode:
authorTerry Truong <terry06890@gmail.com>2023-01-21 15:23:51 +1100
committerTerry Truong <terry06890@gmail.com>2023-01-21 16:17:31 +1100
commitc318c4cedf3f50c21c403649945c2abbbc30a89e (patch)
treec74f967755c1b653a450973712a99bec65724f6a /backend/hist_data
parentd581e5b61a771ef8619a5bfbc84a6e337c7ca13f (diff)
Do more minor refactoring
Document some variables coupled between client and server. Add more term consistency ('unit', 'event density'). Make console messages more consistent.
Diffstat (limited to 'backend/hist_data')
-rw-r--r--backend/hist_data/cal.py14
1 files changed, 14 insertions, 0 deletions
diff --git a/backend/hist_data/cal.py b/backend/hist_data/cal.py
index d86589b..64bc5a4 100644
--- a/backend/hist_data/cal.py
+++ b/backend/hist_data/cal.py
@@ -79,6 +79,19 @@ MIN_CAL_YEAR = -4713 # Year before which JDNs are not usable
MONTH_SCALE = -1;
DAY_SCALE = -2;
SCALES: list[int] = [int(s) for s in [1e9, 1e8, 1e7, 1e6, 1e5, 1e4, 1e3, 100, 10, 1, MONTH_SCALE, DAY_SCALE]];
+ # The timeline is divided into units of SCALES[0], then SCALES[1], etc
+ # Positive ints represent numbers of years, -1 represents 1 month, -2 represents 1 day
+
+if __debug__: # Validate SCALES
+ if SCALES[-1] != DAY_SCALE or SCALES[-2] != MONTH_SCALE or SCALES[-3] != 1:
+ raise Exception('SCALES must end with [1, MONTH_SCALE, DAY_SCALE]');
+ for i in range(1, len(SCALES) - 2):
+ if SCALES[i] <= 0:
+ raise Exception('SCALES must only have positive ints before MONTH_SCALE')
+ if SCALES[i-1] <= SCALES[i]:
+ raise Exception('SCALES must hold decreasing values')
+ if SCALES[i-1] % SCALES[i] > 0:
+ raise Exception('Each positive int in SCALES must divide the previous int')
class HistDate:
"""
@@ -90,6 +103,7 @@ class HistDate:
- False: Indicates a Julian calendar date
- None: 'month' and 'day' are 1 (required for dates before MIN_CAL_YEAR)
"""
+ # Note: Intentionally not enforcing, for gcal=None, that year < MIN_CAL_YEAR
def __init__(self, gcal: bool | None, year: int, month=1, day=1):
self.gcal = gcal
self.year = year