text
stringlengths 0
828
|
---|
""""""
|
Find a data formatter given an input and output format
|
input_format - needed input format. see utils.input.dataformats
|
output_format - needed output format. see utils.input.dataformats
|
""""""
|
#Only take the formatters in the registry
|
selected_registry = [re.cls for re in registry if re.category==RegistryCategories.formatters]
|
needed_formatters = []
|
for formatter in selected_registry:
|
#Initialize the formatter (needed so it can discover its formats)
|
formatter_inst = formatter()
|
if input_format in formatter_inst.input_formats and output_format in formatter_inst.output_formats:
|
needed_formatters.append(formatter)
|
if len(needed_formatters)>0:
|
return needed_formatters[0]
|
return None"
|
375,"def find_needed_input(input_format):
|
""""""
|
Find a needed input class
|
input_format - needed input format, see utils.input.dataformats
|
""""""
|
needed_inputs = [re.cls for re in registry if re.category==RegistryCategories.inputs and re.cls.input_format == input_format]
|
if len(needed_inputs)>0:
|
return needed_inputs[0]
|
return None"
|
376,"def exists_in_registry(category, namespace, name):
|
""""""
|
See if a given category, namespace, name combination exists in the registry
|
category - See registrycategories. Type of module
|
namespace - Namespace of the module, defined in settings
|
name - the lowercase name of the module
|
""""""
|
selected_registry = [re for re in registry if re.category==category and re.namespace==namespace and re.name == name]
|
if len(selected_registry)>0:
|
return True
|
return False"
|
377,"def register(cls):
|
""""""
|
Register a given model in the registry
|
""""""
|
registry_entry = RegistryEntry(category = cls.category, namespace = cls.namespace, name = cls.name, cls=cls)
|
if registry_entry not in registry and not exists_in_registry(cls.category, cls.namespace, cls.name):
|
registry.append(registry_entry)
|
else:
|
log.warn(""Class {0} already in registry"".format(cls))"
|
378,"def _set_fields(self):
|
""""""
|
Initialize the fields for data caching.
|
""""""
|
self.fields = []
|
self.required_input = []
|
for member_name, member_object in inspect.getmembers(self.__class__):
|
if inspect.isdatadescriptor(member_object) and not member_name.startswith(""__""):
|
self.fields.append(member_name)
|
if member_object.required_input:
|
self.required_input.append(member_name)"
|
379,"def subscriber(address,topics,callback,message_type):
|
""""""
|
Creates a subscriber binding to the given address and
|
subscribe the given topics.
|
The callback is invoked for every message received.
|
Args:
|
- address: the address to bind the PUB socket to.
|
- topics: the topics to subscribe
|
- callback: the callback to invoke for every message. Must accept 2 variables - topic and message
|
- message_type: the type of message to receive
|
""""""
|
return Subscriber(address,topics,callback,message_type)"
|
380,"def start(self):
|
""""""
|
Start a thread that consumes the messages and invokes the callback
|
""""""
|
t=threading.Thread(target=self._consume)
|
t.start()"
|
381,"def _get_forecast(api_result: dict) -> List[SmhiForecast]:
|
""""""Converts results fråm API to SmhiForeCast list""""""
|
forecasts = []
|
# Need the ordered dict to get
|
# the days in order in next stage
|
forecasts_ordered = OrderedDict()
|
forecasts_ordered = _get_all_forecast_from_api(api_result)
|
# Used to calc the daycount
|
day_nr = 1
|
for day in forecasts_ordered:
|
forecasts_day = forecasts_ordered[day]
|
if day_nr == 1:
|
# Add the most recent forecast
|
forecasts.append(copy.deepcopy(forecasts_day[0]))
|
total_precipitation = float(0.0)
|
forecast_temp_max = -100.0
|
forecast_temp_min = 100.0
|
forecast = None
|
for forcast_day in forecasts_day:
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.