def __init__(self, **kwargs): generic_asset_type = GenericAssetType( name=kwargs["name"], description=kwargs.get("hover_label", None) ) db.session.add(generic_asset_type) super(WeatherSensorType, self).__init__(**kwargs) if "display_name" not in kwargs: self.display_name = humanize(self.name)
def __init__(self, **kwargs): kwargs["name"] = kwargs["name"].replace(" ", "_").lower() if "display_name" not in kwargs: kwargs["display_name"] = humanize(kwargs["name"]) super(MarketType, self).__init__(**kwargs) generic_asset_type = GenericAssetType(name=kwargs["name"], description=kwargs.get( "hover_label", None)) db.session.add(generic_asset_type)
def __init__(self, **kwargs): # Set default knowledge horizon function for an economic sensor if "knowledge_horizon_fnc" not in kwargs: kwargs["knowledge_horizon_fnc"] = knowledge_horizons.ex_ante.__name__ if "knowledge_horizon_par" not in kwargs: kwargs["knowledge_horizon_par"] = { knowledge_horizons.ex_ante.__code__.co_varnames[1]: "PT0H" } super(Market, self).__init__(**kwargs) self.name = self.name.replace(" ", "_").lower() if "display_name" not in kwargs: self.display_name = humanize(self.name)
def __init__(self, **kwargs): generic_asset_type = GenericAssetType.query.filter_by( name=kwargs["name"] ).one_or_none() if not generic_asset_type: generic_asset_type = GenericAssetType( name=kwargs["name"], description=kwargs.get("hover_label", None) ) db.session.add(generic_asset_type) super(AssetType, self).__init__(**kwargs) self.name = self.name.replace(" ", "_").lower() if "display_name" not in kwargs: self.display_name = humanize(self.name)
def make_weather_figure( selected_resource: Resource, data: pd.DataFrame, forecast_data: Union[None, pd.DataFrame], shared_x_range: Range1d, weather_sensor: WeatherSensor, tools: List[str] = None, ) -> Figure: """Make a bokeh figure for weather data""" # Todo: plot average temperature/total_radiation/wind_speed for asset groups, and update title accordingly if weather_sensor is None: return create_graph(pd.DataFrame()) unit = weather_sensor.unit weather_axis_label = "%s (in %s)" % ( humanize(weather_sensor.sensor_type.display_name), unit, ) if selected_resource.is_unique_asset: title = "%s at %s" % ( humanize(weather_sensor.sensor_type.display_name), selected_resource.display_name, ) else: title = "%s" % humanize(weather_sensor.sensor_type.display_name) return create_graph( data, unit=unit, forecasts=forecast_data, title=title, x_range=shared_x_range, x_label="Time (resolution of %s)" % time_utils.freq_label_to_human_readable_label(session["resolution"]), y_label=weather_axis_label, legend_location="top_right", show_y_floats=True, tools=tools, )
def __init__(self, **kwargs): super(WeatherSensorType, self).__init__(**kwargs) self.name = self.name.replace(" ", "_").lower() if "display_name" not in kwargs: self.display_name = humanize(self.name)
def __init__(self, **kwargs): # Set default knowledge horizon function for an economic sensor if "knowledge_horizon_fnc" not in kwargs: kwargs[ "knowledge_horizon_fnc"] = knowledge_horizons.ex_ante.__name__ if "knowledge_horizon_par" not in kwargs: kwargs["knowledge_horizon_par"] = { knowledge_horizons.ex_ante.__code__.co_varnames[1]: "PT0H" } kwargs["name"] = kwargs["name"].replace(" ", "_").lower() if "display_name" not in kwargs: kwargs["display_name"] = humanize(kwargs["name"]) super(Market, self).__init__(**kwargs) # Create a new Sensor with unique id across assets, markets and weather sensors if "id" not in kwargs: market_type = get_old_model_type(kwargs, MarketType, "market_type_name", "market_type") generic_asset_kwargs = { **kwargs, **copy_old_sensor_attributes( self, old_sensor_type_attributes=[], old_sensor_attributes=[ "display_name", ], old_sensor_type=market_type, ), } new_generic_asset = create_generic_asset("market", **generic_asset_kwargs) new_sensor = Sensor( name=kwargs["name"], generic_asset=new_generic_asset, **copy_old_sensor_attributes( self, old_sensor_type_attributes=[ "daily_seasonality", "weekly_seasonality", "yearly_seasonality", ], old_sensor_attributes=[ "display_name", ], old_sensor_type=market_type, ), ) db.session.add(new_sensor) db.session.flush() # generates the pkey for new_sensor new_sensor_id = new_sensor.id else: # The UI may initialize Market objects from API form data with a known id new_sensor_id = kwargs["id"] self.id = new_sensor_id # Copy over additional columns from (newly created) Market to (newly created) Sensor if "id" not in kwargs: db.session.add(self) db.session.flush( ) # make sure to generate each column for the old sensor new_sensor.unit = self.unit new_sensor.event_resolution = self.event_resolution new_sensor.knowledge_horizon_fnc = self.knowledge_horizon_fnc new_sensor.knowledge_horizon_par = self.knowledge_horizon_par
def __init__(self, **kwargs): if "unit" not in kwargs: kwargs["unit"] = "MW" # current default super(Asset, self).__init__(**kwargs) # Create a new Sensor with unique id across assets, markets and weather sensors # Also keep track of ownership by creating a GenericAsset and assigning the new Sensor to it. if "id" not in kwargs: asset_type = get_old_model_type( kwargs, AssetType, "asset_type_name", "asset_type" ) # Set up generic asset generic_asset_kwargs = { **kwargs, **copy_old_sensor_attributes( self, old_sensor_type_attributes=[ "can_curtail", "can_shift", ], old_sensor_attributes=[ "display_name", "min_soc_in_mwh", "max_soc_in_mwh", "soc_in_mwh", "soc_datetime", "soc_udi_event_id", ], old_sensor_type=asset_type, ), } if "owner_id" in kwargs: owner = User.query.get(kwargs["owner_id"]) if owner: generic_asset_kwargs.update(account_id=owner.account_id) new_generic_asset = create_generic_asset("asset", **generic_asset_kwargs) # Set up sensor new_sensor = Sensor( name=kwargs["name"], generic_asset=new_generic_asset, **copy_old_sensor_attributes( self, old_sensor_type_attributes=[ "is_consumer", "is_producer", "daily_seasonality", "weekly_seasonality", "yearly_seasonality", "weather_correlations", ], old_sensor_attributes=[ "display_name", "capacity_in_mw", "market_id", ], old_sensor_type=asset_type, ), ) db.session.add(new_sensor) db.session.flush() # generates the pkey for new_sensor sensor_id = new_sensor.id else: # The UI may initialize Asset objects from API form data with a known id sensor_id = kwargs["id"] self.id = sensor_id if self.unit != "MW": raise Exception("FlexMeasures only supports MW as unit for now.") self.name = self.name.replace(" (MW)", "") if "display_name" not in kwargs: self.display_name = humanize(self.name) # Copy over additional columns from (newly created) Asset to (newly created) Sensor if "id" not in kwargs: db.session.add(self) db.session.flush() # make sure to generate each column for the old sensor new_sensor.unit = self.unit new_sensor.event_resolution = self.event_resolution new_sensor.knowledge_horizon_fnc = self.knowledge_horizon_fnc new_sensor.knowledge_horizon_par = self.knowledge_horizon_par