Skip to content

Commit

Permalink
Merge pull request #18 from satwikkamath/master
Browse files Browse the repository at this point in the history
storing anonymized data in db
  • Loading branch information
satwikkamath authored May 20, 2024
2 parents dd04168 + 00c7c8d commit 07cb0c6
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 42 deletions.
3 changes: 3 additions & 0 deletions backend/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ def display_anonymized_data():
)
client.close()
print(anonymized_data)
anonymized_db = client['KSP-DataGuardians-Anonymized']
anonymized_collection = anonymized_db[data['file_name']] # Use the same collection name
anonymized_collection.insert_many(anonymized_data)
except Exception as e:
print(f"Error: {e}")
finally:
Expand Down
29 changes: 10 additions & 19 deletions components/Memos.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,44 +14,35 @@ const Memos = ({ state }) => {

return (
<div className="mx-auto max-w-screen-xl text-center">
<h3 className="text-xl font-bold sm:text-2xl py-8" >History</h3>
<h3 className="text-xl font-bold sm:text-2xl py-8">History</h3>
<table className=" bg-gray-700 w-full border-collapse">
<thead>
<th className=" border-2 text-white px-3 py-10">Filename</th>
<th className=" border-2 text-white px-3 py-10">User Name</th>
<th className=" border-2 text-white px-3 py-10">File name</th>
<th className=" border-2 text-white px-3 py-10">Column Name</th>
<th className=" border-2 text-white px-3 py-10">Timestamp</th>
<th className=" border-2 text-white px-3 py-10">Column name</th>
<th className=" border-2 text-white px-3 py-10">User ID</th>
<th className=" border-2 text-white px-3 py-10">Blockchain hash</th>
</thead>
<tbody>
{memos.map((memo, index) => (
<tr key={index}>
<td
className=" border-2 px-3 text-slate-100 py-10 text-left"
>
<td className=" border-2 px-3 text-slate-100 py-10 text-left">
{memo.user_name}
</td>
<td
className=" border-2 px-3 text-slate-100 py-10 text-left"
>
<td className=" border-2 px-3 text-slate-100 py-10 text-left">
{memo.file_name}
</td>
<td
className=" border-2 px-3 text-slate-100 py-10 text-left"
>
<td className=" border-2 px-3 text-slate-100 py-10 text-left">
{memo.column_names.join(", ")}
{/* If you need more complex formatting, you can use something like:
{memo.column_name.map((name, idx) => (
<span key={idx}>{name}</span>
))} */}
</td>
<td
className=" border-2 px-3 text-slate-100 py-10 text-left"
>
<td className=" border-2 px-3 text-slate-100 py-10 text-left">
{new Date(memo.timestamp * 1000).toLocaleString()}
</td>
<td
className=" border-2 px-3 text-slate-100 py-10 text-left"
>
<td className=" border-2 px-3 text-slate-100 py-10 text-left">
{memo.from}
</td>
</tr>
Expand Down
45 changes: 22 additions & 23 deletions test.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,27 @@
import os
from pymongo import MongoClient
from dotenv import load_dotenv

# Connect to MongoDB
client = MongoClient(os.getenv('MONGO_URL'))
db = client['KSP_ANONYMIZED_DATABASE'] # Change this to your database name
collection = db['names'] # Change this to your collection name
# Connection details
source_client = MongoClient('mongodb+srv://satwikroopa:Roopa70263@fruitdb.8sxipgz.mongodb.net/?retryWrites=true&w=majority&appName=FruitDb')
destination_client = MongoClient('mongodb+srv://satwikroopa:Roopa70263@fruitdb.8sxipgz.mongodb.net/?retryWrites=true&w=majority&appName=FruitDb')

# Provided data
data = [
{"First Name": "John", "Last Name": "Smith", "Middle Name": "Doe"},
{"First Name": "Jane", "Last Name": "Brown", "Middle Name": "<PERSON>"},
{"First Name": "Michael", "Last Name": "Johnson", "Middle Name": "<PERSON>"},
{"First Name": "Emily", "Last Name": "Wilson", "Middle Name": "<PERSON>"},
{"First Name": "David", "Last Name": "Taylor", "Middle Name": "<PERSON>"},
{"First Name": "Sarah", "Last Name": "Miller", "Middle Name": "<PERSON>"},
{"First Name": "Daniel", "Last Name": "Davis", "Middle Name": "<PERSON>"},
{"First Name": "Olivia", "Last Name": "Anderson", "Middle Name": "Rose"},
{"First Name": "William", "Last Name": "Martinez", "Middle Name": "<PERSON>"},
{"First Name": "Sophia", "Last Name": "Garcia", "Middle Name": "<PERSON>"}
]
# Source and destination databases
source_db = source_client['KSP_DATABASE']
destination_db = destination_client['KSP-DataGuardians']

# Insert data into MongoDB collection
collection.insert_many(data)
# Get a list of all collections in the source database
collections = source_db.list_collection_names()

# Close connection
client.close()
for collection_name in collections:
# Get the source collection
source_collection = source_db[collection_name]

# Get the destination collection
destination_collection = destination_db[collection_name]

# Copy all documents from source collection to destination collection
documents = source_collection.find()
destination_collection.insert_many(documents)

print(f"Transferred {source_collection.count_documents({})} documents from collection '{collection_name}'")

print("All collections have been transferred.")

0 comments on commit 07cb0c6

Please sign in to comment.