Skip to content

Commit

Permalink
commit
Browse files Browse the repository at this point in the history
  • Loading branch information
khuyentran1401 committed Jun 24, 2021
1 parent 903c380 commit ed773a8
Show file tree
Hide file tree
Showing 10 changed files with 697 additions and 0 deletions.
12 changes: 12 additions & 0 deletions applications/notion_examples/add_new.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from hashlib import new
from notion.client import NotionClient
from notion.block import ColumnBlock, TodoBlock
from rich import inspect

client = NotionClient(token_v2="02a65af9ae61ae50bc17f3333d251e2580d9fd1293bdc68990a474372a458a56b63b1b2868f47e5b21e947ddc093634ce8442de2390f14bcdc54bbaa0d6d2921fad82538d01c9d78c9931f6daea5")
page = client.get_block("https://www.notion.so/1063a61b0a4548959373f995b008d13e?v=6fba291866984949abf7c2c6e2e85ae1")

inspect(page, methods=True)
# print(page)
content = page.get()
print(content)
10 changes: 10 additions & 0 deletions applications/notion_examples/get_title.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from notion.client import NotionClient

client = NotionClient(token_v2="02a65af9ae61ae50bc17f3333d251e2580d9fd1293bdc68990a474372a458a56b63b1b2868f47e5b21e947ddc093634ce8442de2390f14bcdc54bbaa0d6d2921fad82538d01c9d78c9931f6daea5")

page = client.get_block("https://www.notion.so/1063a61b0a4548959373f995b008d13e?v=6fba291866984949abf7c2c6e2e85ae1")
print("Page title is", page.title)

page.title = "My connections"
print("New page title is", page.title)

9 changes: 9 additions & 0 deletions applications/notion_examples/traverse.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from notion.client import NotionClient

client = NotionClient(token_v2="02a65af9ae61ae50bc17f3333d251e2580d9fd1293bdc68990a474372a458a56b63b1b2868f47e5b21e947ddc093634ce8442de2390f14bcdc54bbaa0d6d2921fad82538d01c9d78c9931f6daea5")
page = client.get_block("https://www.notion.so/1063a61b0a4548959373f995b008d13e?v=6fba291866984949abf7c2c6e2e85ae1")

for child in page.children:
print(child.title)

print("Parent of {} is {}".format(page.id, page.parent.id))
493 changes: 493 additions & 0 deletions feature_engineering/sklego_examples/example.ipynb

Large diffs are not rendered by default.

22 changes: 22 additions & 0 deletions python/eventsourcing_examples/aggregation_example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from eventsourcing.domain import Aggregate, event
from loguru import logger

class Person(Aggregate):
@event('Created')
def __init__(self):
self.life = []

@event("LifeHappened")
def deal_with_life(self, some_event):
self.life.append(some_event)

@logger.catch
def main():
ben = Person()
assert ben.life == []

ben.deal_with_life('school')
assert ben.life == ['school']
assert len(ben.collect_events()) == 2

main()
36 changes: 36 additions & 0 deletions python/eventsourcing_examples/aggregation_more.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
from eventsourcing.domain import Aggregate, event
from loguru import logger

class Person(Aggregate):
@event('Created')
def __init__(self):
self.life = []

@event("LifeHappened")
def deal_with_life(self, some_event):
self.life.append(some_event)

@event("Grow")
def learn_from_life(self, some_event):
self.life.append(some_event)

@logger.catch
def main():
ben = Person()
assert ben.life == []

ben.deal_with_life('school')
ben.deal_with_life('friend')
ben.learn_from_life('leave_home')

assert ben.life == ['school', 'friend', 'leave_home']
events = ben.collect_events()
assert len(events) == 4
assert type(events[0]).__qualname__ == 'Person.Created'
assert type(events[1]).__qualname__ == 'Person.LifeHappened'
assert type(events[2]).__qualname__ == 'Person.LifeHappened'
assert type(events[3]).__qualname__ == 'Person.Grow'



main()
55 changes: 55 additions & 0 deletions python/eventsourcing_examples/application_example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
from eventsourcing.application import Application
from eventsourcing.domain import Aggregate, event
from eventsourcing.system import NotificationLogReader
from rich import print

class Person(Aggregate):
@event('Created')
def __init__(self):
self.life = []

@event("LifeHappened")
def deal_with_life(self, some_event):
self.life.append(some_event)

class Record(Application):
def create_person(self):
person = Person()
self.save(person)
return person.id

def deal_with_life(self, person_id, some_event):
person = self.repository.get(person_id)
person.deal_with_life(some_event)
self.save(person)

def view_life(self, person_id):
person = self.repository.get(person_id)
return person.life

def notification_to_table(record):
return [record.id, record.version, record.created_on, record.modified_on, record.history]

def main():
record = Record()
ben = record.create_person()
record.deal_with_life(ben, 'school')
record.deal_with_life(ben, 'friend')
assert record.view_life(ben) == ['school', 'friend']

alex = record.create_person()
assert alex != ben
record.deal_with_life(alex, 'girl')
assert record.view_life(alex) == ['girl']

# Create event notification
reader = NotificationLogReader(record.log)
notifications = list(reader.read(start=1))
assert len(notifications) == 5
print(notifications)
for notification in notifications:
print(notification_to_table(notification))


main()

13 changes: 13 additions & 0 deletions python/eventsourcing_examples/non_eventsourcing_example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class World():
def __init__(self):
self.history = []

def add_to_history(self, something):
self.history.append(something)


world = World()
assert world.history == []

world.add_to_history('something')
assert world.history == ['something']
1 change: 1 addition & 0 deletions python/eventsourcing_examples/plan.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[[], ]
46 changes: 46 additions & 0 deletions statistics/bayesian_example/Bayesian.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "6deefa06",
"metadata": {},
"source": [
"Question: "
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.1"
},
"toc": {
"base_numbering": 1,
"nav_menu": {},
"number_sections": true,
"sideBar": true,
"skip_h1_title": false,
"title_cell": "Table of Contents",
"title_sidebar": "Contents",
"toc_cell": false,
"toc_position": {},
"toc_section_display": true,
"toc_window_display": false
}
},
"nbformat": 4,
"nbformat_minor": 5
}

0 comments on commit ed773a8

Please sign in to comment.