def compute_average_oxidation_state(site):
    """
    Calculates the average oxidation state of a site

    Args:
        site:
            Site to compute average oxidation state

    Returns:
        Average oxidation state of site.
    """
    try:
        avg_oxi = sum([sp.oxi_state * occu
                       for sp, occu in site.species_and_occu.items()
                       if sp is not None])
        return avg_oxi
    except AttributeError:
        pass
    try:
        return site.charge
    except AttributeError:
        raise ValueError("Ewald summation can only be performed on structures "
                         "that are either oxidation state decorated or have "
                         "site charges.")