Update historygenerator.py to use historical values from CSV
This commit is contained in:
@@ -36,6 +36,8 @@ import os.path
|
||||
import weewx.units
|
||||
import weeutil.weeutil
|
||||
|
||||
import csv
|
||||
|
||||
try:
|
||||
from weeutil.weeutil import accumulateLeaves
|
||||
except:
|
||||
@@ -301,6 +303,9 @@ class MyXSearch(SearchList):
|
||||
if NOAA is False and summary_column:
|
||||
table_dict["header"]["summary"] = 'Year'
|
||||
|
||||
weewx_startdate = int(table_options["weewx_startdate"]) # TP
|
||||
startdate = int(table_options["startdate"])
|
||||
|
||||
for year in table_stats.years():
|
||||
year_number = datetime.fromtimestamp(year.timespan[0]).year
|
||||
value = {"value": str(year_number)}
|
||||
@@ -309,6 +314,9 @@ class MyXSearch(SearchList):
|
||||
value["url"] = dt.strftime(table_options['year_filename'])
|
||||
line = {"head": value, "values": []}
|
||||
|
||||
csvFile = open("/etc/weewx/historic_data.csv")
|
||||
csvReader = csv.DictReader(csvFile) # TP
|
||||
|
||||
for month in year.months():
|
||||
if NOAA is True:
|
||||
noaa_value = {"value": ""}
|
||||
@@ -317,6 +325,22 @@ class MyXSearch(SearchList):
|
||||
noaa_value["value"] = dt.strftime("%m-%y")
|
||||
noaa_value["url"] = dt.strftime(table_options['month_filename'])
|
||||
line["values"].append(noaa_value)
|
||||
elif month.timespan[0] < weewx_startdate and month.timespan[0] >= startdate and table in csvReader.fieldnames: # TP - use historical data here
|
||||
month_number = datetime.fromtimestamp(month.timespan[0]).month
|
||||
historic_value = 0
|
||||
for row in csvReader:
|
||||
if int(row["year"]) == year_number and int(row["month"]) == month_number:
|
||||
try:
|
||||
historic_value = float(row[table])
|
||||
except KeyError:
|
||||
historic_value = historic_value
|
||||
except ValueError:
|
||||
historic_value = "NA"
|
||||
break
|
||||
if historic_value == "NA":
|
||||
line["values"].append(self._colorCell([None,1,"mile_per_hour"], format_string, cell_colors, month))
|
||||
else:
|
||||
line["values"].append(self._colorCell([historic_value,1,"mile_per_hour"], format_string, cell_colors, month))
|
||||
else:
|
||||
# update the binding to access the right DB
|
||||
obs_month = getattr(month, obs_type)
|
||||
|
||||
Reference in New Issue
Block a user