Exemplo n.º 1
0
 def __init__(self, simulator: Simulator):
     self.__simulator = simulator
     self.__data_dict: OrderedDict[str,
                                   OrderedDict[str,
                                               List[Decimal]]] = OrdDict()
     self.__data_structure: OrderedDict[str, OrderedDict[str,
                                                         bool]] = OrdDict()
Exemplo n.º 2
0
    def _get_filtered_data(self, feature_filter: str, module_fqn_filter: str) -> OrderedDict[str, Any]:
        r"""
        Filters the data and returns it in the same ordered dictionary format so the relavent views can be displayed.

        Args:
            feature_filter (str): The feature filter, if we want to filter the set of data to only include
                a certain set of features that include feature_filter
                If feature = "", then we do not filter based on any features
            module_fqn_filter (str): The filter on prefix for the module fqn. All modules that have fqn with
                this prefix will be included
                If module_fqn_filter = "" we do not filter based on module fqn, and include all modules

        First, the data is filtered based on module_fqn, and then filtered based on feature
        Returns an OrderedDict (sorted in order of model) mapping:
            module_fqns -> feature_names -> values
        """
        # create return dict
        filtered_dict: OrderedDict[str, Any] = OrdDict()

        for module_fqn in self.generated_reports:
            # first filter based on module
            if module_fqn_filter == "" or module_fqn_filter in module_fqn:
                # create entry for module and loop through features
                filtered_dict[module_fqn] = {}
                module_reports = self.generated_reports[module_fqn]
                for feature_name in module_reports:
                    # check if filtering on features and do so if desired
                    if feature_filter == "" or feature_filter in feature_name:
                        filtered_dict[module_fqn][feature_name] = module_reports[feature_name]

        # we have populated the filtered dict, and must return it

        return filtered_dict
Exemplo n.º 3
0
 def _set_settings_map(self):
     # Each item represents a level setting
     #
     # Key a setter function that takes one argument which receives
     #   the value the level setting is to be set to. Setter function
     #   responsible for implementing all conseqeunces of change in
     #   level setting value. NB All setter functions are class methods.
     #
     # Value an iterator that returns the level setting values, with
     #   first interation returning value for level 1 and each subsequent
     #   call returning value for each successive level. NB iterator
     #   defined as the return of a function assigned to a corresponding
     #   global constant.
     map = OrdDict({
         self._set_level: it.count(1, 1),
         self._set_ship_speed: SHIP_SPEED(),
         self._set_ship_rotation_speed: SHIP_ROTATION_SPEED(),
         self._set_asteroid_speed: ASTEROID_SPEED(),
         self._set_spawn_limit: SPAWN_LIMIT(),
         self._set_num_per_spawn: NUM_PER_SPAWN(),
         self._set_num_asteroids: NUM_ASTEROIDS(),
         self._set_bullet_speed: BULLET_SPEED(),
         self._set_cannon_reload_rate: CANNON_RELOAD_RATE(),
         self._set_radiation_field: RAD_BORDER(),
         self._set_natural_exposure_limit: NAT_EXPOSURE_LIMIT(),
         self._set_high_exposure_limit: HIGH_EXPOSURE_LIMIT(),
         self._set_pickups: NUM_PICKUPS()
     })
     self._settings_map = map
Exemplo n.º 4
0
    def add_data(self, category: str, data_field: str, data: Decimal):
        if not category in self.__data_dict:
            self.__data_dict[category] = OrdDict()

        if not data_field in self.__data_dict[category]:
            self.__data_dict[category][data_field] = []

        self.__data_dict[category][data_field].append(data)
Exemplo n.º 5
0
    def get_category_ranking(self, sample_info):

        # Extract info from named tuple
        av_label_pairs = sample_info[3]
        hashes = [sample_info[0], sample_info[1], sample_info[2]]

        # Whitelist the AVs to filter the ones with meaningful labels
        av_whitelist = self.avs

        # Initialize auxiliary data structures
        duplicates = set()
        category_map = {}

        # Process each AV label
        for (av_name, label) in av_label_pairs:
            # If empty label, nothing to do
            if not label:
                continue

            #####################
            # Duplicate removal #
            #####################

            # If label ends in ' (B)', remove it
            if label.endswith(' (B)'):
                label = label[:-4]

            ##################
            # Suffix removal #
            ##################
            label = self.__remove_suffixes(av_name, label)

            ########################################################
            # Tokenization, token filtering, and alias replacement #
            ########################################################
            tokens = self.__norm_cat(label, hashes)
            # Increase token count in map
            for t in tokens:
                c = category_map[t] if t in category_map else 0
                category_map[t] = c + 1

        ##################################################################
        # Token ranking: sorts tokens by decreasing count and then token #
        ##################################################################
        sorted_category = sorted(category_map.iteritems(),
                                 key=itemgetter(1, 0),
                                 reverse=True)

        # Delete the tokens appearing only in one AV, add rest to output
        sorted_dict = OrdDict()
        for t, c in sorted_category:
            if c > 1:
                sorted_dict[t] = c
            else:
                break

        return sorted_dict
Exemplo n.º 6
0
 def __init__(self):
     self.order = OrdDict()
