Skip to content

Commit

Permalink
lij
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterLuschny committed Nov 21, 2023
1 parent cbd6257 commit 8ae42e5
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 23 deletions.
6 changes: 3 additions & 3 deletions src/_statictics.txt
Original file line number Diff line number Diff line change
Expand Up @@ -808,7 +808,7 @@ Ranking of triangles with regard to their impact:
[65] ('A072233', 'Partition', 168, 98, 1, 4, 45, 123, 65)
[64] ('A064189', 'MotzkinGF', 168, 101, 1, 4, 51, 117, 64)
[63] ('A039599', 'CatalanSqr', 171, 101, 1, 4, 52, 119, 63)
# (47 <= A < 60)
# (45 <= A < 60)
[58] ('A113704', 'Divisibility', 168, 88, 1, 4, 39, 129, 58)
[58] ('A363914', 'MoebiusMat', 168, 88, 1, 4, 39, 129, 58)
[57] ('A122538', 'Schroeder', 168, 103, 1, 4, 55, 113, 57)
Expand All @@ -820,7 +820,7 @@ Ranking of triangles with regard to their impact:
[48] ('A132062', 'Bessel', 168, 103, 1, 4, 80, 88, 48)
[47] ('A053121', 'CatalanAer', 168, 87, 1, 4, 56, 112, 47)
[47] ('A049310', 'ChebyshevS', 168, 87, 1, 4, 56, 112, 47)
# (35 <= A < 47)
# (30 <= A < 45)
[42] ('A124644', 'BinomialCatalan', 127, 92, 1, 3, 62, 65, 42)
[42] ('A119879', 'EulerSec', 168, 89, 1, 4, 72, 96, 42)
[42] ('A002262', 'Ordinals', 81, 46, 1, 2, 3, 78, 42)
Expand All @@ -836,12 +836,12 @@ Ranking of triangles with regard to their impact:
[36] ('A028246', 'Worpitzky', 128, 88, 1, 3, 60, 68, 36)
[35] ('A247453', 'Euler', 168, 72, 1, 4, 65, 103, 35)
[35] ('A104684', 'SchroederP', 168, 106, 1, 4, 107, 61, 35)
# ( A < 35)
[33] ('A048004', 'Composition', 168, 104, 1, 4, 106, 62, 33)
[33] ('A036561', 'Nicomachus', 81, 53, 1, 2, 24, 57, 33)
[33] ('A047999', 'Sierpinski', 131, 49, 1, 3, 27, 104, 33)
[31] ('A056857', 'BinomialBell', 168, 101, 1, 4, 103, 65, 31)
[30] ('A269945', 'CentralSet', 168, 104, 1, 4, 104, 64, 30)
# (A < 30)
[29] ('A022166', 'Gaussq2', 128, 79, 1, 3, 58, 70, 29)
[29] ('A354794', 'Lehmer', 168, 105, 1, 4, 107, 61, 29)
[29] ('A225479', 'OrderedCycle', 81, 55, 1, 2, 36, 45, 29)
Expand Down
72 changes: 52 additions & 20 deletions src/_tabldata.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def fnv(data: bytes) -> int:
MINTERMS = 15


def fnv_hash(seq: list[int], absolut: bool = False) -> str:
def FNVhash(seq: list[int], absolut: bool = False) -> str:
"""Returns the fnv-hash of an integer sequence based on the first MINTERMS terms.
Args:
Expand All @@ -124,7 +124,7 @@ def fnv_hash(seq: list[int], absolut: bool = False) -> str:
str: The hex value of the hash without the '0x'-head.
"""
if len(seq) < MINTERMS:
print(f"*** Warning *** Hash based only on {len(seq)} terms.")
print(f"*** Warning *** Hash based only on {len(seq)} terms, {MINTERMS} required.")
if seq == []:
return "0"
if absolut:
Expand Down Expand Up @@ -232,9 +232,9 @@ def OeisToSql() -> None:
print("Info: Database oeismini.db saved in data/db.")


def QueryDBhash(H: str, oeis_cur: sqlite3.Cursor) -> str:
def QueryDBbyHash(H: str, db_cur: sqlite3.Cursor) -> str:
"""
Query the sequences table in the database for a given hash.
Query the sequences table in the local database for a given hash.
Args:
H (str): The hash value to query.
Expand All @@ -244,12 +244,12 @@ def QueryDBhash(H: str, oeis_cur: sqlite3.Cursor) -> str:
str: The corresponding anum value if the hash is found, otherwise "missing".
"""
sql = "SELECT anum FROM sequences WHERE hash=? LIMIT 1"
res = oeis_cur.execute(sql, (H,))
res = db_cur.execute(sql, (H,))
record = res.fetchone()
return "missing" if record is None else record[0]


