import unittest
import csv
from datetime import datetime, timedelta


def load_raw_data_and_split_by_dt(path, output_dir):
    base_datetime = datetime.strptime('141021', '%y%m%d')
    output_file_dict = {(base_datetime + timedelta(days=x)).strftime('%y%m%d'): open(
        output_dir + '/' + (base_datetime + timedelta(days=x)).strftime('%y%m%d') + '.csv', 'w') for x in range(0, 10)}

    with open(path, 'rb') as csvfile:
        header = csvfile.readline()
        reader = csv.reader(csvfile, delimiter=',')
        for row in reader:
            hour_column = row[2]
            dt = hour_column[:6]
            hour = hour_column[6:]
            output_file_dict[dt].write(",".join(row[:2] + [hour] + row[3:]) + "\n")


class TestCustomPreprocess(unittest.TestCase):
    def test_load_raw_data_and_split_by_dt(self):
        load_raw_data_and_split_by_dt('../fixtures/train.thumb', '../fixtures')


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

@@ -725,126 +725,1046 @@
 )%0A%0A%0A
-class TestCustomPreprocess(unittest.TestCase):%0A    def test_load_raw_data_and_split_by_dt(self):%0A        load_raw_data
+def load_raw_data_and_hash_and_split_by_dt(path, output_dir):%0A    base_datetime = datetime.strptime('141021', '%25y%25m%25d')%0A    output_file_dict = %7B(base_datetime + timedelta(days=x)).strftime('%25y%25m%25d'): open(%0A        output_dir + '/' + (base_datetime + timedelta(days=x)).strftime('%25y%25m%25d') + %22_hashed%22 + '.csv', 'w') for x in range(0, 10)%7D%0A%0A    with open(path, 'rb') as csvfile:%0A        header = csvfile.readline()%0A        reader = csv.reader(csvfile, delimiter=',')%0A        for row in reader:%0A            hour_column = row%5B2%5D%0A            dt = hour_column%5B:6%5D%0A            hour = hour_column%5B6:%5D%0A            row%5B2%5D = hour%0A            for i in range(2, 24):%0A                row%5Bi%5D = str(hash(row%5Bi%5D) %25 1024)%0A            output_file_dict%5Bdt%5D.write(%22,%22.join(row%5B1:%5D) + %22%5Cn%22)%0A%0A%0Aclass TestCustomPreprocess(unittest.TestCase):%0A    def test_load_raw_data_and_split_by_dt(self):%0A        load_raw_data_and_split_by_dt('../fixtures/train.thumb', '../fixtures')%0A%0A    def test_load_raw_data_and_hash_and_split_by_dt(self):%0A        load_raw_data_and_hash
 _and

add simple hash