Exemplo n.º 7
0
    def get_family_ranking(self, sample_info):
        '''
        Returns sorted dictionary of most likely family names for sample
        '''
        # Extract info from named tuple
        av_label_pairs = sample_info[3]
        hashes = [sample_info[0], sample_info[1], sample_info[2]]

        # Whitelist the AVs to filter the ones with meaningful labels
        av_whitelist = self.avs

        # Initialize auxiliary data structures
        duplicates = set()
        token_map = {}

        # Process each AV label
        for (av_name, label) in av_label_pairs:
            # If empty label, nothing to do
            if not label:
                continue

            ################
            # AV selection #
            ################
            if av_whitelist and av_name not in av_whitelist:
                continue

            #####################
            # Duplicate removal #
            #####################

            # If label ends in ' (B)', remove it
            if label.endswith(' (B)'):
                label = label[:-4]

            # If we have seen the label before, skip
            if label in duplicates:
                continue
            # If not, we add it to duplicates
            else:
                duplicates.add(label)

            ##################
            # Suffix removal #
            ##################
            label = self.__remove_suffixes(av_name, label)

            ########################################################
            # Tokenization, token filtering, and alias replacement #
            ########################################################
            tokens = self.__normalize(label, hashes)

            # Increase token count in map
            for t in tokens:
                c = token_map[t] if t in token_map else 0
                token_map[t] = c + 1

        ##################################################################
        # Token ranking: sorts tokens by decreasing count and then token #
        ##################################################################
        sorted_tokens = sorted(token_map.iteritems(),
                               key=itemgetter(1, 0),
                               reverse=True)

        # Delete the tokens appearing only in one AV, add rest to output
        sorted_dict = OrdDict()
        for t, c in sorted_tokens:
            if c > 1:
                sorted_dict[t] = c
            else:
                break

        return sorted_dict
Exemplo n.º 8
0
    def get_family_ranking(self, sample_info):
        '''
        Returns sorted dictionary of most likely family names for sample
        '''
        # Extract info from named tuple
        av_label_pairs = sample_info[3]
        hashes = [ sample_info[0], sample_info[1], sample_info[2] ]

        # Whitelist the AVs to filter the ones with meaningful labels
        av_whitelist = self.avs

        # Initialize auxiliary data structures
        labels_seen = set()
        token_map = {}

        # Process each AV label
        for (av_name, label) in av_label_pairs:
            # If empty label, nothing to do
            if not label:
                continue

            ################
            # AV selection #
            ################
            if av_whitelist and av_name not in av_whitelist:
                continue

            #####################
            # Duplicate removal #
            #####################

            # Emsisoft uses same label as 
            # GData/ESET-NOD32/BitDefender/Ad-Aware/MicroWorld-eScan,
            # but suffixes ' (B)' to their label. Remove the suffix.
            if label.endswith(' (B)'):
                label = label[:-4]

            # F-Secure uses Avira's engine since Nov. 2018
            # but prefixes 'Malware.' to Avira's label. Remove the prefix.
            if label.startswith('Malware.'):
                label = label[8:]

            # Other engines often use exactly the same label, e.g.,
            #   AVG/Avast
            #   K7Antivirus/K7GW
            #   Kaspersky/ZoneAlarm

            # If we have seen the exact same label before, skip
            if label in labels_seen:
                continue
            # If not, we add it to the set of labels seen
            else:
                labels_seen.add(label)

            ##################
            # Suffix removal #
            ##################
            label = self.__remove_suffixes(av_name, label)

            ########################################################
            # Tokenization, token filtering, and alias replacement #
            ########################################################
            tokens = self.__normalize(label, hashes)

            # Increase token count in map
            for t in tokens:
                c = token_map[t] if t in token_map else 0
                token_map[t] = c + 1

        ##################################################################
        # Token ranking: sorts tokens by decreasing count and then token #
        ##################################################################
        sorted_tokens = sorted(token_map.items(), 
                                key=itemgetter(1,0), 
                                reverse=True)

        # Delete the tokens appearing only in one AV, add rest to output
        sorted_dict = OrdDict()
        for t, c in sorted_tokens:
            if c > 1:
                sorted_dict[t] = c
            else:
                break
        
        return sorted_dict
Exemplo n.º 9
0
def filling_ord_dict(num):
    a = OrdDict()
    for i in range(num):
        a[str(i)] = i
    return a
Exemplo n.º 10
0
    def set_collect_data(self, category: str, data_field: str, collect: bool):
        if not category in self.data_structure:
            self.data_structure[category] = OrdDict()

        self.data_structure[category][data_field] = collect
Exemplo n.º 11
0
LEVEL_AUGMENTATION = 1.05

#SHIP CONTROLS
BLUE_CONTROLS = {
    'THRUST_KEY': [pyglet.window.key.I],
    'ROTATE_LEFT_KEY': [pyglet.window.key.J],
    'ROTATE_RIGHT_KEY': [pyglet.window.key.L],
    'SHIELD_KEY': [pyglet.window.key.K],
    'FIRE_KEY': [pyglet.window.key.ENTER],
    'FIRE_FAST_KEY': [pyglet.window.key.BACKSPACE],
    'SLD_KEY': [pyglet.window.key.RCTRL],
    'FIREWORK_KEYS':
    OrdDict({
        pyglet.window.key._7: 200,
        pyglet.window.key._8: 500,
        pyglet.window.key._9: 900
    }),
    'MINE_KEYS':
    OrdDict({
        pyglet.window.key.M: 1,
        pyglet.window.key.COMMA: 3,
        pyglet.window.key.PERIOD: 6
    })
}

RED_CONTROLS = {
    'THRUST_KEY': [pyglet.window.key.W],
    'ROTATE_LEFT_KEY': [pyglet.window.key.A],
    'ROTATE_RIGHT_KEY': [pyglet.window.key.D],
    'SHIELD_KEY': [pyglet.window.key.S],