Commit 592ad8ff authored by Noah Brackenbury's avatar Noah Brackenbury

Fixed unit test, now ready for merge again

parent 18696b5a
...@@ -8,6 +8,8 @@ def WebMessage_parseWebMessage(self): ...@@ -8,6 +8,8 @@ def WebMessage_parseWebMessage(self):
portal=self.getPortalObject() portal=self.getPortalObject()
people = portal.person_module people = portal.person_module
text_content = message.getTextContent() text_content = message.getTextContent()
if text_content is None:
return()
suggested_subject_list = [] suggested_subject_list = []
sender_info=False sender_info=False
...@@ -40,11 +42,8 @@ def WebMessage_parseWebMessage(self): ...@@ -40,11 +42,8 @@ def WebMessage_parseWebMessage(self):
reference='ai_business_bot', reference='ai_business_bot',
title="AI Business Bot") title="AI Business Bot")
erp5_file = portal.portal_catalog.getResultValue(**kw) erp5_file = portal.portal_catalog.getResultValue(**kw)
<<<<<<< HEAD
if not erp5_file: if not erp5_file:
return "No model found to be applied to this Web Message. Run Set Web Message Model in Event Module first." return "No model found to be applied to this Web Message. Run Set Web Message Model in Event Module first."
=======
>>>>>>> 2e83d650106eb861a0c38350ab16aa6d13caea36
model_as_string = erp5_file.getData() model_as_string = erp5_file.getData()
model = pickle.loads(model_as_string) model = pickle.loads(model_as_string)
language_arrays = model[0] language_arrays = model[0]
......
...@@ -36,6 +36,18 @@ ...@@ -36,6 +36,18 @@
<none/> <none/>
</value> </value>
</item> </item>
<item>
<key> <string>text_content_error_message</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>text_content_warning_message</string> </key>
<value>
<tuple/>
</value>
</item>
<item> <item>
<key> <string>version</string> </key> <key> <string>version</string> </key>
<value> <string>erp5</string> </value> <value> <string>erp5</string> </value>
...@@ -99,10 +111,6 @@ ...@@ -99,10 +111,6 @@
<key> <string>action</string> </key> <key> <string>action</string> </key>
<value> <string>validate</string> </value> <value> <string>validate</string> </value>
</item> </item>
<item>
<key> <string>error_message</string> </key>
<value> <string></string> </value>
</item>
<item> <item>
<key> <string>validation_state</string> </key> <key> <string>validation_state</string> </key>
<value> <string>validated</string> </value> <value> <string>validated</string> </value>
......
...@@ -27,11 +27,8 @@ def WebMessage_setModel(self): ...@@ -27,11 +27,8 @@ def WebMessage_setModel(self):
portal_type="Web Message", portal_type="Web Message",
query=NegatedQuery(Query(subject=None)), query=NegatedQuery(Query(subject=None)),
) )
<<<<<<< HEAD
if not training_messages: if not training_messages:
return "No Web Messages to train on" return "No Web Messages to train on"
=======
>>>>>>> 2e83d650106eb861a0c38350ab16aa6d13caea36
for message in training_messages: for message in training_messages:
(language_arrays, tag_arrays) = message.WebMessage_trainOnWebMessage(language_arrays, tag_arrays, stopwords_arrays) (language_arrays, tag_arrays) = message.WebMessage_trainOnWebMessage(language_arrays, tag_arrays, stopwords_arrays)
end_time = time.time() end_time = time.time()
......
...@@ -27,11 +27,8 @@ def WebMessage_testModel(self): ...@@ -27,11 +27,8 @@ def WebMessage_testModel(self):
portal_type="Web Message", portal_type="Web Message",
query=NegatedQuery(Query(subject=None)), query=NegatedQuery(Query(subject=None)),
) )
<<<<<<< HEAD
if not training_messages: if not training_messages:
return "No Web Messages found to train on" return "No Web Messages found to train on"
=======
>>>>>>> 2e83d650106eb861a0c38350ab16aa6d13caea36
for index, message in enumerate(training_messages): for index, message in enumerate(training_messages):
if random.random() <= 0.2: if random.random() <= 0.2:
test_messages.append(message) test_messages.append(message)
...@@ -51,6 +48,8 @@ def WebMessage_testModel(self): ...@@ -51,6 +48,8 @@ def WebMessage_testModel(self):
# clean up header from contact form, if there is one # clean up header from contact form, if there is one
text = message.getTextContent() text = message.getTextContent()
if text is None:
pass
line_array = [line for line in text.splitlines() if line.strip() != ''] line_array = [line for line in text.splitlines() if line.strip() != '']
if line_array[0][:6] == " Name": if line_array[0][:6] == " Name":
line_array = line_array[4:] line_array = line_array[4:]
...@@ -119,18 +118,11 @@ def WebMessage_testModel(self): ...@@ -119,18 +118,11 @@ def WebMessage_testModel(self):
if not suggested_tags_set.intersection(sr) and not suggested_tags_set.intersection(so): if not suggested_tags_set.intersection(sr) and not suggested_tags_set.intersection(so):
type_accuracy += 1 type_accuracy += 1
<<<<<<< HEAD
if not len(test_messages) == 0: if not len(test_messages) == 0:
correct_tags = float(correct_tags) / float(len(test_messages)) correct_tags = float(correct_tags) / float(len(test_messages))
excess_tags = float(excess_tags) / float(len(test_messages)) excess_tags = float(excess_tags) / float(len(test_messages))
language_accuracy = float(language_accuracy) / float(len(test_messages)) language_accuracy = float(language_accuracy) / float(len(test_messages))
type_accuracy = float(type_accuracy) / float(len(test_messages)) type_accuracy = float(type_accuracy) / float(len(test_messages))
=======
correct_tags = float(correct_tags) / float(len(test_messages))
excess_tags = float(excess_tags) / float(len(test_messages))
language_accuracy = float(language_accuracy) / float(len(test_messages))
type_accuracy = float(type_accuracy) / float(len(test_messages))
>>>>>>> 2e83d650106eb861a0c38350ab16aa6d13caea36
end_time = time.time() end_time = time.time()
uptime = end_time - start_time uptime = end_time - start_time
human_uptime = str(datetime.timedelta(seconds=int(uptime))) human_uptime = str(datetime.timedelta(seconds=int(uptime)))
......
...@@ -36,6 +36,21 @@ ...@@ -36,6 +36,21 @@
<none/> <none/>
</value> </value>
</item> </item>
<item>
<key> <string>text_content_error_message</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>text_content_warning_message</string> </key>
<value>
<tuple>
<string>W: 32, 6: Unused variable \'index\' (unused-variable)</string>
<string>W: 40, 2: Unused variable \'m\' (unused-variable)</string>
</tuple>
</value>
</item>
<item> <item>
<key> <string>version</string> </key> <key> <string>version</string> </key>
<value> <string>erp5</string> </value> <value> <string>erp5</string> </value>
...@@ -99,10 +114,6 @@ ...@@ -99,10 +114,6 @@
<key> <string>action</string> </key> <key> <string>action</string> </key>
<value> <string>validate</string> </value> <value> <string>validate</string> </value>
</item> </item>
<item>
<key> <string>error_message</string> </key>
<value> <string></string> </value>
</item>
<item> <item>
<key> <string>validation_state</string> </key> <key> <string>validation_state</string> </key>
<value> <string>validated</string> </value> <value> <string>validated</string> </value>
......
...@@ -5,6 +5,8 @@ def WebMessage_trainOnWebMessage(self, language_arrays, tag_arrays, stopwords_ar ...@@ -5,6 +5,8 @@ def WebMessage_trainOnWebMessage(self, language_arrays, tag_arrays, stopwords_ar
# clean up header from contact form, if there is one # clean up header from contact form, if there is one
text = self.getTextContent() text = self.getTextContent()
if text is None:
return (language_arrays, tag_arrays)
line_array = [line for line in text.splitlines() if line.strip() != ''] line_array = [line for line in text.splitlines() if line.strip() != '']
if line_array[0][:6] == " Name": if line_array[0][:6] == " Name":
line_array = line_array[4:] line_array = line_array[4:]
......
...@@ -36,6 +36,18 @@ ...@@ -36,6 +36,18 @@
<none/> <none/>
</value> </value>
</item> </item>
<item>
<key> <string>text_content_error_message</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>text_content_warning_message</string> </key>
<value>
<tuple/>
</value>
</item>
<item> <item>
<key> <string>version</string> </key> <key> <string>version</string> </key>
<value> <string>erp5</string> </value> <value> <string>erp5</string> </value>
...@@ -99,10 +111,6 @@ ...@@ -99,10 +111,6 @@
<key> <string>action</string> </key> <key> <string>action</string> </key>
<value> <string>validate</string> </value> <value> <string>validate</string> </value>
</item> </item>
<item>
<key> <string>error_message</string> </key>
<value> <string></string> </value>
</item>
<item> <item>
<key> <string>validation_state</string> </key> <key> <string>validation_state</string> </key>
<value> <string>validated</string> </value> <value> <string>validated</string> </value>
......
...@@ -14,22 +14,19 @@ class Test(ERP5TypeTestCase): ...@@ -14,22 +14,19 @@ class Test(ERP5TypeTestCase):
""" """
return ('erp5_base', 'erp5_web', 'erp5_ingestion_mysql_innodb_catalog', 'erp5_crm', 'erp5_dms', 'erp5_business_bot') return ('erp5_base', 'erp5_web', 'erp5_ingestion_mysql_innodb_catalog', 'erp5_crm', 'erp5_dms', 'erp5_business_bot')
message_reference_dict = {}
def afterSetUp(self): def afterSetUp(self):
""" """
This is ran before anything, used to set the environment This is ran before anything, used to set the environment
""" """
message_list = [ message_list = [
dict(title='Tagged Message', subject_list=['ERP5', 'pricing'], text_content="ERP5 pricing"), dict(title='Tagged Message', subject_list=['ERP5', 'pricing'], text_content="ERP5 pricing"),
dict(title='Untagged Message', text_content="ERP5 pricing"), dict(title='Untagged Message', subject_list=[], text_content="ERP5 pricing"),
] ]
for message in message_list: for index, message in enumerate(message_list):
kw = dict(portal_type = 'Web Message', title = message_list[title], text_content=message_list[text_content]) kw = dict(portal_type = 'Web Message', title = message_list[index]["title"], subject = message_list[index]["subject_list"])
existing = self.portal_catalog.getResultValue(**kw) existing = self.portal.portal_catalog.getResultValue(**kw)
if existing is None: if existing is None:
self.message_reference_dict[message['reference']] = self.event_module.newContent(**kw).getReference() self.portal.event_module.newContent(**kw)
else:
self.message_reference_dict[message['reference']] = existing.getReference()
self.commit() self.commit()
self.tic() self.tic()
...@@ -41,11 +38,11 @@ class Test(ERP5TypeTestCase): ...@@ -41,11 +38,11 @@ class Test(ERP5TypeTestCase):
exists in the document module. exists in the document module.
""" """
set_model_result = self.event_module.set_model().split() set_model_result = self.portal.event_module.WebMessage_setModel().split()
self.assertEqual(set_model_result[0], "Model") self.assertEqual(set_model_result[0], "Model")
kw = dict(portal_type = 'Document', title = "AI Business Bot") kw = dict(portal_type = 'File', title = "AI Business Bot")
document = self.portal_catalog.getResultValue(**kw) document = self.portal.portal_catalog.getResultValue(**kw)
self.assertEqual(set_model_result[3], document.getRelativeUrl()) self.assertEqual(set_model_result[3], "/erp5/" + document.getRelativeUrl())
def test_testWebMessageModel(self): def test_testWebMessageModel(self):
""" """
...@@ -53,7 +50,7 @@ class Test(ERP5TypeTestCase): ...@@ -53,7 +50,7 @@ class Test(ERP5TypeTestCase):
would be given the current algorithm for the model and would be given the current algorithm for the model and
the current tagged messages. Data is returned to user. the current tagged messages. Data is returned to user.
""" """
self.assertEqual(self.event_module.test_model().split()[0] , "Model") self.assertEqual(self.portal.event_module.WebMessage_testModel().split()[0] , "Model")
def test_followUpAutomatically(self): def test_followUpAutomatically(self):
""" """
...@@ -61,8 +58,8 @@ class Test(ERP5TypeTestCase): ...@@ -61,8 +58,8 @@ class Test(ERP5TypeTestCase):
wish would be handled by the model. This message now wish would be handled by the model. This message now
has tags. has tags.
""" """
self.event_module.set_model() self.portal.event_module.WebMessage_setModel()
kw = dict(portal_type = 'Web Message', title='Untagged Message', text_content="ERP5 pricing") kw = dict(portal_type = 'Web Message', title='Untagged Message')
message = self.portal_catalog.getResultValue(**kw) message = self.portal.portal_catalog.getResultValue(**kw)
message.follow_up_automatically() message.WebMessage_parseWebMessage()
self.assertEqual(message.getSubjectList(), ['ERP5', 'pricing']) self.assertFalse(message.getSubjectList() == "[]")
\ No newline at end of file
...@@ -34,6 +34,20 @@ ...@@ -34,6 +34,20 @@
<none/> <none/>
</value> </value>
</item> </item>
<item>
<key> <string>text_content_error_message</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>text_content_warning_message</string> </key>
<value>
<tuple>
<string>W: 25, 15: Unused variable \'message\' (unused-variable)</string>
</tuple>
</value>
</item>
<item> <item>
<key> <string>version</string> </key> <key> <string>version</string> </key>
<value> <string>erp5</string> </value> <value> <string>erp5</string> </value>
...@@ -97,10 +111,6 @@ ...@@ -97,10 +111,6 @@
<key> <string>action</string> </key> <key> <string>action</string> </key>
<value> <string>validate</string> </value> <value> <string>validate</string> </value>
</item> </item>
<item>
<key> <string>error_message</string> </key>
<value> <string></string> </value>
</item>
<item> <item>
<key> <string>validation_state</string> </key> <key> <string>validation_state</string> </key>
<value> <string>validated</string> </value> <value> <string>validated</string> </value>
......
erp5_base erp5_base
erp5_web erp5_web
erp5_dms erp5_dms
<<<<<<< HEAD
erp5_crm erp5_crm
erp5_ingestion_mysql_innodb_catalog erp5_ingestion_mysql_innodb_catalog
\ No newline at end of file
=======
erp5_crm
>>>>>>> 2e83d650106eb861a0c38350ab16aa6d13caea36
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