back-end/threats_monitoring/phishtank-alev.py
def time_series_analysis(db):
    """ Collects all the information from the collection and presents the number of blocked IP's per day
        Saves the results in csv and json file respectively for later process (stakeholders and Highcharts)
        @param
            db:     (Mongo Client)  this is the connection returned by Pymongo Client,
                                    we take it from connect_to_mongodb() function
    """

    num_of_docs_in_collection = db.threats.phishtank.count()

    # Process Data if the collection is not empty
    if num_of_docs_in_collection != 0:
        try:
            # retrieve DatetimeUTC for all docs in collection
            cursor = db.threats.phishtank.find({}, {'mongoDate': 1, '_id': 0})
            # Dates list for storing the corresponding query in json file
            dates_list = list([])
            for doc in cursor:
                dates_list.append(doc['mongoDate'])
            ''' Time Series '''
            # a list of "1" to count the docs
            ones = [1] * len(dates_list)
            # the index of the series
            idx = pd.DatetimeIndex(dates_list)
            # the actual series (at series of 1s for the moment)
            time_series = pd.Series(ones, index=idx)
            print(time_series.head())

            # Resampling / bucketing
            per_day = time_series.resample('1D').sum().fillna(0)

            print("Per Day:")
            print(per_day.head())

            print("\nDataFrame per Day")
            s = pd.DataFrame(per_day)
            print(s.head())

            s.to_csv(server_path + 'perdayTimeSeriesPhishtank.csv')
            data_frame_to_json(s, server_path + 'phishtankjson.json')

        except Exception as e:
            print("Unexpected error:", type(e), e)

    else:
        print('Database is empty! Can not retrieve data!')
 Collects all the information from the collection and presents the number of blocked IP's per day
        Saves the results in csv and json file respectively for later process (stakeholders and Highcharts)
        @param
            db:     (Mongo Client)  this is the connection returned by Pymongo Client,
                                    we take it from connect_to_mongodb() function
    
Collects all the information from the collection and presents the number of blocked IP's per day
Saves the results in csv and json file respectively for later process (stakeholders and Highcharts)
Collects all the information from the collection and presents the number of blocked IP ' s per day Saves the results in csv and json file respectively for later process ( stakeholders and Highcharts )
def time_series_analysis(db):
    num_of_docs_in_collection = db.threats.phishtank.count()
    if num_of_docs_in_collection != 0:
        try:
            cursor = db.threats.phishtank.find({}, {'mongoDate': 1, '_id': 0})
            dates_list = list([])
            for doc in cursor:
                dates_list.append(doc['mongoDate'])
            ones = [1] * len(dates_list)
            idx = pd.DatetimeIndex(dates_list)
            time_series = pd.Series(ones, index=idx)
            print(time_series.head())
            per_day = time_series.resample('1D').sum().fillna(0)
            print("Per Day:")
            print(per_day.head())
            print("\nDataFrame per Day")
            s = pd.DataFrame(per_day)
            print(s.head())
            s.to_csv(server_path + 'perdayTimeSeriesPhishtank.csv')
            data_frame_to_json(s, server_path + 'phishtankjson.json')
        except Exception as e:
            print("Unexpected error:", type(e), e)
    else:
        print('Database is empty! Can not retrieve data!')
def time_series_analysis ( db ) : num_of_docs_in_collection = db . threats . phishtank . count ( ) if num_of_docs_in_collection != 0 : try : cursor = db . threats . phishtank . find ( { } , { 'mongoDate' : 1 , '_id' : 0 } ) dates_list = list ( [ ] ) for doc in cursor : dates_list . append ( doc [ 'mongoDate' ] ) ''' Time Series ''' ones = [ 1 ] * len ( dates_list ) idx = pd . DatetimeIndex ( dates_list ) time_series = pd . Series ( ones , index = idx ) print ( time_series . head ( ) ) per_day = time_series . resample ( '1D' ) . sum ( ) . fillna ( 0 ) print ( "Per Day:" ) print ( per_day . head ( ) ) print ( "\nDataFrame per Day" ) s = pd . DataFrame ( per_day ) print ( s . head ( ) ) s . to_csv ( server_path + 'perdayTimeSeriesPhishtank.csv' ) data_frame_to_json ( s , server_path + 'phishtankjson.json' ) except Exception as e : print ( "Unexpected error:" , type ( e ) , e ) else : print ( 'Database is empty! Can not retrieve data!' )
Collects all the information from the collection and presents the number of blocked IP's per day
Saves the results in csv and json file respectively for later process (stakeholders and Highcharts)
Collects all the information from the collection and presents the number of blocked IP ' s per day Saves the results in csv and json file respectively for later process ( stakeholders and Highcharts )
""" Collects all the information from the collection and presents the number of blocked IP's per day
        Saves the results in csv and json file respectively for later process (stakeholders and Highcharts)
        @param
            db:     (Mongo Client)  this is the connection returned by Pymongo Client,
                                    we take it from connect_to_mongodb() function
    """ # Process Data if the collection is not empty
 # retrieve DatetimeUTC for all docs in collection
 # Dates list for storing the corresponding query in json file
 ''' Time Series ''' # a list of "1" to count the docs
 # the index of the series
 # the actual series (at series of 1s for the moment)
 # Resampling / bucketing

db
(Mongo Client)  this is the connection returned by Pymongo Client,
we take it from connect_to_mongodb() function
( Mongo Client ) this is the connection returned by Pymongo Client we take it from connect_to_mongodb () function