# Path: Date.py
# class Date(object):
#     def __init__(self, from_float=None):
#         if from_float is not None:
#             if isinstance(from_float, float):
#                 self._value = Date._from_float(from_float)  # a datetime.date
#             else:
#                 print 'arg from_float %s is of type %s, not float' % (from_float, type(from_float))
#                 assert False, 'construction error'
#         else:
#             print 'bad construction of Date'
#             assert False, 'construct via Data(from_float=<float value>)'
# 
#     def as_datetime_date(self):
#         'return value as a datetime.date'
#         return self._value  # for now, the value is stored as a datetime.date
# 
#     @staticmethod
#     def _from_float(x):
#         'return a datetime.date'
#         assert isinstance(x, float), x
#         assert 0 < x <= 99999999, x
#         year = int(x / 10000)
#         month_day = x - year * 10000
#         month = int(month_day / 100)
#         day = int(month_day - month * 100)
#         result = datetime.date(year, month, day)
#         return result
# 
# Path: TransactionId2.py
# class TransactionId2(object):
#     def __init__(self, sale_date=None, apn=None):
#         assert sale_date is not None, sale_date
#         assert apn is not None, apn
#         assert isinstance(sale_date, datetime.date), sale_date
#         assert isinstance(apn, long), apn
#         self.sale_date = sale_date
#         self.apn = apn
# 
#     def __str__(self):
#         'return informal string representation'
#         return '%sAPN%d' % (self.sale_date, self.apn)
# 
#     def __repr__(self):
#         'return official string representation'
#         return 'TransactionId2(sale_date=%s,apn=%sL)' % (self.sale_date, self.apn)
# 
#     def __eq__(self, other):
#         return self.sale_date == other.sale_date and self.apn == other.apn
# 
#     def __lt__(self, other):
#         if self.sale_date == other.sale_date:
#             return self.apn < other.apn
#         else:
#             return self.sale_date < other.sale_date
# 
#     def __hash__(self):
#         return hash((self.sale_date, self.apn))


import cPickle as pickle
import os
import pandas as pd
import pdb
import unittest
import layout_transactions
import Path
from pprint import pprint
from Date import Date
from TransactionId2 import TransactionId2
        transaction_ids_actuals = set(actuals.index)
        for transaction_id in transaction_ids_actuals:
            # known date is 2007-01-22
            pdb.set_trace()
            if transaction_id.sale_year.year == 2007 and transaction_id.sale_year.month == 1:
                print transaction_id
        pdb.set_trace()

        transaction_ids_common = set()
        for fitted, transaction_ids in predictions.iterkeys():
            for prediction_transaction_id in transaction_ids:
                print prediction_transaction_id
                if prediction_transaction_id in transaction_ids_actuals:
                    transaction_ids_common.add(prediction_transaction_id)
        if len(transaction_ids_common) == 0:
            print len(actuals), len(predictions)
            pdb.set_trace()
        return transaction_ids_common


class TestActualsPredictions(unittest.TestCase):
    def test_construction(self):
        ap = ActualsPredictions('train', just_200701=True, test=True)
        self.assertTrue(isinstance(ap, ActualsPredictions))


if __name__ == '__main__':
    unittest.main()
    if False:
        pdb

# Path: Date.py
# class Date(object):
#     def __init__(self, from_float=None):
#         if from_float is not None:
#             if isinstance(from_float, float):
#                 self._value = Date._from_float(from_float)  # a datetime.date
#             else:
#                 print 'arg from_float %s is of type %s, not float' % (from_float, type(from_float))
#                 assert False, 'construction error'
#         else:
#             print 'bad construction of Date'
#             assert False, 'construct via Data(from_float=<float value>)'
# 
#     def as_datetime_date(self):
#         'return value as a datetime.date'
#         return self._value  # for now, the value is stored as a datetime.date
# 
#     @staticmethod
#     def _from_float(x):
#         'return a datetime.date'
#         assert isinstance(x, float), x
#         assert 0 < x <= 99999999, x
#         year = int(x / 10000)
#         month_day = x - year * 10000
#         month = int(month_day / 100)
#         day = int(month_day - month * 100)
#         result = datetime.date(year, month, day)
#         return result
# 
# Path: TransactionId2.py
# class TransactionId2(object):
#     def __init__(self, sale_date=None, apn=None):
#         assert sale_date is not None, sale_date
#         assert apn is not None, apn
#         assert isinstance(sale_date, datetime.date), sale_date
#         assert isinstance(apn, long), apn
#         self.sale_date = sale_date
#         self.apn = apn
# 
#     def __str__(self):
#         'return informal string representation'
#         return '%sAPN%d' % (self.sale_date, self.apn)
# 
#     def __repr__(self):
#         'return official string representation'
#         return 'TransactionId2(sale_date=%s,apn=%sL)' % (self.sale_date, self.apn)
# 
#     def __eq__(self, other):
#         return self.sale_date == other.sale_date and self.apn == other.apn
# 
#     def __lt__(self, other):
#         if self.sale_date == other.sale_date:
#             return self.apn < other.apn
#         else:
#             return self.sale_date < other.sale_date
# 
#     def __hash__(self):
#         return hash((self.sale_date, self.apn))


# Path: ActualsPredictions.py
import cPickle as pickle
import os
import pandas as pd
import pdb
import unittest
import layout_transactions
import Path
from pprint import pprint
from Date import Date
from TransactionId2 import TransactionId2

        transaction_ids_actuals = set(actuals.index)
        for transaction_id in transaction_ids_actuals:
            # known date is 2007-01-22
            pdb.set_trace()
            if transaction_id.sale_year.year == 2007 and transaction_id.sale_year.month == 1:
                print transaction_id
        pdb.set_trace()

        transaction_ids_common = set()
        for fitted, transaction_ids in predictions.iterkeys():
            for prediction_transaction_id in transaction_ids:
                print prediction_transaction_id
                if prediction_transaction_id in transaction_ids_actuals:
                    transaction_ids_common.add(prediction_transaction_id)
        if len(transaction_ids_common) == 0:
            print len(actuals), len(predictions)
            pdb.set_trace()
        return transaction_ids_common


class TestActualsPredictions(unittest.TestCase):
    def test_construction(self):
        ap = ActualsPredictions('train', just_200701=True, test=True)
        self.assertTrue(isinstance(ap, ActualsPredictions))


if __name__ == '__main__':
    unittest.main()
    if False:
        pdb

        pprint