def QueryDBstr(seq: list[int], oeis_cur: sqlite3.Cursor) -> str:
def QueryDBbySeq(seq: list[int], db_cur: sqlite3.Cursor) -> str:
"""
Query the sequences table in the database for a given sequence.
Expand All @@ -264,12 +264,12 @@ def QueryDBstr(seq: list[int], oeis_cur: sqlite3.Cursor) -> str:
str.maketrans("", "", "[],")
)
sql = "SELECT anum FROM sequences WHERE seq=? LIMIT 1"
res = oeis_cur.execute(sql, (x,))
res = db_cur.execute(sql, (x,))
record = res.fetchone()
return "missing" if record is None else record[0]


def QueryMiniOeis(H: str, seq: list[int], oeis_cur: sqlite3.Cursor) -> str:
def QueryDBbyHashAndSeq(H: str, seq: list[int], db_cur: sqlite3.Cursor) -> str:
"""
Query oeis_mini db only.
Expand All @@ -282,19 +282,19 @@ def QueryMiniOeis(H: str, seq: list[int], oeis_cur: sqlite3.Cursor) -> str:
str: The corresponding anum value if the sequence is found, otherwise "missing".
"""
sql = "SELECT anum FROM sequences WHERE hash=? LIMIT 1"
res = oeis_cur.execute(sql, (H,))
res = db_cur.execute(sql, (H,))
record = res.fetchone()
if record is not None:
return record[0]

# not found by hash, perhaps shifted by one?
H = fnv_hash(seq[1: MINTERMS + 1], True)
res = oeis_cur.execute(sql, (H,))
H = FNVhash(seq[1: MINTERMS + 1], True)
res = db_cur.execute(sql, (H,))
record = res.fetchone()
return "missing" if record is None else record[0]


def QueryOeis(H: str, seq: list[int], oeis_cur: sqlite3.Cursor) -> str:
def QueryOeis(H: str, seq: list[int], db_cur: sqlite3.Cursor) -> str:
"""
First query oeis_mini (local), if nothing found query OEIS (internet).
Expand All @@ -306,10 +306,13 @@ def QueryOeis(H: str, seq: list[int], oeis_cur: sqlite3.Cursor) -> str:
Returns:
str: The corresponding anum value if the sequence is found, otherwise "missing".
"""
rec = QueryMiniOeis(H, seq, oeis_cur)
rec = QueryDBbyHashAndSeq(H, seq, db_cur)
# print(H, seq)
# print("QueryDBbyHashAndSeq", rec)
if rec != "missing":
return rec
bnum = IsInOEIS(seq)
# print("IsInOEIS", bnum)
if bnum == "":
return "missing"
return bnum
Expand Down Expand Up @@ -371,7 +374,7 @@ def SaveTraits(fun: tgen, size: int, traits_cur: sqlite3.Cursor, oeis_cur: sqlit
print(f"Info: {triname} -> {traitname} does not exist.")
continue

hash = fnv_hash(seq, True)
hash = FNVhash(seq, True)
# anum = queryminioeis(hash, seq, oeis_cur) # local
anum = QueryOeis(hash, seq, oeis_cur) # with internet

Expand Down Expand Up @@ -412,12 +415,12 @@ def SaveExtendedTraitsToDB(fun: tgen, size: int, traits_cur: sqlite3.Cursor, oei

TRAITS = RegisterTraits()

thash = fnv_hash(fun.tab(MINTERMS))
thash = FNVhash(fun.tab(MINTERMS))
SaveTraits(fun, size, traits_cur, oeis_cur, table, TRAITS)
fun.id = Tid

r = RevTable(fun, tim)
rhash = fnv_hash(r.tab(MINTERMS))
rhash = FNVhash(r.tab(MINTERMS))
if thash != rhash:
SaveTraits(r, size, traits_cur, oeis_cur, table, TRAITS)

Expand All @@ -429,13 +432,13 @@ def SaveExtendedTraitsToDB(fun: tgen, size: int, traits_cur: sqlite3.Cursor, oei
i = InvTable(fun, tim)
ihash = "0"
if i is not None:
ihash = fnv_hash(i.tab(MINTERMS))
ihash = FNVhash(i.tab(MINTERMS))
SaveTraits(i, size, traits_cur, oeis_cur, table, TRAITS)

# ri = RevInvTable(t, tim)
ri = RevTable(i, tim)
if ri is not None:
rihash = fnv_hash(ri.tab(MINTERMS))
rihash = FNVhash(ri.tab(MINTERMS))
if ihash != rihash:
SaveTraits(ri, size, traits_cur, oeis_cur, table, TRAITS)

Expand Down Expand Up @@ -470,6 +473,7 @@ def SaveTraitsToDB(fun: tgen) -> None:
def ConvertDBtoCSVandMD(dbpath: Path, funname: str) -> int:
"""
Converts a SQLite database to CSV and Markdown files.
We exclude cases 'A000012', 'A000007', and 'A000004', which are trivial.
Args:
dbpath (str): The path to the SQLite database.
Expand Down Expand Up @@ -584,6 +588,15 @@ def test2():
oeis_con.commit()
oeis_con.close()

def test22(hash: str):
oeis_con = sqlite3.connect(GetDataPath("oeismini", "db"))
oeis_cur = oeis_con.cursor()
res = oeis_cur.execute(f"SELECT hash, anum, seq FROM sequences WHERE hash='{hash}'")
output = res.fetchone()
print(output)
oeis_con.commit()
oeis_con.close()

def test3():
oeis_con = sqlite3.connect(GetDataPath("oeismini", "db"))
oeis_cur = oeis_con.cursor()
Expand All @@ -607,10 +620,29 @@ def test99():
def test9():
MergeAllDBs(tabl_fun)

def test33():
from tabl import Fubini, CentralE, CentralO
T = Fubini.tab(32)

ce = CentralE(T)
cehash = FNVhash(ce, True)
#print(cehash, ce)

co = CentralO(T)
cohash = FNVhash(co, True)
#print(cohash, co)

with sqlite3.connect(GetDataPath("oeismini", "db")) as oeis:
res = QueryOeis(cehash, ce, oeis.cursor())
print("test", res)

# GetCompressed()
# SaveAllTraitsToDBandCSVandMD(tabl_fun[2:3])
# SaveTraitsToDB(tabl_fun[3])
#test7()

for fun in tabl_fun:
ConvertDBtoCSVandMD(GetDataPath(fun.id, "db"), fun.id)
#for fun in tabl_fun:
# ConvertDBtoCSVandMD(GetDataPath(fun.id, "db"), fun.id)

test22("d7e6f639f03bf659")

0 comments on commit 8ae42e5

Please sign in to comment.