Skip to content

Commit

Permalink
add key for plotly_chart
Browse files Browse the repository at this point in the history
Signed-off-by: min.tian <[email protected]>
  • Loading branch information
alwayslove2013 committed Oct 28, 2024
1 parent 51390b7 commit 56e5a47
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
15 changes: 9 additions & 6 deletions vectordb_bench/frontend/components/check_results/charts.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from vectordb_bench.backend.cases import Case
from vectordb_bench.frontend.components.check_results.expanderStyle import initMainExpanderStyle
from vectordb_bench.frontend.components.check_results.expanderStyle import (
initMainExpanderStyle,
)
from vectordb_bench.metric import metricOrder, isLowerIsBetterMetric, metricUnitMap
from vectordb_bench.frontend.config.styles import *
from vectordb_bench.models import ResultLabel
Expand All @@ -11,7 +13,7 @@ def drawCharts(st, allData, failedTasks, caseNames: list[str]):
for caseName in caseNames:
chartContainer = st.expander(caseName, True)
data = [data for data in allData if data["case_name"] == caseName]
drawChart(data, chartContainer)
drawChart(data, chartContainer, key_prefix=caseName)

errorDBs = failedTasks[caseName]
showFailedDBs(chartContainer, errorDBs)
Expand All @@ -35,15 +37,16 @@ def showFailedText(st, text, dbs):
)


def drawChart(data, st):
def drawChart(data, st, key_prefix: str):
metricsSet = set()
for d in data:
metricsSet = metricsSet.union(d["metricsSet"])
showMetrics = [metric for metric in metricOrder if metric in metricsSet]

for i, metric in enumerate(showMetrics):
container = st.container()
drawMetricChart(data, metric, container)
key = f"{key_prefix}-{metric}"
drawMetricChart(data, metric, container, key=key)


def getLabelToShapeMap(data):
Expand Down Expand Up @@ -75,7 +78,7 @@ def getLabelToShapeMap(data):
return labelToShapeMap


def drawMetricChart(data, metric, st):
def drawMetricChart(data, metric, st, key: str):
dataWithMetric = [d for d in data if d.get(metric, 0) > 1e-7]
# dataWithMetric = data
if len(dataWithMetric) == 0:
Expand Down Expand Up @@ -161,4 +164,4 @@ def drawMetricChart(data, metric, st):
),
)

chart.plotly_chart(fig, use_container_width=True)
chart.plotly_chart(fig, use_container_width=True, key=key)
18 changes: 13 additions & 5 deletions vectordb_bench/frontend/pages/quries_per_dollar.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
import streamlit as st
from vectordb_bench.frontend.components.check_results.footer import footer
from vectordb_bench.frontend.components.check_results.expanderStyle import initMainExpanderStyle
from vectordb_bench.frontend.components.check_results.expanderStyle import (
initMainExpanderStyle,
)
from vectordb_bench.frontend.components.check_results.priceTable import priceTable
from vectordb_bench.frontend.components.check_results.stPageConfig import initResultsPageConfig
from vectordb_bench.frontend.components.check_results.stPageConfig import (
initResultsPageConfig,
)
from vectordb_bench.frontend.components.check_results.headerIcon import drawHeaderIcon
from vectordb_bench.frontend.components.check_results.nav import NavToResults, NavToRunTest
from vectordb_bench.frontend.components.check_results.nav import (
NavToResults,
NavToRunTest,
)
from vectordb_bench.frontend.components.check_results.charts import drawMetricChart
from vectordb_bench.frontend.components.check_results.filters import getshownData
from vectordb_bench.frontend.components.get_results.saveAsImage import getResults
Expand All @@ -16,7 +23,7 @@
def main():
# set page config
initResultsPageConfig(st)

# header
drawHeaderIcon(st)

Expand Down Expand Up @@ -57,7 +64,8 @@ def main():
dataWithMetric.append(d)
if len(dataWithMetric) > 0:
chartContainer = st.expander(caseName, True)
drawMetricChart(data, metric, chartContainer)
key = f"{caseName}-{metric}"
drawMetricChart(data, metric, chartContainer, key=key)

# footer
footer(st.container())
Expand Down

0 comments on commit 56e5a47

Please sign in to comment.