Пример #1
0
    def test_performance(self):

        to_send = 100

        target = analytics.stats.successful + to_send

        analytics.default_client.async = True
        analytics.default_client.flush_at = 200
        analytics.default_client.max_flush_size = 50
        analytics.default_client.set_log_level(logging.DEBUG)

        for i in range(to_send):
            analytics.track('[email protected]', 'Played a Song', {
                "Artist": "The Beatles",
                "Song": "Eleanor Rigby"
            })

        print 'Finished submitting into the queue'

        start = time()
        while analytics.stats.successful < target:
            print ('Successful ', analytics.stats.successful, 'Left',
                (target - analytics.stats.successful),
                'Duration ', (time() - start))
            analytics.flush()
            sleep(1.0)
Пример #2
0
    def send(self, action, install_method, num_errors):
        """Sends analytics track data to segmentIO.
        variant: string | open or enterprise
        action: string | preflight, deploy, or postflight
        install_method: string | gui, cli or advanced
        """
        analytics.write_key = "51ybGTeFEFU1xo6u10XMDrr6kATFyRyh"

        # Set customer key here rather than __init__ since we want the most up to date config
        # and config may change between __init__ and here.
        config = Config(CONFIG_PATH)
        customer_key = config.hacky_default_get('customer_key', None)

        # provider is always onprem when the cli installer is used
        provider = "onprem"
        # platform defaults to provider value, if not specified
        platform = config.hacky_default_get('platform', provider)

        analytics.track(user_id=customer_key, anonymous_id=self.uuid, event="installer", properties={
            "platform": platform,
            "provider": provider,
            "source": "installer",
            "variant": os.environ["BOOTSTRAP_VARIANT"],
            "install_id": self.uuid,
            "bootstrap_id": os.environ["BOOTSTRAP_ID"],
            "install_method": install_method,
            "action_name": action,
            "errors": num_errors,
            "customerKey": customer_key,
        })
        analytics.flush()
Пример #3
0
    def test_async_basic_identify(self):
        # flush after every message
        analytics.default_client.flush_at = 1
        analytics.default_client.async = True

        last_identifies = analytics.stats.identifies
        last_successful = analytics.stats.successful
        last_flushes = analytics.stats.flushes

        analytics.identify('[email protected]', {
            "Subscription Plan": "Free",
            "Friends": 30
        })

        self.assertEqual(analytics.stats.identifies, last_identifies + 1)

        # this should flush because we set the flush_at to 1
        self.assertEqual(analytics.stats.flushes, last_flushes + 1)

        # this should do nothing, as the async thread is currently active
        analytics.flush()

        # we should see no more flushes here
        self.assertEqual(analytics.stats.flushes, last_flushes + 1)

        sleep(1)

        self.assertEqual(analytics.stats.successful, last_successful + 1)
Пример #4
0
def track():
    try:
        content = request.get_json(silent=True)
        _userId = content.get('userId')
        _event = content.get('event')
        _properties = content.get('properties')
        _context = content.get('context')
        _timestamp = format_timestamp(content.get('timestamp'))
        _anonymous_id = content.get('anonymousId')
        _integrations = content.get('integrations')

        analytics.flush()
        analytics.track(_userId, _event, _properties, _context, _timestamp, _anonymous_id, _integrations)

        return format_response('track')

    except Exception as e:
        return json.dumps({'error': str(e)})
Пример #5
0
    def send(self, action, install_method, num_errors):
        """Sends analytics track data to segmentIO.
        variant: string | open or enterprise
        action: string | preflight, deploy, or postflight
        install_method: string | gui, cli or advanced
        """
        analytics.write_key = "39uhSEOoRHMw6cMR6st9tYXDbAL3JSaP"

        analytics.track(user_id=self.customer_key, anonymous_id=self.uuid, event=action, properties={
            "install_id": self.uuid,
            "bootstrap_id": self.bootstrap_version,
            "provider": self.source,
            "source": "installer",
            "install_method": install_method,
            "stage": action,
            "errors": num_errors,
            "customer_key": self.customer_key,
        })
        analytics.flush()
Пример #6
0
def group():

    try:
        content = request.get_json(silent=True)
        _userId = content.get('userId')
        _groupId = content.get('groupId')
        _traits = content.get('traits')
        _context = content.get('context')
        _timestamp = format_timestamp(content.get('timestamp'))
        _anonymous_id = content.get('anonymousId')
        _integrations = content.get('integrations')

        analytics.flush()
        analytics.group(_userId, _groupId, _traits, _context, _timestamp, _anonymous_id, _integrations)

        return format_response('group')

    except Exception as e:
        return json.dumps({'error': str(e)})
Пример #7
0
def widget_analytics():
    d = {}
    for k, v in request.args.iteritems():
        d[k] = v

    try:
        d["hostname"] = d['url'].split("/")[2]
        d["domain"] = ".".join(d['hostname'].split(".")[-2:])  # like "impactstory.org"
    except KeyError:
        #nevermind then
        pass

    try:
        api_key = d["api-key"]
    except KeyError:
        api_key = "unknown"

    logger.info(u"got widget analytics data: {data}".format(
        data=d))

    try:
        # later look stuff up here from db, based on api-key; send along w identify() call...
        analytics.identify(user_id=api_key)
    except IndexError:
        logger.debug(u"IndexError when doing analytics.identify in widget_analytics")

    try:
        analytics.track(
            user_id=api_key,
            event="Served a page with embedded widget",
            properties=d
        )
    except IndexError:
        logger.debug(u"IndexError when doing analytics.track in widget_analytics")

    try:
        analytics.flush(async=False)  # make sure all the data gets sent to segment.io
    except IndexError:
        # sometimes the data was already flushed and we get an error popping from an empty queue
        logger.debug(u"IndexError when doing analytics.flush in widget_analytics")

    return make_response(request.args.get("callback", "") + '({"status": "success"})', 200)
