예제 #1
0
 def process(self, elem):
     json_dict = json.loads(elem)
     if type(json_dict[FieldNames.DATE_TIME]) is dict:
         json_dict[FieldNames.DATE_TIME] = json_dict[
             FieldNames.DATE_TIME]['millis']
     if FieldNames.NAME in json_dict:
         yield nexmark_model.Person(
             json_dict[FieldNames.ID], json_dict[FieldNames.NAME],
             json_dict[FieldNames.EMAIL_ADDRESS],
             json_dict[FieldNames.CREDIT_CARD], json_dict[FieldNames.CITY],
             json_dict[FieldNames.STATE],
             millis_to_timestamp(json_dict[FieldNames.DATE_TIME]),
             json_dict[FieldNames.EXTRA])
     elif FieldNames.ITEM_NAME in json_dict:
         if type(json_dict[FieldNames.EXPIRES]) is dict:
             json_dict[FieldNames.EXPIRES] = json_dict[
                 FieldNames.EXPIRES]['millis']
         yield nexmark_model.Auction(
             json_dict[FieldNames.ID], json_dict[FieldNames.ITEM_NAME],
             json_dict[FieldNames.DESCRIPTION],
             json_dict[FieldNames.INITIAL_BID],
             json_dict[FieldNames.RESERVE],
             millis_to_timestamp(json_dict[FieldNames.DATE_TIME]),
             millis_to_timestamp(json_dict[FieldNames.EXPIRES]),
             json_dict[FieldNames.SELLER], json_dict[FieldNames.CATEGORY],
             json_dict[FieldNames.EXTRA])
     elif FieldNames.AUCTION in json_dict:
         yield nexmark_model.Bid(
             json_dict[FieldNames.AUCTION], json_dict[FieldNames.BIDDER],
             json_dict[FieldNames.PRICE],
             millis_to_timestamp(json_dict[FieldNames.DATE_TIME]),
             json_dict[FieldNames.EXTRA])
     else:
         raise ValueError('Invalid event: %s.' % str(json_dict))
예제 #2
0
def load(raw_events, query_args=None):
    return (raw_events
            | 'ParseEventFn' >> beam.ParDo(ParseEventFn())
            | 'FilterInBids' >>
            beam.Filter(lambda event: isinstance(event, nexmark_model.Bid))
            | 'ConvertToEuro' >> beam.Map(lambda bid: nexmark_model.Bid(
                bid.auction, bid.bidder,
                (float(bid.price) * 89) // 100, bid.timestamp, bid.extra))
            | 'DisplayQuery1' >> beam.Map(display))  # pylint: disable=expression-not-assigned
예제 #3
0
def load(events, query_args=None):
    return (events
            | nexmark_query_util.JustBids()
            | 'ConvertToEuro' >> beam.Map(lambda bid: nexmark_model.Bid(
                bid.auction, bid.bidder, bid.price * USD_TO_EURO, bid.
                date_time, bid.extra)))