Skip to content

Commit

Permalink
Merge pull request #62 from semiotic-ai/add-version-to-comment
Browse files Browse the repository at this point in the history
Added version to the top of the aa model
  • Loading branch information
aasseman authored May 11, 2023
2 parents 94659a6 + 9e4f001 commit 7719edb
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 2 deletions.
1 change: 0 additions & 1 deletion .gcloudignore
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
#!include:.gitignore
.git
4 changes: 3 additions & 1 deletion autoagora/model_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import asyncio as aio
import logging
from importlib.metadata import version

import asyncpg
import graphql
Expand All @@ -15,7 +16,8 @@
async def model_builder(subgraph: str, pgpool: asyncpg.Pool) -> str:
logs_db = LogsDB(pgpool)
agora_entries = []

aa_version = version("autoagora")
agora_entries += [f"# Generated by AutoAgora {aa_version}"]
most_frequent_queries = await logs_db.get_most_frequent_queries(subgraph)

for frequent_query in most_frequent_queries:
Expand Down
49 changes: 49 additions & 0 deletions tests/test_model_builder.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import random
import re
import string
from math import exp, log
from unittest import mock
from unittest.mock import patch

import asyncpg
import pytest
from numpy.testing import assert_approx_equal

from autoagora import model_builder
from autoagora.logs_db import LogsDB


class TestModelBuilder:
@pytest.fixture
async def pgpool(self, postgresql):
pool = await asyncpg.create_pool(
host=postgresql.info.host,
database=postgresql.info.dbname,
user=postgresql.info.user,
password=postgresql.info.password,
port=postgresql.info.port,
)
assert pool
yield pool
await pool.close()

async def test_build_model(self, pgpool):
with mock.patch(
"autoagora.logs_db.LogsDB.get_most_frequent_queries"
) as mock_get_mfq:
mock_get_mfq.return_value = [
LogsDB.QueryStats(
query="query getData{ values { id } }",
count=100,
min_time=1,
max_time=60,
avg_time=1.2,
stddev_time=0.5,
)
]
model = await model_builder.model_builder(
"Qmadj8x9km1YEyKmRnJ6EkC2zpJZFCfTyTZpuqC3j6e1QH", pgpool
)
pattern = r"# Generated by AutoAgora \d+\.\d+\.\d+"
# To ensure a version is being obtained
assert re.match(pattern, model), f"{model} does not match pattern {pattern}"

0 comments on commit 7719edb

Please sign in to comment.