def make_person(self, index): if index < len(self.demo_data): properties = self.demo_data[index] properties["is_demo"] = True return Person(team=self.team, properties=properties, is_identified=True) else: return super().make_person(index)
def _create_anonymous_users(team: Team, base_url: str) -> None: with open(Path('posthog/demo_data.json').resolve(), 'r') as demo_data_file: demo_data = json.load(demo_data_file) Person.objects.bulk_create([ Person(team=team, properties={'is_demo': True}) for _ in range(0, 100) ]) distinct_ids: List[PersonDistinctId] = [] events: List[Event] = [] days_ago = 7 demo_data_index = 0 for index, person in enumerate(Person.objects.filter(team=team)): if index > 0 and index % 14 == 0: days_ago -= 1 distinct_id = str(uuid.uuid4()) distinct_ids.append(PersonDistinctId(team=team, person=person, distinct_id=distinct_id)) date = now() - relativedelta(days=days_ago) browser = random.choice(['Chrome', 'Safari', 'Firefox']) events.append(Event(team=team, event='$pageview', distinct_id=distinct_id, properties={'$current_url': base_url, '$browser': browser, '$lib': 'web'}, timestamp=date)) if index % 3 == 0: person.properties.update(demo_data[demo_data_index]) person.save() demo_data_index += 1 Event.objects.create( team=team, distinct_id=distinct_id, event='$autocapture', properties={'$current_url': base_url}, timestamp=date + relativedelta(seconds=14), elements=[ Element(tag_name='a', href='/demo/1', attr_class=['btn', 'btn-success'], attr_id='sign-up', text='Sign up') ]) events.append(Event(event='$pageview', team=team, distinct_id=distinct_id, properties={'$current_url': '%s1/' % base_url, '$browser': browser, '$lib': 'web'}, timestamp=date + relativedelta(seconds=15))) if index % 4 == 0: Event.objects.create( team=team, event='$autocapture', distinct_id=distinct_id, properties={'$current_url': '%s1/' % base_url}, timestamp=date + relativedelta(seconds=29), elements=[ Element(tag_name='button', attr_class=['btn', 'btn-success'], text='Sign up!') ]) events.append(Event(event='$pageview', team=team, distinct_id=distinct_id, properties={'$current_url': '%s2/' % base_url, '$browser': browser, '$lib': 'web'}, timestamp=date + relativedelta(seconds=30))) if index % 5 == 0: Event.objects.create( team=team, event='$autocapture', distinct_id=distinct_id, properties={'$current_url': '%s2/' % base_url}, timestamp=date + relativedelta(seconds=59), elements=[ Element(tag_name='button', attr_class=['btn', 'btn-success'], text='Pay $10') ]) events.append(Event(event='$pageview', team=team, distinct_id=distinct_id, properties={'$current_url': '%s3/' % base_url, '$browser': browser, '$lib': 'web'}, timestamp=date + relativedelta(seconds=60))) PersonDistinctId.objects.bulk_create(distinct_ids) Event.objects.bulk_create(events)
def _format_results(self, results): formatted_results = [] for row in results: distinct_ids, email = Person.get_distinct_ids_and_email_by_id( row[1], self._team.id) formatted_results.append({ "max_step": row[0], "distinct_ids": distinct_ids, "email": email }) return formatted_results
def _create_events(self, demo_data, team, base_url): result = urlparse(settings.DATABASE_URL) database = result.path[1:] hostname = result.hostname try: conn = psycopg2.connect(dbname=database, host=hostname) except: print("Unable to connect to the database") conn.autocommit = True cur = conn.cursor() Person.objects.bulk_create([ Person(team=team, properties={'is_demo': True}) for _ in range(0, 100) ]) distinct_ids: List[PersonDistinctId] = [] demo_data_index = 0 for index, person in enumerate(Person.objects.filter(team=team)): distinct_id = str(uuid.uuid4()) distinct_ids.append( PersonDistinctId(team=team, person=person, distinct_id=distinct_id)) if index % 3 == 0: person.properties.update(demo_data[demo_data_index]) person.save() demo_data_index += 1 events_string_iterator = StringIteratorIO(('|'.join( map(clean_csv_value, ( random.choice(['autocapture', '$pageview', '$hello']), json.dumps({ '$current_url': base_url + random.choice(['', '1/', '2/']), '$browser': random.choice(['Chrome', 'Safari', 'Firefox']), '$lib': 'web' }), json.dumps({ 'tag_name': random.choice(['a', 'href']), 'attr_class': ['btn', 'btn-success'], 'attr_id': random.choice(['sign-up', 'click']), 'text': random.choice(['Sign up', 'Pay $10']) }), now() - relativedelta(days=random.choice(range(7))) + relativedelta(seconds=15), team.id, distinct_id, ))) + '\n' for _ in range(10000))) cur.copy_from(events_string_iterator, 'posthog_event', sep='|', columns=[ 'event', 'properties', 'elements', 'timestamp', 'team_id', 'distinct_id' ]) PersonDistinctId.objects.bulk_create(distinct_ids) cur.close()
def _create_anonymous_users(team: Team, base_url: str) -> None: with open(Path("posthog/demo_data.json").resolve(), "r") as demo_data_file: demo_data = json.load(demo_data_file) Person.objects.bulk_create([Person(team=team, properties={"is_demo": True}) for _ in range(0, 100)]) distinct_ids: List[PersonDistinctId] = [] events: List[Event] = [] days_ago = 7 demo_data_index = 0 for index, person in enumerate(Person.objects.filter(team=team)): if index > 0 and index % 14 == 0: days_ago -= 1 distinct_id = str(UUIDT()) distinct_ids.append(PersonDistinctId(team=team, person=person, distinct_id=distinct_id)) # Add first user more 3 distinct id's if index == 0: for _ in range(0, 3): distinct_ids.append(PersonDistinctId(team=team, person=person, distinct_id=str(UUIDT()))) date = now() - relativedelta(days=days_ago) browser = random.choice(["Chrome", "Safari", "Firefox"]) events.append( Event( team=team, event="$pageview", distinct_id=distinct_id, properties={"$current_url": base_url, "$browser": browser, "$lib": "web"}, timestamp=date, ) ) if index % 3 == 0: person.properties.update(demo_data[demo_data_index]) person.is_identified = True person.save() demo_data_index += 1 Event.objects.create( team=team, distinct_id=distinct_id, event="$autocapture", properties={"$current_url": base_url, "$browser": browser, "$lib": "web", "$event_type": "click",}, timestamp=date + relativedelta(seconds=14), elements=[ Element( tag_name="a", href="/demo/1", attr_class=["btn", "btn-success"], attr_id="sign-up", text="Sign up", ), Element(tag_name="form", attr_class=["form"]), Element(tag_name="div", attr_class=["container"]), Element(tag_name="body"), Element(tag_name="html"), ], ) events.append( Event( event="$pageview", team=team, distinct_id=distinct_id, properties={"$current_url": "%s/1" % base_url, "$browser": browser, "$lib": "web",}, timestamp=date + relativedelta(seconds=15), ) ) if index % 4 == 0: Event.objects.create( team=team, event="$autocapture", distinct_id=distinct_id, properties={ "$current_url": "%s/1" % base_url, "$browser": browser, "$lib": "web", "$event_type": "click", }, timestamp=date + relativedelta(seconds=29), elements=[ Element(tag_name="button", attr_class=["btn", "btn-success"], text="Sign up!",), Element(tag_name="form", attr_class=["form"]), Element(tag_name="div", attr_class=["container"]), Element(tag_name="body"), Element(tag_name="html"), ], ) events.append( Event( event="$pageview", team=team, distinct_id=distinct_id, properties={"$current_url": "%s/2" % base_url, "$browser": browser, "$lib": "web",}, timestamp=date + relativedelta(seconds=30), ) ) if index % 5 == 0: Event.objects.create( team=team, event="$autocapture", distinct_id=distinct_id, properties={ "$current_url": "%s/2" % base_url, "$browser": browser, "$lib": "web", "$event_type": "click", }, timestamp=date + relativedelta(seconds=59), elements=[ Element(tag_name="button", attr_class=["btn", "btn-success"], text="Pay $10",), Element(tag_name="form", attr_class=["form"]), Element(tag_name="div", attr_class=["container"]), Element(tag_name="body"), Element(tag_name="html"), ], ) events.append( Event( event="purchase", team=team, distinct_id=distinct_id, properties={"price": 10}, timestamp=date + relativedelta(seconds=60), ) ) events.append( Event( event="$pageview", team=team, distinct_id=distinct_id, properties={"$current_url": "%s/3" % base_url, "$browser": browser, "$lib": "web",}, timestamp=date + relativedelta(seconds=60), ) ) team.event_properties_numerical.append("purchase") team.save() PersonDistinctId.objects.bulk_create(distinct_ids) Event.objects.bulk_create(events)
def _create_person(**kwargs): person = Person.objects.create(**kwargs) return Person(id=str(person.uuid))
def make_person(self, index): return Person(team=self.team, properties={"is_demo": True})
def _create_events(self, demo_data, team, base_url): result = urlparse(settings.DATABASE_URL) database = result.path[1:] hostname = result.hostname try: conn = psycopg2.connect(dbname=database, host=hostname) except: print("Unable to connect to the database") conn.autocommit = True cur = conn.cursor() Person.objects.bulk_create([ Person(team=team, properties={"is_demo": True}) for _ in range(0, 100) ]) distinct_ids: List[PersonDistinctId] = [] demo_data_index = 0 for index, person in enumerate(Person.objects.filter(team=team)): distinct_id = str(UUIDT()) distinct_ids.append( PersonDistinctId(team=team, person=person, distinct_id=distinct_id)) if index % 3 == 0: person.properties.update(demo_data[demo_data_index]) person.save() demo_data_index += 1 events_string_iterator = StringIteratorIO(("|".join( map( clean_csv_value, ( random.choice(["autocapture", "$pageview", "$hello"]), json.dumps({ "$current_url": base_url + random.choice(["", "1/", "2/"]), "$browser": random.choice(["Chrome", "Safari", "Firefox"]), "$lib": "web", }), json.dumps( { "tag_name": random.choice(["a", "href"]), "attr_class": ["btn", "btn-success"], "attr_id": random.choice(["sign-up", "click"]), "text": random.choice(["Sign up", "Pay $10"]), }), now() - relativedelta(days=random.choice(range(7))) + relativedelta(seconds=15), team.id, distinct_id, ), )) + "\n" for _ in range(10000))) cur.copy_from( events_string_iterator, "posthog_event", sep="|", columns=[ "event", "properties", "elements", "timestamp", "team_id", "distinct_id", ], ) PersonDistinctId.objects.bulk_create(distinct_ids) cur.close()
def _get_people(): return [Person(p) for p in sync_execute("select * from person")]