Ejemplo n.º 1
0
 def clicks(self, last_session=False, click_type='Single', _cache_file=None):
     """Generate the click image."""
     self._generate_start()
     
     #Attempt to load data from cache
     cache_data = self.cache_load(_cache_file)
     if cache_data is not None:
         (min_value, max_value), heatmap = cache_data
     skip_calculations = cache_data is not None
     
     if not skip_calculations:
     
         #Detect session information
         if last_session:
             clicks = self.data['Maps']['Session']['Click'][click_type]
         else:
             clicks = self.data['Maps']['Click'][click_type]
     
         lmb = CONFIG['GenerateHeatmap']['_MouseButtonLeft']
         mmb = CONFIG['GenerateHeatmap']['_MouseButtonMiddle']
         rmb = CONFIG['GenerateHeatmap']['_MouseButtonRight']
         valid_buttons = [i for i, v in zip(('Left', 'Middle', 'Right'), (lmb, mmb, rmb)) if v]
         
         numpy_arrays = merge_resolutions(clicks, map_selection=valid_buttons)[1]
         
         width, height = CONFIG['GenerateImages']['_UpscaleResolutionX'], CONFIG['GenerateImages']['_UpscaleResolutionY']
         (min_value, max_value), heatmap = arrays_to_heatmap(numpy_arrays,
                     gaussian_size=gaussian_size(width, height),
                     clip=1-CONFIG['Advanced']['HeatmapRangeClipping'])
     
     #Save cache if it wasn't generated
     if _cache_file is not None and not skip_calculations:
         self.cache_save(_cache_file, min_value, max_value, heatmap)
         
     #Convert each point to an RGB tuple
     try:
         colour_map = calculate_colour_map(CONFIG['GenerateHeatmap']['ColourProfile'])
     except ValueError:
         default_colours = _config_defaults['GenerateHeatmap']['ColourProfile'][0]
         colour_map = calculate_colour_map(default_colours)
     colour_range = ColourRange(min_value, max_value, colour_map)
     
     image_name = self.name.generate('Clicks', reload=True)
     image_output = Image.fromarray(convert_to_rgb(heatmap, colour_range))
     
     if image_output is None:
         _print('No click data was found.')
         return None
         
     return self._generate_end(image_name, image_output, resize=True)
Ejemplo n.º 2
0
    def reload(self):

        g_im = CONFIG['GenerateImages']
        g_hm = CONFIG['GenerateHeatmap']
        g_t = CONFIG['GenerateTracks']
        g_s = CONFIG['GenerateSpeed']
        g_kb = CONFIG['GenerateKeyboard']

        self.width = str(g_im['_OutputResolutionX'])
        self.height = str(g_im['_OutputResolutionY'])
        self.uwidth = str(g_im['_UpscaleResolutionX'])
        self.uheight = str(g_im['_UpscaleResolutionY'])
        self.high_precision = 'High Detail' if g_im[
            'HighPrecision'] else 'Normal'

        self.heatmap_colours = str(g_hm['ColourProfile'])
        self.heatmap_buttons = {
            'LMB': g_hm['_MouseButtonLeft'],
            'MMB': g_hm['_MouseButtonMiddle'],
            'RMB': g_hm['_MouseButtonRight']
        }
        selected_buttons = [k for k, v in get_items(self.heatmap_buttons) if v]
        if len(selected_buttons) == 3:
            self.heatmap_button_group = 'Combined'
        elif len(selected_buttons) == 2:
            self.heatmap_button_group = '+'.join(selected_buttons)
        elif len(selected_buttons) == 1:
            self.heatmap_button_group = selected_buttons[0]
        else:
            self.heatmap_button_group = 'Empty'
        self.heatmap_gaussian_actual = str(
            gaussian_size(g_im['_UpscaleResolutionX'],
                          g_im['_UpscaleResolutionY']))
        self.heatmap_gaussian = str(g_hm['GaussianBlurMultiplier'])

        self.track_colour = str(g_t['ColourProfile'])

        self.speed_colour = str(g_s['ColourProfile'])

        self.keyboard_colour = str(g_kb['ColourProfile'])
        self.keyboard_set = g_kb['DataSet'][0].upper(
        ) + g_kb['DataSet'][1:].lower()
        self.keyboard_exponential = str(g_kb['LinearPower'])
        self.keyboard_size_mult = str(g_kb['SizeMultiplier'])
        self.keyboard_extended = 'Extended' if g_kb[
            'ExtendedKeyboard'] else 'Compact'
Ejemplo n.º 3
0
    def clicks(self, last_session=False, file_name=None, _double_click=False):
        """Render heatmap of clicks."""

        top_resolution, (min_value, max_value), clicks = self.data.get_clicks(
            session=last_session, double_click=_double_click)
        output_resolution, upscale_resolution = calculate_resolution(
            clicks.keys(), top_resolution)

        lmb = CONFIG['GenerateHeatmap']['_MouseButtonLeft']
        mmb = CONFIG['GenerateHeatmap']['_MouseButtonMiddle']
        rmb = CONFIG['GenerateHeatmap']['_MouseButtonRight']
        skip = []
        if lmb or mmb or rmb:
            if not lmb:
                skip.append(0)
            if not mmb:
                skip.append(1)
            if not rmb:
                skip.append(2)
        upscaled_arrays = upscale_arrays_to_resolution(clicks,
                                                       upscale_resolution,
                                                       skip=skip)

        (min_value, max_value), heatmap = arrays_to_heatmap(
            upscaled_arrays,
            gaussian_size=gaussian_size(upscale_resolution[0],
                                        upscale_resolution[1]),
            clip=1 - CONFIG['Advanced']['HeatmapRangeClipping'])

        colour_range = self._get_colour_range(min_value, max_value,
                                              'GenerateHeatmap')

        image_output = Image.fromarray(colour_range.convert_to_rgb(heatmap))
        image_output = image_output.resize(output_resolution, Image.ANTIALIAS)

        if file_name is None:
            file_name = self.name.generate('Clicks', reload=True)

        if self.save:
            create_folder(file_name)
            Message('Saving image to "{}"...'.format(file_name))
            image_output.save(file_name)
            Message('Finished saving.')