text stringlengths 0 828 |
|---|
the :mod:`~aionationstates.happenings` module |
"""""" |
while True: |
happening_bunch = await self._get_happenings( |
nations=nations, regions=regions, filters=filters, |
beforeid=beforeid, beforetime=beforetime |
) |
for happening in happening_bunch: |
yield happening |
if len(happening_bunch) < 100: |
break |
beforeid = happening_bunch[-1].id" |
4283,"async def new_happenings(self, poll_period=30, *, nations=None, |
regions=None, filters=None): |
""""""Iterate through new happenings as they arrive:: |
async for happening in \\ |
world.new_happenings(region='the north pacific'): |
# Your processing code here |
print(happening.text) # As an example |
Guarantees that: |
* Every happening is generated from the moment the generator |
is started; |
* No happening is generated more than once; |
* Happenings are generated in order from oldest to newest. |
Parameters |
---------- |
poll_period : int |
How long to wait between requesting the next portion of |
happenings, in seconds. Note that this should only be |
tweaked for latency reasons, as the function gives a |
guarantee that all happenings will be generated. |
Also note that, regardless of the ``poll_period`` set, all |
of the code in your loop body still has to execute (likely |
several times) before a new portion of happenings can be |
requested. Consider wrapping your happening-processing code |
in a coroutine and launching it as a task from the loop body |
if you suspect this might become an issue. |
Requests made by this generator are, of course, subject to |
the API rate limit, and if the limiter has to temporarily |
block new requests the time spent waiting will be added on |
top of ``poll_period``. |
nations : iterable of str |
Nations happenings of which will be requested. Cannot be |
specified at the same time with ``regions``. |
regions : iterable of str |
Regions happenings of which will be requested. Cannot be |
specified at the same time with ``nations``. |
filters : iterable of str |
Categories to request happenings by. Available filters |
are: ``law``, ``change``, ``dispatch``, ``rmb``, |
``embassy``, ``eject``, ``admin``, ``move``, ``founding``, |
``cte``, ``vote``, ``resolution``, ``member``, and ``endo``. |
Returns |
------- |
an asynchronous iterator yielding any of the classes from \ |
the :mod:`~aionationstates.happenings` module |
"""""" |
try: |
# We only need the happenings from this point forwards |
last_id = (await self._get_happenings( |
nations=nations, regions=regions, filters=filters, |
limit=1))[0].id |
except IndexError: |
# Happenings before this point have all been deleted |
last_id = 0 |
while True: |
# Sleep before the loop body to avoid wasting the first request |
await sleep(poll_period) |
# I don't think there's a cleaner solution, sadly. |
happenings = [] |
async for happening in self.happenings( |
nations=nations, regions=regions, filters=filters): |
if happening.id <= last_id: |
break |
happenings.append(happening) |
with suppress(IndexError): |
last_id = happenings[0].id |
for happening in reversed(happenings): |
yield happening" |
4284,"def find_potential_match_regions(template, transformed_array, method='correlation', raw_tolerance=0.666): |
""""""To prevent prohibitively slow calculation of normalisation coefficient at each point in image |
find potential match points, and normalise these only these. |
This function uses the definitions of the matching functions to calculate the expected match value |
and finds positions in the transformed array matching these- normalisation will then eliminate false positives |
"""""" |
if method == 'correlation': |
match_value = np.sum(template**2) # this will be the value of the match in the |
elif method == 'squared difference': |
match_value = 0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.