diff --git a/DB/api/query_db.py b/DB/api/query_db.py index 7dfec24..cbabd85 100644 --- a/DB/api/query_db.py +++ b/DB/api/query_db.py @@ -301,7 +301,7 @@ def format_data(header, data, json=False): yield ',' + format_data_row(row) yield "]" if json: - yield "}" + yield "}\n" # Newline at Ian's request def write_subsample(query, crosstab=False): diff --git a/DB/api/server.py b/DB/api/server.py index 57d19ab..5710e1f 100755 --- a/DB/api/server.py +++ b/DB/api/server.py @@ -1,5 +1,7 @@ +#!/usr/bin/env python3 import sys import os + # add Backend directory to python path so we can do # cross directory imports path = os.path.dirname(os.path.realpath(__file__)) diff --git a/DB/api/test_query_db.py b/DB/api/test_query_db.py index 2286384..3b5814b 100755 --- a/DB/api/test_query_db.py +++ b/DB/api/test_query_db.py @@ -79,26 +79,6 @@ def format_data(*args): return 'format_data called' return format_data -#TODO: reenable test. - # def test_classify(self): - # self.query_options['device_id'] = 5 - # self.retrieve_args[0] = 5 - - # self.query_options['classify'] = True - # self.query_options['device'] = 'Panel1' - # self.retrieve_args[7] = 'Panel1' - - # self.query_options['start_time'] = 6 - # self.retrieve_args[1] = 6 - - # self.query_options['end_time'] = 7 - # self.retrieve_args[2] = 7 - - # query_db.retrieve_within_filters = self.retrieve_factory() - # Analysis_3.run = self.classify_factory() - - # self.assertEqual(query_db.query(self.query_options), 'classify called') - def test_classify_missing_start_time(self): self.query_options['device_id'] = 10 self.query_options['device'] = "Panel1" diff --git a/DB/classification/__init__.py b/DB/classification/__init__.py index 8b13789..fbe285e 100644 --- a/DB/classification/__init__.py +++ b/DB/classification/__init__.py @@ -1 +1 @@ - +# This is an empty file. There are Reasons behind its existance. Please do not delete it. diff --git a/DB/classification/dataset_converter_unit_tests.py b/DB/classification/dataset_converter_unit_tests.py deleted file mode 100644 index c9a8da5..0000000 --- a/DB/classification/dataset_converter_unit_tests.py +++ /dev/null @@ -1,57 +0,0 @@ -import dataset_converter as conv -import psycopg2 -import unittest -import pickle - -DATABASE = "seads" -USER = "seadapi" -TABLE = "data_raw" - -class TestHDF5Conversion(unittest.TestCase): - - def test_malformed_record(self): - try: - con = psycopg2.connect(database = DATABASE, user = USER) - cursor = con.cursor() - cursor.execute(" select serial, type, data - lag(data, 14) over \ - (order by time), time, device from data_raw where \ - serial = 466419818 and device != 'PowerS' and device \ - != 'PowerG' limit 139;") - records = cursor.fetchall() - file_to_write = open("test_data_incorrect.test", "wb") - pickle.dump(file_to_write, records) -# [indexes, values] = conv.convert_to_hdf5(records) -# self.assertFail() - except Exception as e: - self.assertEqual(str(e), 'Malformed record, check your query') - - def test_HDF5_conversion_to_file(self): - con = psycopg2.connect(database = DATABASE, user = USER) - cursor = con.cursor() - cursor.execute(" select serial, type, data - lag(data, 14) over \ - (order by time), time, device from data_raw where \ - serial = 466419818 and device != 'PowerS' and device \ - != 'PowerG' limit 140;") - records = cursor.fetchall() - conv.convert_to_hdf5_file(records) - try: - open('store.h5') - except: - self.assertFail() - - def test_bad_file_name(self): - try: - con = psycopg2.connect(database = DATABASE, user = USER) - cursor = con.cursor() - cursor.execute(" select serial, type, data - lag(data, 14) over \ - (order by time), time, device from data_raw where \ - serial = 466419818 and device != 'PowerS' and device \ - != 'PowerG' limit 140;") - records = cursor.fetchall() - conv.convert_to_hdf5_file(records, "Hello") - self.assertFail() - except Exception as e: - self.assertEqual(str(e), "File name: Hello must end with .h5") - -if __name__ == '__main__': - unittest.main() diff --git a/DB/classification/models.py b/DB/classification/models.py index 683e6f4..af68649 100644 --- a/DB/classification/models.py +++ b/DB/classification/models.py @@ -117,7 +117,7 @@ def get_model(cls): try: cursor = con.cursor() - query = "SELECT * FROM classifier_model ORDER BY created_at DESC LIMIT 1;" + query = "SELECT classifier_model.id, classifier_model.window_size, classifier_model.created_at, classifier_model.model_type, classifier_model.model, classifier_model.labels, classifier_model.trained FROM classifier_model ORDER BY created_at DESC LIMIT 1;" cursor.execute(query) model_row = cursor.fetchall() except psycopg2.Error as e: diff --git a/DB/classification/test_RandomForestModel.py b/DB/classification/test_RandomForestModel.py index 4262cc1..0ba46d6 100644 --- a/DB/classification/test_RandomForestModel.py +++ b/DB/classification/test_RandomForestModel.py @@ -1,6 +1,5 @@ import psycopg2 import unittest -#import DB.classification.RandomForestModel as rfm import DB.classification.RandomForestModel as rfm import datetime import random diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..3d49e08 --- /dev/null +++ b/requirements.txt @@ -0,0 +1 @@ +psycopg2==2.6.1