Commit 98fc8f0f authored by Alexander Lercher's avatar Alexander Lercher

[SemanticLinking] Storing flattened smart-energy transactions as json

parent aade29cb
......@@ -9,12 +9,14 @@ for modules_path in modules_paths:
sys.path.insert(1, modules_path)
from messaging.MessageHandler import MessageHandler
from db.repository import Repository
# file to read the data from
CSV_FILE = r'Energy_Dataset.csv'
handler = MessageHandler()
CSV_FILE = r'dummy_upload\smart_energy\Energy_Dataset.csv'
handler = MessageHandler(Repository())
processed_transactions = []
def upload_transaction(transaction):
'''{"type": "new-trace",
"content": {"use_case": "smart-energy", "table": "smart-energy", "id": "dd2c5146c919b046d77a32a5cf553d5133163562f7b7e1298c878c575d516025",
......@@ -28,7 +30,31 @@ def upload_transaction(transaction):
'id': uid,
'properties': transaction,
}
handler.handle_new_trace(t)
# handler.handle_new_trace(t)
processed_transactions.append(t)
def store_transactions_for_mirsat():
'''
Stores the processed transactions as if they would be returned
by Trace Retrieval microservice after fixing the message queue bug.
'''
flattened_transactions = []
for transaction in processed_transactions:
transaction = transaction['properties']
transaction['use_case'] = transaction['ApplicationType']
del transaction['ApplicationType']
transaction['table'] = transaction['docType']
del transaction['docType']
flattened_transactions.append(transaction)
import json
with open('flattened_smart_energy_data.json', 'w') as file:
file.write(json.dumps(flattened_transactions))
if __name__ == '__main__':
......@@ -56,3 +82,4 @@ if __name__ == '__main__':
upload_transaction(transaction)
store_transactions_for_mirsat()
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment