Skip to content

Commit

Permalink
logoutput improved
Browse files Browse the repository at this point in the history
  • Loading branch information
grro committed Jan 3, 2023
1 parent 981ed09 commit bfe004c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
4 changes: 2 additions & 2 deletions pvpower/forecast.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from pvpower.weather_forecast import WeatherStation, WeatherForecast
from pvpower.traindata import LabelledWeatherForecast, TrainSampleLog
from pvpower.estimator import Estimator
from pvpower.persistent_estimator import PersistentEstimator
from pvpower.refreshing_estimator import AutoRefreshingEstimator


class ValueRecorder:
Expand Down Expand Up @@ -42,7 +42,7 @@ def __init__(self, station_id: str, pv_forecast_dir: None, estimator: Estimator
self.__train_value_recorder = ValueRecorder()
self.weather_forecast_service = WeatherStation(station_id)
self.train_log = TrainSampleLog(pv_forecast_dir)
self.__estimator = estimator if estimator is not None else PersistentEstimator(self.train_log)
self.__estimator = estimator if estimator is not None else AutoRefreshingEstimator(self.train_log)

def add_current_power_reading(self, real_power: int):
if self.__train_value_recorder.is_expired():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@
from pvpower.trainingcenter import TrainingCenter


class PersistentEstimator(DelegatingEstimator):
class AutoRefreshingEstimator(DelegatingEstimator):

def __init__(self, train_log: TrainSampleLog):
self.__train_log = train_log
self.__lock = Lock()
self.__training_center = TrainingCenter()
self.__date_last_retrain_initiated = datetime.fromtimestamp(0)
super(PersistentEstimator, self).__init__(PersistentEstimator.__load())
super().__init__(AutoRefreshingEstimator.__load())

def predict(self, sample: WeatherForecast) -> int:
try:
return super(PersistentEstimator, self).predict(sample)
return super().predict(sample)
finally:
try:
retrain_period_days = 1 + (self.duration_sec_last_train() * 7 * 24) # min 1 day + 7 days per 1 sec traintime
Expand All @@ -41,19 +41,19 @@ def retrain(self, train_data: TrainData):
@staticmethod
def __store(estimator: Estimator):
try:
with open(PersistentEstimator.__filename(), 'wb') as file:
with open(AutoRefreshingEstimator.__filename(), 'wb') as file:
pickle.dump(estimator, file)
except Exception as e:
logging.warning("error occurred storing pickled estimator " + str(e))

@staticmethod
def __load() -> Estimator:
estimator = SVMEstimator(FullVectorizer())
if exists(PersistentEstimator.__filename()):
if exists(AutoRefreshingEstimator.__filename()):
try:
with open(PersistentEstimator.__filename(), 'rb') as file:
with open(AutoRefreshingEstimator.__filename(), 'rb') as file:
estimator = pickle.load(file)
logging.debug("estimator " + str(estimator) + " loaded from pickle file (" + PersistentEstimator.__filename() + ")")
logging.debug("estimator " + str(estimator) + " loaded from pickle file (" + AutoRefreshingEstimator.__filename() + ")")
except Exception as e:
logging.warning("error occurred loading estimator " + str(e))
return estimator
Expand Down
3 changes: 2 additions & 1 deletion pvpower/weather_forecast.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ def with_time(self, dt: datetime):
self.visibility)

def __str__(self):
return self.time_utc.strftime("%H") + ":00-" + (self.time_utc + timedelta(hours=1)).strftime("%H") + ":00 (utc)" + \
return self.time.strftime("%H") + ":00-" + (self.time + timedelta(hours=1)).strftime("%H") + ":00 " + \
"(" + self.time_utc.strftime("%H") + ":00-" + (self.time_utc + timedelta(hours=1)).strftime("%H") + ":00 utc)" + \
", irradiance=" + str(round(self.irradiance)) + \
", sunshine=" + str(round(self.sunshine)) + \
", cloud_cover_effective=" + str(round(self.cloud_cover_effective)) + \
Expand Down

0 comments on commit bfe004c

Please sign in to comment.