back-end/utils/descriptive_analysis_summer.py
def time_series_analysis_per_month(self, mongoDateType='mongoDate', entity_type=''):
        """ 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 = self.__collection.count()

        # process data if the collection only if it's not empty
        # if it empty return no analysis can be done
        if num_of_docs_in_collection == 0:
            try:
                raise Warning("No documents retrieved. Collection {} seems to be empty".format(self.__collection.name))
            except Exception as e:
                print("DescriptiveAnalysis > time_series_analysis_per_month: ", e)
            return None

        if entity_type in ['IP', 'URL', 'Domain']:
            docs_of_interest = list([])
            for doc in self.__query_results:
                if doc["Entity-Type"] == entity_type:
                    docs_of_interest.append(doc)
        # in any other case entity-type is considered as an empty string by default
        # so the whole collection is retrieved
        else:
            docs_of_interest = self.__query_results

        dates_list = list([])
        for doc in docs_of_interest:
            dates_list.append(doc[mongoDateType])

        ''' 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")
        print(time_series.head())

        # Resampling / bucketing
        per_month = time_series.resample('1M').sum().fillna(0)
        print("\nPer Month Time Series")
        print(per_month.head())

        s = pd.DataFrame(per_month)
        print("\nPer Month DataFrame")
        print(s.head())

        return s
 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_per_month(self, mongoDateType='mongoDate', entity_type=''):
        num_of_docs_in_collection = self.__collection.count()
        if num_of_docs_in_collection == 0:
            try:
                raise Warning("No documents retrieved. Collection {} seems to be empty".format(self.__collection.name))
            except Exception as e:
                print("DescriptiveAnalysis > time_series_analysis_per_month: ", e)
            return None
        if entity_type in ['IP', 'URL', 'Domain']:
            docs_of_interest = list([])
            for doc in self.__query_results:
                if doc["Entity-Type"] == entity_type:
                    docs_of_interest.append(doc)
        else:
            docs_of_interest = self.__query_results
        dates_list = list([])
        for doc in docs_of_interest:
            dates_list.append(doc[mongoDateType])
        ones = [1] * len(dates_list)
        idx = pd.DatetimeIndex(dates_list)
        time_series = pd.Series(ones, index=idx)
        print("Time Series Head")
        print(time_series.head())
        per_month = time_series.resample('1M').sum().fillna(0)
        print("\nPer Month Time Series")
        print(per_month.head())
        s = pd.DataFrame(per_month)
        print("\nPer Month DataFrame")
        print(s.head())
        return s
def time_series_analysis_per_month ( self , mongoDateType = 'mongoDate' , entity_type = '' ) : num_of_docs_in_collection = self . __collection . count ( ) if num_of_docs_in_collection == 0 : try : raise Warning ( "No documents retrieved. Collection {} seems to be empty" . format ( self . __collection . name ) ) except Exception as e : print ( "DescriptiveAnalysis > time_series_analysis_per_month: " , e ) return None if entity_type in [ 'IP' , 'URL' , 'Domain' ] : docs_of_interest = list ( [ ] ) for doc in self . __query_results : if doc [ "Entity-Type" ] == entity_type : docs_of_interest . append ( doc ) else : docs_of_interest = self . __query_results dates_list = list ( [ ] ) for doc in docs_of_interest : dates_list . append ( doc [ mongoDateType ] ) ''' Time Series ''' ones = [ 1 ] * len ( dates_list ) idx = pd . DatetimeIndex ( dates_list ) time_series = pd . Series ( ones , index = idx ) print ( "Time Series Head" ) print ( time_series . head ( ) ) per_month = time_series . resample ( '1M' ) . sum ( ) . fillna ( 0 ) print ( "\nPer Month Time Series" ) print ( per_month . head ( ) ) s = pd . DataFrame ( per_month ) print ( "\nPer Month DataFrame" ) print ( s . head ( ) ) return s
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 only if it's not empty
 # if it empty return no analysis can be done
 # in any other case entity-type is considered as an empty string by default
 # so the whole collection is retrieved
 ''' 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

self
mongoDateType
entity_type
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