= commited on
Commit
2cb4802
·
1 Parent(s): 0f1dc63

sending insertion method

Browse files
pages/provide_sentences_mongo.py CHANGED
@@ -90,13 +90,14 @@ def add_new_sentences():
90
 
91
  else:
92
 
93
-
94
-
95
- ## save the result
96
- sentences.to_csv('wolof_translate/data/sentences/wolof_french.csv', index=False)
 
97
 
98
  # recuperate the already saved sentences (for the moment french/wolof)
99
- sentences = pd.read_csv('wolof_translate/data/sentences/wolof_french.csv')
100
 
101
  # add the last position to delete and modify
102
  st.session_state.line1 = len(sentences) - 1
 
90
 
91
  else:
92
 
93
+ # insert the new sentences
94
+ db_manager.insert_document({
95
+ 'french': sentence_1,
96
+ 'wolof': sentence_2
97
+ })
98
 
99
  # recuperate the already saved sentences (for the moment french/wolof)
100
+ sentences = db_manager.load_data_frames()
101
 
102
  # add the last position to delete and modify
103
  st.session_state.line1 = len(sentences) - 1
send_and_retrieve_data.ipynb CHANGED
@@ -658,18 +658,19 @@
658
  },
659
  {
660
  "cell_type": "code",
661
- "execution_count": 132,
662
  "metadata": {},
663
  "outputs": [
664
  {
665
  "name": "stdout",
666
  "output_type": "stream",
667
  "text": [
668
- "Overwriting wolof-translate/wolof_translate/utils/database_manager.py\n"
669
  ]
670
  }
671
  ],
672
  "source": [
 
673
  "from pymongo.mongo_client import MongoClient\n",
674
  "from pymongo.server_api import ServerApi\n",
675
  "import pandas as pd\n",
@@ -693,7 +694,7 @@
693
  " \n",
694
  " def insert_document(self, document: dict, collection: str = \"sentences\"):\n",
695
  " \n",
696
- " assert '_id' in document\n",
697
  " \n",
698
  " # get the id of the last sentence (recuperate the max id and add 1 to it)\n",
699
  " max_id = self.get_max_id(collection)\n",
 
658
  },
659
  {
660
  "cell_type": "code",
661
+ "execution_count": 1,
662
  "metadata": {},
663
  "outputs": [
664
  {
665
  "name": "stdout",
666
  "output_type": "stream",
667
  "text": [
668
+ "Overwriting wolof_translate/utils/database_manager.py\n"
669
  ]
670
  }
671
  ],
672
  "source": [
673
+ "%%writefile wolof_translate/utils/database_manager.py\n",
674
  "from pymongo.mongo_client import MongoClient\n",
675
  "from pymongo.server_api import ServerApi\n",
676
  "import pandas as pd\n",
 
694
  " \n",
695
  " def insert_document(self, document: dict, collection: str = \"sentences\"):\n",
696
  " \n",
697
+ " assert not '_id' in document\n",
698
  " \n",
699
  " # get the id of the last sentence (recuperate the max id and add 1 to it)\n",
700
  " max_id = self.get_max_id(collection)\n",
wolof_translate/utils/database_manager.py CHANGED
@@ -21,7 +21,7 @@ class TranslationMongoDBManager:
21
 
22
  def insert_document(self, document: dict, collection: str = "sentences"):
23
 
24
- assert '_id' in document
25
 
26
  # get the id of the last sentence (recuperate the max id and add 1 to it)
27
  max_id = self.get_max_id(collection)
@@ -35,7 +35,16 @@ class TranslationMongoDBManager:
35
 
36
  return results
37
 
38
- def update_document(self, id: int, document: dict, collection: str = "sentences"):
 
 
 
 
 
 
 
 
 
39
 
40
  # update the document
41
  results = self.db[collection].update_one(
@@ -49,9 +58,16 @@ class TranslationMongoDBManager:
49
  }
50
  )
51
 
 
 
 
 
 
 
 
52
  return results
53
 
54
- def delete_document(self, id: int, document: dict, collection: str = "sentences", del_collection: str = "deleted"):
55
 
56
  # recuperate the document to delete
57
  del_sent = self.db[collection].find_one(
@@ -70,7 +86,7 @@ class TranslationMongoDBManager:
70
  )
71
 
72
  # add the sentences to the deleted sentences
73
- del_sent['_id'] = len(list(deleted.find()))
74
 
75
  results = self.db[del_collection].insert_one(
76
  del_sent
 
21
 
22
  def insert_document(self, document: dict, collection: str = "sentences"):
23
 
24
+ assert not '_id' in document
25
 
26
  # get the id of the last sentence (recuperate the max id and add 1 to it)
27
  max_id = self.get_max_id(collection)
 
35
 
36
  return results
37
 
38
+ def update_document(self, id: int, document: dict, collection: str = "sentences", update_collection: str = "updated"):
39
+
40
+ # recuperate the document to update
41
+ upd_sent = self.db[collection].find_one(
42
+ {
43
+ '_id': {
44
+ '$eq': id
45
+ }
46
+ }
47
+ )
48
 
49
  # update the document
50
  results = self.db[collection].update_one(
 
58
  }
59
  )
60
 
61
+ # add the sentences to the deleted sentences
62
+ upd_sent['_id'] = len(list(self.db[update_collection].find()))
63
+
64
+ results = self.db[update_collection].insert_one(
65
+ upd_sent
66
+ )
67
+
68
  return results
69
 
70
+ def delete_document(self, id: int, collection: str = "sentences", del_collection: str = "deleted"):
71
 
72
  # recuperate the document to delete
73
  del_sent = self.db[collection].find_one(
 
86
  )
87
 
88
  # add the sentences to the deleted sentences
89
+ del_sent['_id'] = len(list(self.db[del_collection].find()))
90
 
91
  results = self.db[del_collection].insert_one(
92
  del_sent