Skip to content
This repository has been archived by the owner on Jun 5, 2023. It is now read-only.

Commit

Permalink
Revert online status back to db value (#423)
Browse files Browse the repository at this point in the history
  • Loading branch information
madninja authored May 11, 2022
1 parent b9e3f3a commit 9520321
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 26 deletions.
1 change: 1 addition & 0 deletions priv/hotspots.sql
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ select
g.reward_scale,
g.elevation,
g.gain,
s.online as online_status,
s.block as block_status,
s.peer_timestamp as status_timestamp,
s.listen_addrs as listen_addrs,
Expand Down
45 changes: 19 additions & 26 deletions src/bh_route_hotspots.erl
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@
-define(HOTSPOT_LIST_LIMIT, 1000).
-define(HOTSPOT_LIST_NAME_SEARCH_LIMIT, 100).
-define(HOTSPOT_LIST_LOCATION_SEARCH_LIMIT, 500).
% 36 hours of blocks considered for online status
-define(HOTSPOT_OFFLINE_BLOCKS, 2160).

-define(HOTSPOT_MODES, [
<<"full">>,
Expand Down Expand Up @@ -680,9 +678,9 @@ mk_cursor(Limit, CursorBase, Results) when is_list(Results) ->
case lists:last(Results) of
{Height, _LastChangeBlock, FirstBlock, _FirstTimestamp, _LastPocChallenge, Address,
_Mode, _Owner, _Payer, _Location, _LocationHex, _Nonce, _Name, _RewardScale,
_Elevation, _Gain, _BlockStatus, _StatusTimestamp, _ListenAddrs, _ShortStreet,
_LongStreet, _ShortCity, _LongCity, _ShortState, _LongState, _ShortCountry,
_LongCountry, _CityId} ->
_Elevation, _Gain, _OnlineStatus, _BlockStatus, _StatusTimestamp, _ListenAddrs,
_ShortStreet, _LongStreet, _ShortCity, _LongCity, _ShortState, _LongState,
_ShortCountry, _LongCountry, _CityId} ->
CursorBase#{
before_address => Address,
before_block => FirstBlock,
Expand All @@ -693,9 +691,9 @@ mk_cursor(Limit, CursorBase, Results) when is_list(Results) ->
};
{Height, _LastChangeBlock, _FirstBlock, _FirstTimestamp, _LastPocChallenge, Address,
_Mode, _Owner, _Payer, _Location, _LocationHex, _Nonce, _Name, _RewardScale,
_Elevation, _Gain, _BlockStatus, _StatusTimestamp, _ListenAddrs, _ShortStreet,
_LongStreet, _ShortCity, _LongCity, _ShortState, _LongState, _ShortCountry,
_LongCountry, _CityId, Distance} ->
_Elevation, _Gain, _OnlineStatus, _BlockStatus, _StatusTimestamp, _ListenAddrs,
_ShortStreet, _LongStreet, _ShortCity, _LongCity, _ShortState, _LongState,
_ShortCountry, _LongCountry, _CityId, Distance} ->
CursorBase#{
before_address => Address,
before_distance => Distance,
Expand Down Expand Up @@ -758,24 +756,24 @@ to_geo_json(

hotspot_to_json(
{Height, LastChangeBlock, FirstBlock, FirstTimestamp, LastPoCChallenge, Address, Mode, Owner,
Payer, Location, LocationHex, Nonce, Name, RewardScale, Elevation, Gain, BlockStatus,
StatusTimestamp, ListenAddrs, ShortStreet, LongStreet, ShortCity, LongCity, ShortState,
LongState, ShortCountry, LongCountry, CityId, SpecNonce}
Payer, Location, LocationHex, Nonce, Name, RewardScale, Elevation, Gain, OnlineStatus,
BlockStatus, StatusTimestamp, ListenAddrs, ShortStreet, LongStreet, ShortCity, LongCity,
ShortState, LongState, ShortCountry, LongCountry, CityId, SpecNonce}
) ->
Base = hotspot_to_json(
{Height, LastChangeBlock, FirstBlock, FirstTimestamp, LastPoCChallenge, Address, Mode,
Owner, Payer, Location, LocationHex, Nonce, Name, RewardScale, Elevation, Gain,
BlockStatus, StatusTimestamp, ListenAddrs, ShortStreet, LongStreet, ShortCity, LongCity,
ShortState, LongState, ShortCountry, LongCountry, CityId}
OnlineStatus, BlockStatus, StatusTimestamp, ListenAddrs, ShortStreet, LongStreet,
ShortCity, LongCity, ShortState, LongState, ShortCountry, LongCountry, CityId}
),
Base#{
<<"speculative_nonce">> => SpecNonce
};
hotspot_to_json(
{Height, LastChangeBlock, FirstBlock, FirstTimestamp, LastPoCChallenge, Address, Mode, Owner,
Payer, Location, LocationHex, Nonce, Name, RewardScale, Elevation, Gain, BlockStatus,
StatusTimestamp, ListenAddrs, ShortStreet, LongStreet, ShortCity, LongCity, ShortState,
LongState, ShortCountry, LongCountry, CityId}
Payer, Location, LocationHex, Nonce, Name, RewardScale, Elevation, Gain, OnlineStatus,
BlockStatus, StatusTimestamp, ListenAddrs, ShortStreet, LongStreet, ShortCity, LongCity,
ShortState, LongState, ShortCountry, LongCountry, CityId}
) ->
MaybeZero = fun
(null) -> 0;
Expand All @@ -785,11 +783,6 @@ hotspot_to_json(
(null) -> null;
(V) -> iso8601:format(V)
end,
OnlineStatus =
case (Height - MaybeZero(LastChangeBlock)) < ?HOTSPOT_OFFLINE_BLOCKS of
true -> <<"online">>;
_ -> <<"offline">>
end,
?INSERT_LAT_LON(
Location,
#{
Expand Down Expand Up @@ -824,15 +817,15 @@ hotspot_to_json(

hotspot_distance_to_json(
{Height, LastChangeBlock, FirstBlock, FirstTimestamp, LastPoCChallenge, Address, Mode, Owner,
Payer, Location, LocationHex, Nonce, Name, RewardScale, Elevation, Gain, BlockStatus,
StatusTimestamp, ListenAddrs, ShortStreet, LongStreet, ShortCity, LongCity, ShortState,
LongState, ShortCountry, LongCountry, CityId, Distance}
Payer, Location, LocationHex, Nonce, Name, RewardScale, Elevation, Gain, OnlineStatus,
BlockStatus, StatusTimestamp, ListenAddrs, ShortStreet, LongStreet, ShortCity, LongCity,
ShortState, LongState, ShortCountry, LongCountry, CityId, Distance}
) ->
Base = hotspot_to_json(
{Height, LastChangeBlock, FirstBlock, FirstTimestamp, LastPoCChallenge, Address, Mode,
Owner, Payer, Location, LocationHex, Nonce, Name, RewardScale, Elevation, Gain,
BlockStatus, StatusTimestamp, ListenAddrs, ShortStreet, LongStreet, ShortCity, LongCity,
ShortState, LongState, ShortCountry, LongCountry, CityId}
OnlineStatus, BlockStatus, StatusTimestamp, ListenAddrs, ShortStreet, LongStreet,
ShortCity, LongCity, ShortState, LongState, ShortCountry, LongCountry, CityId}
),
Base#{
<<"distance">> => Distance
Expand Down

0 comments on commit 9520321

Please sign in to comment.