Browse Source

finished refactor database

automate2
Stephen Lorenz 4 years ago
parent
commit
8c61695eaf
  1. BIN
      cjs/.app/database/debug/database.db
  2. BIN
      cjs/.app/database/debug2/database.db
  3. BIN
      cjs/.app/state.db
  4. 36
      cjs/core/database.py
  5. 33
      cjs/database.py
  6. 8
      cjs/models/database.py

BIN
cjs/.app/database/debug/database.db

BIN
cjs/.app/database/debug2/database.db

BIN
cjs/.app/state.db

36
cjs/core/database.py

@ -21,8 +21,14 @@ import models.state
from models.state import DatabaseState
import models.database
#from models.database import DatabaseBase
from models.database import *
from models.database import DatabaseBase
from models.database import TestTable
from models.database import EvidenceTable
from models.database import ComparisonTable
from models.database import JobTable
from models.database import BatchTable
from models.database import ResultTable
from models.database import EventTable
# BEGIN: Generic Database API
@ -296,17 +302,33 @@ def database_first(name, Table, expr=True):
# BEGIN: Automation API
def pending_jobs(name):
'''Return a list of all pending jobs.'''
try:
ds = _get_database(name)
jobs = ds.select_tables(JobTable, JobTable.event_id == 1)
return jobs
pass
except:
# TODO: implement fine-grained handling
raise
def next_job(name):
'''Return the next evidence and comparison row.'''
try:
ds = _get_database(name)
pass
# get next job's test_id
next_job = ds.first_record(JobTable, JobTable.event_id == 1)
# use test_id to find the next evidence_id and comparison_id
next_test = ds.first_record(TestTable, TestTable.id_ == next_job.test_id)
# use the evidence_id to get the next evidence row
next_evidence = ds.select_tables(EvidenceTable,
EvidenceTable.id_ == next_test.evidence_id)
# use the evidence_id to get the next comparison row
next_comparison = ds.select_tables(ComparisonTable,
ComparisonTable.id_ == next_test.comparison_id)
return next_evidence[0], next_comparison[0]
except:
# TODO: implement fine-grained handling
raise
@ -314,15 +336,17 @@ def next_job(name):
def current_batch(name):
try:
ds = _get_database(name)
pass
batch = ds.last_record(BatchTable)
return batch
except:
# TODO: implement fine-grained handling
raise
def insert_result(name, filename):
def insert_result(name, result_name, filename):
try:
ds = _get_database(name)
pass
batch = current_batch(name).name
ds.add_tables([result_name, filenamem batch.id])
except:
# TODO: implement fine-grained handling
raise

33
cjs/database.py

@ -35,9 +35,8 @@ from core.database import database_count
from core.database import database_first
from core.database import database_last
import models.reqbt
from models.reqbt import EvidenceSchema
from core.database import next_job
from core.database import current_batch
import models.database
from models.database import TestTable
@ -46,6 +45,9 @@ from models.database import ComparisonTable
from models.database import JobTable
from models.database import BatchTable
import models.reqbt
from models.reqbt import EvidenceSchema
def database_skeleton(root):
try:
create_dir(root)
@ -304,21 +306,10 @@ def status(database_name):
complete_count = get_count(JobTable, JobTable.event_id == 3)
failed_count = get_count(JobTable, JobTable.event_id == 4)
next_job = database_first(database_name,
JobTable,
JobTable.event_id == 1)
next_test = database_first(database_name,
TestTable,
TestTable.id_ == next_job.test_id)
next_evidence = _database_select(database_name,
EvidenceTable,
EvidenceTable.id_ == next_test.evidence_id)[0]
next_comparison = _database_select(database_name,
ComparisonTable,
ComparisonTable.id_ == next_test.comparison_id)[0]
next_job = '%s and %s' % (next_evidence.name, next_comparison.name)
current_batch = database_last(database_name, BatchTable).name
evidence, comparison = next_job(database_name)
job = '%s and %s' % (evidence.name, comparison.name)
batch = current_batch(database_name).name
echo_title('Database Status', fg='yellow', bold=True)
echo_field('Evidence', evidence_count, fg='yellow')
@ -331,10 +322,8 @@ def status(database_name):
echo_field(' Complete', complete_count, fg='yellow')
echo_field(' Failed', failed_count, fg='yellow')
click.echo('')
echo_field('Current Batch', current_batch, fg='yellow')
echo_field('Next Job', next_job, fg='yellow')
echo_field('Current Batch', batch, fg='yellow')
echo_field('Next Job', job, fg='yellow')
echo_field('Average Time', '23.3 sec', fg='yellow')
# END command-line interface

8
cjs/models/database.py

@ -108,16 +108,14 @@ class ResultTable(DatabaseBase):
__tablename__ = 'Result'
id_ = Column('id', Integer, primary_key=True)
batch_id = Column('batch_id', ForeignKey('Batch.id'))
name = Column('name', String(32))
path = Column('path', String(260))
processing_time = Column('processing_time', Integer())
batch_id = Column('batch_id', ForeignKey('Batch.id'))
def __init__(self, name, path, batch_id, time):
def __init__(self, name, path, batch_id):
self.name = name
self.path = path
self.batch_id = batch_id
self.processing_time = time
def __str__(self):
return '%s, %s, %s' % (self.id_, self.name, self.path, self.time)
return '%s, %s, %s' % (self.id_, self.name, self.path, self.batch_id)
Loading…
Cancel
Save