Create a Harris Matrix from archaeological stratigraphy data using Python and Graphviz. See the Harris Matrix Data Package https://codeberg.org/steko/harris-matrix-data-package for a revised and updated version https://www.iosa.it/2008/08/27/harris-matrix-with-graphviz-a-draft-application-with-python/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

50 lines
1.5 KiB

#! /usr/bin/env python
# -*- coding: utf-8 -*-
import sys
if sys.version_info[1] >= 5:
import sqlite3 as sqlite
else:
from pysqlite2 import dbapi2 as sqlite
class DbReader:
'''Reads data from SQLite database.'''
def __init__(self,inputfile,table):
self.con = sqlite.connect(inputfile)
#unicode only for non-ASCII data
self.con.text_factory = sqlite.OptimizedUnicode
self.table = table.split()[0] # stupid hack against SQL injection
def returnList(self):
self.cur = self.con.cursor()
selStatement = str('select * from ' + self.table)
self.cur.execute(selStatement)
return self.cur.fetchall()
class Db2Gv:
'''Converts data from database to Graphviz readable data.'''
def __init__(self,fetchedData):
self.elist = fetchedData
class DbCreator:
'''Creates a new empty sqlite3 database.
CREATE TABLE relations (us1 TEXT, us2 TEXT, rel TEXT)
CREATE TABLE units (us INTEGER PRIMARY KEY, type TEXT)
If no filename is provided, the database is created in the RAM. But remember
that you will lose all yourk work if you don't save it to a file.
'''
def __init__(self,inputfile=':memory:'):
self.con = sqlite.connect(inputfile)
#unicode only for non-ASCII data
self.con.text_factory = sqlite.OptimizedUnicode
self.cur = self.con.cursor()
self.cur.execute('CREATE TABLE relations (us1 TEXT, us2 TEXT, rel TEXT)')
self.cur.execute('CREATE TABLE units (us INTEGER PRIMARY KEY, type TEXT)')