<commit_before>import psycopg2.extras
import pyiem.nws.vtec as vtec
import numpy as np
from pyiem.network import Table as NetworkTable
import pandas as pd


def get_description():
    """ Return a dict describing how to call this plotter """
    d = dict()
    d['cache'] = 86400
    d['data'] = True
    d['description'] = """This chart presents a histogram of issuance times
    for a given watch, warning, or advisory type for a given office."""
    d['arguments'] = [
        dict(type='networkselect', name='station', network='WFO',
             default='DMX', label='Select WFO:'),
        dict(type='phenomena', name='phenomena',
             default='WC', label='Select Watch/Warning Phenomena Type:'),
        dict(type='significance', name='significance',
             default='W', label='Select Watch/Warning Significance Level:'),
    ]
    return d


def plotter(fdict):
    """ Go """
    import matplotlib
    matplotlib.use('agg')
    import matplotlib.pyplot as plt
    pgconn = psycopg2.connect(database='postgis', host='iemdb', user='nobody')
    cursor = pgconn.cursor(cursor_factory=psycopg2.extras.DictCursor)

    wfo = fdict.get('station', 'DMX')
    phenomena = fdict.get('phenomena', 'WC')
    significance = fdict.get('significance', 'W')

    nt = NetworkTable("WFO")

    (fig, ax) = plt.subplots(1, 1)

    tzname = nt.sts[wfo]['tzname']
    cursor.execute("""
    WITH data as (
     SELECT extract(year from issue) as yr, eventid,
     min(issue at time zone %s) as minissue from warnings WHERE
     phenomena = %s and significance = %s
     and wfo = %s GROUP by yr, eventid)

    SELECT extract(hour from minissue) as hr, count(*) from data GROUP by hr
    """, (tzname, phenomena, significance, wfo))
    if cursor.rowcount == 0:
        ax.text(0.5, 0.5, "No Results Found",
                transform=ax.transAxes, ha='center')
        return fig

    data = np.zeros((24,), 'f')
    for row in cursor:
        data[int(row[0])] = row[1]
    df = pd.DataFrame(dict(hour=pd.Series(np.arange(24)),
                           count=pd.Series(data)))

    ax.bar(np.arange(24) - 0.4, data / float(sum(data)) * 100., ec='b', fc='b')
    ax.grid()
    ax.set_xticks(range(0, 25, 1))
    ax.set_xlim(-0.5, 23.5)
    ax.set_xticklabels(["Mid", "", "", "3 AM", "", "", "6 AM", "", "", '9 AM',<commit_msg>prevent missing issuance from tripping up freq plot<commit_after>import psycopg2.extras
import pyiem.nws.vtec as vtec
import numpy as np
from pyiem.network import Table as NetworkTable
import pandas as pd


def get_description():
    """ Return a dict describing how to call this plotter """
    d = dict()
    d['cache'] = 86400
    d['data'] = True
    d['description'] = """This chart presents a histogram of issuance times
    for a given watch, warning, or advisory type for a given office."""
    d['arguments'] = [
        dict(type='networkselect', name='station', network='WFO',
             default='DMX', label='Select WFO:'),
        dict(type='phenomena', name='phenomena',
             default='WC', label='Select Watch/Warning Phenomena Type:'),
        dict(type='significance', name='significance',
             default='W', label='Select Watch/Warning Significance Level:'),
    ]
    return d


def plotter(fdict):
    """ Go """
    import matplotlib
    matplotlib.use('agg')
    import matplotlib.pyplot as plt
    pgconn = psycopg2.connect(database='postgis', host='iemdb', user='nobody')
    cursor = pgconn.cursor(cursor_factory=psycopg2.extras.DictCursor)

    wfo = fdict.get('station', 'DMX')
    phenomena = fdict.get('phenomena', 'WC')
    significance = fdict.get('significance', 'W')

    nt = NetworkTable("WFO")

    (fig, ax) = plt.subplots(1, 1)

    tzname = nt.sts[wfo]['tzname']
    cursor.execute("""
    WITH data as (
     SELECT extract(year from issue) as yr, eventid,
     min(issue at time zone %s) as minissue from warnings WHERE
     phenomena = %s and significance = %s
     and wfo = %s and issue is not null GROUP by yr, eventid)

    SELECT extract(hour from minissue) as hr, count(*) from data GROUP by hr
    """, (tzname, phenomena, significance, wfo))
    if cursor.rowcount == 0:
        ax.text(0.5, 0.5, "No Results Found",
                transform=ax.transAxes, ha='center')
        return fig

    data = np.zeros((24,), 'f')
    for row in cursor:
        data[int(row[0])] = row[1]
    df = pd.DataFrame(dict(hour=pd.Series(np.arange(24)),
                           count=pd.Series(data)))

    ax.bar(np.arange(24) - 0.4, data / float(sum(data)) * 100., ec='b', fc='b')
    ax.grid()
    ax.set_xticks(range(0, 25, 1))
    ax.set_xlim(-0.5, 23.5)
    ax.set_xticklabels(["Mid", "", "", "3 AM", "", "", "6 AM", "", "", '9 AM',
{'fraction_non_alphanumeric': 0.15544260906395596, 'fraction_numerical': 0.0169419737399407, 'mean_word_length': 3.0127442650807135, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2252488', 'n_tokens_mistral': 1645, 'n_tokens_neox': 1544, 'n_words': 425}