import os
import pandas as pd
import numpy as np

"""
    通过代码测试：
    input_file = "data\\0.input\\enron\\ia-enron-email-dynamic.edges"
    dataframe = pd.read_csv(input_file, sep=" ", names=['from_id', 'to_id', 'type', 'timestamp'])
    dataframe['timestamp']=pd.to_datetime(dataframe['timestamp'],unit='ms').dt.strftime('%Y-%m-%d %H:%M:%s')
    print(dataframe['timestamp'].unique())
    最终确定粒度为小时的时候比较合适，会落在以下这几个区间内
    ['1970-01-01 00' '1970-01-14 22' '1970-01-15 01' '1970-01-14 11'
     '1970-01-14 23' '1970-01-14 16' '1970-01-14 17' '1970-01-15 02'
     '1970-01-15 04' '1970-01-15 05' '1970-01-14 15' '1970-01-14 18'
     '1970-01-15 00' '1970-01-14 20' '1970-01-14 14' '1970-01-15 03'
     '1970-01-14 21' '1970-01-14 19' '1970-01-14 13' '1970-01-14 10'
     '1970-01-14 09' '1970-01-14 12' '1970-01-15 06']
"""

def check_and_make_path(to_make):
    if to_make == '':
        return
    if not os.path.exists(to_make):
        os.makedirs(to_make)

