# Path: utility/datafilepath.py
# class DataFilePath:
#     def __init__(self):
#     def getOrderDir_Train(self):  
#     def getOrderDir_Test1(self):  
#     def getTest1Dir(self):
#     def getTest2Dir(self):
#     def getTrainDir(self):
#     def getGapCsv_Train(self):
#     def getGapCsv_Test1(self):
#     def getTestset1Readme(self):
#     def getTestset2Readme(self):
#     def getGapFilename(self):
#     def getGapPredictionFileName(self):
#     def getPrevGapFileName(self):
#     def get_dir_name(self, data_dir):
# 
# Path: utility/dumpload.py
# class DumpLoad:
#     def __init__(self, pickle_filepath):
#         self.pickle_filepath = pickle_filepath
#         dir_path = os.path.dirname(pickle_filepath)
#         if not os.path.exists(dir_path):
#             os.makedirs(dir_path)
#         
#         return
#     def load(self):
#         with open(self.pickle_filepath, 'rb') as handle:
#             dataset = pickle.load(handle)
#         return dataset
#     def isExisiting(self):
#         return os.path.exists(self.pickle_filepath) 
#     def run(self):
#         self.dump((np.arange(10), np.arange(20)))
#         print(self.load())
#         return
#     
#     def dump(self, dataset):
#         with open(self.pickle_filepath, 'wb') as f:
#             pickle.dump(dataset, f, pickle.HIGHEST_PROTOCOL)
#         return


from utility.datafilepath import g_singletonDataFilePath
from timeslot import singletonTimeslot
from exploredata import ExploreData
from time import time
from utility.dumpload import DumpLoad
from  districtid import singletonDistricId
import pandas as pd
import os
        res = 0
        for _, item in level_series.iteritems():
            item = item.split(':')
            res = res + int(item[0]) * int(item[1])            
        return res
    def find_prev_traffic(self, series, traffic_dict=None,pre_num = 2):
        start_district_id = series.iloc[0]
        time_slotid = series.iloc[1]
        index = ['traffic' + str(i + 1) for i in range(pre_num)]
        res = []
        prevSlots = singletonTimeslot.getPrevSlots(time_slotid, pre_num)
        for prevslot in prevSlots:
            try:
                res.append(traffic_dict[(start_district_id, prevslot)])
            except:
                res.append(0)
        return pd.Series(res, index = index)

    
    def process_one_df(self, df):
        df['start_district_id'] = df['start_district_hash'].map(singletonDistricId.convertToId)
        df['traffic'] = df[['level_1', 'level_2', 'level_3']].apply(self.cal_traffic_value, axis = 1,)
        #Remove duplicate time_slotid, retain the ealier ones
#         df.drop_duplicates(subset='time_slotid', keep='first', inplace=True)
        return
    


if __name__ == "__main__":   
    obj= ExploreTraffic()

# Path: utility/datafilepath.py
# class DataFilePath:
#     def __init__(self):
#     def getOrderDir_Train(self):  
#     def getOrderDir_Test1(self):  
#     def getTest1Dir(self):
#     def getTest2Dir(self):
#     def getTrainDir(self):
#     def getGapCsv_Train(self):
#     def getGapCsv_Test1(self):
#     def getTestset1Readme(self):
#     def getTestset2Readme(self):
#     def getGapFilename(self):
#     def getGapPredictionFileName(self):
#     def getPrevGapFileName(self):
#     def get_dir_name(self, data_dir):
# 
# Path: utility/dumpload.py
# class DumpLoad:
#     def __init__(self, pickle_filepath):
#         self.pickle_filepath = pickle_filepath
#         dir_path = os.path.dirname(pickle_filepath)
#         if not os.path.exists(dir_path):
#             os.makedirs(dir_path)
#         
#         return
#     def load(self):
#         with open(self.pickle_filepath, 'rb') as handle:
#             dataset = pickle.load(handle)
#         return dataset
#     def isExisiting(self):
#         return os.path.exists(self.pickle_filepath) 
#     def run(self):
#         self.dump((np.arange(10), np.arange(20)))
#         print(self.load())
#         return
#     
#     def dump(self, dataset):
#         with open(self.pickle_filepath, 'wb') as f:
#             pickle.dump(dataset, f, pickle.HIGHEST_PROTOCOL)
#         return


# Path: exploredata/traffic.py
from utility.datafilepath import g_singletonDataFilePath
from timeslot import singletonTimeslot
from exploredata import ExploreData
from time import time
from utility.dumpload import DumpLoad
from  districtid import singletonDistricId
import pandas as pd
import os

        res = 0
        for _, item in level_series.iteritems():
            item = item.split(':')
            res = res + int(item[0]) * int(item[1])            
        return res
    def find_prev_traffic(self, series, traffic_dict=None,pre_num = 2):
        start_district_id = series.iloc[0]
        time_slotid = series.iloc[1]
        index = ['traffic' + str(i + 1) for i in range(pre_num)]
        res = []
        prevSlots = singletonTimeslot.getPrevSlots(time_slotid, pre_num)
        for prevslot in prevSlots:
            try:
                res.append(traffic_dict[(start_district_id, prevslot)])
            except:
                res.append(0)
        return pd.Series(res, index = index)

    
    def process_one_df(self, df):
        df['start_district_id'] = df['start_district_hash'].map(singletonDistricId.convertToId)
        df['traffic'] = df[['level_1', 'level_2', 'level_3']].apply(self.cal_traffic_value, axis = 1,)
        #Remove duplicate time_slotid, retain the ealier ones
#         df.drop_duplicates(subset='time_slotid', keep='first', inplace=True)
        return
    


if __name__ == "__main__":   
    obj= ExploreTraffic()

    obj.run()