Esempio n. 1
0
    def __init__(self,
                 mkchart,
                 title='Default',
                 show_legend=True,
                 x_title=None,
                 y_title=None,
                 show_dots=False,
                 range=None,
                 xrange=None,
                 show_x_guides=False,
                 show_y_guides=False,
                 fill=False,
                 human_readable=True,
                 style=DarkColorizedStyle):

        self.context = App.get_running_app().root.ids.main_ui
        style.background = 'transparent'
        style.plot_background = 'transparent'
        style.opacity = '.7'
        config = Config()
        config.show_legend = show_legend
        config.human_readable = human_readable
        config.fill = fill
        config.title = title
        config.x_title = x_title
        config.y_title = y_title
        config.show_dots = show_dots
        config.xrange = xrange
        config.range = range
        config.show_x_guides = show_x_guides
        config.show_y_guides = show_y_guides
        config.style = style
        self.config = config
        self.chart = mkchart(config)
        self.view = None
Esempio n. 2
0
def define_config():
    """Defines some configuration options for the pygal plot."""
    config = Config()
    config.show_legend = False
    config.legend_at_bottom = True
    config.human_readable = True
    config.print_values = True
    config.show_x_labels = True
    config.show_y_labels = True
    config.fill = True
    return config
Esempio n. 3
0
def genweightchart():
    '''Generate weight chart with Pygal'''
    weighthistory = session.query(Weight) \
        .filter_by(user_id=current_user.id) \
        .order_by(Weight.id.asc()) \
        .all()

    maxweight = session.query(Weight) \
        .filter_by(user_id=current_user.id) \
        .order_by(Weight.weight.desc()) \
        .first()

    if maxweight is None:
        maxrange = 100
    else:
        maxrange = (int(maxweight.weight) + 5)

    custom_style = Style(
                background='transparent',
                value_font_size=24,
                title_font_size=36,
                label_font_size=24,
                margin=5,
                plot_background='transparent',
                foreground='#53E89B',
                foreground_strong='#53A0E8',
                foreground_subtle='#630C0D',
                opacity='.6',
                opacity_hover='.9',
                transition='400ms ease-in',
                colors=('#5cb85c', '#f0ad4e', '#d9534f'))
    config = Config()
    config.show_legend = False
    config.y_labels = range(0, maxrange, 5)
    config.margin_bottom=50
    config.human_readable = True
    config.fill = True
    config.style=custom_style
    config.print_labels=True
    config.no_data_text='Add weight measurements!'

    wlist = []
    for entry in enumerate(weighthistory):
        wlist.append(entry[1].weight)

    line_chart = pygal.Line(config)
    line_chart.title = "Weight History"
    line_chart.add('Values', wlist)
    chart = line_chart.render(is_unicode=True)
    return chart
Esempio n. 4
0
def genfoodchart(start, end):
    '''Generate food chart with Pygal'''
    now = datetime.datetime.now().strftime("%Y-%m-%d")
    goodcount = session.query(Food) \
        .filter_by(user_id=current_user.id) \
        .filter(Food.food_date.between(start, end)).join(Ranks) \
        .filter_by(rank=1).add_columns(Ranks.rank).count()
    okaycount = session.query(Food) \
        .filter_by(user_id=current_user.id) \
        .filter(Food.food_date.between(start, end)).join(Ranks) \
        .filter_by(rank=2).add_columns(Ranks.rank).count()
    badcount = session.query(Food) \
        .filter_by(user_id=current_user.id) \
        .filter(Food.food_date.between(start, end)).join(Ranks) \
        .filter_by(rank=3).add_columns(Ranks.rank).count()

    custom_style = Style(
                    background='transparent',
                    value_font_size=24,
                    title_font_size=36,
                    margin=1,
                    plot_background='transparent',
                    foreground='#53E89B',
                    foreground_strong='#53A0E8',
                    foreground_subtle='#630C0D',
                    opacity='.6',
                    opacity_hover='.9',
                    transition='400ms ease-in',
                    colors=('#5cb85c', '#f0ad4e', '#d9534f'))

    config = Config()
    config.show_legend = True
    config.legend_at_bottom=True
    config.legend_at_bottom_columns=1
    config.legend_box_size=10
    config.human_readable = True
    config.fill = True
    config.style=custom_style
    config.print_labels=True
    config.print_values=True
    config.no_data_text='Need to add some food!'

    pie_chart = pygal.Pie(config)
    pie_chart.title = "Current Food Stats"
    pie_chart.add('Good', goodcount)
    pie_chart.add('Okay', okaycount)
    pie_chart.add('Bad', badcount)
    chart = pie_chart.render(is_unicode=True)
    return chart
Esempio n. 5
0
def genweightchart():
    '''Generate weight chart with Pygal'''
    weighthistory = session.query(Weight) \
        .filter_by(user_id=current_user.id) \
        .order_by(Weight.id.desc()) \
        .all()

    maxweight = session.query(Weight) \
        .filter_by(user_id=current_user.id) \
        .order_by(Weight.id.desc()) \
        .first()

    if maxweight is None:
        maxrange = 100
    else:
        maxrange = (int(maxweight.weight) + 50)

    custom_style = Style(
                background='transparent',
                value_font_size=24,
                title_font_size=36,
                margin=1,
                plot_background='transparent',
                foreground='#53E89B',
                foreground_strong='#53A0E8',
                foreground_subtle='#630C0D',
                opacity='.6',
                opacity_hover='.9',
                transition='400ms ease-in',
                colors=('#5cb85c', '#f0ad4e', '#d9534f'))
    config = Config()
    config.show_legend = True
    config.legend_at_bottom=True
    config.y_labels = range(0, maxrange, 25)
    config.human_readable = True
    config.fill = True
    config.style=custom_style
    config.print_labels=True
    config.no_data_text='Add weight measurements!'

    wlist = []
    for entry in enumerate(weighthistory):
        wlist.append(entry[1].weight)

    line_chart = pygal.Line(config)
    line_chart.title = "Weight History"
    line_chart.add('Values', wlist)
    chart = line_chart.render(is_unicode=True)
    return chart
Esempio n. 6
0
def genfoodchart(start, end):
    '''Generate food chart with Pygal'''
    now = datetime.datetime.now().strftime("%Y-%m-%d")
    goodcount = session.query(Food) \
        .filter_by(user_id=current_user.id) \
        .filter(Food.food_date.between(start, end)).join(Ranks) \
        .filter_by(rank=1).add_columns(Ranks.rank).count()
    okaycount = session.query(Food) \
        .filter_by(user_id=current_user.id) \
        .filter(Food.food_date.between(start, end)).join(Ranks) \
        .filter_by(rank=2).add_columns(Ranks.rank).count()
    badcount = session.query(Food) \
        .filter_by(user_id=current_user.id) \
        .filter(Food.food_date.between(start, end)).join(Ranks) \
        .filter_by(rank=3).add_columns(Ranks.rank).count()

    custom_style = Style(
                    background='transparent',
                    value_font_size=24,
                    title_font_size=36,
                    margin=1,
                    plot_background='transparent',
                    foreground='#53E89B',
                    foreground_strong='#53A0E8',
                    foreground_subtle='#630C0D',
                    opacity='.6',
                    opacity_hover='.9',
                    transition='400ms ease-in',
                    colors=('#5cb85c', '#f0ad4e', '#d9534f'))

    config = Config()
    config.show_legend = True
    config.legend_at_bottom=True
    config.legend_at_bottom_columns=1
    config.legend_box_size=10
    config.human_readable = True
    config.fill = True
    config.style=custom_style
    config.print_labels=True
    config.print_values=True
    config.no_data_text='Need to add some food!'

    pie_chart = pygal.Pie(config)
    pie_chart.title = "Current Food Stats"
    pie_chart.add('Good', goodcount)
    pie_chart.add('Okay', okaycount)
    pie_chart.add('Bad', badcount)
    chart = pie_chart.render(is_unicode=True)
    return chart
Esempio n. 7
0
    def get_price_chart(self, stat):
        config = Config()
        config.show_legend = False
        config.human_readable = True
        config.x_label_rotation = 90
        config.pretty_print = True
        config.min_scale = 12
        config.height = 480

        price_chart = pygal.Line(config)
        price_chart.title = '售价走势图'
        price_chart.x_labels = map(
            lambda x: x.date_created.strftime("%Y-%m-%d"), stat)
        price_chart.add('价格', [row.price for row in stat])
        return price_chart.render_data_uri()
