Skip to content

Commit

Permalink
code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
jasperan committed Jun 16, 2022
1 parent 6280d04 commit 8180da6
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 17 deletions.
28 changes: 28 additions & 0 deletions src/nn.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import tensorflow as tf
import pandas as pd


mnist = tf.keras.datasets.mnist

(x_train, y_train), (x_test, y_test) = mnist.load_data()
x_train, x_test = x_train / 255.0, x_test / 255.0

model = tf.keras.Sequential([
tf.keras.layers.Flatten(input_shape=(28, 28)),
tf.keras.layers.Dense(128, activation='relu'),
])

loss_fn = tf.keras.losses.SparseCategoricalCrossentropy(from_logits=True)

model.compile(optimizer='adam',
loss=loss_fn,
metrics=['accuracy'])

model.fit(x_train, y_train, epochs=10, batch_size=1024)

my_first_model_path = './model/'
tf.saved_model.save(model, my_first_model_path)

new_model = tf.saved_model.load(my_first_model_path)

print(model)
35 changes: 18 additions & 17 deletions utils/oracle_database.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import cx_Oracle
import yaml
import os
from pathlib import Path
Expand All @@ -10,7 +9,8 @@ def process_yaml():
with open("../config.yaml") as file:
return yaml.safe_load(file)


# deprecated class due to old cx_Oracle library, new one is oracledb and implemented below.
'''
class OracleJSONDatabaseConnection:
def __init__(self, data=process_yaml()):
# wallet location (default is HOME/wallets/wallet_X)
Expand Down Expand Up @@ -76,7 +76,7 @@ def get_collection_names(self):
returning_object = connection.getSodaDatabase().getCollectionNames(startName=None, limit=0)
self.pool.release(connection)
return returning_object

'''



Expand All @@ -87,13 +87,11 @@ def __init__(self, data=process_yaml()):
print('Connection successful.')



def close_pool(self):
self.pool.close()
print('Connection pool closed.')



def insert(self, collection_name, json_object_to_insert):
connection = self.pool.acquire()
connection.autocommit = True
Expand All @@ -110,7 +108,6 @@ def insert(self, collection_name, json_object_to_insert):
return 1



def delete(self, collection_name, on_column, on_value):
connection = self.pool.acquire()
connection.autocommit = True
Expand All @@ -121,26 +118,30 @@ def delete(self, collection_name, on_column, on_value):
self.pool.release(connection)



def get_connection(self):
connection = self.pool.acquire()
connection.autocommit = True
return connection



def close_connection(self, conn_object):
self.pool.release(conn_object)



def get_collection_names(self):
connection = self.pool.acquire()
connection.autocommit = True
returning_object = connection.getSodaDatabase().getCollectionNames(startName=None, limit=0)
self.pool.release(connection)
return returning_object

def open_collection(self, collection_name):
connection = self.pool.acquire()
returning_object = self.pool.acquire().getSodaDatabase().openCollection(collection_name)
self.pool.release(connection)
return returning_object





Expand All @@ -153,13 +154,11 @@ def __init__(self, data=process_yaml()):
print('Connection successful.')



def close_pool(self):
self.pool.close()
print('Connection pool closed.')



def insert(self, collection_name, json_object_to_insert):
connection = self.pool.acquire()
connection.autocommit = True
Expand All @@ -175,8 +174,6 @@ def insert(self, collection_name, json_object_to_insert):
self.pool.release(connection)
return 1



def delete(self, collection_name, on_column, on_value):
connection = self.pool.acquire()
connection.autocommit = True
Expand All @@ -187,19 +184,16 @@ def delete(self, collection_name, on_column, on_value):
self.pool.release(connection)



def get_connection(self):
connection = self.pool.acquire()
connection.autocommit = True
return connection



def close_connection(self, conn_object):
self.pool.release(conn_object)



def get_collection_names(self):
connection = self.pool.acquire()
connection.autocommit = True
Expand All @@ -208,9 +202,16 @@ def get_collection_names(self):
return returning_object


def open_collection(self, collection_name):
connection = self.pool.acquire()
returning_object = self.pool.acquire().getSodaDatabase().openCollection(collection_name)
self.pool.release(connection)
return returning_object



def test_class():
object = OracleJSONDatabaseConnection()
object = OracleJSONDatabaseThickConnection()
print(object.pool)
object.close_pool()

Expand Down

0 comments on commit 8180da6

Please sign in to comment.