From bdb332a59c2868de0cec3239519c6ccf5d0347ae Mon Sep 17 00:00:00 2001 From: cpeter256 Date: Tue, 3 May 2016 12:51:21 -0700 Subject: [PATCH 1/8] patch for issues with already-merged classification branch --- DB/api/query_db.py | 2 +- DB/api/server.py | 2 ++ DB/classification/__init__.py | 2 +- DB/classification/models.py | 2 +- 4 files changed, 5 insertions(+), 3 deletions(-) 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/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/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: From 8bc2747753353ffa89a70ba57d306a44e9ef3024 Mon Sep 17 00:00:00 2001 From: cpeter256 Date: Wed, 4 May 2016 09:50:54 -0700 Subject: [PATCH 2/8] removed duplicate commented import line --- DB/classification/test_RandomForestModel.py | 1 - 1 file changed, 1 deletion(-) 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 From e36e463837ba9e36ae00035cdd9771ddde19dae0 Mon Sep 17 00:00:00 2001 From: cpeter256 Date: Wed, 4 May 2016 09:55:43 -0700 Subject: [PATCH 3/8] nuked useless test --- DB/api/test_query_db.py | 20 -------------------- 1 file changed, 20 deletions(-) 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" From 24e9d9f782280816db0a4498c07ef6bddd319398 Mon Sep 17 00:00:00 2001 From: cpeter256 Date: Wed, 4 May 2016 10:09:43 -0700 Subject: [PATCH 4/8] removed tests for dataset_converter which does not and will not exist --- .../dataset_converter_unit_tests.py | 57 ------------------- 1 file changed, 57 deletions(-) delete mode 100644 DB/classification/dataset_converter_unit_tests.py 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() From 38f15c671085701a51c65815a85657b5a68fb7d8 Mon Sep 17 00:00:00 2001 From: cpeter256 Date: Wed, 4 May 2016 10:56:54 -0700 Subject: [PATCH 5/8] trying to get psycopg2 on circleci --- requirements.txt | 1 + 1 file changed, 1 insertion(+) create mode 100644 requirements.txt 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 From 128f3fa5bf84af32a5da48de67e26cb8259a18ed Mon Sep 17 00:00:00 2001 From: cpeter256 Date: Wed, 4 May 2016 11:02:06 -0700 Subject: [PATCH 6/8] added sklearn as a dependancy --- requirements.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/requirements.txt b/requirements.txt index 3d49e08..05c370a 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1,2 @@ psycopg2==2.6.1 +scikit-learn=0.17.1 From 42493e948dae45feeb55fb88fe7d872dd141c987 Mon Sep 17 00:00:00 2001 From: cpeter256 Date: Wed, 4 May 2016 11:03:14 -0700 Subject: [PATCH 7/8] durp --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 05c370a..607cb1b 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,2 @@ psycopg2==2.6.1 -scikit-learn=0.17.1 +scikit-learn==0.17.1 From 47e248add9029c4e2ff36a70daa530053a385191 Mon Sep 17 00:00:00 2001 From: cpeter256 Date: Wed, 4 May 2016 11:06:49 -0700 Subject: [PATCH 8/8] asdfbj --- requirements.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 607cb1b..3d49e08 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1 @@ psycopg2==2.6.1 -scikit-learn==0.17.1