class FBTransformer:
    input_file: str
    format_output_path: str
    use_good_data: bool
    good_data_format: str
    good_data_list: list

    def __init__(self, input_file, output_base_path):
        self.input_file = input_file
        self.format_output_path = os.path.join(output_base_path, "1.format")
        self.node_list_output_path = os.path.join(output_base_path, "nodes_set")

        # 创建路径
        check_and_make_path(self.format_output_path)

    def transform(self, trans_type=None, use_good_data=False):
        print("transforming FB...")

        self.use_good_data = use_good_data

        if trans_type is None:
            trans_type = ['day', 'month', 'year']

        if 'day' in trans_type:
            self.handle_by_day()

        if 'month' in trans_type:
            self.handle_by_month()

        if 'year' in trans_type:
            self.handle_by_year()

        print("transforming FB complete\n")

    def handle_by_day(self):
        # 按天处理
        dataframe = pd.read_csv(self.input_file, sep=" ", names=['from_id', 'to_id', 'type', 'timestamp'])
        dataframe['timestamp'] = pd.to_datetime(dataframe['timestamp'], unit='s').dt.strftime('%Y-%m-%d')
        candidate = ['1970-01-01', '2006-09-05', '2006-09-06', '2006-09-07', '2006-09-08',
                     '2006-09-09', '2006-09-10', '2006-09-11', '2006-09-12', '2006-09-13',
                     '2006-09-14', '2006-09-15', '2006-09-16', '2006-09-17', '2006-09-18',
                     '2006-09-19', '2006-09-20', '2006-09-21', '2006-09-22', '2006-09-23',
                     '2006-09-24', '2006-09-25', '2006-09-26', '2006-09-27', '2006-09-28',
                     '2006-09-29', '2006-09-30', '2006-10-01', '2006-10-02', '2006-10-03',
                     '2006-10-04', '2006-10-05', '2006-10-06', '2006-10-07', '2006-10-08',
                     '2006-10-09', '2006-10-10', '2006-10-11', '2006-10-12', '2006-10-13',
                     '2006-10-14', '2006-10-15', '2006-10-16', '2006-10-17', '2006-10-18',
                     '2006-10-19', '2006-10-20', '2006-10-21', '2006-10-22', '2006-10-23',
                     '2006-10-24', '2006-10-25', '2006-10-26', '2006-10-27', '2006-10-28',
                     '2006-10-29', '2006-10-30', '2006-10-31', '2006-11-01', '2006-11-02',
                     '2006-11-03', '2006-11-04', '2006-11-05', '2006-11-06', '2006-11-07',
                     '2006-11-08', '2006-11-09', '2006-11-10', '2006-11-11', '2006-11-12',
                     '2006-11-13', '2006-11-14', '2006-11-15', '2006-11-16', '2006-11-17',
                     '2006-11-18', '2006-11-19', '2006-11-20', '2006-11-21', '2006-11-22',
                     '2006-11-23', '2006-11-24', '2006-11-25', '2006-11-26', '2006-11-27',
                     '2006-11-28', '2006-11-29', '2006-11-30', '2006-12-01', '2006-12-02',
                     '2006-12-03', '2006-12-04', '2006-12-05', '2006-12-06', '2006-12-07',
                     '2006-12-08', '2006-12-09', '2006-12-10', '2006-12-11', '2006-12-12',
                     '2006-12-13', '2006-12-14', '2006-12-15', '2006-12-16', '2006-12-17',
                     '2006-12-18', '2006-12-19', '2006-12-20', '2006-12-21', '2006-12-22',
                     '2006-12-23', '2006-12-24', '2006-12-25', '2006-12-26', '2006-12-27',
                     '2006-12-28', '2006-12-29', '2006-12-30', '2006-12-31', '2007-01-01',
                     '2007-01-02', '2007-01-03', '2007-01-04', '2007-01-05', '2007-01-06',
                     '2007-01-07', '2007-01-08', '2007-01-09', '2007-01-10', '2007-01-11',
                     '2007-01-12', '2007-01-13', '2007-01-14', '2007-01-15', '2007-01-16',
                     '2007-01-17', '2007-01-18', '2007-01-19', '2007-01-20', '2007-01-21',
                     '2007-01-22', '2007-01-23', '2007-01-24', '2007-01-25', '2007-01-26',
                     '2007-01-27', '2007-01-28', '2007-01-29', '2007-01-30', '2007-01-31',
                     '2007-02-01', '2007-02-02', '2007-02-03', '2007-02-04', '2007-02-05',
                     '2007-02-06', '2007-02-07', '2007-02-08', '2007-02-09', '2007-02-10',
                     '2007-02-11', '2007-02-12', '2007-02-13', '2007-02-14', '2007-02-15',
                     '2007-02-16', '2007-02-17', '2007-02-18', '2007-02-19', '2007-02-20',
                     '2007-02-21', '2007-02-22', '2007-02-23', '2007-02-24', '2007-02-25',
                     '2007-02-26', '2007-02-27', '2007-02-28', '2007-03-01', '2007-03-02',
                     '2007-03-03', '2007-03-04', '2007-03-05', '2007-03-06', '2007-03-07',
                     '2007-03-08', '2007-03-09', '2007-03-10', '2007-03-11', '2007-03-12',
                     '2007-03-13', '2007-03-14', '2007-03-15', '2007-03-16', '2007-03-17',
                     '2007-03-18', '2007-03-19', '2007-03-20', '2007-03-21', '2007-03-22',
                     '2007-03-23', '2007-03-24', '2007-03-25', '2007-03-26', '2007-03-27',
                     '2007-03-28', '2007-03-29', '2007-03-30', '2007-03-31', '2007-04-01',
                     '2007-04-02', '2007-04-03', '2007-04-04', '2007-04-05', '2007-04-06',
                     '2007-04-07', '2007-04-08', '2007-04-09', '2007-04-10', '2007-04-11',
                     '2007-04-12', '2007-04-13', '2007-04-14', '2007-04-15', '2007-04-16',
                     '2007-04-17', '2007-04-18', '2007-04-19', '2007-04-20', '2007-04-21',
                     '2007-04-22', '2007-04-23', '2007-04-24', '2007-04-25', '2007-04-26',
                     '2007-04-27', '2007-04-28', '2007-04-29', '2007-04-30', '2007-05-01',
                     '2007-05-02', '2007-05-03', '2007-05-04', '2007-05-05', '2007-05-06',
                     '2007-05-07', '2007-05-08', '2007-05-09', '2007-05-10', '2007-05-11',
                     '2007-05-12', '2007-05-13', '2007-05-14', '2007-05-15', '2007-05-16',
                     '2007-05-17', '2007-05-18', '2007-05-19', '2007-05-20', '2007-05-21',
                     '2007-05-22', '2007-05-23', '2007-05-24', '2007-05-25', '2007-05-26',
                     '2007-05-27', '2007-05-28', '2007-05-29', '2007-05-30', '2007-05-31',
                     '2007-06-01', '2007-06-02', '2007-06-03', '2007-06-04', '2007-06-05',
                     '2007-06-06', '2007-06-07', '2007-06-08', '2007-06-09', '2007-06-10',
                     '2007-06-11', '2007-06-12', '2007-06-13', '2007-06-14', '2007-06-15',
                     '2007-06-16', '2007-06-17', '2007-06-18', '2007-06-19', '2007-06-20',
                     '2007-06-21', '2007-06-22', '2007-06-23', '2007-06-24', '2007-06-25',
                     '2007-06-26', '2007-06-27', '2007-06-28', '2007-06-29', '2007-06-30',
                     '2007-07-01', '2007-07-02', '2007-07-03', '2007-07-04', '2007-07-05',
                     '2007-07-06', '2007-07-07', '2007-07-08', '2007-07-09', '2007-07-10',
                     '2007-07-11', '2007-07-12', '2007-07-13', '2007-07-14', '2007-07-15',
                     '2007-07-16', '2007-07-17', '2007-07-18', '2007-07-19', '2007-07-20',
                     '2007-07-21', '2007-07-22', '2007-07-23', '2007-07-24', '2007-07-25',
                     '2007-07-26', '2007-07-27', '2007-07-28', '2007-07-29', '2007-07-30',
                     '2007-07-31', '2007-08-01', '2007-08-02', '2007-08-03', '2007-08-04',
                     '2007-08-05', '2007-08-06', '2007-08-07', '2007-08-08', '2007-08-09',
                     '2007-08-10', '2007-08-11', '2007-08-12', '2007-08-13', '2007-08-14',
                     '2007-08-15', '2007-08-16', '2007-08-17', '2007-08-18', '2007-08-19',
                     '2007-08-20', '2007-08-21', '2007-08-22', '2007-08-23', '2007-08-24',
                     '2007-08-25', '2007-08-26', '2007-08-27', '2007-08-28', '2007-08-29',
                     '2007-08-30', '2007-08-31', '2007-09-01', '2007-09-02', '2007-09-03',
                     '2007-09-04', '2007-09-05', '2007-09-06', '2007-09-07', '2007-09-08',
                     '2007-09-09', '2007-09-10', '2007-09-11', '2007-09-12', '2007-09-13',
                     '2007-09-14', '2007-09-15', '2007-09-16', '2007-09-17', '2007-09-18',
                     '2007-09-19', '2007-09-20', '2007-09-21', '2007-09-22', '2007-09-23',
                     '2007-09-24', '2007-09-25', '2007-09-26', '2007-09-27', '2007-09-28',
                     '2007-09-29', '2007-09-30', '2007-10-01', '2007-10-02', '2007-10-03',
                     '2007-10-04', '2007-10-05', '2007-10-06', '2007-10-07', '2007-10-08',
                     '2007-10-09', '2007-10-10', '2007-10-11', '2007-10-12', '2007-10-13',
                     '2007-10-14', '2007-10-15', '2007-10-16', '2007-10-17', '2007-10-18',
                     '2007-10-19', '2007-10-20', '2007-10-21', '2007-10-22', '2007-10-23',
                     '2007-10-24', '2007-10-25', '2007-10-26', '2007-10-27', '2007-10-28',
                     '2007-10-29', '2007-10-30', '2007-10-31', '2007-11-01', '2007-11-02',
                     '2007-11-03', '2007-11-04', '2007-11-05', '2007-11-06', '2007-11-07',
                     '2007-11-08', '2007-11-09', '2007-11-10', '2007-11-11', '2007-11-12',
                     '2007-11-13', '2007-11-14', '2007-11-15', '2007-11-16', '2007-11-17',
                     '2007-11-18', '2007-11-19', '2007-11-20', '2007-11-21', '2007-11-22',
                     '2007-11-23', '2007-11-24', '2007-11-25', '2007-11-26', '2007-11-27',
                     '2007-11-28', '2007-11-29', '2007-11-30', '2007-12-01', '2007-12-02',
                     '2007-12-03', '2007-12-04', '2007-12-05', '2007-12-06', '2007-12-07',
                     '2007-12-08', '2007-12-09', '2007-12-10', '2007-12-11', '2007-12-12',
                     '2007-12-13', '2007-12-14', '2007-12-15', '2007-12-16', '2007-12-17',
                     '2007-12-18', '2007-12-19', '2007-12-20', '2007-12-21', '2007-12-22',
                     '2007-12-23', '2007-12-24', '2007-12-25', '2007-12-26', '2007-12-27',
                     '2007-12-28', '2007-12-29', '2007-12-30', '2007-12-31', '2008-01-01',
                     '2008-01-02', '2008-01-03', '2008-01-04', '2008-01-05', '2008-01-06',
                     '2008-01-07', '2008-01-08', '2008-01-09', '2008-01-10', '2008-01-11',
                     '2008-01-12', '2008-01-13', '2008-01-14', '2008-01-15', '2008-01-16',
                     '2008-01-17', '2008-01-18', '2008-01-19', '2008-01-20', '2008-01-21',
                     '2008-01-22', '2008-01-23', '2008-01-24', '2008-01-25', '2008-01-26',
                     '2008-01-27', '2008-01-28', '2008-01-29', '2008-01-30', '2008-01-31',
                     '2008-02-01', '2008-02-02', '2008-02-03', '2008-02-04', '2008-02-05',
                     '2008-02-06', '2008-02-07', '2008-02-08', '2008-02-09', '2008-02-10',
                     '2008-02-11', '2008-02-12', '2008-02-13', '2008-02-14', '2008-02-15',
                     '2008-02-16', '2008-02-17', '2008-02-18', '2008-02-19', '2008-02-20',
                     '2008-02-21', '2008-02-22', '2008-02-23', '2008-02-24', '2008-02-25',
                     '2008-02-26', '2008-02-27', '2008-02-28', '2008-02-29', '2008-03-01',
                     '2008-03-02', '2008-03-03', '2008-03-04', '2008-03-05', '2008-03-06',
                     '2008-03-07', '2008-03-08', '2008-03-09', '2008-03-10', '2008-03-11',
                     '2008-03-12', '2008-03-13', '2008-03-14', '2008-03-15', '2008-03-16',
                     '2008-03-17', '2008-03-18', '2008-03-19', '2008-03-20', '2008-03-21',
                     '2008-03-22', '2008-03-23', '2008-03-24', '2008-03-25', '2008-03-26',
                     '2008-03-27', '2008-03-28', '2008-03-29', '2008-03-30', '2008-03-31',
                     '2008-04-01', '2008-04-02', '2008-04-03', '2008-04-04', '2008-04-05',
                     '2008-04-06', '2008-04-07', '2008-04-08', '2008-04-09', '2008-04-10',
                     '2008-04-11', '2008-04-12', '2008-04-13', '2008-04-14', '2008-04-15',
                     '2008-04-16', '2008-04-17', '2008-04-18', '2008-04-19', '2008-04-20',
                     '2008-04-21', '2008-04-22', '2008-04-23', '2008-04-24', '2008-04-25',
                     '2008-04-26', '2008-04-27', '2008-04-28', '2008-04-29', '2008-04-30',
                     '2008-05-01', '2008-05-02', '2008-05-03', '2008-05-04', '2008-05-05',
                     '2008-05-06', '2008-05-07', '2008-05-08', '2008-05-09', '2008-05-10',
                     '2008-05-11', '2008-05-12', '2008-05-13', '2008-05-14', '2008-05-15',
                     '2008-05-16', '2008-05-17', '2008-05-18', '2008-05-19', '2008-05-20',
                     '2008-05-21', '2008-05-22', '2008-05-23', '2008-05-24', '2008-05-25',
                     '2008-05-26', '2008-05-27', '2008-05-28', '2008-05-29', '2008-05-30',
                     '2008-05-31', '2008-06-01', '2008-06-02', '2008-06-03', '2008-06-04',
                     '2008-06-05', '2008-06-06', '2008-06-07', '2008-06-08', '2008-06-09',
                     '2008-06-10', '2008-06-11', '2008-06-12', '2008-06-13', '2008-06-14',
                     '2008-06-15', '2008-06-16', '2008-06-17', '2008-06-18', '2008-06-19',
                     '2008-06-20', '2008-06-21', '2008-06-22', '2008-06-23', '2008-06-24',
                     '2008-06-25', '2008-06-26', '2008-06-27', '2008-06-28', '2008-06-29',
                     '2008-06-30', '2008-07-01', '2008-07-02', '2008-07-03', '2008-07-04',
                     '2008-07-05', '2008-07-06', '2008-07-07', '2008-07-08', '2008-07-09',
                     '2008-07-10', '2008-07-11', '2008-07-12', '2008-07-13', '2008-07-14',
                     '2008-07-15', '2008-07-16', '2008-07-17', '2008-07-18', '2008-07-19',
                     '2008-07-20', '2008-07-21', '2008-07-22', '2008-07-23', '2008-07-24',
                     '2008-07-25', '2008-07-26', '2008-07-27', '2008-07-28', '2008-07-29',
                     '2008-07-30', '2008-07-31', '2008-08-01', '2008-08-02', '2008-08-03',
                     '2008-08-04', '2008-08-05', '2008-08-06', '2008-08-07', '2008-08-08',
                     '2008-08-09', '2008-08-10', '2008-08-11', '2008-08-12', '2008-08-13',
                     '2008-08-14', '2008-08-15', '2008-08-16', '2008-08-17', '2008-08-18',
                     '2008-08-19', '2008-08-20', '2008-08-21', '2008-08-22', '2008-08-23',
                     '2008-08-24', '2008-08-25', '2008-08-26', '2008-08-27', '2008-08-28',
                     '2008-08-29', '2008-08-30', '2008-08-31', '2008-09-01', '2008-09-02',
                     '2008-09-03', '2008-09-04', '2008-09-05', '2008-09-06', '2008-09-07',
                     '2008-09-08', '2008-09-09', '2008-09-10', '2008-09-11', '2008-09-12',
                     '2008-09-13', '2008-09-14', '2008-09-15', '2008-09-16', '2008-09-17',
                     '2008-09-18', '2008-09-19', '2008-09-20', '2008-09-21', '2008-09-22',
                     '2008-09-23', '2008-09-24', '2008-09-25', '2008-09-26', '2008-09-27',
                     '2008-09-28', '2008-09-29', '2008-09-30', '2008-10-01', '2008-10-02',
                     '2008-10-03', '2008-10-04', '2008-10-05', '2008-10-06', '2008-10-07',
                     '2008-10-08', '2008-10-09', '2008-10-10', '2008-10-11', '2008-10-12',
                     '2008-10-13', '2008-10-14', '2008-10-15', '2008-10-16', '2008-10-17',
                     '2008-10-18', '2008-10-19', '2008-10-20', '2008-10-21', '2008-10-22',
                     '2008-10-23', '2008-10-24', '2008-10-25', '2008-10-26', '2008-10-27',
                     '2008-10-28', '2008-10-29', '2008-10-30', '2008-10-31', '2008-11-01',
                     '2008-11-02', '2008-11-03', '2008-11-04', '2008-11-05', '2008-11-06',
                     '2008-11-07', '2008-11-08', '2008-11-09', '2008-11-10', '2008-11-11',
                     '2008-11-12', '2008-11-13', '2008-11-14', '2008-11-15', '2008-11-16',
                     '2008-11-17', '2008-11-18', '2008-11-19', '2008-11-20', '2008-11-21',
                     '2008-11-22', '2008-11-23', '2008-11-24', '2008-11-25', '2008-11-26',
                     '2008-11-27', '2008-11-28', '2008-11-29', '2008-11-30', '2008-12-01',
                     '2008-12-02', '2008-12-03', '2008-12-04', '2008-12-05', '2008-12-06',
                     '2008-12-07', '2008-12-08', '2008-12-09', '2008-12-10', '2008-12-11',
                     '2008-12-12', '2008-12-13', '2008-12-14', '2008-12-15', '2008-12-16',
                     '2008-12-17', '2008-12-18', '2008-12-19', '2008-12-20', '2008-12-21',
                     '2008-12-22', '2008-12-23', '2008-12-24', '2008-12-25', '2008-12-26',
                     '2008-12-27', '2008-12-28', '2008-12-29', '2008-12-30', '2008-12-31',
                     '2009-01-01', '2009-01-02', '2009-01-03', '2009-01-04', '2009-01-05',
                     '2009-01-06', '2009-01-07', '2009-01-08', '2009-01-09', '2009-01-10',
                     '2009-01-11', '2009-01-12', '2009-01-13', '2009-01-14', '2009-01-15',
                     '2009-01-16', '2009-01-17', '2009-01-19', '2009-01-20', '2009-01-21']
        good_data = ['2008-01-01', '2008-01-02', '2008-01-03', '2008-01-04', '2008-01-05', '2008-01-06', '2008-01-07']
        # 处理时间戳为0的(就变成了这里的1970-01-01)
        if self.use_good_data:
            self.good_data_format = '%Y-%m-%d'
            self.good_data_list = good_data
        for day in (good_data if self.use_good_data else candidate):
            tem = dataframe[['from_id', 'to_id']][dataframe['timestamp'] == day]
            tem['from_id'] = tem['from_id'].map(lambda x: "U" + str(x))  # user
            tem['to_id'] = tem['to_id'].map(lambda x: "U" + str(x))  # user
            # 统计权重
            tem = tem.groupby(['from_id', 'to_id']).size().reset_index().rename(columns={0: 'weight'})
            tem.to_csv(os.path.join(self.format_output_path, str(day) + ".csv"), sep='\t', header=1, index=0)

    def handle_by_month(self):
        # 按月处理
        dataframe = pd.read_csv(self.input_file, sep=" ", names=['from_id', 'to_id', 'type', 'timestamp'])
        dataframe['timestamp'] = pd.to_datetime(dataframe['timestamp'], unit='s').dt.strftime('%Y-%m')
        candidate = ['1970-01', '2006-09', '2006-10', '2006-11', '2006-12', '2007-01', '2007-02', '2007-03', '2007-04',
                     '2007-05', '2007-06', '2007-07', '2007-08', '2007-09', '2007-10', '2007-11', '2007-12', '2008-01',
                     '2008-02', '2008-03', '2008-04', '2008-05', '2008-06', '2008-07', '2008-08', '2008-09', '2008-10',
                     '2008-11', '2008-12', '2009-01']
        good_data = ['2006-10', '2006-11', '2006-12', '2007-01', '2007-02', '2007-03', '2007-04', '2007-05', '2007-06',
                     '2007-07', '2007-08', '2007-09', '2007-10', '2007-11', '2007-12', '2008-01', '2008-02', '2008-03',
                     '2008-04', '2008-05', '2008-06', '2008-07', '2008-08', '2008-09', '2008-10', '2008-11', '2008-12']
        # good_data = ['2006-09', '2006-10', '2006-11', '2006-12', '2007-01', '2007-02', '2007-03', '2007-04', '2007-05',
        #              '2007-06', '2007-07', '2007-08', '2007-09', '2007-10', '2007-11', '2007-12', '2008-01', '2008-02',
        #              '2008-03', '2008-04', ]
        # good_data = ['2007-01', '2007-02', '2007-03', '2007-04', '2007-05', '2007-06', '2007-07']
        # 处理时间戳为0的(就变成了这里的1970-01-01)
        if self.use_good_data:
            self.good_data_format = '%Y-%m'
            self.good_data_list = good_data
        for month in (good_data if self.use_good_data else candidate):
            tem = dataframe[['from_id', 'to_id']][dataframe['timestamp'] == month]
            tem['from_id'] = tem['from_id'].map(lambda x: "U" + str(x))  # user
            tem['to_id'] = tem['to_id'].map(lambda x: "U" + str(x))  # user
            # 统计权重
            tem = tem.groupby(['from_id', 'to_id']).size().reset_index().rename(columns={0: 'weight'})
            tem.to_csv(os.path.join(self.format_output_path, str(month) + ".csv"), sep='\t', header=1, index=0)

    def handle_by_year(self):
        # 按年处理
        dataframe = pd.read_csv(self.input_file, sep=" ", names=['from_id', 'to_id', 'type', 'timestamp'])
        dataframe['timestamp'] = pd.to_datetime(dataframe['timestamp'], unit='s').dt.strftime('%Y')
        candidate = ['1970', '2006', '2007', '2008', '2009']
        # 处理时间戳为0的(就变成了这里的1970-01-01)
        for year in candidate:
            tem = dataframe[['from_id', 'to_id']][dataframe['timestamp'] == year]
            tem['from_id'] = tem['from_id'].map(lambda x: "U" + str(x))  # user
            tem['to_id'] = tem['to_id'].map(lambda x: "U" + str(x))  # user
            # 统计权重
            tem = tem.groupby(['from_id', 'to_id']).size().reset_index().rename(columns={0: 'weight'})
            tem.to_csv(os.path.join(self.format_output_path, str(year) + ".csv"), sep='\t', header=1, index=0)

    def test_granularity(self, time_format='%Y-%m-%d %H:%M:%s'):
        dataframe = pd.read_csv(self.input_file, sep=" ", names=['from_id', 'to_id', 'type', 'timestamp'])
        print("top 10 rows:\n")
        print(dataframe[0:10])
        print("shape:")
        print(dataframe.shape)
        dataframe['timestamp'] = pd.to_datetime(dataframe['timestamp'], unit='s').dt.strftime(time_format)
        print(np.sort(dataframe['timestamp'].unique()))

    def get_full_node_set(self):
        print("get full node set")

        nodes_set_path = self.node_list_output_path
        check_and_make_path(nodes_set_path)

        dataframe = pd.read_csv(self.input_file, sep=" ", names=['from_id', 'to_id', 'type', 'timestamp'])

        if self.use_good_data:
            dataframe['timestamp'] = pd.to_datetime(dataframe['timestamp'], unit='s').dt.strftime(self.good_data_format)
            dataframe = dataframe[np.isin(dataframe['timestamp'], self.good_data_list, invert=False)]

        # nodes_set = np.sort(pd.concat([dataframe['from_id'], dataframe['to_id']], axis=0, ignore_index=True).unique())
        nodes_set = pd.concat([dataframe['from_id'], dataframe['to_id']], axis=0, ignore_index=True).unique()
        pd_data = pd.DataFrame(nodes_set, columns=['node'])
        pd_data['node'] = pd_data['node'].map(lambda x: "U" + str(x))
        pd_data = pd_data.sort_values(by='node')

        pd_data.to_csv(os.path.join(nodes_set_path, 'nodes.csv'), index=0, header=0)

        print("got it\n")

def transform(trans_type=None, use_good_data=False):
    if trans_type is None:
        trans_type = ['day']
    fb = FBTransformer(input_file="/data/facebook/0.input/fb-wosn-friends.edges", output_base_path="/data/facebook/")
    fb.transform(trans_type, use_good_data=use_good_data)
    fb.get_full_node_set()

if __name__ == '__main__':
    transform(trans_type=['month'], use_good_data=True)