Code Monkey home page Code Monkey logo

fake-web-events's Introduction

Fake Web Events

Generator of semi-random fake web events.

When prototyping event streaming and analytics tools such as Kinesis, Kafka, Spark Streaming, you usually want to have a fake stream of events to test your application. However you will not want to test it with complete random events, they must have some logic and constraints to become similar to the real world.

This package generates semi-random web events for your prototypes, so that when you build some charts out of the event stream, they are not completely random. This is a typical fake event generated with this package:

{
  "event_timestamp": "2020-07-05 14:32:45.407110",
  "event_type": "pageview",
  "page_url": "http://www.dummywebsite.com/home",
  "page_url_path": "/home",
  "referer_url": "www.instagram.com",
  "referer_url_scheme": "http",
  "referer_url_port": "80",
  "referer_medium": "internal",
  "utm_medium": "organic",
  "utm_source": "instagram",
  "utm_content": "ad_2",
  "utm_campaign": "campaign_2",
  "click_id": "b6b1a8ad-88ca-4fc7-b269-6c9efbbdad55",
  "geo_latitude": "41.75338",
  "geo_longitude": "-86.11084",
  "geo_country": "US",
  "geo_timezone": "America/Indiana/Indianapolis",
  "geo_region_name": "Granger",
  "ip_address": "209.139.207.244",
  "browser_name": "Firefox",
  "browser_user_agent": "Mozilla/5.0 (Macintosh; U; PPC Mac OS X 10_5_5; rv:1.9.6.20) Gecko/2012-06-06 09:24:19 Firefox/3.6.20",
  "browser_language": "tn_ZA",
  "os": "Android 2.0.1",
  "os_name": "Android",
  "os_timezone": "America/Indiana/Indianapolis",
  "device_type": "Mobile",
  "device_is_mobile": true,
  "user_custom_id": "[email protected]",
  "user_domain_id": "3d648067-9088-4d7e-ad32-45d009e8246a"
}

Installation

To install simply do pip install fake_web_events

Running

It is easy to run a simulation as well:

from fake_web_events import Simulation


simulation = Simulation(user_pool_size=100, sessions_per_day=100000)
events = simulation.run(duration_seconds=60)

for event in events:
    print(event)

How it works

We create fake users, then generate session events based on a set of probabilities.

Probabilities

There is a configuration file where we define a set of probabilities for each event. Let's say browser preference:

browsers:
  Chrome: 0.5
  Firefox: 0.25
  InternetExplorer: 0.05
  Safari: 0.1
  Opera: 0.1

Also, when a user is in a determined page, there are some defined probabilities of what are the next page he's going to visit:

home:
  home: 0.45
  product_a: 0.17
  product_b: 0.12
  session_end: 0.26

This means that at the next iteration there are 45% chance user stays at home page, 17% chance user goes to product_a page and so on.

Website Map

We designed a really simple website map to allow user browsing. website_map

Green pages are those where a user can land at the beginning of a session. Yellow pages are only accessible to user who are already browsing.

You can fin how the probabilities for each page are defined in the config.template.yml file

Fake user information

To generate fake user information, such as IP and email addresses we are using the module Faker.

User Pool

We create a user pool from where users are randomly chosen (with replacement). This enables users to have different sessions over time.

Simulation

When you run a simulation, it will pick an user and iterate until that user reaches session_end. Simulation will run in steps defined by batch_size. The default batch_size is 10 seconds, meaning that each iteration will add 10 seconds to the timer (with some randomness).

For each iteration an event is generated for each user when the current page is different from the previous page.

Simulate events

When calling simulate_events() you have to define a duration in seconds. Please note that this duration is in "real time", and that time inside the simulation will usually run faster than real time.

This will return a generator, so you need to iterate over it and decide what to do to each event inside the loop.

Advanced

If you want to customize the probabilities, you can create a file called config.yml in the same directory where you are running the script. This file will take precedence over config.template.yml.

Examples

In the folder examples you are going to find some use cases and examples on how to use this package.

Page visit distribution

After running the simulation for a few seconds, we get the following distribution of events per page: pageview_funnel

Page views per hour

We also have different visit rates per hour of day. This is the distribution after running the simulation: events_per_hour

Wanna help?

Fork, improve and PR.

fake-web-events's People

Contributors

andresionek91 avatar mmatheusvidal avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

fake-web-events's Issues

Simulate users sign-up and login

Some users should visit the website without any information about who they are (except by the domain user id). User information is only captured after the signup/login. This will allow people training with user stitching using this fake data.

Simulate microservices events

A good idea would be to simulate microservices events, linked to web events. Some events I can think of are:

  • user_created
  • order_created
  • payment_completed
  • payment_failed
  • order_dispatched
  • order_completed

Make ads depend on campaigns

Campaigns should be one level above on hierarchy than ads. Something like this:

campaigns:
  campaign_a:
    ad_1: 0.25
    ad_2: 0.25
  campaign_b:
    ad_3: 0.25
    ad_4: 0.25

Meaning that one add is linked to a specific campaign when running the simulation. Right now the simulation will pick a random ad and a random campaign.

Some users should also come without ad or campaign associated to simulate direct access.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.