Skip to content

Commit

Permalink
merge
Browse files Browse the repository at this point in the history
  • Loading branch information
cabreraalex committed Sep 12, 2023
2 parents 7d2a07e + 230b016 commit cb3cffa
Show file tree
Hide file tree
Showing 124 changed files with 3,196 additions and 6,596 deletions.
19 changes: 1 addition & 18 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,23 +42,6 @@ jobs:
with:
path: "backend/zeno_backend/"

format-api:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: psf/black@stable
with:
options: "--check --verbose"
src: "zeno_api/zeno_api/"

lint-api:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: jpetrucciani/ruff-check@main
with:
path: "zeno_api/zeno_api/"

typecheck-python:
runs-on: ubuntu-latest
steps:
Expand All @@ -75,7 +58,7 @@ jobs:
python-version: 3.11

- name: Install Poetry
uses: snok/[email protected].3
uses: snok/[email protected].4
with:
virtualenvs-in-project: true
virtualenvs-path: ~/.virtualenvs
Expand Down
264 changes: 141 additions & 123 deletions backend/poetry.lock

Large diffs are not rendered by default.

13 changes: 7 additions & 6 deletions backend/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ homepage = "https://zenoml.com"
[tool.poetry.dependencies]
aiofiles = "^23.2.1"
cognitojwt = "^1.4.1"
fastapi = "0.103.0"
fastapi = "^0.103.1"
fastapi-cloudauth = "^0.4.3"
inquirer = "^3.1.2"
nest-asyncio = "^1.5.6"
pandas = "^2.0.0"
pandas = "^2.1.0"
pathos = "^0.3.1"
psycopg = "^3.1.10"
python = "^3.11"
Expand All @@ -25,13 +25,14 @@ uvicorn = "^0.23.2"
zeno-sliceline = "^0.0.1"
pyarrow = "^13.0.0"
sqlalchemy = "^2.0.20"
amplitude-analytics = "^1.1.3"

[tool.poetry.dev-dependencies]
black = "^23.3.0"
pre-commit = "^3.3.3"
black = "^23.9.1"
pre-commit = "^3.4.0"
pyright = "^1.1.323"
pytest = "^7.3.2"
ruff = "^0.0.286"
pytest = "^7.4.1"
ruff = "^0.0.287"