Esempio n. 8
0
def PygalConfigFile():
    config = Config()
    config.human_readable = True
    config.height = 250
    config.width = 700
    config.style = NeonStyle
    config.show_minor_y_labels = True
    config.x_label_rotation = 25
    config.value_font_size = 8
    config.title_font_size = 8
    config.legend_font_size = 8
    config.legend_box_size = 12
    config.label_font_size = 6

    return (config)
Esempio n. 9
0
	def renderJobActionAveragesGraph(self,jobActionAverages):
		if jobActionAverages:
			params = self.getGraphParams(jobActionAverages)
			aStyle = DefaultStyle(font_family='Arial',colors=self.getColors(),background='rgba(255,255,255,1)')
			config = Config()
			config.y_title = 'Days to Completion'
			config.x_title = 'Year'
			config.human_readable = True
			bar_chart2 = pygal.Bar(config,style=aStyle)
			bar_chart2.title = 'Time to Completion'
			bar_chart2.x_labels = map(str,params.get('dateRange',()))
			for item in params.get('items',[]):
				bar_chart2.add(item.get('title',''), item.get('days',[0]))

			return bar_chart2.render()
		return ''
Esempio n. 10
0
def define_config():
    """Defines some configuration settings for the pygal plot."""
    config = Config()
    config.show_legend = False
    config.human_readable = True
    config.fill = False
    config.height = 1000
    config.width = 2000
    config.x_label_rotation = 300
    config.show_legend = False
    config.x_labels_major_every = 200  # 200
    config.show_minor_x_labels = False
    config.show_dots = False
    config.fill = True
    config.logarithmic = False
    return config
Esempio n. 11
0
def PygalConfigFileBlue():
    configB = Config()
    configB.human_readable = True
    configB.height = 250
    configB.width = 700
    configB.style = NeonStyle
    configB.show_minor_y_labels = True
    configB.x_label_rotation = 25
    configB.value_font_size = 8
    configB.title_font_size = 8
    configB.legend_font_size = 8
    configB.legend_box_size = 12
    configB.label_font_size = 6
    configB.colors = ['#000099', '#009999']

    return (configB)
Esempio n. 12
0
def languages_draw(prefix, file_name, dir_name, time_title, names, counts):
    chart = pygal.Bar(interpolate='cubic', width=1000)

    config = Config()
    config.show_legend = False
    config.human_readable = True
    config.fill = True
    config.style = DarkColorizedStyle
    config.label_font_size = 36
    config.x_label_rotation = 45

    chart.config = config

    chart.title = file_name + " [" + time_title + "]"
    chart.x_labels = names
    chart.add(prefix, counts)

    save_name = os.path.join(dir_name, file_name + ".svg")
    chart.render_to_file(save_name)
Esempio n. 13
0
	def renderMetricsGraph(self,metric):
		if metric:
			aStyle = DefaultStyle(font_family='Arial',colors=self.getColors(),background='rgba(255,255,255,1)')
			config = Config()
			config.y_title = ''
			config.truncate_legend = 50
			config.x_title = 'Percent'
			config.y_labels = (10, 20, 30, 40, 50, 60, 70, 80, 90, 100)

			config.human_readable = True
			bar_chart = pygal.HorizontalBar(config,style=aStyle)
			bar_chart.title = metric.get('description','')
			bar_chart.add('Responded %s' % (metric.get('pctHasResponse').strip()) + '%', float(metric.get('pctHasResponse')))
			bar_chart.add('No Response %s' % (metric.get('pctNoResponse').strip()) + '%', float(metric.get('pctNoResponse')))
			bar_chart.add('Approved %s' % (metric.get('pctApproved').strip()) + '%', float(metric.get('pctApproved')))
			bar_chart.add('Declined %s' % (metric.get('pctDeclined').strip()) + '%', float(metric.get('pctDeclined')))
			bar_chart.add('Denied %s' % (metric.get('pctDenied').strip()) + '%', float(metric.get('pctDenied')))
			return bar_chart.render()
		return ''
Esempio n. 14
0
	def __prepareSVGConfigGeneric(colors):
		config = Config()
		config.show_legend = True
		config.human_readable = True
		config.fill = True
		config.order_min = 0
		config.x_label_rotation = 80
		config.margin = 80
		config.legend_font_size = 10
		config.tooltip_border_radius = 10
		config.legend_font_size = 10
		config.no_data_text = "No changes found"
		config.style = Style(background='transparent',
									plot_background='#f5f5f5',
									foreground='#428bca',
									foreground_light='#000000',
									foreground_dark='#428bca',
									opacity='.6',
									opacity_hover='.9',
									transition='400ms ease-in',
									colors=colors)
		return config
Esempio n. 15
0
    def get_sale_chart(self, stat, df):
        config = Config()
        config.show_legend = False
        config.human_readable = True
        # config.fill = True
        config.x_label_rotation = 90
        config.pretty_print = True
        config.min_scale = 12
        config.height = 480
        # config.print_values = True
        # config.print_values_position = 'top'
        # config.value_font_size=30

        sale_chart = pygal.Line(config)
        sale_chart.title = '销量与销售额'
        sale_chart.x_labels = map(
            lambda x: x.date_created.strftime("%Y-%m-%d"), stat)
        price_se = df.price.convert_objects(convert_numeric=True)
        sale_se = df.sale_num.diff().fillna(0)
        sale_chart.add('销量', [row for row in sale_se])
        sale_chart.add('销售额', [row for row in price_se.mul(sale_se)],
                       secondary=True)
        # return sale_chart.render()
        return sale_chart.render_data_uri()
Esempio n. 16
0
def drawappplicationsfigure(techlist, applicationslist):
    config = Config()
    config.show_legend = False
    config.xrange = (0, len(techlist) + 1)
    #labels, dots depending on number of technologies compared
    config.dots_size = 7
    labelsize = 10
    if len(techlist) > 3:
        config.truncate_label = 20
        config.x_label_rotation = 20
        config.dots_size = 6
    if len(techlist) > 5:
        config.dots_size = 6
    if len(techlist) > 13:
        config.dots_size = 5
    if len(techlist) > 17:
        config.dots_size = 4
        labelsize = 9
    if len(techlist) > 23:
        labelsize = 8
    if len(techlist) > 28:
        labelsize = 7

    config.human_readable = True

    #config.show_dots = False
    config.style = pygal.style.styles['default'](label_font_size=labelsize)
    xy_chart = pygal.XY(config)
    dictlist = []
    applicationsconverter = {
        'frequency containment reserve (primary control)': 1,
        'frequency restoration reserve (secondary control)': 2,
        'replacement reserve (tertiary control)': 3,
        'black start': 4,
        'energy arbitrage': 5,
        'grid investment deferral': 6,
        'increase of self-consumption': 7,
        'island operation': 8,
        'load levelling': 9,
        'mobility': 10,
        'off grid applications': 11,
        'peak shaving': 12,
        'portable electronic applications': 13,
        'power reliability': 14,
        'renewable energy integration': 15,
        'uninterrupted power supply': 16,
        'voltage support': 17
    }
    xy_chart.y_labels = [{
        'label': 'frequency containment reserve',
        'value': 1
    }, {
        'label': 'frequency restoration reserve',
        'value': 2
    }, {
        'label': 'replacement reserve',
        'value': 3
    }, {
        'label': 'black start',
        'value': 4
    }, {
        'label': 'energy arbitrage',
        'value': 5
    }, {
        'label': 'grid investment deferral',
        'value': 6
    }, {
        'label': 'increase of self-consumption',
        'value': 7
    }, {
        'label': 'island operation',
        'value': 8
    }, {
        'label': 'load levelling',
        'value': 9
    }, {
        'label': 'mobility',
        'value': 10
    }, {
        'label': 'off-grid applications',
        'value': 11
    }, {
        'label': 'peak shaving',
        'value': 12
    }, {
        'label': 'portable electronic applications',
        'value': 13
    }, {
        'label': 'power reliability',
        'value': 14
    }, {
        'label': 'renewable energy integration',
        'value': 15
    }, {
        'label': 'uninterrupted power supply',
        'value': 16
    }, {
        'label': 'voltage support',
        'value': 17
    }]
    i = 1
    for tech in techlist:
        for application in applicationslist:
            if application in tech.applications:
                xy_chart.add(f"{tech.name}",
                             [{
                                 'value':
                                 (i, applicationsconverter[application]),
                                 'label': "",
                                 'color': 'DodgerBlue'
                             }])
        dictlist.append({'label': f"{tech.name}", 'value': i})
        i = i + 1
    xy_chart.x_labels = (dictlist)
    xy_chart.x_value_formatter = lambda x: ""
    xy_chart.render()
    return xy_chart.render_data_uri()
