Пример #1
0
    def load_subscription_details(self):
        all_subscriptions = frappe.db.sql(
            """
                SELECT
                    si.outstanding_amount AS amount,
                    si.status AS status,
                    gs.to_date AS end_date
                FROM `tabGym Subscription` AS gs, `tabSales Invoice` AS si
                WHERE
                    gs.docstatus = 1 AND
                    gs.member = '{member}' AND
                    gs.reference_invoice = si.name
                ORDER BY gs.from_date DESC
            """.format(member=self.name),
            as_dict=True,
        )
        unpaid_subscriptions = filter(lambda x: x.get('status') != 'Paid',
                                      all_subscriptions)
        outstanding = reduce(operator.add, pluck('amount',
                                                 unpaid_subscriptions), 0)

        self.set_onload(
            'subscription_details', {
                'total_invoices': count(all_subscriptions),
                'unpaid_invoices': count(unpaid_subscriptions),
                'outstanding': outstanding,
            })
        self.set_onload('subscriptions', get_currents(self.name))
Пример #2
0
    def load_subscription_details(self):
        all_subscriptions = frappe.db.sql(
            """
                SELECT
                    si.outstanding_amount AS amount,
                    si.status AS status,
                    gs.to_date AS end_date
                FROM `tabGym Subscription` AS gs, `tabSales Invoice` AS si
                WHERE
                    gs.docstatus = 1 AND
                    gs.member = '{member}' AND
                    gs.reference_invoice = si.name
                ORDER BY gs.from_date DESC
            """.format(member=self.name),
            as_dict=True,
        )
        unpaid_subscriptions = filter(lambda x: x.get("status") != "Paid",
                                      all_subscriptions)
        outstanding = reduce(operator.add, pluck("amount",
                                                 unpaid_subscriptions), 0)

        self.set_onload(
            "subscription_details",
            {
                "total_invoices": count(all_subscriptions),
                "unpaid_invoices": count(unpaid_subscriptions),
                "outstanding": outstanding,
            },
        )
        subscriptions = get_currents(self.name)
        self.set_onload("subscriptions", subscriptions)
        self.set_onload("last_trainer", _get_trainer(self.name, subscriptions))
Пример #3
0
    def __init__(
        self,
        frame: pd.DataFrame,
        window: int = 10,
        window_two: int = 3,
        is_fold: bool = False,
        x_label: List[str] = ["state"],
        y_label: List[str] = ["reward"]
    ):
        self.n = 0
        self.is_fold = is_fold
        local_frame = frame.copy()
        np_conv = lambda x: x.to_numpy()
        swindows = sliding_window(window)

        func = lambda x: pipe(x, np_conv, swindows)
        stay = stack_array(window_two)
        _slice_target = slice_target(window, window_two)
        self.x_axis = pipe(
            local_frame[x_label], np_conv, map(compress_row), swindows,
            map(compose(concat_tuple)), map(stay)
        )
        self.y_axis = pipe(
            frame[y_label], func, map(lambda x: torch.tensor(x).view(-1)),
            map(log_el), map(_slice_target)
        )

        self.count = toolz.count(self.copy()[0])

        self.zip_list = None
Пример #4
0
def test_chunks():
    x = np.array([(int(i), float(i)) for i in range(100)],
                 dtype=[('a', np.int32), ('b', np.float32)])
    b = bcolz.ctable(x)

    assert count(chunks(b, chunksize=10)) == 10
    assert (next(chunks(b, chunksize=10)) == x[:10]).all()
Пример #5
0
def test_chunks():
    x = np.array([(int(i), float(i)) for i in range(100)],
                 dtype=[('a', np.int32), ('b', np.float32)])
    b = bcolz.ctable(x)

    assert count(chunks(b, chunksize=10)) == 10
    assert (next(chunks(b, chunksize=10)) == x[:10]).all()
Пример #6
0
def test_mutable_ecs(num_original_entities: int) -> None:

    ecdb: EntityComponentDatabase = create_ecdb()

    # Add a few entities
    for _ in range(num_original_entities):
        ecdb, _ = add_entity(ecdb=ecdb,
                             components=(PositionComponent(y_axis=0, x_axis=0),
                                         VelocityComponent(y_axis=0,
                                                           x_axis=0)))

    systems: Systems[SystemUnion] = create_systems()
    systems = add_system(systems=systems, priority=0, system=MovementSystem())
    systems = add_system(systems=systems,
                         priority=1,
                         system=RemoveRandomEntitySystem())

    loop_index = 0
    while True:
        ecdb = process_systems(ecdb=ecdb,
                               systems=systems,
                               process_system=process_system,
                               process_action=process_action)

        assert len(ecdb) == num_original_entities - loop_index - 1

        if count(query(ecdb=ecdb)) == 0:
            break

        loop_index += 1
Пример #7
0
 def test_startService(self):
     """
     L{FusionIndexServiceMaker} creates a multiservice with the store and
     web services hooked up.
     """
     maker = FusionIndexServiceMaker()
     service = maker.makeService({
         'db': self.mktemp(),
         'port': 'tcp:0',
         })
     self.assertEqual(count(service), 2)
Пример #8
0
 def test_startService(self):
     """
     L{FusionIndexServiceMaker} creates a multiservice with the store and
     web services hooked up.
     """
     maker = FusionIndexServiceMaker()
     service = maker.makeService({
         'db': self.mktemp(),
         'port': 'tcp:0',
     })
     self.assertEqual(count(service), 2)
