fix: conform to python style guidelines
@@ -18,7 +18,7 @@ For API access:
Entry Point:
----------------
-analyzeGas()
+analyze_gas()
Returns:
----------------
@@ -42,10 +42,12 @@ AUTH = json.load(open(os.path.dirname(__file__) + "/../../credentials.json"))
def to_gwei(x: float) -> float:
return x / 10**9
+
# Initialize the ElasticSearch Client
def initialize_elastic(network: str) -> any:
return Elasticsearch(hosts=[network], http_auth=(AUTH['email'], AUTH['key']), timeout=180)
+
# fetch average hourly gas prices over the last specified days
def fetch_gas_hour(network: str, days=7) -> list[float]:
es = initialize_elastic(network)
@@ -82,6 +84,7 @@ def fetch_gas_hour(network: str, days=7) -> list[float]:
})
return [ x['avgGasHour']['value'] for x in data['aggregations']['hour_bucket']['buckets'] if x['avgGasHour']['value']]
+
# fetch average hourly gas prices over the last specified days
def fetch_gas_min(network: str, days=1) -> list[float]:
es = initialize_elastic(network)
@@ -117,6 +120,7 @@ def fetch_gas_min(network: str, days=1) -> list[float]:
})
return [ x['avgGasMin']['value'] for x in data['aggregations']['minute_bucket']['buckets'] if x['avgGasMin']['value']]
+
def is_outlier(points: list[float], thresh=3.5) -> list[bool]:
"""
Returns a boolean array with True if points are outliers and False
@@ -150,8 +154,9 @@ def is_outlier(points: list[float], thresh=3.5) -> list[bool]:
return modified_z_score > thresh
+
# main entry point
-def analyzeGas() -> tuple[float, float, float]:
+def analyze_gas() -> tuple[float, float, float]:
gas_data = []
# fetch data
@@ -184,9 +189,10 @@ def analyzeGas() -> tuple[float, float, float]:
return (midpoint, standard_dev, median)
-# run this to test analyzeGas and print values
+
+# run this to test analyze_gas and print values
def test() -> tuple[float, float, float]:
- results = analyzeGas()
+ results = analyze_gas()
print('timeframe:', HISTORICAL_TIMEFRAME)
print('approximate most common gas price:', to_gwei(results[0]))
print('standard deviation:', to_gwei(results[1]))
