Skip to content

Commit

Permalink
Merge pull request #403 from fetchai/fix/carpark_skills
Browse files Browse the repository at this point in the history
Add fix for carpark skills
  • Loading branch information
DavidMinarsch authored Nov 8, 2019
2 parents 7820172 + d6d27e7 commit f1f73df
Show file tree
Hide file tree
Showing 9 changed files with 72 additions and 17 deletions.
6 changes: 4 additions & 2 deletions aea/context/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
from aea.connections.base import ConnectionStatus
from aea.decision_maker.base import OwnershipState, Preferences
from aea.mail.base import OutBox
from aea.crypto.default import DEFAULT
from aea.crypto.fetchai import FETCHAI
from aea.crypto.ledger_apis import LedgerApis


Expand Down Expand Up @@ -83,12 +85,12 @@ def addresses(self) -> Dict[str, str]:
@property
def address(self) -> str:
"""Get the defualt address."""
return self._addresses['default']
return self._addresses[FETCHAI] if FETCHAI in self._addresses.keys() else self._addresses[DEFAULT]

@property
def public_key(self) -> str:
"""Get the default public key."""
return self._public_keys['default']
return self._public_keys[FETCHAI] if FETCHAI in self._public_keys.keys() else self._public_keys[DEFAULT]

@property
def connection_status(self) -> ConnectionStatus:
Expand Down
53 changes: 53 additions & 0 deletions docs/car-park.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,57 @@

The Fetch.ai car park agent demo is documented in its own repo [here](https://github.com/fetchai/carpark_agent).


## To test the AEA functionality (without the detection)

First, create the carpark detection agent:
```
aea create car_detector
cd car_detector
aea add skill carpark_detection
aea install
```

Then, create the carpark client agent:
```
aea create car_data_buyer
cd car_data_buyer
aea add skill carpark_client
aea install
aea generate-key fetchai
```

Add the ledger info to both aea configs:
```
ledger_apis:
- ledger_api:
ledger: fetchai
addr: alpha.fetch-ai.com
port: 80
```

Fund the carpark client agent:
```
cd ..
python scripts/fetchai_wealth_generation.py --private-key car_data_buyer/fet_private_key.txt --amount 10000000000 --addr alpha.fetch-ai.com --port 80
```

Then, in the carpark detection agent comment out database related settings:
```
# db_is_rel_to_cwd: true
# db_rel_dir: ../temp_files
```

Then, in the client agent do:
```
max_detection_age: 36000000
```

Then, launch an OEF node instance:
```
python scripts/oef/launch.py -c ./scripts/oef/launch_config.json
```

Finally, run both agents with `aea run`.

<br />
5 changes: 1 addition & 4 deletions packages/skills/carpark_client/dialogues.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,6 @@ def __init__(self, **kwargs) -> None:
"""
SharedClass.__init__(self, **kwargs)
self._dialogues = {} # type: Dict[DialogueLabel, Dialogue]
self._dialogue_id = 0
self._dialogue_stats = DialogueStats()

@property
Expand All @@ -179,9 +178,7 @@ def _next_dialogue_id(self) -> int:
:return: the next id
"""
self._dialogue_id = random.randint(1, 10000000)
print("_next_dialogue_id: _dialogue_id = {}".format(self._dialogue_id))
return self._dialogue_id
return random.randint(1, 10000000)

def is_belonging_to_registered_dialogue(self, fipa_msg: Message, sender: Address, agent_pbk: Address) -> bool:
"""
Expand Down
17 changes: 9 additions & 8 deletions packages/skills/carpark_detection/detection_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,15 @@
# ------------------------------------------------------------------------------
"""Communicate between the database and the python objects."""

import sqlite3
import logging
import os
import shutil
import sqlite3
import skimage # type: ignore
import time

logger = logging.getLogger("aea.carpark_detection_skill")


class DetectionDatabase:
"""Communicate between the database and the python objects."""
Expand Down Expand Up @@ -57,7 +60,7 @@ def is_db_exits(self):
def reset_database(self):
"""Reset the database and remove all data."""
# If we need to reset the database, then remove the table and any stored images
print("Database being reset")
logger.info("Database being reset.")

# Remove the actual database file
if os.path.isfile(self.database_path):
Expand All @@ -68,14 +71,14 @@ def reset_database(self):
shutil.rmtree(self.processed_image_dir)

# Recreate them
print("initialise_backend")
logger.info("Initialising backend ...")
self.initialise_backend()
print("FINISH initialise_backend")
logger.info("Finished initialising backend!")

def reset_mask(self):
"""Just reset the detection mask."""
# If we need to reset the database, then remove the table and any stored images
print("Database being reset")
logger.info("Mask being reset.")

# Remove the actual database file
if os.path.isfile(self.mask_image_path):
Expand Down Expand Up @@ -115,8 +118,6 @@ def initialise_backend(self):
self.set_system_status("lon", "UNKNOWN")
self.set_system_status("db", "Exists")

print("**** backend initialised")

def set_fet(self, amount, t):
"""Record how much FET we have and when we last read it from the ledger."""
self.execute_single_sql(
Expand Down Expand Up @@ -317,7 +318,7 @@ def execute_single_sql(self, command, print_exceptions=True):
conn.commit()
except Exception as e:
if print_exceptions:
print("Exception in database: {}".format(e))
logger.warning("Exception in database: {}".format(e))
finally:
if conn is not None:
conn.close()
Expand Down
2 changes: 0 additions & 2 deletions packages/skills/carpark_detection/dialogues.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,6 @@ def __init__(self) -> None:
self._other_initiated = {Dialogue.EndState.SUCCESSFUL: 0,
Dialogue.EndState.DECLINED_PROPOSE: 0} # type: Dict[Dialogue.EndState, int]

print("__init__: self._other_initiated = {}".format(self._other_initiated))

@property
def other_initiated(self) -> Dict[Dialogue.EndState, int]:
"""Get the stats dictionary on other initiated dialogues."""
Expand Down
6 changes: 5 additions & 1 deletion packages/skills/carpark_detection/strategy.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
# ------------------------------------------------------------------------------

"""This module contains the strategy class."""

import logging
import os
from typing import Any, Dict, List, Tuple, TYPE_CHECKING, cast
import time
Expand All @@ -37,6 +39,8 @@
DEFAULT_DB_IS_REL_TO_CWD = False
DEFAULT_DB_REL_DIR = "temp_files_placeholder"

logger = logging.getLogger("aea.carpark_detection_skill")


class Strategy(SharedClass):
"""This class defines a strategy for the agent."""
Expand Down Expand Up @@ -67,7 +71,7 @@ def __init__(self, **kwargs) -> None:
self.db.set_system_status("ledger-status", self.context.ledger_apis.last_tx_statuses['fetchai'])

if not os.path.isdir(db_dir):
print("WARNING - DATABASE dir does not exist")
logger.warning("Database directory does not exist!")

self.record_balance(balance)
self.other_carpark_processes_running = False
Expand Down
Binary file modified packages/skills/carpark_detection/temp_files_placeholder/detection_results.db
100644 → 100755
Binary file not shown.
Binary file modified packages/skills/carpark_detection/temp_files_placeholder/mask.tiff
100644 → 100755
Binary file not shown.
Binary file modified packages/skills/carpark_detection/temp_files_placeholder/mask_ref.tiff
100644 → 100755
Binary file not shown.

0 comments on commit f1f73df

Please sign in to comment.