Пример #9
0
def linecount(fn):
    """ Count the number of lines in a textfile

    We need this to build the graph for read_csv.  This is much faster than
    actually parsing the file, but still costly.
    """
    extension = os.path.splitext(fn)[-1].lstrip('.')
    myopen = opens.get(extension, open)
    f = myopen(os.path.expanduser(fn))
    result = toolz.count(f)
    f.close()
    return result
Пример #10
0
def linecount(fn):
    """ Count the number of lines in a textfile

    We need this to build the graph for read_csv.  This is much faster than
    actually parsing the file, but still costly.
    """
    extension = os.path.splitext(fn)[-1].lstrip('.')
    myopen = opens.get(extension, open)
    f = myopen(os.path.expanduser(fn))
    result = toolz.count(f)
    f.close()
    return result
Пример #11
0
 def onload(self):
     all_fees = frappe.db.sql(
         """
             SELECT
                 si.rounded_total AS amount,
                 fee.status AS status,
                 fee.to_date AS end_date
             FROM `tabGym Fee` AS fee, `tabSales Invoice` AS si
             WHERE
                 fee.docstatus = 1 AND
                 fee.membership = '{membership}' AND
                 fee.reference_invoice = si.name
             ORDER BY fee.to_date DESC
         """.format(membership=self.name),
         as_dict=True,
     )
     unpaid_fees = filter(lambda x: x.get('status') == 'Unpaid', all_fees)
     self.set_onload('total_invoices', count(all_fees))
     self.set_onload('unpaid_invoices', count(unpaid_fees))
     outstanding = reduce(operator.add, pluck('amount', unpaid_fees), 0)
     self.set_onload('outstanding', outstanding)
     paid_fees = filter(lambda x: x.get('status') == 'Paid', all_fees)
     end_date = get('end_date', first(paid_fees)) if paid_fees else None
     self.set_onload('end_date', end_date)
Пример #12
0
def compute_up_1d(t, seq, **kwargs):
    return toolz.count(filter(None, seq))
Пример #13
0
def compute_up_1d(expr, seq, **kwargs):
    try:
        return len(seq)
    except TypeError:
        return toolz.count(seq)
Пример #14
0
c1, c2, c3 = sns.palettes.color_palette('colorblind', 3)

for r, c, rr, cc in zip(*[list(rbc4_short[i]) for i in ['row1', 'col1', 'row2', 'col2']]):
    plt.plot([c, cc], [r, rr], color=c1, marker=None)
    
for r, c, rr, cc in zip(*[list(rbc4_mid[i]) for i in ['row1', 'col1', 'row2', 'col2']]):
    plt.plot([c, cc], [r, rr], color=c2, marker=None)
    
    
for r, c, rr, cc in zip(*[list(rbc4_long[i]) for i in ['row1', 'col1', 'row2', 'col2']]):
    plt.plot([c, cc], [r, rr], color=c3, marker=None)
    
rbcim3 = rbcim2[:1758]
rbcim4 = filters.gaussian(rbcim3, sigma=3)
rbcim_med = filters.median(rbcim4, morphology.disk(100 / scale))
rbcim5 = img_as_ubyte(rbcim4) > rbcim_med
rbcskel = morphology.skeletonize(rbcim5)
rbcskel_ids = np.zeros(rbcskel.shape, int)
rbcskel_ids[rbcskel] = np.arange(1, np.sum(rbcskel) + 1)

import skeleton as skelpy
import networkx as nx
import toolz as tz
g = skelpy.skeleton_to_nx(rbcskel)
g.number_of_nodes()
tz.count(i for i in g.nodes_iter() if g.node[i]['type'] == 'junction')
cc = max(nx.connected_component_subgraphs(g), key=len)
n0, n1 = cc.nodes()[0], cc.nodes()[-1]
print(nx.shortest_path_length(cc, n0, n1, weight='weight'))
Пример #15
0
def has_multiple_bases(expr):
    return toolz.count(find_immediate_parent_tables(expr)) > 1
Пример #16
0
def has_multiple_bases(expr):
    return toolz.count(find_immediate_parent_tables(expr)) > 1
 def count_quorum(self, lvl: int) -> int:
     return count([q for q in self.level_quorum_count[lvl].values() if q])
def test_line_count_of_known_input():
    "confirm all Lines read from basic input file"
    expected_entry_count = count(entries)
    found_entry_count = pipe(path, entries_from_path, count)
    assert expected_entry_count == found_entry_count
 def __len__(self):
     """Returns the number of entries in the mapping"""
     return count(iter(self))
Пример #20
0
 def __len__(self) -> int:
     return count(self.path.glob('[!_]*'))  # type: ignore
Пример #21
0
def compute_up_1d(expr, seq, **kwargs):
    try:
        return len(seq)
    except TypeError:
        return toolz.count(seq)
Пример #22
0
 def __len__(self):
     """Returns the number of entries in the mapping"""
     return count(iter(self))
Пример #23
0
def compute_up_1d(t, seq, **kwargs):
    return toolz.count(filter(None, seq))
Пример #24
0
import sys
import itertools
import toolz

from gensim.models import word2vec

data_file = sys.argv[1]

sentences = [
    s for s in word2vec.LineSentence(data_file)
    if toolz.count(toolz.unique(s)) >= 2
]

cmb = toolz.frequencies(
    toolz.mapcat(lambda s: itertools.combinations(sorted(toolz.unique(s)), 2),
                 sentences))

for (k1, k2), v in sorted(cmb.items(), key=lambda x: -x[1]):
    print(f"item1 = {k1}, item2 = {k2}, freq = {v}")
Пример #25
0
 def count_active_neighbours(self, point: Point) -> int:
     # Includes self, if active
     return count((neighbour for neighbour in self.neighbours([point])
                   if neighbour in self.data))
Пример #26
0
 def __len__(self):
     return count(iter(self))