def test_scatterplot2(self):
     s = self.scheduler()
     random = RandomTable(2, rows=2000000, scheduler=s)
     sp = MCScatterPlot(scheduler=s,
                        classes=[('Scatterplot', '_1', '_2')],
                        approximate=True)
     sp.create_dependent_modules(random, 'table', with_sampling=False)
     cnt = Every(proc=self.terse, constant_time=True, scheduler=s)
     cnt.input.df = random.output.table
     prt = Print(proc=self.terse, scheduler=s)
     prt.input.df = sp.output.table
     decorate(s, VariablePatch1("variable_1"))
     decorate(s, VariablePatch2("variable_2"))
     decorate(s, ScatterPlotPatch("mc_scatter_plot_1"))
     sp.scheduler().start(idle_proc=idle_proc)
     s.join()
     js = sp.to_json()
     x, y, _ = zip(*js['sample']['data'])
     min_x = min(x)
     max_x = max(x)
     min_y = min(y)
     max_y = max(y)
     self.assertGreaterEqual(min_x, LOWER_X)
     self.assertGreaterEqual(min_y, LOWER_Y)
     self.assertLessEqual(max_x, UPPER_X)
     self.assertLessEqual(max_y, UPPER_Y)
    def test_scatterplot2(self) -> None:
        s = self.scheduler(clean=True)
        with s:
            random = RandomTable(2, rows=2000000, throttle=1000, scheduler=s)
            sp = MCScatterPlot(scheduler=s,
                               classes=[("Scatterplot", "_1", "_2")],
                               approximate=True)
            sp.create_dependent_modules(random, "result", with_sampling=False)
            cnt = Every(proc=self.terse, constant_time=True, scheduler=s)
            cnt.input[0] = random.output.result
            prt = Print(proc=self.terse, scheduler=s)
            prt.input[0] = sp.output.result

        async def fake_input_1(scheduler: Scheduler, rn: int) -> None:
            module = scheduler["dyn_var_1"]
            print("from input dyn_var_1")
            await module.from_input({"x": LOWER_X, "y": LOWER_Y})

        async def fake_input_2(scheduler: Scheduler, rn: int) -> None:
            module = scheduler["dyn_var_2"]
            print("from input dyn_var_2")
            await module.from_input({"x": UPPER_X, "y": UPPER_Y})

        # finp1 = fake_input(s, "dyn_var_1", 6, {"x": LOWER_X, "y": LOWER_Y})
        # finp2 = fake_input(s, "dyn_var_2", 6, {"x": UPPER_X, "y": UPPER_Y})
        # sts = sleep_then_stop(s, 10)
        s.on_loop(self._stop, 10)
        # s.on_loop(prt)
        s.on_loop(fake_input_1, 3)
        s.on_loop(fake_input_2, 3)
        # aio.run_gather(sp.scheduler().start(), sts)
        aio.run(s.start())
        js = sp.to_json()
        x, y, _ = zip(*js["sample"]["data"])
        min_x = min(x)
        max_x = max(x)
        min_y = min(y)
        max_y = max(y)
        self.assertGreaterEqual(min_x, LOWER_X)
        self.assertGreaterEqual(min_y, LOWER_Y)
        self.assertLessEqual(max_x, UPPER_X)
        self.assertLessEqual(max_y, UPPER_Y)
]

FILENAMES = pd.DataFrame({'filename': URLS})
CST = Constant(Table('filenames', data=FILENAMES), scheduler=s)
CSV = CSVLoader(index_col=False,
                skipinitialspace=True,
                usecols=['pickup_longitude', 'pickup_latitude'],
                filter_=_filter,
                scheduler=s)

CSV.input.filenames = CST.output.table
PR = Every(scheduler=s)
PR.input.df = CSV.output.table
SCATTERPLOT = MCScatterPlot(scheduler=s,
                            classes=[('Scatterplot', 'pickup_longitude',
                                      'pickup_latitude')],
                            approximate=True)
SCATTERPLOT.create_dependent_modules(CSV, 'table')
s.set_interaction_opts(starving_mods=SCATTERPLOT.get_starving_mods(),
                       max_iter=3,
                       max_time=1.5)
if __name__ == '__main__':
    s.start()
    while True:
        time.sleep(2)
        s.to_json()
        SCATTERPLOT.to_json()  # simulate a web query
        #SCATTERPLOT.get_image()
    s.join()
    print(len(CSV.table()))
CSV = CSVLoader(index_col=False,
                skipinitialspace=True,
                usecols=[
                    'pickup_longitude', 'pickup_latitude', 'dropoff_longitude',
                    'dropoff_latitude'
                ],
                filter_=_filter,
                scheduler=s)  # TODO: reimplement filter in read_csv.py

CSV.input.filenames = CST.output.table
PR = Every(scheduler=s)
PR.input.df = CSV.output.table
MULTICLASS = MCScatterPlot(scheduler=s,
                           classes=[('pickup', 'pickup_longitude',
                                     'pickup_latitude'),
                                    ('dropoff', 'dropoff_longitude',
                                     'dropoff_latitude')],
                           approximate=True)
MULTICLASS.create_dependent_modules(CSV, 'table')
s.set_interaction_opts(starving_mods=MULTICLASS.get_starving_mods(),
                       max_iter=3,
                       max_time=1.5)
if __name__ == '__main__':
    s.start()
    while True:
        time.sleep(2)
        s.to_json()
        MULTICLASS.to_json()  # simulate a web query
    s.join()
    print(len(CSV.table()))