From 76f64787dc3027d41e29745f0730e76789c5dde8 Mon Sep 17 00:00:00 2001 From: freqnik Date: Wed, 20 Dec 2023 02:43:53 -0500 Subject: [PATCH] Update AWOC. Add Sentinel Health Check, MD icons - issue #69 --- src/awoc/datum/world.json | 2 +- src/cli/sentinel.py | 27 +++++++++++++++++++++++++++ src/geography/continents.py | 1 + src/kv/meile.kv | 19 ++++++++++++++----- src/typedef/konstants.py | 3 +++ src/ui/screens.py | 14 ++++++++++++++ 6 files changed, 60 insertions(+), 6 deletions(-) diff --git a/src/awoc/datum/world.json b/src/awoc/datum/world.json index b2fdd530..0f58dfd6 100755 --- a/src/awoc/datum/world.json +++ b/src/awoc/datum/world.json @@ -3960,7 +3960,7 @@ "Area KM2": "780580" }, { - "Country Name": "Türkiye", + "Country Name": "T\u00FCrkiye", "ISO2": "TR", "ISO3": "TUR", "TLD": "tr", diff --git a/src/cli/sentinel.py b/src/cli/sentinel.py index 9d286c1f..874e89d1 100755 --- a/src/cli/sentinel.py +++ b/src/cli/sentinel.py @@ -26,6 +26,7 @@ class NodeTreeData(): NodeScores = {} NodeLocations = {} NodeTypes = {} + NodeHealth = {} def __init__(self, node_tree): if not node_tree: @@ -117,6 +118,32 @@ def get_nodes(self, latency, *kwargs): self.GetNodeScores() self.GetNodeLocations() self.GetNodeTypes() + self.GetHealthCheckData() + + + def GetHealthCheckData(self): + Request = HTTPRequests.MakeRequest(TIMEOUT=2) + http = Request.hadapter() + try: + r = http.get(HTTParams.HEALTH_CHECK) #specify a constant in konstants.py + data = r.json() + + for nodehealthdata in data['result']: + # integrity check + if nodehealthdata['status'] != 1: + self.NodeHealth[nodehealthdata['addr']] = False + elif "info_fetch_error " in nodehealthdata: + self.NodeHealth[nodehealthdata['addr']] = False + elif "config_exchange_error" in nodehealthdata: + self.NodeHealth[nodehealthdata['addr']] = False + elif "location_fetch_error" in nodehealthdata: + self.NodeHealth[nodehealthdata['addr']] = False + else: + self.NodeHealth[nodehealthdata['addr']] = True + + + except Exception as e: + print(str(e)) def GetNodeScores(self): Request = HTTPRequests.MakeRequest(TIMEOUT=3) diff --git a/src/geography/continents.py b/src/geography/continents.py index ac850354..559faa37 100755 --- a/src/geography/continents.py +++ b/src/geography/continents.py @@ -132,6 +132,7 @@ class OurWorld(): 'Tajikistan': [38.6281733, 70.8156541], 'Thailand': [14.8971921, 100.83273], 'Turkey': [38.9597594, 34.9249653], + 'Türkiye': [38.9597594, 34.9249653], 'United Arab Emirates': [24.0002488, 53.9994829], 'Uzbekistan': [41.32373, 63.9528098], 'Vietnam': [15.9266657, 107.9650855], diff --git a/src/kv/meile.kv b/src/kv/meile.kv index 7eed9bc5..7eb7a225 100755 --- a/src/kv/meile.kv +++ b/src/kv/meile.kv @@ -581,7 +581,7 @@ WindowManager: size: "180dp", "180dp" pos_hint: {"center_x": .5, "center_y": .5} orientation: "vertical" - padding: 10,10 + #padding: 10,10 border_radius: 20 radius: [10] md_bg_color: get_color_from_hex("#121212") @@ -600,6 +600,8 @@ WindowManager: city: " " icon: "" tooltip: "" + healthcheck: "" + healthchecktooltip: "" ripple_behavior: True on_press: root.subscribe_to_node(root.price_text, root.hourly_price_text, root.address_text, root.moniker_text) MDGridLayout: @@ -624,10 +626,7 @@ WindowManager: font_size: "10sp" text_color: (0/255.0,141/255.0,155/255.0,255/255.0) pos_hint: {"x" : 0, "top" : 1.125} - TooltipMDIconButton: - icon: root.icon - tooltip_text: root.tooltip - pos_hint: {"x" : .265, "top" : .80} + MDLabel: text: root.type_text theme_text_color: "Custom" @@ -710,6 +709,16 @@ WindowManager: pos_hint: {"x" : .44 , "top": .95 } size_hint: None, .525 + TooltipMDIconButton: + icon: root.icon + tooltip_text: root.tooltip + pos_hint: {"x" : .445, "top" : .40} + TooltipMDIconButton: + icon: root.healthcheck + tooltip_text: root.healthchecktooltip + pos_hint: {"x" : .475, "top" : .40 } + size_hint: None, None + MDLabel: text: root.country_text theme_text_color: "Custom" diff --git a/src/typedef/konstants.py b/src/typedef/konstants.py index 01752371..66b21b82 100755 --- a/src/typedef/konstants.py +++ b/src/typedef/konstants.py @@ -38,6 +38,7 @@ class HTTParams(): 'https://rpc-sentinel-ia.cosmosia.notional.ventures:443'] GRPC = "grpc+http://aimokoivunen.mathnodes.com:9090/" #GRPC = "grpc+http://128.199.90.172:9090/" + HEALTH_CHECK = "https://api.health.sentinel.co/v1/records" NODE_SCORE_ENDPOINT = "/api/nodescores" NODE_LOCATION_ENDPOINT = "/api/nodelocations" NODE_TYPE_ENDPOINT = "/api/nodetypes" @@ -74,6 +75,8 @@ class MeileColors(): INACTIVE_DIALOG_BG_COLOR = "#50507c" FONT_FACE = "fonts/mplus-2c-bold.ttf" MAP_MARKER = "imgs/location_pin.png" + HEALTH_ICON = "shield-plus" + SICK_ICON = "emoticon-sick" class NodeKeys(): diff --git a/src/ui/screens.py b/src/ui/screens.py index bc1b664f..2e007a93 100755 --- a/src/ui/screens.py +++ b/src/ui/screens.py @@ -1436,6 +1436,18 @@ def add_rv_data(self, node, flagloc): IconButton = "alpha-r-circle" ToolTipText = "Residential" + if node[NodeKeys.NodesInfoKeys[1]].lstrip().rstrip() in self.NodeTree.NodeHealth: + if self.NodeTree.NodeHealth[node[NodeKeys.NodesInfoKeys[1]].lstrip().rstrip()]: + HealthButton = MeileColors.HEALTH_ICON + HealthToolTip = "Passed Sentinel Health Check" + else: + HealthButton = MeileColors.SICK_ICON + HealthToolTip = "Failed Sentinel Health Check" + + else: + HealthButton = MeileColors.SICK_ICON + HealthToolTip = "Failed Sentinel Health Check" + self.ids.rv.data.append( { "viewclass" : "RecycleViewRow", @@ -1451,6 +1463,8 @@ def add_rv_data(self, node, flagloc): "city" : city, "icon" : IconButton, "tooltip" : ToolTipText, + "healthcheck" : HealthButton, + "healthchecktooltip" : HealthToolTip, "speed_image" : self.MeileConfig.resource_path(speedimage), "source_image" : self.MeileConfig.resource_path(flagloc)