Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a directory for projects built with moose to the mono-repo #1760

Merged
merged 5 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions built-with-moose-projects/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
In this directory we have some of the projects — in Python and Typescript — we've built with Moose. From proptypes built on the weekend to production grade 100TB/day observability-as-a-service products, if data ingestion, transformation and exploration is at the core of your project, Moose makes your developer life 10x more productive and easy.

Feel free to browse, comment and if/when you build something (awesome!) with Moose, we'd love to add a link to the repo here to share with the community. Join us on [slack](https://join.slack.com/t/moose-community/shared_invite/zt-2fjh5n3wz-cnOmM9Xe9DYAgQrNu8xKxg), and we'd be happy to roll up our sleeves and support you at any phase while you build. We're data nerds and builders — so you'd be in good company.

— 514/Moose Core Team
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"recommendations": [
"frigus02.vscode-sql-tagged-template-literals-syntax-only",
"mtxr.sqltools",
"ultram4rine.sqltools-clickhouse-driver",
"jeppeandersen.vscode-kafka",
"rangav.vscode-thunder-client"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"sqltools.connections": [
{
"server": "localhost",
"port": 18123,
"useHTTPS": false,
"database": "local",
"username": "panda",
"enableTls": false,
"password": "pandapass",
"driver": "ClickHouse",
"name": "moose clickhouse"
}
],
"python.analysis.extraPaths": [".moose/versions"]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
TODO: Link to the tutorial when the python version is complete
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
def run(client, params):
limit = int(params.get('limit', [10])[0])
return client.query(
''' SELECT
language,
COUNT(DISTINCT user) AS number_of_users
FROM userLanguages
GROUP BY
language
ORDER BY
number_of_users DESC
LIMIT {limit}
''',
{
"limit": limit
}
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
from dataclasses import dataclass
from typing import List

@dataclass
class Blocks:
teardown: List[str]
setup: List[str]

# Define the SQL queries for setup and teardown
setup_queries = [
"""
CREATE VIEW userLanguages AS
SELECT DISTINCT
username AS user,
arrayFirst(x->x IS NOT NULL, language_object.language) AS language,
arrayFirst(x->x IS NOT NULL, language_object.bytes) AS bytes
FROM
local.ProcessedStarEvent_0_0
ARRAY JOIN
languages AS language_object
"""
]

teardown_queries = [
"DROP VIEW userLanguages"
]

# Create the block with setup and teardown queries
block = Blocks(teardown=teardown_queries, setup=setup_queries)
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
from moose_lib import Key
from dataclasses import dataclass
from datetime import date
from typing import Optional

@dataclass
class Sender:
login: Key[str]
repos_url: str

# @dataclass
# class Repository:
# html_url: str
# url: str

@dataclass
class RawStarEvent:
starred_at: Optional[str]
action: Key[str]
sender: Sender
# repository: Repository

@dataclass
class LanguageCount:
language: Key[str]
bytes: int

@dataclass
class ProcessedStarEvent:
starred_at: Key[str]
username: str
languages: list[LanguageCount]
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@

# Add your models & start the development server to import these types
from app.datamodels.models import RawStarEvent, ProcessedStarEvent, LanguageCount

from moose_lib import StreamingFunction
from typing import Optional
from datetime import datetime
import requests
import os

def fn(source: RawStarEvent) -> Optional[ProcessedStarEvent]:
if source.starred_at is None:
return None
print('source.sender', source.sender)
languages = get_user_language(source.sender['repos_url'])
print(languages)

return ProcessedStarEvent(
starred_at=source.starred_at,
username=source.sender['login'],
languages=languages,
)

my_function = StreamingFunction(
run=fn
)

def get_user_language(repo_url: str) -> list[LanguageCount]:
print('get_user_language', repo_url)
repositories = call_github_api(repo_url)
print('repositories', repositories)
# Dictionary to store language counts
language_counts = []
for repo in repositories:
# Calls the API per repository to get language counts
languages = call_github_api(repo['languages_url'])
print(languages)
for language, count in languages.items():
# Sum the counts for each language
language_counts.append(LanguageCount(language=language, bytes=count))
return language_counts

def call_github_api(url: str) -> dict:
response = requests.get(url, auth=('Bearer token ', os.environ['GITHUB_TOKEN']))
return response.json()
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
language = "Python"

[redpanda_config]
broker = "localhost:19092"
message_timeout_ms = 1000
retention_ms = 30000
replication_factor = 1

[clickhouse_config]
db_name = "local"
user = "panda"
password = "pandapass"
use_ssl = false
host = "localhost"
host_port = 18123
native_port = 9000

[http_server_config]
host = "localhost"
port = 4000
management_port = 5000

[git_config]
main_branch_name = "main"

[supported_old_versions]
14 changes: 14 additions & 0 deletions built-with-moose-projects/github-star-analytics-python/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

from setuptools import setup

setup(
name='github-star-analytics-python',
version='0.0',
install_requires=[
"kafka-python-ng==2.2.2",
"clickhouse_connect==0.7.16",
"requests==2.32.3",
"moose-cli",
"moose-lib",
],
)