<commit_before>"""
Command that will allow for the creation of arbitrary events in the database.
"""
from rhobot.components.rdf_publish import RDFSourceStanza
from rhobot.components.commands.base_command import BaseCommand
from rhobot.components.storage import StoragePayload
import logging
from rdflib.namespace import Namespace

SCHEMA = Namespace('http://schema.org/')
WGS_84 = Namespace('http://www.w3.org/2003/01/geo/wgs84_pos#')

logger = logging.getLogger(__name__)

class CreateEventCommand(BaseCommand):

    def initialize_command(self):
        super(CreateEventCommand, self).initialize_command()

        logger.info('Initialize Command')
        self._initialize_command(identifier='create_event', name='Create Event',
                                 additional_dependencies={'rho_bot_rdf_publish', 'rho_bot_storage_client', })

    def command_start(self, request, initial_session):
        """
        Provide the configuration details back to the requester and end the command.
        :param request:
        :param initial_session:
        :return:
        """
        form = self.xmpp['xep_0004'].make_form()

        form.add_field(var='title', label='Title', ftype='text-single')
        form.add_field(var='description', label='Description', ftype='text-multi')
        form.add_field(var='event_start', label='Start Time', ftype='text-single')
        form.add_field(var='event_stop', label='Stop Time', ftype='text-single')

        initial_session['payload'] = form
        initial_session['next'] = self.store_results
        initial_session['has_next'] = False

        def handle_results_from_search(results):
            options = []

            results.results.sort(cmp=lambda x, y: cmp(x.get_column('http://degree')[0],
                                                      y.get_column('http://degree')[0]),
                                 reverse=True)

            for result in results.results:
                options.append({'value': result.about, 'label': result.get_column(str(SCHEMA.name))[0]})

            options = options[:10]

            location_field = form.add_field(var='locations', label='Location', ftype='list-single', options=options)

            if hasattr(results, 'sources'):
                for source in results.sources:
                    source_stanza = RDFSourceStanza()
                    source_stanza['name'] = source[0]
                    source_stanza['command'] = source[1]

                    location_field.append(source_stanza)

            return initial_session

        payload = StoragePayload()
        payload.add_type(WGS_84.SpatialThing)

        return self.xmpp['rho_bot_rdf_publish'].send_out_search(payload, timeout=2.0).then(handle_results_from_search)

    def store_results(self, payload, session):

        logger.info('Payload: %s' % payload)
        logger.info('Session: %s' % session)

        return session


create_event = CreateEventCommand<commit_msg>Start to clean up journal_bot to fix references and changes to core framework<commit_after>"""
Command that will allow for the creation of arbitrary events in the database.
"""
from rhobot.components.rdf_publish import RDFSourceStanza
from rhobot.components.commands.base_command import BaseCommand
from rhobot.components.storage import StoragePayload
from rhobot.namespace import GRAPH
import logging
from rdflib.namespace import Namespace

SCHEMA = Namespace('http://schema.org/')
WGS_84 = Namespace('http://www.w3.org/2003/01/geo/wgs84_pos#')

logger = logging.getLogger(__name__)

class CreateEventCommand(BaseCommand):

    def initialize_command(self):
        super(CreateEventCommand, self).initialize_command()
        self._initialize_command(identifier='create_event', name='Create Event',
                                 additional_dependencies={'rho_bot_rdf_publish', 'rho_bot_storage_client', })

    def post_init(self):
        super(CreateEventCommand, self).post_init()

        self._rdf_publish = self.xmpp['rho_bot_rdf_publish']
        self._storage_client = self.xmpp['rho_bot_storage_client']

    def command_start(self, request, initial_session):
        """
        Provide the configuration details back to the requester and end the command.
        :param request:
        :param initial_session:
        :return:
        """
        form = self._forms.make_form()

        form.add_field(var='title', label='Title', ftype='text-single')
        form.add_field(var='description', label='Description', ftype='text-multi')
        form.add_field(var='event_start', label='Start Time', ftype='text-single')
        form.add_field(var='event_stop', label='Stop Time', ftype='text-single')

        initial_session['payload'] = form
        initial_session['next'] = self.store_results
        initial_session['has_next'] = False

        def handle_results_from_search(results):
            options = []

            results.results.sort(cmp=lambda x, y: cmp(x.get_column(str(GRAPH.degree))[0],
                                                      y.get_column(str(GRAPH.degree))[0]),
                                 reverse=True)

            for result in results.results:
                options.append({'value': result.about, 'label': result.get_column(str(SCHEMA.name))[0]})

            options = options[:10]

            location_field = form.add_field(var='locations', label='Location', ftype='list-single', options=options)

            if hasattr(results, 'sources'):
                for source in results.sources:
                    source_stanza = RDFSourceStanza()
                    source_stanza['name'] = source[0]
                    source_stanza['command'] = source[1]

                    location_field.append(source_stanza)

            return initial_session

        payload = StoragePayload()
        payload.add_type(WGS_84.SpatialThing)

        return self._rdf_publish.send_out_search(payload, timeout=2.0).then(handle_results_from_search)

    def store_results(self, payload, session):

        logger.info('Payload: %s' % payload)
        logger.info('Session: %s' % session)

        return session


create_event = CreateEventCommand
{'fraction_non_alphanumeric': 0.11195970100747481, 'fraction_numerical': 0.007799805004874878, 'mean_word_length': 2.8253573648228714, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1452709', 'n_tokens_mistral': 1743, 'n_tokens_neox': 1666, 'n_words': 329}