File risk_service.py
has 497 lines of code (exceeds 250 allowed). Consider refactoring. Open
import logging
import os
import numpy as np
import pandas as pd
RiskService
has 24 functions (exceeds 20 allowed). Consider refactoring. Open
class RiskService(object):
def __init__(self, user_selections):
# DB Connection
self.engine = sqlalchemy.create_engine(os.getenv('POSTGRES_URL'))
self.metadata = sqlalchemy.MetaData(bind=self.engine)
Function calc_risk
has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring. Open
def calc_risk(self):
"""
Purpose: Runs analysis on the fly instead of using precalcuted results
(For when users define current protection level, find annual impact themselves)
Output:
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function run_stats
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
def run_stats(self, dataframe):
"""
Purpose: Finds the average, min, and max impact for all impact types
Input:
dataframe: Data associated with flood, geography, exposure type for all climate models
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function find_impact
has 6 arguments (exceeds 4 allowed). Consider refactoring. Open
def find_impact(self, impact_cc, impact_soc, impact_sub, impact_cc_soc, impact_urb, model):
Function select_projection_data
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
def select_projection_data(self, dataframe, climate, model, socioecon, year):
Function compute_rp_change
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
def compute_rp_change(self, ref_impact, target_impact, rp, min_rp=2, max_rp=1000):
Function user_selections
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def user_selections(self):
"""
Purpose: Gather all necessary inputs to run any analysis
Input:
flood: Riverine of Coastal (User must select)
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function bench
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def bench(self):
defaultfn = "precalc_agg_{0}_{1}_{2}".format(self.flood, self.geogunit_type, self.sub_abb)
print(defaultfn)
# cols = ['{0} as {1}'.format(col, col.replace(self.exposure, 'bench').replace('urban_damage_v2', 'bench').replace("_"+ self.scen_abb, '')) for col in sqlalchemy.Table(defaultfn, self.metadata).columns.keys() if ((self.exposure in col) or ('urban_damage_v2' in col)) and (self.scen_abb in col) and ("cc" not in col) and ("soc" not in col) and ("sub" not in col) and ("avg" in col)]
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"