Improve interactive hello world example
Change-Id: Id0adbe60b347a9badd6f1f80625511dc26b26118
diff --git a/examples/hello_world_interactive.py b/examples/hello_world_interactive.py
index edc5662..f93e799 100755
--- a/examples/hello_world_interactive.py
+++ b/examples/hello_world_interactive.py
@@ -1,33 +1,31 @@
#!/usr/bin/env python3
import altair as alt
-
+import pandas as pd
from KorAPClient import KorAPClient, KorAPConnection
QUERY = "Hello World"
YEARS = range(2010, 2019)
COUNTRIES = ["DE", "CH"]
+df = pd.DataFrame(YEARS, columns=["Year"], dtype=str).merge(pd.DataFrame(COUNTRIES, columns=["Country"]), how="cross")
+df["vc"] = "textType=/Zeit.*/ & pubPlaceKey = " + df.Country + " & pubDate in " + df.Year
+
kcon = KorAPConnection(verbose=True)
-vcs = [f"textType=/Zeit.*/ & pubPlaceKey={c} & pubDate in {y}" for c in COUNTRIES for y in YEARS]
-df = KorAPClient.ipm(kcon.frequencyQuery(QUERY, vcs))
-print(df)
-
-df['Year'] = [y for c in COUNTRIES for y in YEARS]
-df['Country'] = [c for c in COUNTRIES for y in YEARS]
+df = KorAPClient.ipm(kcon.frequencyQuery(QUERY, df.vc)).merge(df)
df['tooltip'] = "ctrl+click to open concordances in new tab"
band = alt.Chart(df).mark_errorband().encode(
- y=alt.Y("conf.low", title=""),
+ y=alt.Y("conf.low", title="ipm"),
y2="conf.high",
- x="Year",
+ x="Year:T",
color="Country",
tooltip=["Country", "Year", alt.Tooltip("ipm", format=".2f")]
)
line = alt.Chart(df).mark_line(point=True).encode(
y="ipm",
- x="Year",
+ x="Year:T",
color="Country",
href="webUIRequestUrl",
tooltip="tooltip"