Skip to content

Commit

Permalink
Adjusted files for PEP-8 compliance
Browse files Browse the repository at this point in the history
  • Loading branch information
c0c0n3 authored and actions-user committed Mar 9, 2021
1 parent 34db97d commit 35d83b2
Show file tree
Hide file tree
Showing 56 changed files with 343 additions and 286 deletions.
16 changes: 8 additions & 8 deletions experiments/dataModels/subscribe_ql.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,19 @@ def create_subscription(entity_type, notify_url):
"description": "Subscription for {}".format(entity_type),
"subject": {
"entities": [
{
"idPattern": ".*",
"type": entity_type
}
{
"idPattern": ".*",
"type": entity_type
}
],
"condition": {
"attrs": [
]
"attrs": [
]
}
},
},
"notification": {
"http": {
"url": notify_url
"url": notify_url
},
"attrs": [
],
Expand Down
22 changes: 11 additions & 11 deletions experiments/dataModels/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@
HEADERS_PUT['Content-Type'] = 'application/json'

COORDS = [
[51.235170, 4.421283],
[51.233103, 4.423617],
[51.257595, 4.432838],
[51.260580, 4.426038],
[51.208525, 4.437985],
[51.210266, 4.425305],
[51.204714, 4.416675],
[51.208948, 4.418556],
[51.217179, 4.341202],
[51.218305, 4.336690],
]
[51.235170, 4.421283],
[51.233103, 4.423617],
[51.257595, 4.432838],
[51.260580, 4.426038],
[51.208525, 4.437985],
[51.210266, 4.425305],
[51.204714, 4.416675],
[51.208948, 4.418556],
[51.217179, 4.341202],
[51.218305, 4.336690],
]