Esempio n. 17
0
def using_pygal(DataFile):
    print("--using_pygal...")
    # Get the data as dataframe
    RightData = mold_data(DataFile)  
    
    # Remove unnecessary information
    RightData = RightData.drop("edit-no", axis=1)
    RightData = RightData.drop("type", axis=1)
    RightData = RightData.drop("analysis", axis=1)
    RightData = RightData.drop("char-diff", axis=1)
    RightData = RightData.drop("char-diff-abs", axis=1)

    # RightData1: set levenshtein to zero for substantives (effectively ignoring them) 
    RightData1 = RightData.copy(deep=True)
    RightData1.loc[RightData1["category"] =="other","levenshtein"] = 0
    # Fix some details: levenshtein as numerical, remove x from line-id
    RightData1["levenshtein"] = RightData1["levenshtein"].astype(str).convert_objects(convert_numeric=True)
    RightData1["line-id"] = RightData1["line-id"].map(lambda x: x.rstrip("x"))
    RightData1 = RightData1.groupby("line-id").sum()
    #print(RightData1.head(20))

    # RightData2: set levenshtein to zero for copyedits (effectively ignoring them) 
    RightData2 = RightData.copy(deep=True)
    RightData2.loc[RightData2["category"] =="copyedit","levenshtein"] = 0
    # Fix some details: levenshtein as numerical, remove x from line-id
    RightData2["levenshtein"] = RightData2["levenshtein"].astype(str).convert_objects(convert_numeric=True)
    RightData2["line-id"] = RightData2["line-id"].map(lambda x: x.rstrip("x"))
    RightData2 = RightData2.groupby("line-id").sum()
    #print(RightData2.head(20))
        
    # Select the range of data we want
    Lines = RightData1.index.values
    Copyedits = RightData1.loc[:,"levenshtein"]
    Substantives = RightData2.loc[:,"levenshtein"]
    
    # Apply some interpolation    
    CopyeditsSF = sf(Copyedits, 35, 1, mode="nearest")
    SubstantivesSF = sf(Substantives, 35, 1, mode="nearest")

    # Graph general configuration
    config = Config()
    config.show_legend = False
    config.human_readable = True
    config.fill = False

    # Line chart
    LineChart = pygal.StackedLine(config, 
                           height=1000,
                           width = 2000,
                           x_label_rotation=300, 
                           show_legend=False,
                           x_labels_major_every=200,
                           show_minor_x_labels=False,
                           show_dots=False,
                           fill=True,
                           logarithmic=False,
                           range=(0, 60))
    LineChart.title ="The Martian Modifications (copyedits and substantives)"
    LineChart.y_title = "Levenshtein distance (smoothed)"
    LineChart.x_title = "Lines in the novel"
    LineChart.x_labels = Lines
    LineChart.add("Copyedits", CopyeditsSF)
    LineChart.add("Substantives", SubstantivesSF)
    LineChart.render_to_file("MartianMods_copyedits+substantives.svg")
Esempio n. 18
0
    def identify(self, filename):
        self.report["filename"] = os.path.basename(filename)
        self.report["filename_absolute"] = filename
        self.report["filemimetype"] = utils.file_mimetype(filename)
        self.report["filemagic"] = utils.file_magic(filename)
        if self.report["filemimetype"] in self.pcapmimetypes:
            self.report["filecategory"] = "CAP"
            self.report["filetype"] = "PCAP"
            self.logger.info(
                "Identified %s as type %s (%s)"
                % (self.report["filename"], self.report["filetype"], self.report["filemimetype"])
            )
        else:
            self.logger.info(
                "File %s of type %s is not supported in the current version"
                % (self.report["filename"], self.report["filemimetype"])
            )
            return None

        self.logger.debug("Calculating file hashes for %s" % (self.report["filename"]))
        self.report["hashes"]["crc32"] = utils.file_hashes(filename, "crc32")
        self.report["hashes"]["md5"] = utils.file_hashes(filename, "md5")
        self.report["hashes"]["sha1"] = utils.file_hashes(filename, "sha1")
        self.report["hashes"]["sha256"] = utils.file_hashes(filename, "sha256")
        self.report["hashes"]["sha512"] = utils.file_hashes(filename, "sha512")
        self.report["hashes"]["ssdeep"] = utils.file_hashes(filename, "ssdeep")
        self.logger.info("Completed crc32/md5/sha{1,256,512}/ssdeep hash calculations")

        if self.config["enable_entropy_compression_stats"]:
            self.logger.debug("Collecting entropy compression stats for %s" % (self.report["filename"]))
            stats = utils.entropy_compression_stats(filename)
            self.report["filesize"] = stats["filesizeinbytes"]
            self.report["fileminsize"] = float(stats["minfilesize"])
            self.report["filecompressionratio"] = float(stats["compressionratio"])
            self.report["fileentropy"] = float(stats["shannonentropy"])

            # if entropy falls within the 0 - 1 or 7 - 8 range, categorize as suspicious
            if (self.report["fileentropy"] > 0 and self.report["fileentropy"] < 1) or self.report["fileentropy"] > 7:
                self.report["fileentropy_category"] = "SUSPICIOUS"
            else:
                self.report["fileentropy_category"] = "NORMAL"

            self.logger.info("Completed entropy compression stats collection")

        else:
            stats = {}

        if self.config["enable_bytefreq_histogram"]:
            self.logger.debug("Generating Byte-Frequency histogram for %s" % (self.report["filename"]))
            config = Config()
            config.x_title = "Bytes"
            config.y_title = "Frequency"

            config.x_scale = 0.25
            config.y_scale = 0.25
            config.width = 900
            config.height = 300
            config.title_font_size = 9
            config.tooltip_font_size = 0
            config.tooltip_border_radius = 0
            config.no_data_text = ""

            config.show_legend = False
            config.show_only_major_dots = True
            config.human_readable = False
            config.show_y_labels = False
            config.fill = True

            config.style = CleanStyle
            bar_chart = pygal.Bar(config)

            if "bytefreqlist" in stats.keys():
                bar_chart.add("", stats["bytefreqlist"])

            self.report["filebytefreqhistogram"] = bar_chart.render(is_unicode=False)
            self.logger.info("Completed Byte-Frequency histogram generation")

        # testing and db support to identify visually similar files/sessions
        if self.config["enable_file_visualization"]:
            self.logger.debug("Generating file visualization for %s" % (self.report["filename"]))
            self.report["filevis_png"] = utils.file_to_pngimage(filename)
            self.report["filevis_png_bw"] = utils.file_to_pngimage(filename, enable_colors=False)
            self.logger.info("Completed file visualization generation")

        return dict(self.report)
