Beispiel #1
0
async def main():
    ctx = context(toplevel=True)
    ctx.cell1 = cell("int").set(1)
    ctx.cell2 = cell("int").set(2)
    #ctx.code = cell("transformer")
    #ctx.code = cell("transformer").set("c = 'test'")
    #ctx.code = cell("transformer").set("raise Exception")
    #ctx.code = cell("transformer").set("import time; time.sleep(2); c = a + b")
    ctx.code = cell("transformer").set("a + b")
    ctx.result = cell("int")
    ctx.tf = transformer({
        "a": "input",
        "b": "input",
        "c": "output"
    })
    ctx.cell1_unilink = unilink(ctx.cell1)
    ctx.cell1_unilink.connect(ctx.tf.a)
    ctx.cell2.connect(ctx.tf.b)
    ctx.code_copy = cell("transformer")
    ctx.code.connect(ctx.code_copy)
    ctx.code_copy.connect(ctx.tf.code)
    ctx.result_unilink = unilink(ctx.result)
    ctx.tf.c.connect(ctx.result_unilink)
    ctx.result_copy = cell("int")
    ctx.result.connect(ctx.result_copy)
    await ctx.computation(1)
    print("STOP")
    print(ctx.cell1.value, ctx.cell1, ctx.cell1.status)
    print(ctx.cell2.value, ctx.cell2, ctx.cell2.status)
    print(ctx.code.value, ctx.code, ctx.code.status)
    print(ctx.code_copy.value, ctx.code_copy, ctx.code_copy.status)
    print(ctx.result.value, ctx.result, ctx.result.status)
    print(ctx.result_copy.value, ctx.result_copy, ctx.result_copy.status)
    print(ctx.tf.value, ctx.tf, ctx.tf.status)
    print(ctx.status)
    print(ctx.tf.exception)
    await ctx.computation()
    ctx.cell1.set(10)
    await ctx.computation()
    print(ctx.result.value, ctx.status)
    ctx.code.set("c = a + b + 1000")
    await ctx.computation()
    print(ctx.result.value, ctx.status)
    print("Introduce delay...")
    ctx.code.set("import time; time.sleep(2); c = -(a + b)")
    await ctx.computation(1.0)
    print("after 1.0 sec...")
    print(ctx.result.value, ctx.status)
    print("...")
    await ctx.computation()
    print(ctx.result.value, ctx.status)
Beispiel #2
0
def define_ctx():
    with macro_mode_on():
        ctx = context(toplevel=True)
        ctx.cell1 = cell().set(1)
        ctx.cell2 = cell().set(2)
    ctx.compute()
    with macro_mode_on():
        ctx.result = cell()
        ctx.tf = transformer({"a": "input", "b": "input", "c": "output"})
        ctx.cell1_unilink = unilink(ctx.cell1)
        ctx.cell1_unilink.connect(ctx.tf.a)
        ctx.cell2.connect(ctx.tf.b)
        ctx.code = cell("transformer").set("c = a + b")
        ctx.code.connect(ctx.tf.code)
        ctx.result_unilink = unilink(ctx.result)
        ctx.tf.c.connect(ctx.result_unilink)
    return ctx
Beispiel #3
0
seamless.database_cache.connect()

ctx = context(toplevel=True)
ctx.cell1 = cell("int").set_checksum(
    "bc4bb29ce739b5d97007946aa4fdb987012c647b506732f11653c5059631cd3d"  # 1
)
ctx.cell2 = cell("int").set_checksum(
    "191fb5fc4a9bf2ded9a09a0a2c4eb3eb90f15ee96deb1eec1a970df0a79d09ba"  # 2
)
ctx.code = cell("transformer").set_checksum(
    "1cbba7cc10e067273fdec7cc350d2b87508c1959d26bbab4f628f6f59ec49607"  # a + b
)
ctx.result = cell("int")
ctx.tf = transformer({"a": "input", "b": "input", "c": "output"})
ctx.cell1_unilink = unilink(ctx.cell1)
ctx.cell1_unilink.connect(ctx.tf.a)
ctx.cell2.connect(ctx.tf.b)
ctx.code_copy = cell("transformer")
ctx.code.connect(ctx.code_copy)
ctx.code_copy.connect(ctx.tf.code)
ctx.result_unilink = unilink(ctx.result)
ctx.tf.c.connect(ctx.result_unilink)
ctx.result_copy = cell("int")
ctx.result.connect(ctx.result_copy)
ctx.compute()
print(ctx.cell1, ctx.cell1.value)  # Retrieved from database value cache
print(ctx.cell2, ctx.cell2.value)  # Retrieved from database value cache
print(ctx.code, ctx.code.value)  # Retrieved from database value cache
print(ctx.result.checksum)  #  checksum from database transformer result cache
print(ctx.result.value)  #  3 is the value that corresponds to a3b..27e
Beispiel #4
0
    ctx.tfxx = cell("text")
    ctx.tfx.x.connect(ctx.tfxx)
    ctx.tfxx.connect(ctx.macro.ctx.x_unilink)
    ctx.tfx.x.connect(ctx.x)
    ctx.y = cell("text")
    ctx.macro.ctx.y.connect(ctx.y)
    ctx.e = cell("plain")
    ctx.e2 = cell("plain")
    p_d = path(ctx.macro.ctx).d
    p_d.connect(ctx.e)
    p_tf2e = path(ctx.macro.ctx).tf2e
    p_tf2e2 = path(ctx.macro.ctx).tf2e2
    ctx.e.connect(p_tf2e)
    p_tf2e2.connect(ctx.e2)
    ctx.z = cell("text").set("z")
    ctx.z_unilink = unilink(ctx.z)
    ctx.z_unilink.connect(ctx.macro.ctx.z)
    ctx.q = cell("text")
    ctx.macro.ctx.q_unilink.connect(ctx.q)
    ctx.subq = cell("text")
    ctx.macro.ctx.q.connect(ctx.subq)
    ctx.subq.connect(ctx.macro.ctx.qq)
    ctx.r = cell("text")
    ctx.r_unilink = unilink(ctx.r)
    ctx.macro.ctx.r_unilink.connect(ctx.r_unilink)
    ctx.r.connect(ctx.macro.ctx.rr_unilink)


def report():
    print("%-20s" % "macro a", ctx.macro.ctx.a.value)
    print("%-20s" % "macro b", ctx.macro.ctx.b.value)