[build-system]
requires = ["poetry-core"]
Expand Down
12 changes: 12 additions & 0 deletions backend/zeno_backend/classes/chart.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,15 @@ def default(
object: a dict to be encoded by a JSON encoder and saved into the database.
"""
return o.__dict__


class ChartResponse(CamelModel):
"""Chart specification and data.
Parameters:
chart (Chart): The chart specification.
chart_data (str): The chart data in JSON string.
"""

chart: Chart
chart_data: str
6 changes: 6 additions & 0 deletions backend/zeno_backend/classes/filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ class Operation(str, Enum):
LTE = "LTE"
GTE = "GTE"
LIKE = "LIKE"
ILIKE = "ILIKE"
REGEX = "REGEX"

def literal(self) -> LiteralString:
"""Obtain a string representation to be used in a SQL filter.
Expand All @@ -35,6 +37,10 @@ def literal(self) -> LiteralString:
return ">="
if self == Operation.LTE:
return "<="
if self == Operation.ILIKE:
return "ILIKE"
if self == Operation.REGEX:
return "~"
return "LIKE"


Expand Down
8 changes: 5 additions & 3 deletions backend/zeno_backend/classes/metadata.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Type representations for metric data."""
from zeno_backend.classes.base import CamelModel, ZenoColumn
from zeno_backend.classes.filter import Operation
from zeno_backend.classes.metric import Metric
from zeno_backend.classes.slice import FilterPredicateGroup

Expand All @@ -9,6 +10,9 @@ class HistogramBucket(CamelModel):

bucket: float | bool | int | str
bucket_end: float | bool | int | str | None = None
size: int | None = None
filtered_size: int | None = None
metric: float | None = None


class HistogramColumnRequest(CamelModel):
Expand All @@ -33,6 +37,4 @@ class StringFilterRequest(CamelModel):

column: ZenoColumn
filter_string: str
is_regex: bool
case_match: bool
whole_word_match: bool
operation: Operation
27 changes: 26 additions & 1 deletion backend/zeno_backend/classes/project.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
"""Types for Zeno projects."""

from zeno_backend.classes.base import CamelModel
from zeno_backend.classes.base import CamelModel, ZenoColumn
from zeno_backend.classes.folder import Folder
from zeno_backend.classes.metric import Metric
from zeno_backend.classes.slice import Slice
from zeno_backend.classes.tag import Tag


class Project(CamelModel):
Expand Down Expand Up @@ -45,3 +48,25 @@ class ProjectStats(CamelModel):
num_instances: int
num_charts: int
num_models: int


class ProjectState(CamelModel):
"""State variables for a Zeno project.
Attributes:
project (Project): The project object with project metadata.
models (list[str]): The names of the models in the project.
metrics (list[Metric]): The metrics to calculate for the project.
columns (list[ZenoColumn]): The columns in the project.
slices (list[Slice]): The slices in the project.
tags (list[Tag]): The tags in the project.
folders (list[Folder]): The folders in the project.
"""

project: Project
models: list[str]
metrics: list[Metric]
columns: list[ZenoColumn]
slices: list[Slice]
tags: list[Tag]
folders: list[Folder]
1 change: 1 addition & 0 deletions backend/zeno_backend/classes/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class TableRequest(CamelModel):
"""A request specification for table data."""

columns: list[ZenoColumn]
model: str | None = None
diff_column_1: ZenoColumn | None = None
diff_column_2: ZenoColumn | None = None
offset: int
Expand Down
67 changes: 50 additions & 17 deletions backend/zeno_backend/database/insert.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,12 +279,20 @@ def system(

with Database() as db:
for col in columns:
data_type = db.execute_return(
sql.SQL(
"SELECT data_type FROM information_schema.columns WHERE "
"table_schema = 'public' AND table_name = 'tmp' AND "
"column_name = {};"
).format(sql.Literal(col.id))
)

db.execute(
sql.SQL("ALTER TABLE {} ADD {}{};").format(
sql.SQL("ALTER TABLE {} ADD {} ").format(
sql.Identifier(project),
sql.Identifier(col.id),
sql.Literal(col.data_type),
)
+ sql.SQL(data_type[0][0] + ";"),
)
db.execute(
sql.SQL(
Expand Down Expand Up @@ -322,96 +330,121 @@ def report(name: str, user: User):
)


def folder(project: str, name: str):
def folder(project: str, name: str) -> int | None:
"""Adding a folder to an existing project.
Args:
project (str): the project the user is currently working with.
name (str): name of the folder to be added.
Returns:
int | None: the id of the newly created folder.
"""
db = Database()
db.connect_execute(
"INSERT INTO folders (name, project_uuid) VALUES (%s,%s);",
id = db.connect_execute_return(
"INSERT INTO folders (name, project_uuid) VALUES (%s,%s) RETURNING id;",
[name, project],
)
if id is not None and len(id) > 0:
return id[0][0]


def slice(project: str, req: Slice):
def slice(project: str, req: Slice) -> int | None:
"""Add a slice to an existing project.
Args:
project (str): the project the user is currently working with.
req (Slice): the slice to be added to the project.
Returns:
int | None: the id of the newly created slice.
"""
db = Database()
db.connect_execute(
ids = db.connect_execute_return(
"INSERT INTO slices (name, folder_id, filter, project_uuid) "
"VALUES (%s,%s,%s,%s);",
"VALUES (%s,%s,%s,%s) RETURNING id;",
[
req.slice_name,
req.folder_id,
json.dumps(req.filter_predicates, cls=PredicatesEncoder),
project,
],
)
if ids is not None:
return ids[0][0]
else:
return None


def chart(project: str, chart: Chart):
def chart(project: str, chart: Chart) -> int | None:
"""Add a chart to an existing project.
Args:
project (str): the project the user is currently working with.
chart (Chart): the chart to be added to the project.
Returns:
int | None: the id of the newly created chart.
"""
db = Database()
db.connect_execute(
id = db.connect_execute_return(
"INSERT INTO charts (name, type, parameters, project_uuid) "
"VALUES (%s,%s,%s,%s);",
"VALUES (%s,%s,%s,%s) RETURNING id;",
[
chart.name,
chart.type,
json.dumps(chart.parameters, cls=ParametersEncoder),
project,
],
)
if id is not None and len(id) > 0:
return id[0][0]


def tag(project: str, tag: Tag):
def tag(project: str, tag: Tag) -> int | None:
"""Add a tag to an existing project.
Args:
project (str): the project the user is currently working with.
tag (Tag): the tag to be added to the project.
Returns:
int | None: the id of the newly created tag.
"""
with Database() as db:
id = db.execute_return(
"INSERT INTO tags (name, folder_id, project_uuid) VALUES (%s,%s,%s) "
"RETURNING id;",
[tag.tag_name, tag.folder_id, project],
)
if id is None:
if id is None or len(id) == 0:
return
for datapoint in tag.data_ids:
db.execute(
sql.SQL("INSERT INTO {} (tag_id, data_id) VALUES (%s,%s);").format(
sql.Identifier(f"{project}_tags_datapoints")
),
[id[0], datapoint],
[id[0][0], datapoint],
)
db.commit()
return id[0][0]


def user(user: User):
def user(user: User) -> int | None:
"""Add a new user to the database.
Args:
user (User): the user to be added.
"""
db = Database()
db.connect_execute(
'INSERT INTO users ("name") values(%s)',
id = db.connect_execute_return(
'INSERT INTO users ("name") values(%s) RETURNING id;',
[user.name],
)
if id is not None:
return id[0][0]


def organization(user: User, organization: Organization):
Expand Down
Loading

0 comments on commit cb3cffa

Please sign in to comment.