Esempio n. 19
0
  def identify(self, filename):
    self.report['filename'] = os.path.basename(filename)
    self.report['filename_absolute'] = filename
    self.report['filemimetype'] = utils.file_mimetype(filename)
    self.report['filemagic'] = utils.file_magic(filename)
    if self.report['filemimetype'] in self.pcapmimetypes:
      self.report['filecategory'] = 'CAP'
      self.report['filetype'] = 'PCAP'
      self.logger.info('Identified %s as type %s (%s)' % (self.report['filename'], self.report['filetype'], self.report['filemimetype']))
    else:
      self.logger.info('File %s of type %s is not supported in the current version' % (self.report['filename'], self.report['filemimetype']))
      return None

    self.logger.debug('Calculating file hashes for %s' % (self.report['filename']))
    self.report['hashes']['crc32'] = utils.file_hashes(filename, 'crc32')
    self.report['hashes']['md5'] = utils.file_hashes(filename, 'md5')
    self.report['hashes']['sha1'] = utils.file_hashes(filename, 'sha1')
    self.report['hashes']['sha256'] = utils.file_hashes(filename, 'sha256')
    self.report['hashes']['sha512'] = utils.file_hashes(filename, 'sha512')
    self.report['hashes']['ssdeep'] = utils.file_hashes(filename, 'ssdeep')
    self.logger.info('Completed crc32/md5/sha{1,256,512}/ssdeep hash calculations')

    if self.config['enable_entropy_compression_stats']:
      self.logger.debug('Collecting entropy compression stats for %s' % (self.report['filename']))
      stats = utils.entropy_compression_stats(filename)
      self.report['filesize'] = stats['filesizeinbytes']
      self.report['fileminsize'] = float(stats['minfilesize'])
      self.report['filecompressionratio'] = float(stats['compressionratio'])
      self.report['fileentropy'] = float(stats['shannonentropy'])

      # if entropy falls within the 0 - 1 or 7 - 8 range, categorize as suspicious
      if (self.report['fileentropy'] > 0 and self.report['fileentropy'] < 1) or self.report['fileentropy'] > 7:
        self.report['fileentropy_category'] = 'SUSPICIOUS'
      else:
        self.report['fileentropy_category'] = 'NORMAL'

      self.logger.info('Completed entropy compression stats collection')

    else:
      stats = {}

    if self.config['enable_bytefreq_histogram']:
      self.logger.debug('Generating Byte-Frequency histogram for %s' % (self.report['filename']))
      config = Config()
      config.x_title = 'Bytes'
      config.y_title = 'Frequency'

      config.x_scale = .25
      config.y_scale = .25
      config.width = 900
      config.height = 300
      config.title_font_size = 9
      config.tooltip_font_size = 0
      config.tooltip_border_radius = 0
      config.no_data_text = ""

      config.show_legend = False
      config.show_only_major_dots = True
      config.human_readable = False
      config.show_y_labels = False
      config.fill = True

      config.style = CleanStyle
      bar_chart = pygal.Bar(config)

      if 'bytefreqlist' in stats.keys():
        bar_chart.add('', stats['bytefreqlist'])

      self.report['filebytefreqhistogram'] = bar_chart.render(is_unicode=False)
      self.logger.info('Completed Byte-Frequency histogram generation')

    # testing and db support to identify visually similar files/sessions
    if self.config['enable_file_visualization']:
      self.logger.debug('Generating file visualization for %s' % (self.report['filename']))
      self.report['filevis_png'] = utils.file_to_pngimage(filename)
      self.report['filevis_png_bw'] = utils.file_to_pngimage(filename, enable_colors=False)
      self.logger.info('Completed file visualization generation')

    return dict(self.report)
Esempio n. 20
0
counts = {'Male': 0, 'Female': 0, 'Unknown': 0}
friends = itchat.get_friends(update=True)[0:]

for friend in friends:
    if (friend['Sex'] == 0):
        counts['Unknown'] += 1
    elif (friend['Sex'] == 1):
        counts['Male'] += 1
    elif (friend['Sex'] == 2):
        counts['Female'] += 1

print(counts)

config = Config()
config.show_legend = False
config.human_readable = True
config.print_values = True
config.style = LightColorizedStyle

pie_chart = pygal.Bar(config)
pie_chart.title = 'Gender histogram of Wechat friends'
pie_chart.x_labels = ['Male', 'Female', 'Unknown']

