示例#1
0
 def schema():
     return {
         'name': declare_field(mds.typing.composites.String)
         'number': declare_field(mds.typing.primitives.unsigned)
         'dept': declare_field(mds.typing.composities.Record)
         'nbr_sold': declare_field(mds.typing.primitives.unsigned)
         'sales_rank': declare_field(mds.typing.primitives.unsigned)
     }
示例#2
0
 def schema():
     return {
         'shelf_life': declare_field(mds.typing.primitives.unsigned)
         'oldest': declare_field(mds.typing.primitives.unsigned)
         'today': declare_field(mds.typing.primitives.unsigned)
         'wastage': declare_field(mds.typing.primitives.unsigned)
         # TODO: How to instantiate MDSList(dtype=mds.types.unsigned) without len
         'stock_on_hand': declare_field(mds.typing.arrays.UIntArray)
     }
示例#3
0
    def schema():
        """
        This method *must* be overridden in Record-derived classes, and follow the
        following syntax for declaring the record schema.

        Once the class `cls` has come into scope, an instantiated copy of this object
        will be available via cls.type_decl
        """
        return {
            "is_active": declare_field(mds.typing.primitives.bool),
            "number_of_players": declare_field(mds.typing.primitives.ushort)
        }
示例#4
0
 def schema() -> dict:
     return {
         "is_active":
         declare_field(mds.typing.primitives.bool),
         "numerator":
         declare_field(mds.typing.primitives.float),
         "denominator":
         declare_field(mds.typing.primitives.double),
         "measurements":
         declare_field(mds.typing.primitives.double),
         "observers":
         declare_field(mds.typing.composites.record[SimpleRecord],
                       make_const=True)
     }
示例#5
0
 def schema():
     return {
         # TODO: Again, how to declare MDSList instance of type T
         'depts': declare_field(mds.typing.arrays.Record[Department], original=ds)
示例#6
0
 def schema():
     return {
         'purchases': declare_field(mds.typing.arrays.Record, reserve=n)  # TODO: Allocation
         'next_purchase': declare_field(mds.typing.primitives.unsigned)
         'window_size': declare_field(mds.typing.primitives.unsigned)
     }
示例#7
0
 def schema():
     return {
         'items': declare_field(mds.typing.arrays.Record[BasketItem])
     }
示例#8
0
 def schema():
     return {
         'product': declare_field(mds.typing.composite.Record[Product], p)
         'quantity': declare_field(mds.types.unsigned)
     }
示例#9
0
 def schema():
     return {
         'stock_on_hand': declare_field(mds.typing.primitives.unsigned)
     }
示例#10
0
 def schema():
     return {
         'name': declare_field(mds.typing.primitives.String)
         'number': declare_field(mds.typing.primitives.unsigned)
         'sales_rank': declare_field(mds.typing.primitives.unsigned)
     }
示例#11
0

class Store(mds.managed.Record, ident=RECORD_NAME('Store'):

    def __init__(self, ds: RecordArray, ps: RecordArray, window_size: int):
        self.depts = []
        self.products = []
        self.perishable = []
        self.recent_purchases = None

    @staticmethod
    def schema():
        return {
            # TODO: Again, how to declare MDSList instance of type T
            'depts': declare_field(mds.typing.arrays.Record[Department], original=ds)
            'products': declare_field(mds.typing.arrays.Record[Product], original=ps)
            'perishable': declare_field(mds.typing.arrays.Record[PerishableProduct], filter(lambda x: isinstance(x, PerishableProduct), ps))
            'recent_purchases': declare_field(mds.typing.composites.Record[RecentPurchases], window_size)  # TODO: Forward args?
        }

    def purchase(self, basket: Basket, button: Pause.Button=None) -> None:
        basket.purchase(self.recent_purchases, button)

    def restock(self, qfn: Callable, button: Pause.Button=None) -> None:
        # TODO: Pretty sure this is very broken

        def worker(qfn: Callable, products: RecordArray, button: Pause.Button) -> None:
            def task_worker(qfn, p, button):
                q = qfn(p)

                if q > 0:
示例#12
0
 def schema():
     return {
         "is_active": declare_field(mds.typing.primitives.bool),
         "numerator": declare_field(mds.typing.primitives.float),
         "denominator": declare_field(mds.typing.primitives.double)
     }
示例#13
0
 def schema():
     return {"is_active": declare_field(mds.typing.primitives.bool)}