original_docstring: 
          Generates the json status object from the database for the available HWRF data
          :return: json status object
          
docstring: Generates the json status object from the database for the available HWRF data
docstring_tokens: Generates the json status object from the database for the available HWRF data
code: def hwrf_status(self):
          """
          Generates the json status object from the database for the available HWRF data
          :return: json status object
          """
          import sqlite3
          from datetime import datetime
          db = sqlite3.connect(self.__db)
  
          # Use SQL to generate a distinct list of storms and then
          # iterate over them to determine the available forecast data
          sql = "SELECT DISTINCT stormname FROM hwrf"
          stormlist = []
          rows = db.execute(sql).fetchall()
          for row in rows:
              stormlist.append({"storm": row[0]})
  
          hwrf_stat = []
  
          # For each storm, determine the availability of data
          for s in stormlist:
              sql = "SELECT DATE FROM hwrf WHERE stormname = '" + s[
                  "storm"] + "' ORDER BY DATE"
              rows = db.execute(sql).fetchall()
              fcst_min = rows[0][0]
              fcst_max = rows[-1][0]
              sql = "SELECT DISTINCT FORECASTCYCLE FROM hwrf WHERE stormname = '" + s[
                  "storm"] + "' ORDER BY FORECASTCYCLE"
              rows = db.execute(sql).fetchall()
              cyc_min = rows[0][0]
              cyc_max = rows[-1][0]
  
              latest_complete = None
              latest_start = None
              latest_end = None
              latest_length = None
              time_since_forecast = 0
              cycle_list = []
  
              # Backwards loop to see the most recent complete forecast cycle
              for f in reversed(rows):
                  sql = "SELECT MIN(DATE) AS FIRST, MAX(DATE) AS LAST FROM hwrf WHERE stormname = '" + s[
                      "storm"] + "' AND FORECASTCYCLE = datetime('" + f[
                            0] + "') ORDER BY DATE"
                  r = db.execute(sql).fetchall()
                  start = datetime.strptime(r[0][0], "%Y-%m-%d %H:%M:%S")
                  end = datetime.strptime(r[0][1], "%Y-%m-%d %H:%M:%S")
                  avail_len = (end - start).total_seconds() / 3600
                  if avail_len >= 126:
                      cycle_list.append(f[0])
                      latest_start = start.strftime("%Y-%m-%d %H:%M:%S")
                      latest_end = end.strftime("%Y-%m-%d %H:%M:%S")
                      latest_length = avail_len
                      latest_complete = f[0]
                      time_since_forecast = datetime.now() - datetime.strptime(
                          f[0], "%Y-%m-%d %H:%M:%S")
                      time_since_forecast = time_since_forecast.total_seconds(
                      ) / 86400
                      break
  
              # Assemble a storm object. We're only going to write data available in the last 10 days
              if time_since_forecast < 10:
                  hwrf_stat.append({
                      "storm":
                          s["storm"],
                      "min_forecast_date":
                          fcst_min,
                      "max_forecast_date":
                          fcst_max,
                      "first_available_cycle":
                          cyc_min,
                      "last_available_cycle":
                          cyc_max,
                      "latest_complete_forecast":
                          latest_complete,
                      "latest_complete_forecast_start":
                          latest_start,
                      "latest_complete_forecast_end":
                          latest_end,
                      "latest_complete_forecast_length":
                          latest_length,
                      "cycle_list": cycle_list
                  })
  
          return hwrf_stat
code_tokens: def hwrf_status ( self ) : import sqlite3 from datetime import datetime db = sqlite3 . connect ( self . __db ) sql = "SELECT DISTINCT stormname FROM hwrf" stormlist = [ ] rows = db . execute ( sql ) . fetchall ( ) for row in rows : stormlist . append ( { "storm" : row [ 0 ] } ) hwrf_stat = [ ] for s in stormlist : sql = "SELECT DATE FROM hwrf WHERE stormname = '" + s [ "storm" ] + "' ORDER BY DATE" rows = db . execute ( sql ) . fetchall ( ) fcst_min = rows [ 0 ] [ 0 ] fcst_max = rows [ - 1 ] [ 0 ] sql = "SELECT DISTINCT FORECASTCYCLE FROM hwrf WHERE stormname = '" + s [ "storm" ] + "' ORDER BY FORECASTCYCLE" rows = db . execute ( sql ) . fetchall ( ) cyc_min = rows [ 0 ] [ 0 ] cyc_max = rows [ - 1 ] [ 0 ] latest_complete = None latest_start = None latest_end = None latest_length = None time_since_forecast = 0 cycle_list = [ ] for f in reversed ( rows ) : sql = "SELECT MIN(DATE) AS FIRST, MAX(DATE) AS LAST FROM hwrf WHERE stormname = '" + s [ "storm" ] + "' AND FORECASTCYCLE = datetime('" + f [ 0 ] + "') ORDER BY DATE" r = db . execute ( sql ) . fetchall ( ) start = datetime . strptime ( r [ 0 ] [ 0 ] , "%Y-%m-%d %H:%M:%S" ) end = datetime . strptime ( r [ 0 ] [ 1 ] , "%Y-%m-%d %H:%M:%S" ) avail_len = ( end - start ) . total_seconds ( ) / 3600 if avail_len >= 126 : cycle_list . append ( f [ 0 ] ) latest_start = start . strftime ( "%Y-%m-%d %H:%M:%S" ) latest_end = end . strftime ( "%Y-%m-%d %H:%M:%S" ) latest_length = avail_len latest_complete = f [ 0 ] time_since_forecast = datetime . now ( ) - datetime . strptime ( f [ 0 ] , "%Y-%m-%d %H:%M:%S" ) time_since_forecast = time_since_forecast . total_seconds ( ) / 86400 break if time_since_forecast < 10 : hwrf_stat . append ( { "storm" : s [ "storm" ] , "min_forecast_date" : fcst_min , "max_forecast_date" : fcst_max , "first_available_cycle" : cyc_min , "last_available_cycle" : cyc_max , "latest_complete_forecast" : latest_complete , "latest_complete_forecast_start" : latest_start , "latest_complete_forecast_end" : latest_end , "latest_complete_forecast_length" : latest_length , "cycle_list" : cycle_list } ) return hwrf_stat
short_docstring: Generates the json status object from the database for the available HWRF data
short_docstring_tokens: Generates the json status object from the database for the available HWRF data
comment: """
          Generates the json status object from the database for the available HWRF data
          :return: json status object
          """$SEP$# Use SQL to generate a distinct list of storms and then$SEP$# iterate over them to determine the available forecast data$SEP$# For each storm, determine the availability of data$SEP$# Backwards loop to see the most recent complete forecast cycle$SEP$# Assemble a storm object. We're only going to write data available in the last 10 days