Skip to content

Commit

Permalink
Merge branch 'score_tests_improvements' of https://github.com/mckinse…
Browse files Browse the repository at this point in the history
…y/vizro into score_tests_improvements
  • Loading branch information
l0uden committed Dec 27, 2024
2 parents 34a7ccf + 99d0fd7 commit d96a6e6
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 25 deletions.
1 change: 0 additions & 1 deletion .github/workflows/test-score-vizro-ai.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ jobs:
- python-version: "3.12"
hatch-env: all.py3.12


steps:
- uses: actions/checkout@v4

Expand Down
2 changes: 1 addition & 1 deletion vizro-ai/tests/score/prompts.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,4 @@
- The first column is empty.
- The second column is occupied by the area for card 2.
- The third column is occupied by the area for card 3.
"""
"""
58 changes: 35 additions & 23 deletions vizro-ai/tests/score/test_dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
from typing import Literal

import chromedriver_autoinstaller
import numpy as np
import pytest
import vizro.plotly.express as px
import numpy as np
from prompts import complex_prompt, easy_prompt, medium_prompt
from vizro import Vizro

from vizro_ai import VizroAI
from prompts import easy_prompt, medium_prompt, complex_prompt

df1 = px.data.gapminder()
df2 = px.data.stocks()
Expand Down Expand Up @@ -168,17 +168,34 @@ def logic( # noqa: PLR0912, PLR0915
{"score_name": "no_browser_console_errors_score", "weight": 0.1, "score": no_browser_console_errors},
{"score_name": "pages_score", "weight": 0.2, "score": sum(pages_exist) / len(pages_exist)},
{"score_name": "components_score", "weight": 0.1, "score": sum(components_num) / len(components_num)},
{"score_name": "component_types_score", "weight": 0.1, "score": sum(components_types_names) / len(components_types_names)},
{
"score_name": "component_types_score",
"weight": 0.1,
"score": sum(components_types_names) / len(components_types_names),
},
{"score_name": "controls_score", "weight": 0.1, "score": sum(controls_num) / len(controls_num)},
{"score_name": "controls_types_score", "weight": 0.1, "score": sum(controls_types_names) / len(controls_types_names)},
{
"score_name": "controls_types_score",
"weight": 0.1,
"score": sum(controls_types_names) / len(controls_types_names),
},
]

scores_values = np.array([score["score"] for score in scores])
weights = np.array([score["weight"] for score in scores])
weighted_score = np.average(scores_values, weights=weights)

# csv report creation
data_rows = [datetime.now(), vizro_type, branch, python_version, model_name, prompt_tier, prompt_text, weighted_score]
data_rows = [
datetime.now(),
vizro_type,
branch,
python_version,
model_name,
prompt_tier,
prompt_text,
weighted_score,
]
data_rows.extend(score["score"] for score in scores)

with open(f"{report_dir}/report_model_{model_name}_{vizro_type}.csv", "a", newline=""):
Expand All @@ -187,14 +204,15 @@ def logic( # noqa: PLR0912, PLR0915
first_line = csvfile.readline()
if not first_line:
header_rows = [
"timestamp",
"vizro_type",
"branch",
"python_version",
"model",
"prompt_tier",
"prompt_text",
"weighted_score"]
"timestamp",
"vizro_type",
"branch",
"python_version",
"model",
"prompt_tier",
"prompt_text",
"weighted_score",
]
header_rows.extend(score["score_name"] for score in scores)
writer.writerow(header_rows)
writer.writerow(data_rows)
Expand Down Expand Up @@ -224,7 +242,8 @@ def logic( # noqa: PLR0912, PLR0915
ids=[
"gpt-4o-mini",
"claude-3-5-sonnet-latest",
])
],
)
def test_easy_dashboard(dash_duo, model_name):
dashboard = VizroAI(model=model_name).dashboard([df1, df2], easy_prompt)

Expand Down Expand Up @@ -259,10 +278,7 @@ def test_easy_dashboard(dash_duo, model_name):


@pytest.mark.medium_dashboard
@pytest.mark.parametrize(
"model_name",
["gpt-4o-mini"],
ids=["gpt-4o-mini"])
@pytest.mark.parametrize("model_name", ["gpt-4o-mini"], ids=["gpt-4o-mini"])
def test_medium_dashboard(dash_duo, model_name):
dashboard = VizroAI(model=model_name).dashboard([df1, df2, df3], medium_prompt)

Expand Down Expand Up @@ -337,11 +353,7 @@ def test_complex_dashboard(dash_duo, model_name):
Component(type="graph"),
Component(type="graph"),
],
"controls": [
Control(type="filter"),
Control(type="filter"),
Control(type="filter")
],
"controls": [Control(type="filter"), Control(type="filter"), Control(type="filter")],
},
{
"components": [
Expand Down

0 comments on commit d96a6e6

Please sign in to comment.