From 7d47f6805e1a8ee30c185bf7ca39e8f6a61de3f6 Mon Sep 17 00:00:00 2001 From: Will Woods Date: Jun 23 2020 02:14:05 +0000 Subject: column name changes Change a couple column names to avoid confusion around "count", "countme", and the SQL "count()" function: * use "sys_age" instead of "countme" * use "hits" instead of "count" --- diff --git a/countme-csv2sqlite.sh b/countme-csv2sqlite.sh index 8af65c9..b583451 100755 --- a/countme-csv2sqlite.sh +++ b/countme-csv2sqlite.sh @@ -15,17 +15,20 @@ if [ ! -r "$COUNTME_CSV" ]; then exit 2 fi +# TODO: CLI switch for weeknum or week_start+week_end +# TODO: maybe other schemas (schemata?) too? + sqlite3 "$COUNTME_SQLITE" <<__SQLITE__ .bail on CREATE TABLE $COUNTME_TABLE ( week_start DATETIME NOT NULL, week_end DATETIME NOT NULL, - count INTEGER NOT NULL, + hits INTEGER NOT NULL, os_name TEXT NOT NULL, os_version TEXT NOT NULL, os_variant TEXT NOT NULL, os_arch TEXT NOT NULL, - countme INTEGER NOT NULL, + sys_age INTEGER NOT NULL, repo_tag TEXT NOT NULL, repo_arch TEXT NOT NULL ); diff --git a/countme-totals.py b/countme-totals.py index a20fd62..c587569 100755 --- a/countme-totals.py +++ b/countme-totals.py @@ -54,7 +54,7 @@ class CountBucket(NamedTuple): os_version: str os_variant: str os_arch: str - countme: int + sys_age: int repo_tag: str repo_arch: str @@ -68,13 +68,13 @@ BucketSelect = CountBucket( os_version = "os_version", os_variant = "os_variant", os_arch = "os_arch", - countme = "countme", + sys_age = "sys_age", repo_tag = "repo_tag", repo_arch = "repo_arch" ) -TotalsItem = NamedTuple("TotalsItem", [("count", int)] + list(CountBucket.__annotations__.items())) -TotalsItem.__doc__ = '''TotalsItem is CountBucket with a "count" on the front.''' +TotalsItem = NamedTuple("TotalsItem", [("hits", int)] + list(CountBucket.__annotations__.items())) +TotalsItem.__doc__ = '''TotalsItem is CountBucket with a "hits" count on the front.''' class CSVCountItem(NamedTuple): ''' @@ -84,21 +84,21 @@ class CSVCountItem(NamedTuple): ''' week_start: str week_end: str - count: int + hits: int os_name: str os_version: str os_variant: str os_arch: str - countme: int + sys_age: int repo_tag: str repo_arch: str @classmethod def from_totalitem(cls, item): '''Use this method to convert a CountItem to a CSVCountItem.''' - count, weeknum, *rest = item + hits, weeknum, *rest = item week_start, week_end = daterange(weeknum) - return cls._make([week_start, week_end, count] + rest) + return cls._make([week_start, week_end, hits] + rest) # =========================================================================== # ====== SQL + Progress helpers ============================================= @@ -211,15 +211,15 @@ def main(): desc = f"week {week} ({mon} -- {sun})" total = rawdb.week_count(week) prog = Progress(total=total, desc=desc, disable=True if not args.progress else None, unit="row", unit_scale=False) - counts = Counter() + hitcount = Counter() # Select raw items into their buckets and count 'em up - for item in rawdb.week_iter(week, select=BucketSelect): - counts[item] += 1 + for bucket in rawdb.week_iter(week, select=BucketSelect): + hitcount[bucket] += 1 prog.update() # Write the resulting totals into countme_totals - totals.write_items((count,)+bucket for bucket,count in counts.items()) + totals.write_items((hits,)+bucket for bucket,hits in hitcount.items()) prog.close() # Oh and make sure we index them by time. diff --git a/countme/__init__.py b/countme/__init__.py index 6da822f..c853ac1 100644 --- a/countme/__init__.py +++ b/countme/__init__.py @@ -152,7 +152,7 @@ class CountmeItem(NamedTuple): os_version: str os_variant: str os_arch: str - countme: int + sys_age: int repo_tag: str repo_arch: str @@ -202,7 +202,7 @@ class CountmeMatcher(LogMatcher): os_version = match['os_version'], os_variant = match['os_variant'], os_arch = match['os_arch'], - countme = int(query.get('countme')), + sys_age = int(query.get('countme')), repo_tag = query.get('repo'), repo_arch = query.get('arch'))