Skip to content

Commit b534792

Browse files
committed
adding lost files
1 parent 2d63f58 commit b534792

15 files changed

+3844
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# flake8: noqa
2+
from .constructor import Constructor
3+
from .desc_stats import DescStatsW
4+
from .facade_creator import FacadeCreatorW
5+
from .heatmap import HeatmapW
6+
from .group_by import GroupByW
7+
from .aggregate import AggregateW
8+
from .dump_table import DumpPTableW
9+
from .join import JoinW
10+
from .multi_series import MultiSeriesW
11+
from .scatterplot import ScatterplotW
12+
from .columns import PColumnsW
13+
from .histogram import HistogramW
14+
from .iscaler import ScalerW
15+
__all__ = [
16+
"Constructor",
17+
"DescStatsW",
18+
"GroupByW",
19+
"AggregateW",
20+
"DumpPTableW",
21+
"JoinW",
22+
"MultiSeriesW",
23+
"ScatterplotW",
24+
"PColumnsW",
25+
"HistogramW",
26+
"ScalerW",
27+
"FacadeCreatorW",
28+
"HeatmapW"
29+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
multi_series_no_data = {
2+
"$schema": "https://vega.github.io/schema/vega-lite/v5.json",
3+
"height": 400,
4+
"width": 400,
5+
"description": "Multi series template",
6+
"data": {"name": "data"},
7+
"mark": "line",
8+
"encoding": {
9+
"x": {"field": "date", "type": "temporal"},
10+
"y": {"field": "level", "type": "quantitative"},
11+
"color": {"field": "symbol", "type": "nominal"}
12+
}
13+
}
14+
15+
16+
_static_scatterplot_no_data = {
17+
"$schema": "https://vega.github.io/schema/vega-lite/v5.json",
18+
"description": "A scatterplot template",
19+
"data": {"name": "data"},
20+
"mark": "point",
21+
"encoding": {
22+
"x": {"field": "xcol", "type": "quantitative"},
23+
"y": {"field": "ycol", "type": "quantitative"},
24+
"color": {"field": "tcol", "type": "nominal"},
25+
}
26+
}
27+
28+
scatterplot_no_data = {
29+
"$schema": "https://vega.github.io/schema/vega-lite/v5.json",
30+
"height": 400,
31+
"width": 400,
32+
"description": "A scatterplot template",
33+
"data": {"name": "data"},
34+
"mark": "point",
35+
"encoding": {
36+
}
37+
}
38+
39+
histogram1d_no_data = {
40+
"$schema": "https://vega.github.io/schema/vega-lite/v5.json",
41+
"height": 400,
42+
"width": 400,
43+
"description": "An histogram template",
44+
"data": {"name": "data"},
45+
"mark": "bar",
46+
"encoding": {
47+
}
48+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
from .utils import make_button, stage_register, VBoxTyped, TypedBase, amend_last_record, replay_next
2+
import ipywidgets as ipw
3+
import pandas as pd
4+
from progressivis.table.aggregate import Aggregate
5+
from progressivis.core import Sink, Module
6+
7+
from typing import Any as AnyType, Optional, List, Tuple, Dict, Callable
8+
9+
WidgetType = AnyType
10+
11+
12+
def get_flag_status(dt: str, op: str) -> bool:
13+
return dt in ("string", "datetime64") # op in type_op_mismatches.get(dt, set())
14+
15+
16+
class AggregateW(VBoxTyped):
17+
class Typed(TypedBase):
18+
hidden_sel: ipw.SelectMultiple
19+
grid: ipw.GridBox
20+
freeze_ck: ipw.Checkbox
21+
start_btn: ipw.Button
22+
23+
def init(self) -> None:
24+
self.hidden_cols: List[str] = []
25+
fncs = ["hide"] + list(Aggregate.registry.keys())
26+
self.all_functions = dict(zip(fncs, fncs))
27+
self.child.hidden_sel = ipw.SelectMultiple(
28+
options=self.hidden_cols,
29+
value=[],
30+
rows=5,
31+
description="❎",
32+
disabled=False,
33+
)
34+
self.child.hidden_sel.observe(self._selm_obs_cb, "value")
35+
self.visible_cols: List[str] = list(self.dtypes.keys())
36+
self.obs_flag = False
37+
self.info_cbx: Dict[Tuple[str, str], ipw.Checkbox] = {}
38+
self.child.grid = self.draw_matrix()
39+
self.child.freeze_ck = ipw.Checkbox(description="Freeze")
40+
self.child.start_btn = make_button(
41+
"Activate", cb=self._start_btn_cb, disabled=True
42+
)
43+
44+
def init_aggregate(self, compute: AnyType) -> Aggregate:
45+
s = self.input_module.scheduler()
46+
with s:
47+
aggr = Aggregate(compute=compute, scheduler=s)
48+
aggr.input.table = self.input_module.output[self.input_slot]
49+
sink = Sink(scheduler=s)
50+
sink.input.inp = aggr.output.result
51+
return aggr
52+
53+
def draw_matrix(self, ext_df: Optional[pd.DataFrame] = None) -> ipw.GridBox:
54+
lst: List[WidgetType] = [ipw.Label("")] + [
55+
ipw.Label(s) for s in self.all_functions.values()
56+
]
57+
width_ = len(lst)
58+
for col in sorted(self.visible_cols):
59+
col_type = self.dtypes[col]
60+
lst.append(ipw.Label(f"{col}:{col_type}"))
61+
for k in self.all_functions.keys():
62+
lst.append(self._info_checkbox(col, k, get_flag_status(col_type, k)))
63+
gb = ipw.GridBox(
64+
lst,
65+
layout=ipw.Layout(grid_template_columns=f"200px repeat({width_-1}, 70px)"),
66+
)
67+
return gb
68+
69+
def _info_checkbox(self, col: str, func: str, dis: bool) -> ipw.Checkbox:
70+
wgt = ipw.Checkbox(value=False, description="", disabled=dis, indent=False)
71+
self.info_cbx[(col, func)] = wgt
72+
wgt.observe(self._make_cbx_obs(col, func), "value")
73+
return wgt
74+
75+
def _start_btn_cb(self, btn: ipw.Button) -> None:
76+
compute = [
77+
(col, fnc)
78+
for ((col, fnc), ck) in self.info_cbx.items()
79+
if fnc != "hide" and ck.value
80+
]
81+
if self.child.freeze_ck.value:
82+
amend_last_record({'frozen': dict(compute=compute)})
83+
self.output_module = self.init_aggregate(compute)
84+
self.output_slot = "result"
85+
btn.disabled = True
86+
self.make_chaining_box()
87+
self.dag_running()
88+
89+
def run(self) -> None:
90+
content = self.frozen_kw
91+
self.output_module = self.init_aggregate(**content)
92+
self.output_slot = "result"
93+
self.dag_running()
94+
replay_next(self.carrier)
95+
96+
def _selm_obs_cb(self, change: AnyType) -> None:
97+
self.obs_flag = True
98+
cols = change["new"]
99+
for col in cols:
100+
self.hidden_cols.remove(col)
101+
self.visible_cols.append(col)
102+
self.child.hidden_sel.options = sorted(self.hidden_cols)
103+
self.child.grid = self.draw_matrix()
104+
105+
def _make_cbx_obs(self, col: str, func: str) -> Callable[[AnyType], None]:
106+
def _cbk(change: AnyType) -> None:
107+
if func == "hide":
108+
self.child.start_btn.disabled = True
109+
self.hidden_cols.append(col)
110+
self.visible_cols.remove(col)
111+
self.child.hidden_sel.options = sorted(self.hidden_cols)
112+
self.child.grid = self.draw_matrix()
113+
else:
114+
self.child.start_btn.disabled = False
115+
116+
return _cbk
117+
118+
def get_underlying_modules(self) -> List[Module]:
119+
return [self.output_module]
120+
121+
122+
stage_register["Aggregate"] = AggregateW

0 commit comments

Comments
 (0)