Skip to content

Commit 9e3c658

Browse files
author
ci bot
committed
Merge branch 'fix-duplicated-results' into 'enterprise'
fix(scoring): flush empty list of results and breakdown items See merge request dkinternal/testgen/dataops-testgen!221
2 parents 0e8def5 + 8aa4236 commit 9e3c658

4 files changed

Lines changed: 17 additions & 6 deletions

File tree

testgen/commands/run_refresh_score_cards_results.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import logging
33
import time
44

5-
from testgen.common.models import with_database_session
5+
from testgen.common.models import get_current_session, with_database_session
66
from testgen.common.models.scores import (
77
SCORE_CATEGORIES,
88
ScoreCard,
@@ -36,6 +36,7 @@ def run_refresh_score_cards_results(
3636
LOG.exception("CurrentStep: Stopping scorecards results refresh after unexpected error")
3737
return
3838

39+
db_session = get_current_session()
3940
for definition in definitions:
4041
LOG.info(
4142
"CurrentStep: Refreshing results for scorecard %s in project %s",
@@ -45,6 +46,10 @@ def run_refresh_score_cards_results(
4546

4647
try:
4748
fresh_score_card = definition.as_score_card()
49+
definition.results = []
50+
definition.breakdown = []
51+
db_session.flush([definition])
52+
4853
definition.results = _score_card_to_results(fresh_score_card)
4954
definition.breakdown = _score_definition_to_results_breakdown(definition)
5055
if add_history_entry:

testgen/common/logs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def configure_logging(
3333

3434
file_handler = ConcurrentTimedRotatingFileHandler(
3535
get_log_full_path(),
36-
when="D",
36+
when="MIDNIGHT",
3737
interval=1,
3838
backupCount=int(settings.LOG_FILE_MAX_QTY),
3939
)

testgen/common/models/scores.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -361,17 +361,22 @@ def recalculate_scores_history(self) -> None:
361361
)
362362
overall_scores = get_current_session().execute(query).mappings().all()
363363
current_history: dict[tuple[datetime, str, str], ScoreDefinitionResultHistoryEntry] = {}
364-
for entry in self.history:
365-
current_history[(entry.last_run_time, entry.category,)] = entry
366-
367364
renewed_history: dict[tuple[datetime, str, str], float] = {}
365+
368366
for scores in overall_scores:
369367
renewed_history[(scores["last_run_time"], "score",)] = scores["score"]
370368
renewed_history[(scores["last_run_time"], "cde_score",)] = scores["cde_score"]
371369

370+
for entry in self.history:
371+
entry_key = (entry.last_run_time, entry.category,)
372+
if entry_key in renewed_history:
373+
current_history[entry_key] = entry
374+
372375
for key, entry in current_history.items():
373376
entry.score = renewed_history[key]
374377

378+
self.history = list(current_history.values())
379+
375380
def _get_raw_query_filters(self, cde_only: bool = False, prefix: str | None = None) -> list[str]:
376381
values_by_field = defaultdict(list)
377382
for filter_ in self.filters:

testgen/ui/views/score_explorer.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from datetime import datetime
12
from io import BytesIO
23
from typing import ClassVar
34

@@ -246,7 +247,7 @@ def save_score_definition(_) -> None:
246247
latest_run = max(
247248
profiling_queries.get_latest_run_date(project_code),
248249
test_run_queries.get_latest_run_date(project_code),
249-
key=lambda run: getattr(run, "run_time", 0),
250+
key=lambda run: getattr(run, "run_time", datetime.min),
250251
)
251252

252253
refresh_kwargs = {

0 commit comments

Comments
 (0)