pie_chart.add('', [{
    'value': counts['Male'],
    'style': 'fill: blue; stroke: black; stroke-width: 2'
}, {
    'value': counts['Female'],
    'style': 'fill: red; stroke: black; stroke-width: 2'
}, {
    'value': counts['Unknown'],
Esempio n. 21
0
"""Render graph svg file"""
import pygal
from pygal import Config
import requests

config = Config()
config.show_legend = True
config.human_readable = True

def main():
    """Render Maps with total population in the world"""
    worldmap_chart = pygal.maps.world.World(print_labels = True)
    worldmap_chart.title = 'Total Population in each Contries'
    country = {'Afghanistan':'af', 'Albania':'al', 'Algeria':'dz', 'Angola':'ao',\
    'Azerbaijan':'az', 'Argentina':'ar', 'Australia':'au', 'Austria':'at', \
    'Bahrain':'bh', 'Bangladesh':'bd', 'Armenia':'am', 'Belgium':'be', \
    'Bhutan':'bt', 'Bolivia':'bo', 'Bosnia and Herzegovina':'ba', \
    'Botswana':'bw', 'Brazil':'br', 'Belize':'bz', 'Brunei Darussalam':'bn', \
    'Bulgaria':'bg', 'Myanmar':'mm', 'Burundi':'bi', 'Belarus':'by', \
    'Cambodia':'kh', 'Cameroon':'cm', 'Canada':'ca', 'Cabo Verde':'cv', \
    'Central African Republic':'cf', 'Sri Lanka':'lk', 'Chad':'td', 'Chile':'cl', \
    'China':'cn', 'Colombia':'co', 'Mayotte':'yt', 'Congo':'cg', \
    'Dem Rep of Congo':'cd', 'Costa Rica':'cr', 'Croatia':'hr', 'Cuba':'cu', \
    'Cyprus':'cy', 'Czech Republic':'cz', 'Benin':'bj', 'Denmark':'dk', \
    'Dominican Republic':'do', 'Ecuador':'ec', 'El Salvador':'sv', \
    'Equatorial Guinea':'eq', 'Ethiopia':'et', 'Eritrea':'er', 'Estonia':'ee', \
    'Finland':'fi', 'France':'fr', 'French Guiana':'gf', 'Djibouti':'dj', \
    'Gabon':'ga', 'Georgia':'ge', 'The Gambia':'gm', 'Germany':'de', 'Ghana':'gh', \
    'Greece':'gr', 'Guam':'gu', 'Guatemala':'gt', 'Guinea':'gw', 'Guyana':'gy', \
    'Haiti':'ht', 'Honduras':'hn', 'Hong Kong SAR-China':'hk', 'Hungary':'hu', \
    'Iceland':'is', 'India':'in', 'Indonesia':'id', 'Islamic Republic of Iran':'ir', \
Esempio n. 22
0
def drawfigure(techlist, par):
    config = Config()
    config.show_legend = False
    config.xrange = (0, len(techlist) + 1)
    #labels, dots and stroke depending on number of technologies compared
    config.dots_size = 7
    config.stroke_style = {'width': 50}
    labelsize = 12
    if len(techlist) > 3:
        config.truncate_label = 20
        config.x_label_rotation = 20
        config.dots_size = 6
        config.stroke_style = {'width': 40}
    if len(techlist) > 5:
        config.dots_size = 5
        config.stroke_style = {'width': 30}
    if len(techlist) > 10:
        config.stroke_style = {'width': 27}
    if len(techlist) > 13:
        config.dots_size = 4
        config.stroke_style = {'width': 25}
    if len(techlist) > 15:
        config.dots_size = 4
        config.stroke_style = {'width': 22}
        labelsize = 11
    if len(techlist) > 17:
        config.dots_size = 3
        config.stroke_style = {'width': 20}
    if len(techlist) > 20:
        labelsize = 10
        config.stroke_style = {'width': 18}
    if len(techlist) > 23:
        labelsize = 9
        config.stroke_style = {'width': 15}
    if len(techlist) > 27:
        labelsize = 8
        config.stroke_style = {'width': 14}
    if len(techlist) > 31:
        labelsize = 7
        config.stroke_style = {'width': 12}

    config.human_readable = True
    unit = Parameter.query.filter_by(name=par + '_min').first().unit
    config.y_title = par.replace('_', ' ') + ' [' + unit + ']'
    #config.show_dots = False
    config.style = pygal.style.styles['default'](
        stroke_opacity=1,
        label_font_size=labelsize,
        stroke_opacity_hover=1,
        transition='100000000000s ease-in')
    if par == 'efficiency':
        config.range = (0, 100)

    xy_chart = pygal.XY(config)

    if par == 'discharge_time':
        xy_chart.y_labels = [{
            'label': 'milliseconds',
            'value': 1
        }, {
            'label': 'seconds',
            'value': 2
        }, {
            'label': 'minutes',
            'value': 3
        }, {
            'label': 'hours',
            'value': 4
        }, {
            'label': 'days',
            'value': 5
        }, {
            'label': 'weeks',
            'value': 6
        }, {
            'label': 'months',
            'value': 7
        }]

    if par == 'response_time':
        xy_chart.y_labels = [{
            'label': 'milliseconds',
            'value': 1
        }, {
            'label': 'seconds',
            'value': 2
        }, {
            'label': 'minutes',
            'value': 3
        }]

    dictlist = []
    ymin = 100000000000
    ymax = 0
    logscale = False
    for tech in techlist:
        if Parameter.query.filter_by(technology_name=tech.name).filter_by(
                name=par + "_min").first().value != None:
            ymin = min(
                Parameter.query.filter_by(technology_name=tech.name).filter_by(
                    name=par + "_min").first().value, ymin)
            ymax = max(
                Parameter.query.filter_by(technology_name=tech.name).filter_by(
                    name=par + "_max").first().value, ymax)
    if (ymin * 100) < ymax:
        xy_chart.logarithmic = True
        xy_chart.xrange = (0, 10**(len(techlist) + 1))
        if ymax < 100000:
            xy_chart.range = (10**int(math.floor(math.log10(ymin))),
                              10**(int(math.floor(math.log10(ymax))) + 1) + 1)
        else:
            xy_chart.range = (10**int(math.floor(math.log10(ymin))),
                              10**(int(math.floor(math.log10(ymax)))) + 1)
        logscale = True
    if logscale:
        i = 10
    else:
        i = 1
    for tech in techlist:
        minxlink = ''
        maxxlink = ''
        minlabel = ''
        maxlabel = ''
        if Source.query.filter_by(id=Parameter.query.filter_by(
                technology_name=tech.name).filter_by(
                    name=par + "_min").first().source_id).first() is not None:
            minxlink = Source.query.filter_by(id=Parameter.query.filter_by(
                technology_name=tech.name).filter_by(
                    name=par + "_min").first().source_id).first().link
            minlabel = Source.query.filter_by(id=Parameter.query.filter_by(
                technology_name=tech.name).filter_by(
                    name=par +
                    "_min").first().source_id).first().author + ', ' + str(
                        Source.query.filter_by(id=Parameter.query.filter_by(
                            technology_name=tech.name).filter_by(
                                name=par +
                                "_min").first().source_id).first().releaseyear)
        if Source.query.filter_by(id=Parameter.query.filter_by(
                technology_name=tech.name).filter_by(
                    name=par + "_max").first().source_id).first() is not None:
            maxxlink = Source.query.filter_by(id=Parameter.query.filter_by(
                technology_name=tech.name).filter_by(
                    name=par + "_max").first().source_id).first().link
            maxlabel = Source.query.filter_by(id=Parameter.query.filter_by(
                technology_name=tech.name).filter_by(
                    name=par +
                    "_max").first().source_id).first().author + ', ' + str(
                        Source.query.filter_by(id=Parameter.query.filter_by(
                            technology_name=tech.name).filter_by(
                                name=par +
                                "_max").first().source_id).first().releaseyear)
        xy_chart.add(f"{tech.name}", [{
            'value':
            (i, Parameter.query.filter_by(technology_name=tech.name).filter_by(
                name=par + "_min").first().value),
            'label':
            minlabel,
            'xlink': {
                'href': minxlink,
                'target': '_blank'
            }
        }, {
            'value':
            (i, Parameter.query.filter_by(technology_name=tech.name).filter_by(
                name=par + "_max").first().value),
            'label':
            maxlabel,
            'xlink': {
                'href': maxxlink,
                'target': '_blank'
            }
        }])
        dictlist.append({'label': f"{tech.name}", 'value': i})
        if logscale:
            i = i * 10
        else:
            i = i + 1
    xy_chart.x_labels = (dictlist)
    xy_chart.x_value_formatter = lambda x: ""
    xy_chart.render()
    return xy_chart.render_data_uri()
Esempio n. 23
0
def using_pygal(DataFile):
    print("using_pygal...")
    
    ## Getting the data
    with open(DataFile, "r") as infile:
        AllData = pd.read_table(infile)
        #print(AllData.head())
                        
        # Select the data we want
        Lines = AllData.loc[:,"line-no"][0:50]
        ItemIDs = AllData.loc[:,"item-id"][0:50]
        Version1s = AllData.loc[:,"version1"][0:50]
        Version2s = AllData.loc[:,"version2"][0:50]
        Categories = AllData.loc[:,"category"][0:50]
        Types = AllData.loc[:,"type"][0:50]
        LevDists = AllData.loc[:,"levenshtein"][0:50]
        CharDiffsAbs = AllData.loc[:,"char-delta-abs"][0:50]
        CharDiffs = AllData.loc[:,"char-delta"][0:50]

        # Apply very simple smoothing to LevDists 
        LevDistsSmth = []
        Smthp0 = (LevDists[0] + LevDists[1])/2
        Smthp1 = (LevDists[1] + LevDists[2])/2
        LevDistsSmth.append(Smthp0)
        LevDistsSmth.append(Smthp1)
        for i in range(2, len(LevDists)-2): 
            NewValue = (LevDists[i-2]/2 + LevDists[i-1] + LevDists[i] + LevDists[i+1] + LevDists[i+2]/2) / 4
            LevDistsSmth.append(NewValue)
        Smthm0 = (LevDists[len(LevDists)-2] + LevDists[len(LevDists)-3]) / 2
        Smthm1 = (LevDists[len(LevDists)-1] + LevDists[len(LevDists)-2]) / 2
        LevDistsSmth.append(Smthm0)
        LevDistsSmth.append(Smthm1)
    
        # Graph general configuration
        config = Config()
        config.show_legend = False
        config.human_readable = True
        config.fill = False
    
        # Graphing: bar chart
        BarChart1 = pygal.Bar(config)
        BarChart1.title = "The Martian Modifications (Char-Diff)"
        BarChart1.x_labels = map(str, range(0, 50))
        #BarChart.add("Levenshtein", LevDists)
        BarChart1.add("Char-Diff", CharDiffs)
        #chart.add("Char-Diff-Abs", CharDiffsAbs)
        BarChart1.render_to_file("BarChart1.svg")
        
        # Graphing: another bar chart
        BarChart2 = pygal.Bar(config, x_label_rotation=270)
        BarChart2.title ="The Martian Modifications (Labels)"
        #LineChart.x_labels = map(str, ItemIDs)
        for i in range(0,30): 
            BarChart2.add(ItemIDs[i], [{"value" : CharDiffs[i], "label" : str(Version1s[i])+" => "+str(Version2s[i]), 'color': 'red'}])
        BarChart2.render_to_file("BarChart2.svg")
               
        # Line chart
        LineChart1 = pygal.Line(config, x_label_rotation=270, show_legend=True)
        LineChart1.title ="The Martian Modifications (smoothed)"
        LineChart1.add("LevDists", LevDists)
        LineChart1.add("LevDistsSmth", LevDistsSmth)
        LineChart1.render_to_file("LineChart1.svg")
Esempio n. 24
0
    #		if nTotalDataCount > nMaxDataCount:
    #			for iDataNum in reversed(range(0, nTotalDataCount)):
    #				# Remove all entries who
    #				if iDataNum % nDataStepCount == 0:
    #					aMajorXData.append( aData[aFields[0]][iDataNum] )

    # Import Style
#	from pygal.style import LightSolarizedStyle
#	from pygal.style import DefaultStyle
    from pygal.style import RotateStyle

    # Create Config object
    from pygal import Config
    chartCfg = Config()
    chartCfg.show_legend = True
    chartCfg.human_readable = True
    chartCfg.pretty_print = True
    if bFilledLineChart:
        chartCfg.fill = True
    else:
        chartCfg.fill = False
    chartCfg.x_scale = 1
    chartCfg.y_scale = 1
    chartCfg.x_label_rotation = 45
    chartCfg.include_x_axis = True
    chartCfg.show_dots = False
    if nMaxDataCount > 0:
        chartCfg.show_minor_x_labels = False
        chartCfg.x_labels_major_count = nMaxDataCount
    #chartCfg.style = DefaultStyle #LightSolarizedStyle
    chartCfg.style = RotateStyle('#FF0000')
Esempio n. 25
0
def drawdensityfigure(techlist, par):
    config = Config()
    config.show_legend = True
    config.human_readable = True
    config.dots_size = 3
    config.x_label_rotation = 270
    config.legend_at_bottom = True
    if par == "gravimetric":
        power_unit = "[W/kg]"
        energy_unit = "[Wh/kg]"
    else:
        power_unit = "[kW/m^3]"
        energy_unit = "[kWh/m^3]"
    config.x_title = par + " power density " + power_unit
    config.y_title = par + " energy density " + energy_unit
    #config.show_dots = False
    config.logarithmic = True
    config.fill = True
    #config.show_minor_x_labels = False
    config.stroke_style = {'width': 1}
    config.style = pygal.style.styles['default'](
        label_font_size=12,
        stroke_opacity=0,
        stroke_opacity_hover=0,
        transition='100000000000s ease-in')
    xy_chart = pygal.XY(config)
    xmin = 10000
    ymin = 10000
    xmax = 0.001
    ymax = 0.001
    for tech in techlist:
        power_minstring = par + "_power_density_min"
        power_maxstring = par + "_power_density_max"
        energy_minstring = par + "_energy_density_min"
        energy_maxstring = par + "_energy_density_max"
        minpowerlink = ''
        maxpowerlink = ''
        minenergylink = ''
        maxenergylink = ''
        minpowerlabel = ''
        maxpowerlabel = ''
        minenergylabel = ''
        maxenergylabel = ''
        if Source.query.filter_by(id=Parameter.query.filter_by(
                technology_name=tech.name).filter_by(name=power_minstring).
                                  first().source_id).first() is not None:
            minpowerlink = Source.query.filter_by(id=Parameter.query.filter_by(
                technology_name=tech.name).filter_by(
                    name=power_minstring).first().source_id).first().link
            minpowerlabel = 'min. power density: ' + Source.query.filter_by(
                id=Parameter.query.filter_by(
                    technology_name=tech.name).filter_by(name=power_minstring).
                first().source_id).first().author + ', ' + str(
                    Source.query.filter_by(id=Parameter.query.filter_by(
                        technology_name=tech.name).filter_by(
                            name=power_minstring).first().source_id).first().
                    releaseyear)
        if Source.query.filter_by(id=Parameter.query.filter_by(
                technology_name=tech.name).filter_by(name=power_maxstring).
                                  first().source_id).first() is not None:
            maxpowerlink = Source.query.filter_by(id=Parameter.query.filter_by(
                technology_name=tech.name).filter_by(
                    name=power_maxstring).first().source_id).first().link
            maxpowerlabel = 'max. power density: ' + Source.query.filter_by(
                id=Parameter.query.filter_by(
                    technology_name=tech.name).filter_by(name=power_maxstring).
                first().source_id).first().author + ', ' + str(
                    Source.query.filter_by(id=Parameter.query.filter_by(
                        technology_name=tech.name).filter_by(
                            name=power_maxstring).first().source_id).first().
                    releaseyear)
        if Source.query.filter_by(id=Parameter.query.filter_by(
                technology_name=tech.name).filter_by(name=energy_minstring).
                                  first().source_id).first() is not None:
            minenergylink = Source.query.filter_by(
                id=Parameter.query.filter_by(
                    technology_name=tech.name).filter_by(
                        name=energy_minstring).first().source_id).first().link
            minenergylabel = 'min. energy density: ' + Source.query.filter_by(
                id=Parameter.query.filter_by(
                    technology_name=tech.name).filter_by(name=energy_minstring)
                .first().source_id).first().author + ', ' + str(
                    Source.query.filter_by(id=Parameter.query.filter_by(
                        technology_name=tech.name).filter_by(
                            name=energy_minstring).first().source_id).first().
                    releaseyear)
        if Source.query.filter_by(id=Parameter.query.filter_by(
                technology_name=tech.name).filter_by(name=energy_maxstring).
                                  first().source_id).first() is not None:
            maxenergylink = Source.query.filter_by(
                id=Parameter.query.filter_by(
                    technology_name=tech.name).filter_by(
                        name=energy_maxstring).first().source_id).first().link
            maxenergylabel = 'max. energy density: ' + Source.query.filter_by(
                id=Parameter.query.filter_by(
                    technology_name=tech.name).filter_by(name=energy_maxstring)
                .first().source_id).first().author + ', ' + str(
                    Source.query.filter_by(id=Parameter.query.filter_by(
                        technology_name=tech.name).filter_by(
                            name=energy_maxstring).first().source_id).first().
                    releaseyear)
        xy_chart.add(f"{tech.name}", [{
            'value':
            (Parameter.query.filter_by(technology_name=tech.name).filter_by(
                name=power_minstring).first().value,
             Parameter.query.filter_by(technology_name=tech.name).filter_by(
                 name=energy_minstring).first().value),
            'label':
            minenergylabel,
            'xlink': {
                'href': minenergylink,
                'target': '_blank'
            }
        }, {
            'value':
            (Parameter.query.filter_by(technology_name=tech.name).filter_by(
                name=power_minstring).first().value,
             Parameter.query.filter_by(technology_name=tech.name).filter_by(
                 name=energy_maxstring).first().value),
            'label':
            minpowerlabel,
            'xlink': {
                'href': minpowerlink,
                'target': '_blank'
            }
        }, {
            'value':
            (Parameter.query.filter_by(technology_name=tech.name).filter_by(
                name=power_maxstring).first().value,
             Parameter.query.filter_by(technology_name=tech.name).filter_by(
                 name=energy_maxstring).first().value),
            'label':
            maxenergylabel,
            'xlink': {
                'href': maxenergylink,
                'target': '_blank'
            }
        }, {
            'value':
            (Parameter.query.filter_by(technology_name=tech.name).filter_by(
                name=power_maxstring).first().value,
             Parameter.query.filter_by(technology_name=tech.name).filter_by(
                 name=energy_minstring).first().value),
            'label':
            maxpowerlabel,
            'xlink': {
                'href': maxpowerlink,
                'target': '_blank'
            }
        }, {
            'value':
            (Parameter.query.filter_by(technology_name=tech.name).filter_by(
                name=power_minstring).first().value,
             Parameter.query.filter_by(technology_name=tech.name).filter_by(
                 name=energy_minstring).first().value),
            'label':
            minenergylabel,
            'xlink': {
                'href': minenergylink,
                'target': '_blank'
            }
        }])

        if Parameter.query.filter_by(technology_name=tech.name).filter_by(
                name=power_minstring).first().value is not None:
            xmin = min(
                xmin,
                Parameter.query.filter_by(technology_name=tech.name).filter_by(
                    name=power_minstring).first().value)
            xmax = max(
                xmax,
                Parameter.query.filter_by(technology_name=tech.name).filter_by(
                    name=power_maxstring).first().value)
        if Parameter.query.filter_by(technology_name=tech.name).filter_by(
                name=energy_minstring).first().value is not None:
            ymin = min(
                ymin,
                Parameter.query.filter_by(technology_name=tech.name).filter_by(
                    name=energy_minstring).first().value)
            ymax = max(
                ymax,
                Parameter.query.filter_by(technology_name=tech.name).filter_by(
                    name=energy_maxstring).first().value)

    xy_chart.xrange = (10**int(math.floor(math.log10(xmin))),
                       10**(int(math.floor(math.log10(xmax))) + 1) + 1)
    xy_chart.range = (10**int(math.floor(math.log10(ymin))),
                      10**(int(math.floor(math.log10(ymax))) + 1) + 1)
    xy_chart.render()
    return xy_chart.render_data_uri()
Esempio n. 26
0
def drawcapitalcostcomponentsfigure(techlist):
    config = Config()
    config.show_legend = True
    config.human_readable = True
    config.dots_size = 3
    config.x_label_rotation = 270
    config.legend_at_bottom = True
    config.x_title = "capital cost of power based components [$/kW]"
    config.y_title = "capital cost of energy based components [$/kWh]"
    #config.show_dots = False
    config.fill = True
    #config.show_minor_x_labels = False
    config.stroke_style = {'width': 1}
    config.style = pygal.style.styles['default'](
        label_font_size=12,
        stroke_opacity=0,
        stroke_opacity_hover=0,
        transition='100000000000s ease-in')
    xy_chart = pygal.XY(config)
    xmin = 10000
    ymin = 10000
    xmax = 0.001
    ymax = 0.001
    for tech in techlist:
        power_minstring = "capital_cost_of_power_based_components_min"
        power_maxstring = "capital_cost_of_power_based_components_max"
        energy_minstring = "capital_cost_of_energy_based_components_min"
        energy_maxstring = "capital_cost_of_energy_based_components_max"
        minpowerlink = ''
        maxpowerlink = ''
        minenergylink = ''
        maxenergylink = ''
        minpowerlabel = ''
        maxpowerlabel = ''
        minenergylabel = ''
        maxenergylabel = ''
        if Source.query.filter_by(id=Parameter.query.filter_by(
                technology_name=tech.name).filter_by(name=power_minstring).
                                  first().source_id).first() is not None:
            minpowerlink = Source.query.filter_by(id=Parameter.query.filter_by(
                technology_name=tech.name).filter_by(
                    name=power_minstring).first().source_id).first().link
            minpowerlabel = 'min. cost of power based components: ' + Source.query.filter_by(
                id=Parameter.query.filter_by(
                    technology_name=tech.name).filter_by(name=power_minstring).
                first().source_id).first().author + ', ' + str(
                    Source.query.filter_by(id=Parameter.query.filter_by(
                        technology_name=tech.name).filter_by(
                            name=power_minstring).first().source_id).first().
                    releaseyear)
        if Source.query.filter_by(id=Parameter.query.filter_by(
                technology_name=tech.name).filter_by(name=power_maxstring).
                                  first().source_id).first() is not None:
            maxpowerlink = Source.query.filter_by(id=Parameter.query.filter_by(
                technology_name=tech.name).filter_by(
                    name=power_maxstring).first().source_id).first().link
            maxpowerlabel = 'max. cost of power based components: ' + Source.query.filter_by(
                id=Parameter.query.filter_by(
                    technology_name=tech.name).filter_by(name=power_maxstring).
                first().source_id).first().author + ', ' + str(
                    Source.query.filter_by(id=Parameter.query.filter_by(
                        technology_name=tech.name).filter_by(
                            name=power_maxstring).first().source_id).first().
                    releaseyear)
        if Source.query.filter_by(id=Parameter.query.filter_by(
                technology_name=tech.name).filter_by(name=energy_minstring).
                                  first().source_id).first() is not None:
            minenergylink = Source.query.filter_by(
                id=Parameter.query.filter_by(
                    technology_name=tech.name).filter_by(
                        name=energy_minstring).first().source_id).first().link
            minenergylabel = 'min. cost of energy based components: ' + Source.query.filter_by(
                id=Parameter.query.filter_by(
                    technology_name=tech.name).filter_by(name=energy_minstring)
                .first().source_id).first().author + ', ' + str(
                    Source.query.filter_by(id=Parameter.query.filter_by(
                        technology_name=tech.name).filter_by(
                            name=energy_minstring).first().source_id).first().
                    releaseyear)
        if Source.query.filter_by(id=Parameter.query.filter_by(
                technology_name=tech.name).filter_by(name=energy_maxstring).
                                  first().source_id).first() is not None:
            maxenergylink = Source.query.filter_by(
                id=Parameter.query.filter_by(
                    technology_name=tech.name).filter_by(
                        name=energy_maxstring).first().source_id).first().link
            maxenergylabel = 'max. cost of energy based components: ' + Source.query.filter_by(
                id=Parameter.query.filter_by(
                    technology_name=tech.name).filter_by(name=energy_maxstring)
                .first().source_id).first().author + ', ' + str(
                    Source.query.filter_by(id=Parameter.query.filter_by(
                        technology_name=tech.name).filter_by(
                            name=energy_maxstring).first().source_id).first().
                    releaseyear)
        xy_chart.add(f"{tech.name}", [{
            'value':
            (Parameter.query.filter_by(technology_name=tech.name).filter_by(
                name=power_minstring).first().value,
             Parameter.query.filter_by(technology_name=tech.name).filter_by(
                 name=energy_minstring).first().value),
            'label':
            minenergylabel,
            'xlink': {
                'href': minenergylink,
                'target': '_blank'
            }
        }, {
            'value':
            (Parameter.query.filter_by(technology_name=tech.name).filter_by(
                name=power_minstring).first().value,
             Parameter.query.filter_by(technology_name=tech.name).filter_by(
                 name=energy_maxstring).first().value),
            'label':
            minpowerlabel,
            'xlink': {
                'href': minpowerlink,
                'target': '_blank'
            }
        }, {
            'value':
            (Parameter.query.filter_by(technology_name=tech.name).filter_by(
                name=power_maxstring).first().value,
             Parameter.query.filter_by(technology_name=tech.name).filter_by(
                 name=energy_maxstring).first().value),
            'label':
            maxenergylabel,
            'xlink': {
                'href': maxenergylink,
                'target': '_blank'
            }
        }, {
            'value':
            (Parameter.query.filter_by(technology_name=tech.name).filter_by(
                name=power_maxstring).first().value,
             Parameter.query.filter_by(technology_name=tech.name).filter_by(
                 name=energy_minstring).first().value),
            'label':
            maxpowerlabel,
            'xlink': {
                'href': maxpowerlink,
                'target': '_blank'
            }
        }, {
            'value':
            (Parameter.query.filter_by(technology_name=tech.name).filter_by(
                name=power_minstring).first().value,
             Parameter.query.filter_by(technology_name=tech.name).filter_by(
                 name=energy_minstring).first().value),
            'label':
            minenergylabel,
            'xlink': {
                'href': minenergylink,
                'target': '_blank'
            }
        }])

        if Parameter.query.filter_by(technology_name=tech.name).filter_by(
                name=power_minstring).first().value is not None:
            xmin = min(
                xmin,
                Parameter.query.filter_by(technology_name=tech.name).filter_by(
                    name=power_minstring).first().value)
            xmax = max(
                xmax,
                Parameter.query.filter_by(technology_name=tech.name).filter_by(
                    name=power_maxstring).first().value)
        if Parameter.query.filter_by(technology_name=tech.name).filter_by(
                name=energy_minstring).first().value is not None:
            ymin = min(
                ymin,
                Parameter.query.filter_by(technology_name=tech.name).filter_by(
                    name=energy_minstring).first().value)
            ymax = max(
                ymax,
                Parameter.query.filter_by(technology_name=tech.name).filter_by(
                    name=energy_maxstring).first().value)

        xup = 10**int(math.floor(math.log10(xmax)))
        yup = 10**int(math.floor(math.log10(ymax)))
        while xup < xmax:
            xup = xup + 10**int(math.floor(math.log10(xmax)))
        while yup < ymax:
            yup = yup + 10**int(math.floor(math.log10(ymax)))

    xy_chart.xrange = (10**int(math.floor(math.log10(xmin))), xup)
    xy_chart.range = (10**int(math.floor(math.log10(ymin))), yup)
    xy_chart.render()
    return xy_chart.render_data_uri()
Esempio n. 27
0
  def analyze(self):
    self.report.filebasename = file_basename(self.config.filename)
    self.report.filedirname = file_dirname(self.config.filename)
    self.report.filemimetype = file_mimetype(self.config.filename)
    magicresult = file_magic(self.config.filename)
    self.report.filemagic = "%s (%s)" % (magicresult["match"]["longname"], magicresult["match"]["shortname"]) if magicresult["match"] else None
    self.report.hashes.crc32 = file_hashes(self.config.filename, 'crc32')
    self.report.hashes.md5 = file_hashes(self.config.filename, 'md5')
    self.report.hashes.sha1 = file_hashes(self.config.filename, 'sha1')
    self.report.hashes.sha256 = file_hashes(self.config.filename, 'sha256')
    self.report.hashes.sha512 = file_hashes(self.config.filename, 'sha512')
    self.report.hashes.ssdeep = file_hashes(self.config.filename, 'ssdeep')

    with nostdout():
      self.report.subfiles = file_subfiles(self.config.filename)

    # this might take some time to finish
    # based on the filesize, runtime might increase
    # will be autodisabled based on statsfilesizelimit config option
    if self.config.enableentropycompressionstats:
      stats = objdict(file_entropy_compression_stats(self.config.filename))
      self.report.filesize = stats.filesizeinbytes
      self.report.fileminsize = float(stats.minfilesize)
      self.report.filecompressionratio = float(stats.compressionratio)
      self.report.fileentropy = float(stats.entropy)
      self.report.fileentropycategory = stats.entropycategory

    # this might take some time to finish
    # based on the filesize, runtime might increase
    # should be autodisabled based on (statsfilesizelimit) config option
    if self.config.enablefilevisualization:
      self.report.visual.pngrgb = file_to_pngimage(self.config.filename)
      self.report.visual.pnggray = file_to_pngimage(self.config.filename, enable_colors=False)
      rh = identicon(self.report.hashes.sha256)
      self.report.visual.identicon = rh.identicon if rh.success else None

      config = Config()
      config.x_title = 'Bytes'
      config.y_title = 'Frequency'
      config.x_scale = .25
      config.y_scale = .25
      config.width = 900
      config.height = 300
      config.title_font_size = 9
      config.tooltip_font_size = 0
      config.tooltip_border_radius = 0
      config.no_data_text = ""
      config.show_legend = False
      config.show_only_major_dots = True
      config.human_readable = False
      config.show_y_labels = False
      config.fill = True
      config.style = CleanStyle
      bar_chart = pygal.Bar(config)

      # if enableentropycompressionstats config option is disabled, stats won't be generated above
      # as such we need to explicitly generate, on-demand
      if not stats:
        stats = objdict(file_entropy_compression_stats(self.config.filename))

      bar_chart.add('', stats.bytefreqlist)
      self.report.visual.bytefreqhistogram = bar_chart.render(is_unicode=False)
      # pygal inserts a copyright symbol in rendered chart output
      # need to explicitly clean it before returning
      pygalregex = re.compile(r"\xc2\xa9")
      self.report.visual.bytefreqhistogram = pygalregex.sub("", self.report.visual.bytefreqhistogram)

    else:
      self.report.visual.pngrgb = None
      self.report.visual.pnggray = None
      self.report.visual.identicon = None
      self.report.visual.bytefreqhistogram = None

    # done with analysis, normalize report and return
    self.report = dict_normalize(self.report)
Esempio n. 28
0
#		nTotalDataCount = len( aData[aFields[0]] )
#		nDataStepCount = nTotalDataCount / (nMaxDataCount)
#		if nTotalDataCount > nMaxDataCount:
#			for iDataNum in reversed(range(0, nTotalDataCount)):
#				# Remove all entries who 
#				if iDataNum % nDataStepCount == 0:
#					aMajorXData.append( aData[aFields[0]][iDataNum] )
			
	# Import Style
#	from pygal.style import LightSolarizedStyle

	# Create Config object
	from pygal import Config
	chartCfg = Config()
	chartCfg.show_legend = True
	chartCfg.human_readable = True
	chartCfg.pretty_print=True
	if bFilledLineChart: 
		chartCfg.fill = True
	else:
		chartCfg.fill = False
	chartCfg.x_scale = 1
	chartCfg.y_scale = 1
	chartCfg.x_label_rotation = 45
	chartCfg.include_x_axis = True
	chartCfg.show_dots=False
	if nMaxDataCount > 0: 
		chartCfg.show_minor_x_labels=False
		chartCfg.x_labels_major_count=nMaxDataCount
	chartCfg.js = [	'svg.jquery.js','pygal-tooltips.js' ] # Use script from local
#	chartCfg.style = LightSolarizedStyle
Esempio n. 29
0
def create_chartguardian(id_station, station):

    data_status = dict()
    data_time = dict()
    list_status = list()
    list_time = list()
    station_name = str()
    station_id = str()
    data_down = list()
    data_up = list()
    data_label = list()
    last_problem = str()
    status_alert = str()
    provider_alert = str()
    mediatype_alert = str()
    streamuri_alert = str()
    stationid_alert = str()

    ts = int(time.time())
    date_query = datetime.datetime.fromtimestamp(ts).strftime('%Y-%m-%d')

    with drt.connect(db=data_config[env_app]['RETHINK-DB']) as conn:
        cursor_up = drt.table(data_config[env_app]['RETHINK-TABLE']).filter((drt.row["date"] == date_query) & (drt.row["station_id"] == id_station)).run(conn)
        cursor_down = drt.table(data_config[env_app]['RETHINK-TABLE']).filter((drt.row["date"] == date_query) & (drt.row["station_id"] == id_station)).run(conn)

        for document_down in cursor_down:
            station_name = document_down["station_name"]
            station_id = document_down["station_id"]
            if len(document_down["status_array"]) < 31:
                print("Size array status DOWN")
                print(len(document_down["status_array"]))
                start_point = 0
            else:
                start_point = len(document_down["status_array"]) - 31
            stat_array = document_down["status_array"]
            provider_alert = document_down["provider"]
            mediatype_alert = stream_config[env_app][station]['media-type']
            streamuri_alert =  stream_config[env_app][station]['uri-stream']
            stationid_alert = id_station
            for index, item in enumerate(stat_array[start_point:]):
                status_len = len(document_down["status_array"])
                ts = int(item["time"])
                date_down = datetime.datetime.fromtimestamp(ts).strftime('%H:%M:%S')
                #[None, None, None, None, None, None, {'value': 0, 'label': '10:10:10'}
                if item["status"] == "down":
                    item_down = {
                        'value': 0,
                        'label': date_down
                    }
                    item_label = date_down
                    data_down.append(item_down)
                    data_label.append(item_label)
                    last_problem = date_down
                    status_alert = item["status"]
                else:
                    item_none = None
                    data_down.append(item_none)
                    item_label = None
                    data_label.append(item_label)
                ts = int(item["time"])
                date_day = datetime.datetime.fromtimestamp(ts).strftime('%Y-%m-%d')
                data_status.update({ index: item["status"] })
                data_time.update({ index: date_day })
                list_status.append(item["status"])
                list_time.append(date_day)

        for document_up in cursor_up:
            print("==== document_up ===")
            print(document_up)
            station_name = document_up["station_name"]
            station_id = document_up["station_id"]
            if len(document_up["status_array"]) < 31:
                print("Size array status UP")
                len(document_up["status_array"])
                start_point = 0
            else:
                start_point = len(document_up["status_array"]) - 31
            stat_array = document_up["status_array"]
            for index, item in enumerate(stat_array[start_point:]):
                status_len = len(document_up["status_array"])
                #{'value': 1, 'label': ''}
                if item["status"] == "up":
                    print("====== ITEM STATUS =====")
                    print(item)
                    status_val = 1
                    status_label = "Sin Problemas"
                    item_up = {
                        'value': 1,
                        'label': ''
                    }
                    data_up.append(item_up)
                else:
                    status_val = 0
                    status_label = "Problemas"
                    item_down = None
                    data_up.append(item_down)

        try:
            custom_style = Style(
            opacity='.6',
            opacity_hover='.9',
            transition='400ms ease-in',
            label_font_family='Liberation Mono',
            label_font_size=8,
            major_label_font_size=10,
            colors=('#e74c3c', '#2980b9', '#e67e22', '#E87653', '#E89B53'))


            configpg = Config()
            configpg.human_readable = True
            configpg.fill = False
            configpg.x_title='Ultimo Problema: ' + last_problem
            configpg.show_y_labels=False
            configpg.legend_at_bottom_columns=False
            configpg.legend_at_bottom=True
            configpg.width=850
            configpg.height=400
            configpg.print_labels=False
            configpg.margin_bottom=30
            configpg.x_label_rotation=60
            configpg.range=(0, 1)
            configpg.show_y_labels=True
            configpg.pretty_print=True

            extra_args = {
                'ACL': 'public-read', 
                'CacheControl': 'no-cache, no-store, must-revalidate'
                }

            line_chart = pygal.Line(style=custom_style, config=configpg)
            line_chart.title = station_name + ' - ' + date_query
            line_chart.x_labels = (data_label)
            line_chart.x_labels_major = (data_label)
            line_chart.add('Problemas', data_down , allow_interruptions=True, dots_size=5, stroke_style={'width': 4, 'linecap': 'round', 'linejoin': 'round'})
            line_chart.add('Activo',data_up , allow_interruptions=True, show_dots=True, dots_size=5, stroke_style={'width': 4, 'linecap': 'round', 'linejoin': 'round'})
            line_chart.add('Rango: 30 minutos', None)
            line_chart.render_to_png(station_id + '-' + date_query + '.png')
            #connection.close()
            #connection.close()
            upload_s3 = s3.upload_file(station_id + '-' + date_query + '.png', bucket_name, env_app+'/'+station_id + '-' + str(ts) + '.png', ExtraArgs=extra_args)
            os.remove(station_id + '-' + date_query + '.png')
            print(last_problem)
            alert_data = {
                's3_key': env_app+'/'+station_id + '-' + str(ts) + '.png',
                'time_alert': last_problem
            }
            
            if status_alert == "down":
                #alert_error(status_alert, station_name, provider_alert, ts, mediatype_alert, streamuri_alert, stationid_alert, date_query, alert_data)
                streaming_alert(status_alert, station_name, provider_alert, ts, mediatype_alert, streamuri_alert, stationid_alert, date_query, alert_data)
                return alert_data
            else:
                message = "No se tiene data que mostrar"
                print(message)
                return message
        except IOError as e:
            print("Se tiene un problema")
            print(e)
            message = e
            return message

#create_chartguardian("tv-capital", "capital-tv")