def insert_entities(entities, sleep, orion_url):
Expand Down
22 changes: 11 additions & 11 deletions experiments/iotagent/subscribe_ql.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,22 @@ def subscribe(entity_type):
"description": "Test subscription",
"subject": {
"entities": [
{
"idPattern": ".*",
"type": entity_type
}
{
"idPattern": ".*",
"type": entity_type
}
],
"condition": {
"attrs": [
"temperature",
"pressure",
"humidity",
]
"attrs": [
"temperature",
"pressure",
"humidity",
]
}
},
},
"notification": {
"http": {
"url": NOTIFY_URL
"url": NOTIFY_URL
},
"attrs": [
"temperature",
Expand Down
49 changes: 26 additions & 23 deletions experiments/iotagent/temperature_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,46 +41,49 @@
def register():
# Register Service
data = {
"services": [
"services": [
{
"apikey": API_KEY,
"cbroker": ORION_URL,
"entity_type": "thing",
"resource": "/iot/d"
"apikey": API_KEY,
"cbroker": ORION_URL,
"entity_type": "thing",
"resource": "/iot/d"
}
]
]
}
r = requests.post('{}/iot/services'.format(AGENT_CONFIG_URL, API_KEY, DEVICE_ID), data=json.dumps(data), headers=CONFIG_HEADERS)
r = requests.post('{}/iot/services'.format(AGENT_CONFIG_URL, API_KEY,
DEVICE_ID), data=json.dumps(data), headers=CONFIG_HEADERS)
assert r.ok, r.text

# Register Sensor
data = {
"devices": [
"devices": [
{
"device_id": DEVICE_ID,
"x": "my_entity_01",
"entity_type": "thing",
"protocol": "PDI-IoTA-UltraLight",
"timezone": "Europe/Madrid",
"attributes": [
{
"object_id": "t",
"name": "temperature",
"type": "float"
}
]
"device_id": DEVICE_ID,
"x": "my_entity_01",
"entity_type": "thing",
"protocol": "PDI-IoTA-UltraLight",
"timezone": "Europe/Madrid",
"attributes": [
{
"object_id": "t",
"name": "temperature",
"type": "float"
}
]
}
]
]
}
r = requests.post('{}/iot/devices'.format(AGENT_CONFIG_URL, API_KEY, DEVICE_ID), data=json.dumps(data), headers=CONFIG_HEADERS)
r = requests.post('{}/iot/devices'.format(AGENT_CONFIG_URL, API_KEY,
DEVICE_ID), data=json.dumps(data), headers=CONFIG_HEADERS)
assert r.ok, r.text


def send():
temperature = random.random() * 40
data = 't|{}'.format(temperature)
print("sending {}".format(data))
r = requests.post('{}/iot/d?k={}&i={}'.format(AGENT_NOTIFY_URL, API_KEY, DEVICE_ID), data=data, headers=NOTIFY_HEADERS)
r = requests.post('{}/iot/d?k={}&i={}'.format(AGENT_NOTIFY_URL,
API_KEY, DEVICE_ID), data=data, headers=NOTIFY_HEADERS)
return r


Expand Down
6 changes: 4 additions & 2 deletions experiments/iotagent/weather_station.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ def get_attrs_to_update():
entity_id = entity['id']

# Insert
r = requests.post('{}/v2/entities?options=keyValues'.format(ORION_URL), data=json.dumps(entity), headers=HEADERS_PUT)
r = requests.post('{}/v2/entities?options=keyValues'.format(ORION_URL),
data=json.dumps(entity), headers=HEADERS_PUT)
if not r.ok:
raise RuntimeError(r.text)
print("Inserted: {}".format(entity))
Expand All @@ -77,4 +78,5 @@ def get_attrs_to_update():

finally:
# Delete
r = requests.delete('{}/v2/entities/{}'.format(ORION_URL, entity_id), headers=HEADERS)
r = requests.delete(
'{}/v2/entities/{}'.format(ORION_URL, entity_id), headers=HEADERS)
29 changes: 17 additions & 12 deletions experiments/partitioning/test_partitioning.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,19 +79,21 @@ def random_entries(batch):

def create_table(cursor, table_name, clustered_by, partitioned_by):
stmt = "create table {} (" \
" entity_type string, " \
" entity_id string, " \
" temperature double, " \
" pressure double, " \
" time_index timestamp, " \
" month timestamp GENERATED ALWAYS AS date_trunc('month', time_index)) " \
"clustered by ({})" \
"partitioned by ({})".format(table_name, clustered_by, partitioned_by)
" entity_type string, " \
" entity_id string, " \
" temperature double, " \
" pressure double, " \
" time_index timestamp, " \
" month timestamp GENERATED ALWAYS AS date_trunc('month', time_index)) " \
"clustered by ({})" \
"partitioned by ({})".format(
table_name, clustered_by, partitioned_by)
cursor.execute(stmt)


def insert_records(cursor, table_name):
col_names = ['entity_type', 'entity_id', 'temperature', 'pressure', 'time_index']
col_names = ['entity_type', 'entity_id',
'temperature', 'pressure', 'time_index']
stmt = "insert into {} ({}) values ({})".format(
table_name,
', '.join(col_names),
Expand Down Expand Up @@ -147,7 +149,8 @@ def check_scenario(create_table):
res[VC] = query(cursor, table_name)

# Common
res[C] = query(cursor, table_name, extra_clause="AND entity_id = 'room 0'")
res[C] = query(cursor, table_name,
extra_clause="AND entity_id = 'room 0'")

finally:
cleanup(cursor, table_name)
Expand All @@ -165,9 +168,11 @@ def dump_test_results(f=sys.stdout):
print("*" * 50, file=f)

# Gather data
res_sc1 = check_scenario(functools.partial(create_table, clustered_by='entity_id', partitioned_by='month'))
res_sc1 = check_scenario(functools.partial(
create_table, clustered_by='entity_id', partitioned_by='month'))
time.sleep(SLEEP)
res_sc2 = check_scenario(functools.partial(create_table, clustered_by='month', partitioned_by='entity_id'))
res_sc2 = check_scenario(functools.partial(
create_table, clustered_by='month', partitioned_by='entity_id'))

# Print Results
def print_results(T):
Expand Down
3 changes: 2 additions & 1 deletion src/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ def format(self, record):
record.remote_addr = request.remote_addr
record.srv = request.headers.get('fiware-service', None)
if record.srv:
record.subserv = request.headers.get('fiware-servicepath', None)
record.subserv = request.headers.get(
'fiware-servicepath', None)
else:
record.subserv = None
if len(request.data) > 0 and request.json and request.json['data']:
Expand Down
4 changes: 4 additions & 0 deletions src/exceptions/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ class QLError(Exception):
"""
Error raised in QuantumLeap usage.
"""

def __init__(self, message="Quantum Leap Error"):
self.message = message
super().__init__(self.message)
Expand All @@ -26,6 +27,7 @@ class AmbiguousNGSIIdError(NGSIUsageError):
Examples include querying for an entity_id without specifying entity_type
being entity_id not unique across entity_types.
"""

def __init__(self, entity_id=''):
msg = "There are multiple entities with the given entity_id {}. " \
"Please specify entity_type."
Expand All @@ -36,6 +38,7 @@ class InvalidParameterValue(QLError):
"""
Passed parameter value is not valid.
"""

def __init__(self, par_value='', par_name=''):
msg = "The parameter value '{}' for parameter {} is not valid."
QLError.__init__(self, msg.format(par_value, par_name))
Expand All @@ -45,6 +48,7 @@ class InvalidHeaderValue(QLError):
"""
Passed parameter value is not valid.
"""

def __init__(self, header_value='', header_name='', message=''):
msg = "The header value '{}' for header {} is not valid. {}"
QLError.__init__(self, msg.format(header_value, header_name, message))
8 changes: 4 additions & 4 deletions src/geocoding/centroid.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ def centroid2d(points):

def is_point(coords_list):
return coords_list and \
isinstance(coords_list, Sequence) and \
len(coords_list) > 1 and \
isinstance(coords_list[0], Real) and \
isinstance(coords_list[1], Real)
isinstance(coords_list, Sequence) and \
len(coords_list) > 1 and \
isinstance(coords_list[0], Real) and \
isinstance(coords_list[1], Real)


def best_effort_centroid2d(points):
Expand Down
1 change: 0 additions & 1 deletion src/geocoding/geocache.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,3 @@ def temp_geo_cache(host, port):
yield gc
finally:
gc.redis.flushall()

2 changes: 1 addition & 1 deletion src/geocoding/location.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def geometry_value(self) -> Optional[str]:

def is_geojson(self):
return self.geometry_type() == _GEOJSON_TYPE or \
self.geometry_type() == _GEOJSON_LD_TYPE
self.geometry_type() == _GEOJSON_LD_TYPE

def _compute_geojson_centroid(self):
lon_lat = geojson_centroid(self.geometry_value())
Expand Down
2 changes: 2 additions & 0 deletions src/geocoding/slf/querytypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class NearQuery(SlfQuery):
"""
Represents the near query, i.e. a query having ``georel=near``.
"""

def __init__(self,
geometry: SlfGeometry,
min_distance: Optional[float],
Expand Down Expand Up @@ -54,6 +55,7 @@ class ShapeQuery(SlfQuery):
Factors out functionality shared by all queries that involve determining
in which relationship two shapes stand.
"""

def __init__(self, geometry: SlfGeometry):
self._reference_shape = geometry

Expand Down
4 changes: 2 additions & 2 deletions src/geocoding/slf/tests/test_locparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,8 @@ def test_parse_geojson_location():
actual = from_location_attribute(
'geo:json',
{
'type': 'Point',
'coordinates': [2.186447514, 41.3763726]
'type': 'Point',
'coordinates': [2.186447514, 41.3763726]
})

assert actual is None
Expand Down
2 changes: 2 additions & 0 deletions src/geocoding/tests/test_geocoding.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ def test_entity_add_point(air_quality_observed):
assert_lon_lat(r, expected_lon=51.23, expected_lat=4.42)

# TODO Inspect why this test fails


@pytest.mark.skip(reason="no way of currently testing this")
def test_entity_add_point_negative_coord(air_quality_observed):
air_quality_observed.pop('location')
Expand Down
10 changes: 5 additions & 5 deletions src/reporter/api.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@

def list_of_api():
return {
'notify_url': '/v2/notify',
'subscriptions_url': '/v2/subscriptions',
'entities_url': '/v2/entities',
'types_url': '/v2/types',
'attributes_url': '/v2/attrs'
'notify_url': '/v2/notify',
'subscriptions_url': '/v2/subscriptions',
'entities_url': '/v2/entities',
'types_url': '/v2/types',
'attributes_url': '/v2/attrs'
}
2 changes: 1 addition & 1 deletion src/reporter/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ def notification():
@pytest.fixture()
def clean():
yield
do_clean_crate()
do_clean_crate()
6 changes: 4 additions & 2 deletions src/reporter/delete.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ def delete_entities(entity_type, from_date=None, to_date=None,
with translator_for(fiware_s()) as trans:
if drop_table:
trans.drop_table(etype=entity_type, fiware_service=fiware_s())
logging.getLogger(__name__).info("dropped entity_type {}".format(entity_type))
logging.getLogger(__name__).info(
"dropped entity_type {}".format(entity_type))
return 'entity table dropped', 204

deleted = trans.delete_entities(etype=entity_type,
Expand All @@ -45,7 +46,8 @@ def delete_entities(entity_type, from_date=None, to_date=None,
fiware_service=fiware_s(),
fiware_servicepath=fiware_sp(),)

logging.getLogger(__name__).info("deleted {} entities of type {}".format(deleted, entity_type))
logging.getLogger(__name__).info(
"deleted {} entities of type {}".format(deleted, entity_type))
if deleted == 0:
r = {
"error": "Not Found",
Expand Down
Loading

0 comments on commit 35d83b2

Please sign in to comment.