Exemplo n.º 1
0
    def process(self, data):
        frame = {'summary': {}, 'props':  self.props, 'data': data}

        # thread_last(frame, *self.filters)
        # thread_last(frame, *self.analyzers)
        # thread_last(frame, *self.loggers)
        thread_last(frame, *self.ops)
        return frame
Exemplo n.º 2
0
 def generate_slices(self, qn, response, vars=[], filt={}):
     # create the overall filter
     filt_fmla = u.fmla_for_filt(filt)
     # subset the rdf as necessary
     subs = subset_des_wexpr(self.rdf,
                             filt_fmla) if len(filt) > 0 else self.rdf
     # create a formula for generating the cross-tabs/breakouts across
     #   the selected vars
     lvl_f = Formula('~%s' % ' + '.join(vars)) if len(vars) > 0 else None
     # generate the crosstab/breakouts for the selected vars,
     #   turn them into R selector expressions and concatenate
     #   each non-empty selector with the R selector for the outer filter
     calls = thread_first(
         rstats.xtabs(lvl_f, subs), rbase.as_data_frame, pandas2ri.ri2py,
         (pd.DataFrame.query, "Freq > 0"),
         (pd.DataFrame.get,
          vars), lambda df: df.apply(lambda z: thread_last(
              z.to_dict(),
              lambda y: [(v, y[v]) for v in vars],
              list,
              lambda x: [tuple(x[:i + 1]) for i in range(len(x))],
          ),
                                     axis=1),
         (pd.DataFrame.to_records, False), list, concat, set, map(dict),
         list) if len(vars) > 0 else []
     # setup the formula based on the qn and response
     # add the base case with empty slice filter
     #   and dicts of qn/resp fmla, slice selector fmla, filt fmla
     res = [{
         'q': qn,
         'r': response,
         'f': filt,
         's': s
     } for s in [{}, *calls]]
     return res
Exemplo n.º 3
0
def test_thread_last():
    assert list(thread_last([1, 2, 3], (map, inc), (filter, iseven))) == [2, 4]
    assert list(thread_last([1, 2, 3], (map, inc), (filter, isodd))) == [3]
    assert thread_last(2, (add, 5), double) == 14
Exemplo n.º 4
0
def test_thread_last():
    assert list(thread_last([1, 2, 3], (map, inc), (filter, even))) == [2, 4]
Exemplo n.º 5
0
def _parse_obstacles_str(s):
    return tzf.thread_last(s.split(';'),
                           (map, _parse_map_str),
                           (filter, None),
                           list)
Exemplo n.º 6
0
def _output_actions_filepath(desc_path):
    desc_name = tzf.thread_last(desc_path,
                                os.path.basename,
                                os.path.splitext)[0]
    return './data/output/{}.sol'.format(desc_name)
Exemplo n.º 7
0
def _output_image_dir(desc_path):
    desc_name = tzf.thread_last(desc_path,
                                os.path.basename,
                                os.path.splitext)[0]
    return os.path.join('./data/output', desc_name, 'imgs')
Exemplo n.º 8
0
def _parse_map_str(map_str):
    return tzf.thread_last(re.findall(_point_pattern(), map_str),
                           (map, lambda p: tuple(int(x) for x in p)),
                           list)
Exemplo n.º 9
0
def test_thread_last():
    assert list(thread_last([1, 2, 3], (map, inc), (filter, iseven))) == [2, 4]