def setUp(self): self.order_list = MarketOrderList() self.order1 = MarketOrder(order_id=2413387906, is_bid=True, region_id=10000068, solar_system_id=30005316, station_id=60011521, type_id=10000068, price=52875, volume_entered=10, volume_remaining=4, minimum_volume=1, order_issue_date=now_dtime_in_utc(), order_duration=90, order_range=5, generated_at=now_dtime_in_utc()) self.order_list.add_order(self.order1) # This order isn't added, but it's here for the test to add. self.order2 = MarketOrder(order_id=1234566, is_bid=False, region_id=10000032, solar_system_id=30005312, station_id=60011121, type_id=10000067, price=52, volume_entered=10, volume_remaining=500, minimum_volume=1, order_issue_date=now_dtime_in_utc(), order_duration=90, order_range=5, generated_at=now_dtime_in_utc()) self.history = MarketHistoryList() self.history1 = MarketHistoryEntry( type_id=2413387906, region_id=10000068, historical_date=now_dtime_in_utc(), num_orders=5, low_price=5.0, high_price=10.5, average_price=7.0, total_quantity=200, generated_at=now_dtime_in_utc(), ) self.history.add_entry(self.history1) # This order isn't added, but it's here for the test to add. self.history2 = MarketHistoryEntry( type_id=1413387203, region_id=10000067, historical_date=now_dtime_in_utc(), num_orders=50, low_price=50.0, high_price=100.5, average_price=70.0, total_quantity=2000, generated_at=now_dtime_in_utc(), )
def test_contains(self): """ Tests the __contains__ method via the 'in' Python keyword. __contains__ lookup is based off of the item's type ID. This is different from MarketOrderList, which uses order ID. """ history_list = MarketHistoryList() # This type ID hasn't been added yet, so this should be False. self.assertFalse(2413387906 in history_list) new_history = MarketHistoryEntry( type_id=2413387906, region_id=10000068, historical_date=now_dtime_in_utc(), num_orders=5, low_price=5.0, high_price=10.5, average_price=7.0, total_quantity=200, generated_at=now_dtime_in_utc(), ) history_list.add_entry(new_history) # The entry was added, so this should succeed. self.assertTrue(2413387906 in history_list) # Use the object form. self.assertTrue(new_history in history_list)
def test_entry_counting(self): """ Test the various history counting counting methods. """ history_list = MarketHistoryList() # There are no history entries yet. self.assertEqual(0, len(history_list)) history_list.add_entry(MarketHistoryEntry( type_id=2413387906, region_id=10000068, historical_date=now_dtime_in_utc(), num_orders=5, low_price=5.0, high_price=10.5, average_price=7.0, total_quantity=200, generated_at=now_dtime_in_utc(), )) # Just added one. self.assertEqual(1, len(history_list)) # Adding another item type in the same region. history_list.add_entry(MarketHistoryEntry( type_id=2413387905, region_id=10000068, historical_date=now_dtime_in_utc(), num_orders=5, low_price=5.0, high_price=10.5, average_price=7.0, total_quantity=200, generated_at=now_dtime_in_utc(), )) self.assertEqual(2, len(history_list)) # Adding to another region. history_list.add_entry(MarketHistoryEntry( type_id=2413387905, region_id=10000067, historical_date=now_dtime_in_utc(), num_orders=5, low_price=5.0, high_price=10.5, average_price=7.0, total_quantity=200, generated_at=now_dtime_in_utc(), )) # There are now three total. self.assertEqual(3, len(history_list))
def parse_from_dict(json_dict): """ Given a Unified Uploader message, parse the contents and return a MarketHistoryList instance. :param dict json_dict: A Unified Uploader message as a dict. :rtype: MarketOrderList :returns: An instance of MarketOrderList, containing the orders within. """ history_columns = json_dict['columns'] history_list = MarketHistoryList( upload_keys=json_dict['uploadKeys'], history_generator=json_dict['generator'], ) for rowset in json_dict['rowsets']: generated_at = parse_datetime(rowset['generatedAt']) region_id = rowset['regionID'] type_id = rowset['typeID'] history_list.set_empty_region(region_id, type_id, generated_at) for row in rowset['rows']: history_kwargs = _columns_to_kwargs( SPEC_TO_KWARG_CONVERSION, history_columns, row) historical_date = parse_datetime(history_kwargs['historical_date']) history_kwargs.update({ 'type_id': type_id, 'region_id': region_id, 'historical_date': historical_date, 'generated_at': generated_at, }) history_list.add_entry(MarketHistoryEntry(**history_kwargs)) return history_list
def serialize_history(doc_dict, region_data): """ Serializes a GetOldPriceHistory cache file's contents. :param dict doc_dict: The parsed cache document in dict form. :rtype: str :returns: The UUDIF serialized JSON message. """ hist_list = MarketHistoryList( order_generator=ORDER_GENERATOR, upload_keys=UPLOAD_KEYS, ) # timezone-aware datetime. generated_at = now_dtime_in_utc() region_id = region_data[2] type_id = region_data[3] for hist_item in doc_dict['lret']: #print hist_item entry = MarketHistoryEntry( type_id=type_id, region_id=region_id, historical_date=wintime_to_datetime(hist_item['historyDate']), num_orders=hist_item['orders'], low_price=hist_item['lowPrice'], high_price=hist_item['highPrice'], average_price=hist_item['avgPrice'], total_quantity=hist_item['volume'], generated_at=generated_at, ) hist_list.add_entry(entry) if len(hist_list) is 0: # There were no orders for this item+region combo. hist_list.set_empty_region(region_id, type_id, generated_at) return encode_to_json(hist_list)