Quellcode durchsuchen

fixed some bugs in the commenting part

justtheboss97 vor 4 Jahren
Ursprung
Commit
da9cd449a3
1 geänderte Dateien mit 43 neuen und 29 gelöschten Zeilen
  1. 43 29
      linked data testing.ipynb

+ 43 - 29
linked data testing.ipynb

@@ -13,25 +13,27 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 117,
+   "execution_count": 31,
    "metadata": {},
    "outputs": [
     {
      "name": "stdout",
      "output_type": "stream",
      "text": [
-      "comments got removed\n",
       "{'data': {'client': 'some company',\n",
       "          'contractor': 'semmtech',\n",
       "          'discription': 'a sample project',\n",
       "          'name': 'project',\n",
       "          'people': ['astrix', 'obelix']},\n",
-      " 'date of initiation': '2021-01-07 15:23:49',\n",
+      " 'date of initiation': '2021-01-08 11:22:59',\n",
       " 'id': 0,\n",
       " 'initiated by': 'astrix',\n",
-      " 'last update': '2021-01-07 15:23:49',\n",
       " 'terms': {'Sign time': 'not yet signed',\n",
       "           'accepted': False,\n",
+      "           'comments': {0: {'author': 'astrix',\n",
+      "                            'body': 'I like the progress',\n",
+      "                            'contract': 0,\n",
+      "                            'time': '2021-01-08 11:22:59'}},\n",
       "           'deadline': '1 month',\n",
       "           'price': 10000,\n",
       "           'progress': '0%'},\n",
@@ -45,12 +47,12 @@
       "          'discription': 'a real project',\n",
       "          'name': 'r project',\n",
       "          'people': ['samson', 'gert']},\n",
-      " 'date of initiation': '2021-01-07 15:23:49',\n",
+      " 'date of initiation': '2021-01-08 11:22:59',\n",
       " 'id': 1,\n",
       " 'initiated by': 'samson',\n",
+      " 'last update': '2021-01-08 11:22:59',\n",
       " 'terms': {'Sign time': 'not yet signed',\n",
       "           'accepted': False,\n",
-      "           'comments': {},\n",
       "           'deadline': '31-12-2021',\n",
       "           'price': 10000,\n",
       "           'progress': '0%'},\n",
@@ -64,15 +66,23 @@
       "          'discription': 'to contain 096',\n",
       "          'name': 'containment',\n",
       "          'people': ['doctor bright', '05-12']},\n",
-      " 'date of initiation': '2021-01-07 15:23:49',\n",
+      " 'date of initiation': '2021-01-08 11:22:59',\n",
       " 'id': 2,\n",
       " 'initiated by': '05-2',\n",
       " 'terms': {'Sign time': 'not yet signed',\n",
       "           'accepted': False,\n",
-      "           'comments': {4: {'author': 'doctor bright',\n",
+      "           'comments': {0: {'author': 'doctor bright',\n",
+      "                            'body': 'needs to be terminated',\n",
+      "                            'contract': 2,\n",
+      "                            'time': '2021-01-08 11:22:59'},\n",
+      "                        1: {'author': '05-12',\n",
+      "                            'body': 'doctor bright is wrong',\n",
+      "                            'contract': 2,\n",
+      "                            'time': '2021-01-08 11:22:59'},\n",
+      "                        2: {'author': 'doctor bright',\n",
       "                            'body': 'no im right 05-12 is defo wrong',\n",
       "                            'contract': 2,\n",
-      "                            'time': '2021-01-07 15:23:49'}},\n",
+      "                            'time': '2021-01-08 11:22:59'}},\n",
       "           'deadline': '31-12-2021',\n",
       "           'price': 'at all costs',\n",
       "           'progress': '0%'},\n",
@@ -81,12 +91,12 @@
       "\n",
       "\n",
       "\n",
-      "[{2: {'author': 'doctor bright', 'body': 'needs to be terminated', 'time': '2021-01-07 15:23:49', 'contract': 2}}, {3: {'author': '05-12', 'body': 'doctor bright is wrong', 'time': '2021-01-07 15:23:49', 'contract': 2}}, {4: {'author': 'doctor bright', 'body': 'no im right 05-12 is defo wrong', 'time': '2021-01-07 15:23:49', 'contract': 2}}]\n",
+      "[{0: {'author': 'doctor bright', 'body': 'needs to be terminated', 'time': '2021-01-08 11:22:59', 'contract': 2}}, {1: {'author': '05-12', 'body': 'doctor bright is wrong', 'time': '2021-01-08 11:22:59', 'contract': 2}}, {2: {'author': 'doctor bright', 'body': 'no im right 05-12 is defo wrong', 'time': '2021-01-08 11:22:59', 'contract': 2}}]\n",
       "7\n",
       "[{'accepted': True,\n",
       "  'change': {'deadline': '1 month'},\n",
       "  'id': 0,\n",
-      "  'last update': '2021-01-07 15:23:49',\n",
+      "  'last update': '2021-01-08 11:22:59',\n",
       "  'type': 'modify',\n",
       "  'update id': 0,\n",
       "  'updated': 'deadline',\n",
@@ -222,7 +232,7 @@
     "                if item['type'] == 'init':\n",
     "                    self.state = item\n",
     "                    continue\n",
-    "                \n",
+    "\n",
     "                # if update is not accept update, save it to updates dict\n",
     "                if item['type'] != 'accept':\n",
     "                    \n",
@@ -240,7 +250,6 @@
     "                \n",
     "                # check if the update was removal\n",
     "                if item['type'] == 'remove':\n",
-    "                    print(attr + ' got removed')\n",
     "                    \n",
     "                    # delete item in the right part of the dict\n",
     "                    try:\n",
@@ -259,9 +268,10 @@
     "                    self.state['data'][attr] = item['change'][attr]\n",
     "                    \n",
     "                elif attr in self.state['terms']:\n",
-    "                    \n",
+    "   \n",
     "                    # special case for comments\n",
     "                    if attr == 'comments' and item['type'] not in ['remove', 'init']:\n",
+    "                        \n",
     "                        k = list(item['change'][attr].keys())[0]\n",
     "                        self.state['terms'][attr][k] = item['change'][attr][k]\n",
     "                    \n",
@@ -302,7 +312,6 @@
     "                            updates.append(item)\n",
     "                    # updates for specific contract and specific attr\n",
     "                    else:\n",
-    "                        print(item)\n",
     "                        if item['type'] != 'init' and item['updated'] == attr and item['id'] == iden:\n",
     "                            updates.append(item)\n",
     "        return updates\n",
@@ -329,19 +338,20 @@
     "        for block in self.blockchain + [self.current_block]:\n",
     "            for item in block.block:\n",
     "                if 'updated' in item:\n",
-    "                    if item['updated'] == 'comments':\n",
+    "                    if item['updated'] == 'comments' and item['id'] == iden:\n",
     "                        comment_updates.append(item)\n",
-    "        \n",
+    "           \n",
     "        # create transaction\n",
-    "        self.current_block.add({'id':iden,\n",
-    "                                'updated':'comments',\n",
-    "                                'accept':True,\n",
-    "                                'type':'update',\n",
-    "                                'last update':get_t(),\n",
-    "                                'change':{'comments':{len(comment_updates):{'author':author,\n",
-    "                                                                           'body': body, \n",
-    "                                                                           'time': get_t(),\n",
-    "                                                                           'contract':iden}}}})\n",
+    "        to_add = {'id':iden,\n",
+    "                'updated':'comments',\n",
+    "                'accept':True,\n",
+    "                'type':'modify',\n",
+    "                'last update':get_t(),\n",
+    "                'change':{'comments':{len(comment_updates):{'author':author,\n",
+    "                                                           'body': body, \n",
+    "                                                           'time': get_t(),\n",
+    "                                                           'contract':iden}}}}\n",
+    "        self.current_block.add(to_add)       \n",
     "        if self.current_block.size() > 10:\n",
     "            self.new_block()\n",
     "    \n",
@@ -454,7 +464,7 @@
     "chain.update_contract(1, 'Sign time', get_t(), 'gert')\n",
     "chain.update_contract(1, 'name', 'actual project', 'samson')\n",
     "chain.update_contract(1, 'price', 16969, 'gert')\n",
-    "chain.remove_item(0, 'comments')\n",
+    "chain.remove_item(1, 'comments')\n",
     "\n",
     "# updates for contract 2\n",
     "chain.add_comment(2, 'needs to be terminated', 'doctor bright')\n",
@@ -493,7 +503,8 @@
    "source": [
     "Todo:  \n",
     "linking to other contracts   \n",
-    "milestones  \n"
+    "milestones  \n",
+    "fix comments"
    ]
   },
   {
@@ -521,7 +532,10 @@
    "execution_count": null,
    "metadata": {},
    "outputs": [],
-   "source": []
+   "source": [
+    "[{'id': 2, 'updated': 'comments', 'accept': True, 'type': 'update', 'last update': '2021-01-08 10:31:09', 'change': {'comments': {0: {'author': 'doctor bright', 'body': 'needs to be terminated', 'time': '2021-01-08 10:31:09', 'contract': 2}}}}\n",
+    " , {'id': 2, 'updated': 'comments', 'accept': True, 'type': 'update', 'last update': '2021-01-08 10:31:09', 'change': {'comments': {1: {'author': '05-12', 'body': 'doctor bright is wrong', 'time': '2021-01-08 10:31:09', 'contract': 2}}}}]"
+   ]
   }
  ],
  "metadata": {