From a4f15c2e7b9a3a0ab87e46b491eb5f72b34491e4 Mon Sep 17 00:00:00 2001 From: Anthony Carmona Date: Sat, 22 Apr 2023 21:30:45 -0700 Subject: [PATCH 1/7] First attempt at exporting the data --- #Neuro-Tech Software 2022 - 2023.py | 32 +++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 #Neuro-Tech Software 2022 - 2023.py diff --git a/#Neuro-Tech Software 2022 - 2023.py b/#Neuro-Tech Software 2022 - 2023.py new file mode 100644 index 0000000..ab1bb12 --- /dev/null +++ b/#Neuro-Tech Software 2022 - 2023.py @@ -0,0 +1,32 @@ +#Neuro-Tech Software 2022 - 2023 +import pymongo +import csv + +#Connecting to the MongoDB +client = pymongo.MongoClient('mongodb://localhost:27017/') + +db = client['mydatabase'] +collection = db['mycollection'] +documents = collection.find() + +with open('mycollection.csv', 'w', newline='') as f: + writer = csv.writer(f) + writer.writerow(['_id', 'field1', 'field2']) + # I need to replace 'field1', 'field2' with the names of the fields in the documents from the data + for document in documents: + writer.writerow([document['_id'], document['field1'], document['field2']]) + # Again I need to replace 'field1', 'field2' with the names of the fields in the documents from the data + + + + + + + + + + + + + + From 1ced06ac1708259fc1fc64c8e6ca8a03d4757ce7 Mon Sep 17 00:00:00 2001 From: Anthony Carmona Date: Wed, 26 Apr 2023 11:28:25 -0700 Subject: [PATCH 2/7] Second attempt at exporting --- frontend/src/data.csv | 0 frontend/src/main.py | 24 ++++++++++++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 frontend/src/data.csv diff --git a/frontend/src/data.csv b/frontend/src/data.csv new file mode 100644 index 0000000..e69de29 diff --git a/frontend/src/main.py b/frontend/src/main.py index b852013..e679eea 100644 --- a/frontend/src/main.py +++ b/frontend/src/main.py @@ -2,14 +2,38 @@ import requests import pymongo from pymongo import MongoClient +from io import BytesIO +from flask import Flask, send_file +#import requests +#import pymongo +#from pymongo import MongoClient +import csv app = Flask(__name__) client = MongoClient('mongodb://root:example@mongo:27017') +db = client['mydatabase'] +collection = db['mycollection'] @app.route('/') def hello_world(): return 'Hello Flafdsdk!!d' +@app.route('/export') +def export_data(): + # Grabbing the data from MongoDB + data = collection.find() + #Writing to a CSV File + display = BytesIO() + writer = csv.writer(display) + for text in data: + writer.writerow([text['_id'], text['name']]) + with open("data.csv", "wb") as f: + f.write(display.getbuffer()) + #Close CSV file to user + display.seek(0) + return send_file('data.csv', as_attachment=True) + + if __name__ == '__main__': print(client.list_database_names()) print("\n\n\n") From 18d06cf9b63878c4764100e996b7e0585c43d015 Mon Sep 17 00:00:00 2001 From: Rico Rodriguez Date: Wed, 26 Apr 2023 11:39:28 -0700 Subject: [PATCH 3/7] Fixed csv file not sending on /export route. --- frontend/src/main.py | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/frontend/src/main.py b/frontend/src/main.py index e679eea..56c1166 100644 --- a/frontend/src/main.py +++ b/frontend/src/main.py @@ -21,24 +21,22 @@ def hello_world(): @app.route('/export') def export_data(): # Grabbing the data from MongoDB - data = collection.find() + data = collection.find({}) #Writing to a CSV File - display = BytesIO() - writer = csv.writer(display) - for text in data: - writer.writerow([text['_id'], text['name']]) - with open("data.csv", "wb") as f: - f.write(display.getbuffer()) + with open("data.csv", "w") as f: + csvwriter = csv.writer(f, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL) + for item in data: + print(item) + csvwriter.writerow([item['name'], item['_id']]) #Close CSV file to user - display.seek(0) return send_file('data.csv', as_attachment=True) if __name__ == '__main__': print(client.list_database_names()) print("\n\n\n") - db = client["testdb"] - coll = db["testcoll"] + db = client["mydatabase"] + coll = db["mycollection"] post1 = {"name": "hello"} coll.insert_one(post1) results = coll.find({}) From bffe143fcae9f9e137cf2a04953e0067077dad1e Mon Sep 17 00:00:00 2001 From: AnthonyC247 <129124691+AnthonyC247@users.noreply.github.com> Date: Fri, 26 May 2023 18:32:47 -0700 Subject: [PATCH 4/7] Add files via upload "Exporting data from Subvocal Phenome" --- export.py | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 export.py diff --git a/export.py b/export.py new file mode 100644 index 0000000..209f0f2 --- /dev/null +++ b/export.py @@ -0,0 +1,62 @@ +# -*- coding: utf-8 -*- +"""export + +Automatically generated by Colaboratory. + +Original file is located at + https://colab.research.google.com/drive/1V8B2EPMowGqGI0N6KfeiU_5kchmJuFRB +""" + +from collections.abc import Callable, Iterable, Mapping +import tkinter as tk +import threading +import pymongo +import csv + +class SubvocalPhonemeGUI(threading.Thread): + def __init__(self, threadID): + threading.Thread.__init__(self) + self.threadID = threadID + + #Creating the main window of the application + self.root = tk.Tk() + + #Setting up GUI elements + self.label = tk.Label(self.root, text="Hello, World!", font=('Arial', 18)) + self.label.pack() + + self.button = tk.Button(self.root, text="Click", command=lambda: self.export_data()) + self.button.pack() + + self.button = tk.Button(self.root, text="Export Data", command=self.export_data) + self.button.pack() + + #Connecting to the MongoDB + self.client = pymongo.MongoClient("mongodb://localhost:27017/") + self.db = self.client["subvocal_database"] + self.collection = self.db["subvocal_collection"] + + def export_data(self): + self.status_label.config(text="Exporting Data...") + + #Query the data from the MongoDB + #Limiting the data amount 50 lines + data = self.collection.find({}).limit(50) + + #Write the data to a CSV file + with open('data_export.csv', 'w') as f: + csvwriter = csv.writer(f, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL) + #write each row of data + for item in data: + csvwriter.writerow([item['name'], item['_id']]) + return send_file('data.csv', as_attachment=True) + + self.status_label.config(text="Data Exported Successfully") + + def run(self): + self.root.mainloop() + +if __name__ == '__main__': + gui = SubvocalPhonemeGUI(1) + gui.start() + gui.join() \ No newline at end of file From 64c1005ad52a2bc100a3939c55a696aa4802cbd9 Mon Sep 17 00:00:00 2001 From: AnthonyC247 <129124691+AnthonyC247@users.noreply.github.com> Date: Tue, 30 May 2023 10:26:44 -0700 Subject: [PATCH 5/7] Delete export.py --- export.py | 62 ------------------------------------------------------- 1 file changed, 62 deletions(-) delete mode 100644 export.py diff --git a/export.py b/export.py deleted file mode 100644 index 209f0f2..0000000 --- a/export.py +++ /dev/null @@ -1,62 +0,0 @@ -# -*- coding: utf-8 -*- -"""export - -Automatically generated by Colaboratory. - -Original file is located at - https://colab.research.google.com/drive/1V8B2EPMowGqGI0N6KfeiU_5kchmJuFRB -""" - -from collections.abc import Callable, Iterable, Mapping -import tkinter as tk -import threading -import pymongo -import csv - -class SubvocalPhonemeGUI(threading.Thread): - def __init__(self, threadID): - threading.Thread.__init__(self) - self.threadID = threadID - - #Creating the main window of the application - self.root = tk.Tk() - - #Setting up GUI elements - self.label = tk.Label(self.root, text="Hello, World!", font=('Arial', 18)) - self.label.pack() - - self.button = tk.Button(self.root, text="Click", command=lambda: self.export_data()) - self.button.pack() - - self.button = tk.Button(self.root, text="Export Data", command=self.export_data) - self.button.pack() - - #Connecting to the MongoDB - self.client = pymongo.MongoClient("mongodb://localhost:27017/") - self.db = self.client["subvocal_database"] - self.collection = self.db["subvocal_collection"] - - def export_data(self): - self.status_label.config(text="Exporting Data...") - - #Query the data from the MongoDB - #Limiting the data amount 50 lines - data = self.collection.find({}).limit(50) - - #Write the data to a CSV file - with open('data_export.csv', 'w') as f: - csvwriter = csv.writer(f, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL) - #write each row of data - for item in data: - csvwriter.writerow([item['name'], item['_id']]) - return send_file('data.csv', as_attachment=True) - - self.status_label.config(text="Data Exported Successfully") - - def run(self): - self.root.mainloop() - -if __name__ == '__main__': - gui = SubvocalPhonemeGUI(1) - gui.start() - gui.join() \ No newline at end of file From 9573346494d5322dac23706e9dedde4dfa6a102e Mon Sep 17 00:00:00 2001 From: AnthonyC247 <129124691+AnthonyC247@users.noreply.github.com> Date: Tue, 30 May 2023 10:28:43 -0700 Subject: [PATCH 6/7] Add files via upload Commented an unnecessary line of code to export the data to automatically close CSV file --- export.py | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 export.py diff --git a/export.py b/export.py new file mode 100644 index 0000000..6170f63 --- /dev/null +++ b/export.py @@ -0,0 +1,62 @@ +# -*- coding: utf-8 -*- +"""export + +Automatically generated by Colaboratory. + +Original file is located at + https://colab.research.google.com/drive/1V8B2EPMowGqGI0N6KfeiU_5kchmJuFRB +""" + +from collections.abc import Callable, Iterable, Mapping +import tkinter as tk +import threading +import pymongo +import csv + +class SubvocalPhonemeGUI(threading.Thread): + def __init__(self, threadID): + threading.Thread.__init__(self) + self.threadID = threadID + + #Creating the main window of the application + self.root = tk.Tk() + + #Setting up GUI elements + self.label = tk.Label(self.root, text="Hello, World!", font=('Arial', 18)) + self.label.pack() + + self.button = tk.Button(self.root, text="Click", command=lambda: self.export_data()) + self.button.pack() + + self.button = tk.Button(self.root, text="Export Data", command=self.export_data) + self.button.pack() + + #Connecting to the MongoDB + self.client = pymongo.MongoClient("mongodb://localhost:27017/") + self.db = self.client["subvocal_database"] + self.collection = self.db["subvocal_collection"] + + def export_data(self): + self.status_label.config(text="Exporting Data...") + + #Query the data from the MongoDB + #Limiting the data amount 50 lines + data = self.collection.find({}).limit(50) + + #Write the data to a CSV file + with open('data_export.csv', 'w') as f: + csvwriter = csv.writer(f, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL) + #write each row of data + for item in data: + csvwriter.writerow([item['name'], item['_id']]) + #return send_file('data.csv', as_attachment=True) + + self.status_label.config(text="Data Exported Successfully") + + def run(self): + self.root.mainloop() + +if __name__ == '__main__': + gui = SubvocalPhonemeGUI(1) + gui.start() + gui.join() \ No newline at end of file From 883dbdb48f7c748e5fb157dca0feefaa7ac2d338 Mon Sep 17 00:00:00 2001 From: AnthonyC247 <129124691+AnthonyC247@users.noreply.github.com> Date: Tue, 30 May 2023 10:29:43 -0700 Subject: [PATCH 7/7] Update export.py Deleted more unnecessary lines of code for exporting the data and then closing the CSV file. --- export.py | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/export.py b/export.py index 6170f63..1090875 100644 --- a/export.py +++ b/export.py @@ -1,12 +1,3 @@ -# -*- coding: utf-8 -*- -"""export - -Automatically generated by Colaboratory. - -Original file is located at - https://colab.research.google.com/drive/1V8B2EPMowGqGI0N6KfeiU_5kchmJuFRB -""" - from collections.abc import Callable, Iterable, Mapping import tkinter as tk import threading @@ -59,4 +50,4 @@ def run(self): if __name__ == '__main__': gui = SubvocalPhonemeGUI(1) gui.start() - gui.join() \ No newline at end of file + gui.join()