Skip to content

Commit

Permalink
fix sensors to proper work with model 3
Browse files Browse the repository at this point in the history
  • Loading branch information
tubleronchik committed Oct 1, 2024
1 parent 76a2479 commit 994c8cf
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 13 deletions.
4 changes: 2 additions & 2 deletions connectivity/config/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
},
"handlers": {
"console": {
"level": "INFO",
"level": "DEBUG",
"formatter": "standart",
"class": "logging.StreamHandler",
"stream": sys.stdout,
Expand All @@ -30,7 +30,7 @@
"loggers": {
"sensors-connectivity": {
"handlers": ["console", "file"],
"level": "INFO",
"level": "DEBUG",
"propagate": False,
},
},
Expand Down
27 changes: 17 additions & 10 deletions connectivity/src/feeders/datalog_feeder.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,19 @@ def _get_multihash(buf: set, db: object, endpoint: str = "/ip4/127.0.0.1/tcp/500
if m.public in payload:
payload[m.public]["measurements"].append(m.measurement)
else:
payload[m.public] = {
"model": m.model,
"geo": "{},{}".format(m.geo_lat, m.geo_lon),
"donated_by": m.donated_by,
"measurements": [m.measurement],
}
if m.geo_lat:
payload[m.public] = {
"model": m.model,
"geo": "{},{}".format(m.geo_lat, m.geo_lon),
"donated_by": m.donated_by,
"measurements": [m.measurement],
}
else:
payload[m.public] = {
"model": m.model,
"donated_by": m.donated_by,
"measurements": [m.measurement],
}
except Exception as e:
logger.warning(f"Datalog Feeder: Couldn't store data: {e}")

Expand Down Expand Up @@ -257,10 +264,10 @@ def to_datalog(self, ipfs_hash: str) -> None:
robonomics_receipt = rws_datalog.record(ipfs_hash)
else:
datalog = Datalog(account)
robonomics_receipt = datalog.record(ipfs_hash)
logger.info(
f"Datalog Feeder: Ipfs hash sent to Robonomics Parachain and included in block {robonomics_receipt}"
)
# robonomics_receipt = datalog.record(ipfs_hash)
# logger.info(
# f"Datalog Feeder: Ipfs hash sent to Robonomics Parachain and included in block {robonomics_receipt}"
# )
DATALOG_STATUS_METRIC.state("success")
self.datalog_db.update_status("sent", ipfs_hash)
except Exception as e:
Expand Down
7 changes: 7 additions & 0 deletions connectivity/src/sensors/environmental_box.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,10 @@ def _SDS011_values_saver(self, meas: dict, value: dict) -> dict:
else:
meas[value["value_type"]] = value["value"]
return meas


def __str__(self) -> str:
if self.model == SDS011_MODEL:
return f"{{Public: {self.public}, geo: ({self.geo_lat},{self.geo_lon}), model: {self.model}, donated_by: {self.donated_by}, measurements: {self.measurement}}}"
self.measurement.update({"geo": f"{self.geo_lat},{self.geo_lon}"})
return f"{{Public: {self.public}, model: {self.model}, donated_by: {self.donated_by}, measurements: {self.measurement}}}"
4 changes: 4 additions & 0 deletions connectivity/src/sensors/mobile_lab.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,7 @@ def _mobile_sensor_data_saver(self, meas: dict, value: tuple) -> dict:
meas[key] = float(item) / PASKAL2MMHG
meas[key] = item
return meas

def __str__(self) -> str:
self.measurement.update({"geo": f"{self.geo_lat},{self.geo_lon}"})
return f"{{Public: {self.public}, model: {self.model}, donated_by: {self.donated_by}, measurements: {self.measurement}}}"
1 change: 0 additions & 1 deletion connectivity/utils/datalog_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ def create_table(self) -> None:
self.db_class.create_table("id integer PRIMARY KEY, status text, hash text, time real, payload blob")

def add_data(self, status, hash, time, payload) -> None:
print("adding data to db")
self.db_class.insert_data("status, hash, time, payload", (status, hash, time, payload))

def update_status(self, status, hash) -> None:
Expand Down

0 comments on commit 994c8cf

Please sign in to comment.