<commit_before>import psycopg2.extras
import datetime
import numpy as np
import math
from pyiem.network import Table as NetworkTable
from pyiem.nws import vtec
import calendar
import pandas as pd
from pyiem.util import get_autoplot_context
from pyiem import reference

PDICT = {'yes': "Limit Plot to Year-to-Date",
         'no': 'Plot Entire Year'}
PDICT2 = {'single': "Plot Single VTEC Phenomena + Significance",
          'svrtor': 'Plot Severe Thunderstorm + Tornado Warnings'}
PDICT3 = {'wfo': 'Plot for Single/All WFO',
          'state': 'Plot for a Single State'}


def get_description():
    """ Return a dict describing how to call this plotter """
    d = dict()
    d['cache'] = 86400
    d['data'] = True
    d['description'] = """This plot displays an accumulated total of
    office issued watch, warning, advisories.  These totals are not official
    and based on IEM processing of NWS text warning data.  The totals are for
    individual warnings and not some combination of counties + warnings. The
    archive begin date varies depending on which phenomena you are interested
    in."""
    d['arguments'] = [
        dict(type='select', name='opt', options=PDICT3, default='wfo',
             label='Plot for a WFO or a State?'),
        dict(type='networkselect', name='station', network='WFO',
             default='DMX', label='Select WFO (when appropriate):', all=True),
        dict(type='state', default='IA', name='state',
             label='Select State (when appropriate):'),
        dict(type='select', name='limit', default='no',
             label='End Date Limit to Plot:', options=PDICT),
        dict(type='select', name='c', default='svrtor',
             label='Single or Combination of Products:', options=PDICT2),
        dict(type='phenomena', name='phenomena',
             default='TO', 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)
    ctx = get_autoplot_context(fdict, get_description())
    station = ctx['station']
    limit = ctx['limit']
    combo = ctx['c']
    phenomena = ctx['phenomena'][:2]
    significance = ctx['significance'][:2]
    opt = ctx['opt']
    state = ctx['state'][:2]

    nt = NetworkTable('WFO')
    nt.sts['_ALL'] = {'name': 'All Offices'}

    lastdoy = 367
    if limit.lower() == 'yes':
        lastdoy = int(datetime.datetime.today().strftime("%j")) + 1
    wfolimiter = " and wfo = '%s' " % (station, )
    if opt == 'state':
        wfolimiter = " and substr(ugc, 1, 2) = '%s' " % (state, )
    eventlimiter = ""
    if combo == 'svrtor':
        eventlimiter = " or (phenomena = 'SV' and significance = 'W') "
        phenomena = 'TO'
        significance = 'W'

    cursor.execute("""
    WITH data as (
        SELECT extract(year from issue) as yr,
        issue, phenomena, significance, eventid, wfo from warnings WHERE
        ((phenomena = %s and significance = %s) """ + eventlimiter + """)
        and extract(doy from issue) < %s """ + wfolimiter + """),
    agg1 as (
        SELECT yr, min(issue) as min_issue, eventid, wfo, phenomena,
        significance from data
        GROUP by yr, eventid, wfo, phenomena, significance),
    agg2 as (
        SELECT yr, extract(doy from min_issue) as doy, count(*)
        from agg1 GROUP by yr, doy)
    SELECT yr, doy, sum(count) OVER (PARTITION by yr ORDER by doy ASC)
    from agg2 ORDER by yr ASC, doy ASC
    """, (phenomena, significance, lastdoy))

    data = {}
    for yr in range(1986, datetime.datetime.now().year + 1):
        data[yr] = {'doy': [0], 'counts': [0]}
    rows = []<commit_msg>fix all station plot<commit_after>import psycopg2.extras
import datetime
import numpy as np
import math
from pyiem.network import Table as NetworkTable
from pyiem.nws import vtec
import calendar
import pandas as pd
from pyiem.util import get_autoplot_context
from pyiem import reference

PDICT = {'yes': "Limit Plot to Year-to-Date",
         'no': 'Plot Entire Year'}
PDICT2 = {'single': "Plot Single VTEC Phenomena + Significance",
          'svrtor': 'Plot Severe Thunderstorm + Tornado Warnings'}
PDICT3 = {'wfo': 'Plot for Single/All WFO',
          'state': 'Plot for a Single State'}


def get_description():
    """ Return a dict describing how to call this plotter """
    d = dict()
    d['cache'] = 86400
    d['data'] = True
    d['description'] = """This plot displays an accumulated total of
    office issued watch, warning, advisories.  These totals are not official
    and based on IEM processing of NWS text warning data.  The totals are for
    individual warnings and not some combination of counties + warnings. The
    archive begin date varies depending on which phenomena you are interested
    in."""
    d['arguments'] = [
        dict(type='select', name='opt', options=PDICT3, default='wfo',
             label='Plot for a WFO or a State?'),
        dict(type='networkselect', name='station', network='WFO',
             default='DMX', label='Select WFO (when appropriate):', all=True),
        dict(type='state', default='IA', name='state',
             label='Select State (when appropriate):'),
        dict(type='select', name='limit', default='no',
             label='End Date Limit to Plot:', options=PDICT),
        dict(type='select', name='c', default='svrtor',
             label='Single or Combination of Products:', options=PDICT2),
        dict(type='phenomena', name='phenomena',
             default='TO', 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)
    ctx = get_autoplot_context(fdict, get_description())
    station = ctx['station']
    limit = ctx['limit']
    combo = ctx['c']
    phenomena = ctx['phenomena'][:2]
    significance = ctx['significance'][:2]
    opt = ctx['opt']
    state = ctx['state'][:2]

    nt = NetworkTable('WFO')
    nt.sts['_ALL'] = {'name': 'All Offices'}

    lastdoy = 367
    if limit.lower() == 'yes':
        lastdoy = int(datetime.datetime.today().strftime("%j")) + 1
    wfolimiter = " and wfo = '%s' " % (station, )
    if opt == 'state':
        wfolimiter = " and substr(ugc, 1, 2) = '%s' " % (state, )
    if opt == 'wfo' and station == '_ALL':
        wfolimiter = ''
    eventlimiter = ""
    if combo == 'svrtor':
        eventlimiter = " or (phenomena = 'SV' and significance = 'W') "
        phenomena = 'TO'
        significance = 'W'

    cursor.execute("""
    WITH data as (
        SELECT extract(year from issue) as yr,
        issue, phenomena, significance, eventid, wfo from warnings WHERE
        ((phenomena = %s and significance = %s) """ + eventlimiter + """)
        and extract(doy from issue) <= %s """ + wfolimiter + """),
    agg1 as (
        SELECT yr, min(issue) as min_issue, eventid, wfo, phenomena,
        significance from data
        GROUP by yr, eventid, wfo, phenomena, significance),
    agg2 as (
        SELECT yr, extract(doy from min_issue) as doy, count(*)
        from agg1 GROUP by yr, doy)
    SELECT yr, doy, sum(count) OVER (PARTITION by yr ORDER by doy ASC)
    from agg2 ORDER by yr ASC, doy ASC
    """, (phenomena, significance, lastdoy))

    data = {}
    for yr in range(1986, datetime.datetime.now().year + 1):
        data[yr] = {'doy': [0], 'counts': [0]}
    rows = []
{'fraction_non_alphanumeric': 0.1393575803024622, 'fraction_numerical': 0.007999000124984376, 'mean_word_length': 3.0516455696202534, 'pattern_counts': {'":': 0, '<': 5, '<?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': '3500361', 'n_tokens_mistral': 2570, 'n_tokens_neox': 2424, 'n_words': 772}