Skip to content

Commit

Permalink
fix(overview): set default value for pandas null
Browse files Browse the repository at this point in the history
  • Loading branch information
luis-dk committed Nov 26, 2024
1 parent 3a15652 commit 00d267a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 13 deletions.
12 changes: 7 additions & 5 deletions testgen/ui/components/frontend/js/pages/overview.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
*/
import van from '../van.min.js';
import { Streamlit } from '../streamlit.js';
import { emitEvent, getValue, loadStylesheet, friendlyPercent } from '../utils.js';
import { emitEvent, getValue, loadStylesheet, friendlyPercent, resizeFrameHeightToElement } from '../utils.js';
import { formatTimestamp } from '../display_utils.js';
import { Card } from '../components/card.js';
import { Caption } from '../components/caption.js';
Expand All @@ -83,7 +83,6 @@ const { div, h3, hr, span, strong } = van.tags;
const Overview = (/** @type Properties */ props) => {
loadStylesheet('overview', stylesheet);
Streamlit.setFrameHeight(1);
window.frameElement.style.setProperty('height', 'calc(100vh - 200px)');
window.testgen.isPage = true;

const isEmpty = van.derive(() => {
Expand All @@ -106,12 +105,15 @@ const Overview = (/** @type Properties */ props) => {

van.derive(() => {
const sortByField = getValue(tableGroupsSortOption);
const sortFn = sortFunctions[sortByField] ?? sortFunctions.latest_activity_date
filteredTableGroups.val = getValue(filteredTableGroups).sort(sortFn);
const sortFn = sortFunctions[sortByField] ?? sortFunctions.latest_activity_date;
filteredTableGroups.val = Array.from(getValue(filteredTableGroups).sort(sortFn));
});

const wrapperId = 'overview-wrapper';
resizeFrameHeightToElement(wrapperId);

return div(
{ class: 'flex-column tg-overview' },
{ id: wrapperId, class: 'flex-column tg-overview' },
() => !getValue(isEmpty)
? div(
{ class: 'flex-row fx-align-stretch fx-gap-4' },
Expand Down
25 changes: 17 additions & 8 deletions testgen/ui/views/overview.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

STALE_PROFILE_DAYS = 30
PAGE_ICON = "home"
T = typing.TypeVar("T")


class OverviewPage(Page):
Expand All @@ -30,7 +31,7 @@ def render(self, project_code: str | None = None, **_kwargs):
)

project_code = project_code or session.project
table_groups_df: pd.DataFrame = get_table_groups_summary(project_code)
table_groups = get_table_groups_summary(project_code)
project_summary_df = project_queries.get_summary_by_code(project_code)

table_groups_fields: list[str] = [
Expand Down Expand Up @@ -76,9 +77,9 @@ def render(self, project_code: str | None = None, **_kwargs):
"overview",
props={
"project": {
"table_groups_count": len(table_groups_df.index),
"test_suites_count": int(table_groups_df["latest_tests_suite_ct"].sum()),
"test_definitions_count": int(table_groups_df["latest_tests_ct"].sum()),
"table_groups_count": len(table_groups.index),
"test_suites_count": int(table_groups["latest_tests_suite_ct"].sum()),
"test_definitions_count": int(table_groups["latest_tests_ct"].sum()),
"test_runs_count": int(project_summary_df["test_runs_ct"]),
"profiling_runs_count": int(project_summary_df["profiling_runs_ct"]),
"connections_count": int(project_summary_df["connections_ct"]),
Expand All @@ -96,7 +97,7 @@ def render(self, project_code: str | None = None, **_kwargs):
"dq_score_profiling": friendly_score(table_group["dq_score_profiling"]),
"dq_score_testing": friendly_score(table_group["dq_score_testing"]),
}
for _, table_group in table_groups_df.iterrows()
for _, table_group in table_groups.iterrows()
if (table_group_id := str(table_group["id"]))
],
"table_groups_sort_options": [
Expand Down Expand Up @@ -125,6 +126,8 @@ def format_field(field: typing.Any) -> typing.Any:
return str(field)
elif isinstance(field, pd.Timestamp):
return field.value / 1_000_000
elif pd.isnull(field):
return None
return field


Expand Down Expand Up @@ -266,19 +269,25 @@ def get_table_groups_summary(project_code: str) -> pd.DataFrame:
LEFT JOIN latest_tests ON (groups.id = latest_tests.table_groups_id)
WHERE groups.project_code = '{project_code}';
"""

return db.retrieve_data(sql)


def score(profiling_score: float, tests_score: float) -> float:
final_score = profiling_score or tests_score or 0
final_score = _pandas_default(profiling_score, 0.0) or _pandas_default(tests_score, 0.0) or 0.0
if profiling_score and tests_score:
final_score = (profiling_score * tests_score) / 100

return final_score


def _pandas_default(value: typing.Any, default: T) -> T:
if pd.isnull(value):
return default
return value


def friendly_score(score: float) -> str:
if not score:
if not score or pd.isnull(score):
return "--"

prefix = ""
Expand Down

0 comments on commit 00d267a

Please sign in to comment.