<commit_before>import logging

import os
import glob
from unittest import TestCase
from decimal import Decimal

from sqlalchemy import MetaData, create_engine
from sqlalchemy.exc import SAWarning
import zmq

import warnings
# Filter out pysqlite Decimal loss of precision warning.
warnings.filterwarnings('ignore',
                        '.*pysqlite does \*not\* support Decimal',
                        SAWarning,
                        'sqlalchemy.types')
# Turn unicode bind param warnings into errors.
warnings.filterwarnings('error',
                        r'Unicode type received non-unicode bind',
                        SAWarning,
                        'sqlalchemy.engine.default')

from manhattan.worker import Worker

from manhattan.log.memory import MemoryLog
from manhattan.log.zeromq import ZeroMQLog
from manhattan.log.timerotating import TimeRotatingLog

from manhattan.backend import Backend

from . import data

logging.basicConfig()
logging.getLogger('sqlalchemy.engine').setLevel(logging.DEBUG)


def drop_existing_tables(engine):
    "Drop all tables, including tables that aren't defined in metadata."
    temp_metadata = MetaData()
    temp_metadata.reflect(bind=engine)
    for table in reversed(temp_metadata.sorted_tables):
        table.drop(bind=engine)


class TestCombinations(TestCase):

    def _check_backend_queries(self, backend):
        self.assertEqual(backend.count(u'add to cart', site_id=1), 5)
        self.assertEqual(backend.count(u'began checkout', site_id=1), 4)
        self.assertEqual(backend.count(u'viewed page', site_id=1), 6)

        self.assertEqual(backend.count(u'add to cart', site_id=2), 1)
        self.assertEqual(backend.count(u'began checkout', site_id=2), 1)
        self.assertEqual(backend.count(u'completed checkout', site_id=2), 0)
        self.assertEqual(backend.count(u'viewed page', site_id=2), 1)

        #sessions = backend.get_sessions(goal='add to cart')
        #self.assertIn('a', sessions)
        #self.assertIn('b', sessions)
        #self.assertNotIn('c', sessions)

        #sessions = backend.get_sessions(
        #    goal='completed checkout',
        #    variant=('red checkout form', 'False'))
        #self.assertEqual(len(sessions), 1)
        #self.assertIn('b', sessions)

        #sessions = backend.get_sessions(
        #    variant=('red checkout form', 'False'))
        #self.assertEqual(len(sessions), 1)
        #self.assertIn('b', sessions)

        num = backend.count(u'completed checkout',
                            variant=(u'red checkout form', u'False'),
                            site_id=1)
        self.assertEqual(num, 3)

        #sessions = backend.get_sessions()
        #self.assertEqual(len(sessions), 6)

        revenue = backend.goal_value(u'completed checkout', site_id=1)
        self.assertEqual(revenue, Decimal('108.19'))

        revenue_nored = backend.goal_value(
            u'completed checkout',
            variant=(u'red checkout form', u'False'), site_id=1)
        self.assertEqual(revenue_nored, Decimal('108.19'))

        noreds = backend.count(variant=(u'red checkout form', u'False'),
                               site_id=1)
        self.assertEqual(noreds, 3)

        margin = backend.goal_value(u'order margin', site_id=1)
        margin = margin.quantize(Decimal('.01'))
        self.assertEqual(margin, Decimal('23.47'))

        margin_per = backend.goal_value(u'margin per session', site_id=1)<commit_msg>remove commented-out test code corresponding to backend.get_sessions(), that feature is not going to be added back anytime soon<commit_after>import logging

import os
import glob
from unittest import TestCase
from decimal import Decimal

from sqlalchemy import MetaData, create_engine
from sqlalchemy.exc import SAWarning
import zmq

import warnings
# Filter out pysqlite Decimal loss of precision warning.
warnings.filterwarnings('ignore',
                        '.*pysqlite does \*not\* support Decimal',
                        SAWarning,
                        'sqlalchemy.types')
# Turn unicode bind param warnings into errors.
warnings.filterwarnings('error',
                        r'Unicode type received non-unicode bind',
                        SAWarning,
                        'sqlalchemy.engine.default')

from manhattan.worker import Worker

from manhattan.log.memory import MemoryLog
from manhattan.log.zeromq import ZeroMQLog
from manhattan.log.timerotating import TimeRotatingLog

from manhattan.backend import Backend

from . import data

logging.basicConfig()
logging.getLogger('sqlalchemy.engine').setLevel(logging.DEBUG)


def drop_existing_tables(engine):
    "Drop all tables, including tables that aren't defined in metadata."
    temp_metadata = MetaData()
    temp_metadata.reflect(bind=engine)
    for table in reversed(temp_metadata.sorted_tables):
        table.drop(bind=engine)


class TestCombinations(TestCase):

    def _check_backend_queries(self, backend):
        self.assertEqual(backend.count(u'add to cart', site_id=1), 5)
        self.assertEqual(backend.count(u'began checkout', site_id=1), 4)
        self.assertEqual(backend.count(u'viewed page', site_id=1), 6)

        self.assertEqual(backend.count(u'add to cart', site_id=2), 1)
        self.assertEqual(backend.count(u'began checkout', site_id=2), 1)
        self.assertEqual(backend.count(u'completed checkout', site_id=2), 0)
        self.assertEqual(backend.count(u'viewed page', site_id=2), 1)

        num = backend.count(u'completed checkout',
                            variant=(u'red checkout form', u'False'),
                            site_id=1)
        self.assertEqual(num, 3)

        revenue = backend.goal_value(u'completed checkout', site_id=1)
        self.assertEqual(revenue, Decimal('108.19'))

        revenue_nored = backend.goal_value(
            u'completed checkout',
            variant=(u'red checkout form', u'False'), site_id=1)
        self.assertEqual(revenue_nored, Decimal('108.19'))

        noreds = backend.count(variant=(u'red checkout form', u'False'),
                               site_id=1)
        self.assertEqual(noreds, 3)

        margin = backend.goal_value(u'order margin', site_id=1)
        margin = margin.quantize(Decimal('.01'))
        self.assertEqual(margin, Decimal('23.47'))

        margin_per = backend.goal_value(u'margin per session', site_id=1)
{'fraction_non_alphanumeric': 0.10703651465287572, 'fraction_numerical': 0.012380504623099827, 'mean_word_length': 2.9153374233128835, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2747422', 'n_tokens_mistral': 1930, 'n_tokens_neox': 1790, 'n_words': 424}