# Path: lib/channelunits.py
# def getCleanTierName(sTierName):
#     try:
#         return sTierName.replace(' ', '').replace('/', '').replace('-', '')
#     except Exception, e:
#         raise DataException("Invalid or null tiername passed to 'getCleanTierName()'")


import json
from metricUtil import populateDefaultColumns
from reachMetrics import visitReachMetrics
from pebbleMetrics import visitPebbleMetrics
from coverMetrics import visitCoverMetrics
from fishMetrics import *
from woodMetrics import *
from lib.channelunits import getCleanTierName




def calculateMetricsForVisit(visitobj):
    visitMetrics = dict()
    visitid = visitobj["visit_id"]
    populateDefaultColumns(visitMetrics, visitid)

    visitFishCountMetrics(visitMetrics, visitobj)
    visitLWDMetrics(visitMetrics, visitobj)
    visitCoverMetrics(visitMetrics, visitobj)
    visitPebbleMetrics(visitMetrics, visitobj)
    visitReachMetrics(visitMetrics, visitobj)

    return visitMetrics


def calculateMetricsForChannelUnitSummary(visitobj):
    channelUnitMetrics = []
    visitid = visitobj["visit_id"]
    channelUnits = visitobj['channelUnits']
    # create the channel unit summary metric rows with the channel unit id

    if channelUnits is not None:
        for c in channelUnits["values"]:
            cu = dict()
            cu["ChannelUnitID"] = c["value"]["ChannelUnitID"]
            cu["ChannelUnitNumber"] = c["value"]["ChannelUnitNumber"]

# Path: lib/channelunits.py
# def getCleanTierName(sTierName):
#     try:
#         return sTierName.replace(' ', '').replace('/', '').replace('-', '')
#     except Exception, e:
#         raise DataException("Invalid or null tiername passed to 'getCleanTierName()'")


# Path: tools/auxmetrics/metriclib/auxMetrics.py
import json
from metricUtil import populateDefaultColumns
from reachMetrics import visitReachMetrics
from pebbleMetrics import visitPebbleMetrics
from coverMetrics import visitCoverMetrics
from fishMetrics import *
from woodMetrics import *
from lib.channelunits import getCleanTierName





def calculateMetricsForVisit(visitobj):
    visitMetrics = dict()
    visitid = visitobj["visit_id"]
    populateDefaultColumns(visitMetrics, visitid)

    visitFishCountMetrics(visitMetrics, visitobj)
    visitLWDMetrics(visitMetrics, visitobj)
    visitCoverMetrics(visitMetrics, visitobj)
    visitPebbleMetrics(visitMetrics, visitobj)
    visitReachMetrics(visitMetrics, visitobj)

    return visitMetrics


def calculateMetricsForChannelUnitSummary(visitobj):
    channelUnitMetrics = []
    visitid = visitobj["visit_id"]
    channelUnits = visitobj['channelUnits']
    # create the channel unit summary metric rows with the channel unit id

    if channelUnits is not None:
        for c in channelUnits["values"]:
            cu = dict()
            cu["ChannelUnitID"] = c["value"]["ChannelUnitID"]
            cu["ChannelUnitNumber"] = c["value"]["ChannelUnitNumber"]

            cu["Tier1"] = c["value"]["Tier1"]