Пример #8
0
    def test_async_basic_track(self):

        analytics.default_client.flush_at = 50
        analytics.default_client.async = True

        last_tracks = analytics.stats.tracks
        last_successful = analytics.stats.successful

        analytics.track('[email protected]', 'Played a Song', {
            "Artist": "The Beatles",
            "Song": "Eleanor Rigby"
        })

        self.assertEqual(analytics.stats.tracks, last_tracks + 1)

        analytics.flush()

        sleep(2)

        self.assertEqual(analytics.stats.successful, last_successful + 1)
Пример #9
0
    def test_time_policy(self):

        analytics.default_client.async = False
        analytics.default_client.flush_at = 1

        # add something so we have a reason to flush
        analytics.track('[email protected]', 'Played a Song', {
            "Artist": "The Beatles",
            "Song": "Eleanor Rigby"
        })

        # flush to reset flush count
        analytics.flush()

        last_flushes = analytics.stats.flushes

        # set the flush size trigger high
        analytics.default_client.flush_at = 50
        # set the time policy to 1 second from now
        analytics.default_client.flush_after = timedelta(seconds=1)

        analytics.track('[email protected]', 'Played a Song', {
            "Artist": "The Beatles",
            "Song": "Eleanor Rigby"
        })

        # that shouldn't of triggered a flush
        self.assertEqual(analytics.stats.flushes, last_flushes)

        # sleep past the time-flush policy
        sleep(1.2)

        # submit another track to trigger the policy
        analytics.track('[email protected]', 'Played a Song', {
            "Artist": "The Beatles",
            "Song": "Eleanor Rigby"
        })

        self.assertEqual(analytics.stats.flushes, last_flushes + 1)
    def send(self, action, install_method, num_errors):
        """Sends analytics track data to segmentIO.
        variant: string | open or enterprise
        action: string | preflight, deploy, or postflight
        install_method: string | gui, cli or advanced
        """
        analytics.write_key = "51ybGTeFEFU1xo6u10XMDrr6kATFyRyh"

        # We set customer key from config to avoid loading the config during class init
        customer_key = backend.get_config().get("customer_key", None)

        analytics.track(user_id=customer_key, anonymous_id=self.uuid, event=action, properties={
            "provider": "onprem",
            "source": "installer",
            "variant": os.environ["BOOTSTRAP_VARIANT"],
            "install_id": self.uuid,
            "bootstrap_id": os.environ["BOOTSTRAP_ID"],
            "install_method": install_method,
            "stage": action,
            "errors": num_errors,
            "customerKey": customer_key,
        })
        analytics.flush()
Пример #11
0
 def test_alias(self):
     analytics.alias('previousId', 'userId')
     analytics.flush()
Пример #12
0
            self.downloadOne()



if __name__ == "__main__" and "--restart" in sys.argv:
    conn = MongoClient(settings.MONGO_URI)
    db = conn.requests
    db.download.update({},{"canDownload":1})

if __name__ == "__main__" and "--download" in sys.argv:
    try:
        link = sys.argv[sys.argv.index("--download")+1]
        data = sys.argv[sys.argv.index("--download")+2]
        downloader = Downloader().downloadItem({
            "_id" : str(ObjectId()),
            "links" : [(link,True)],
            "data" : data
        })
        
        send_download_status(link, downloader)
        analytics.flush()

    except Exception as e:
        print("Invalid Data : %s" % e)
        print("Usage : downloader --download link jsondata")

if __name__ == "__main__" and "--startdownloader" in sys.argv:
    conn = MongoClient(settings.MONGO_URI)
    db = conn.requests
    Downloader(db=db).start()
Пример #13
0
 def test_track(self):
     analytics.track('userId', 'python module event')
     analytics.flush()
Пример #14
0
import impactstoryanalytics.widgets
from impactstoryanalytics.widgets.widget_api_helpers import Couchdb


logger = logging.getLogger("analytics.run_couch")


def run_couch():

    analytics.identify(user_id="stats")

    rows = Couchdb.get_view("collections_per_genre/collections_per_genre", True)
    products_per_quasigenre = {}
    for row in rows:
        products_per_quasigenre[row["key"]] = row["value"]

    products_per_quasigenre["total"] = products_per_quasigenre[":"]
    del products_per_quasigenre[":"]

    logger.info("products_per_quasigenre:" + str(products_per_quasigenre))

    analytics.track(user_id="stats", event='Profiles per quasigenre', properties=products_per_quasigenre)

    return(rows)

run_couch()

analytics.flush(async=False)  # make sure all the data gets sent to segment.io
Пример #15
0
 def test_flush(self):
     analytics.flush()
Пример #16
0
 def test_screen(self):
     analytics.screen('userId')
     analytics.flush()
Пример #17
0
 def test_page(self):
     analytics.page('userId')
     analytics.flush()
Пример #18
0
 def test_group(self):
     analytics.group('userId', 'groupId')
     analytics.flush()
Пример #19
0
 def test_identify(self):
     analytics.identify('userId', { 'email': '[email protected]' })
     analytics.flush()