import pandas as pd
import numpy as np
from IPython.core.display import display, HTML
display(HTML("<style>.container { width:100% !important; }</style>"))

df = pd.read_csv('../../data/processed/facilities-3-29-scrape.csv')

"""
Explanation: This is a dataset of Assisted Living, Nursing and Residential Care facilities in Oregon, open as of September, 2016. For each, we have:
Data were munged here.

<i>facility_id:</i> Unique ID used to join to complaints
<i>fac_ccmunumber:</i> Unique ID used to join to ownership history
<i>facility_type:</i> NF - Nursing Facility; RCF - Residential Care Facility; ALF - Assisted Living Facility
<i>fac_capacity:</i> Number of beds facility is licensed to have. Not necessarily the number of beds facility does have.
<i>facility_name:</i> Facility name at time of September extract.
<i>offline:</i> created in munging notebook, a count of complaints that DO NOT appear when facility is searched on state's complaint search website.
<i>online:</i> created in munging notebook, a count of complaints that DO appear when facility is searched on state's complaint search website.
End of explanation
"""


df.count()[0]

"""
Explanation: <h3>How many facilities are there?</h3>
End of explanation
"""


df[(df['offline'].isnull())].count()[0]

"""
Explanation: <h3>How many facilities have accurate records online?</h3>

Those that have no offline records.
End of explanation
"""


df[(df['offline'].notnull())].count()[0]

"""
Explanation: <h3>How many facilities have inaccurate records online?<h/3>

Those that have offline records.
End of explanation
"""


df[(df['offline']>df['online']) & (df['online'].notnull())].count()[0]

"""
Explanation: <h3>How many facilities had more than double the number of complaints shown online?</h3>
End of explanation
"""


df[(df['online'].isnull()) & (df['offline'].notnull())].count()[0]

"""
Explanation: <h3>How many facilities show zero complaints online but have complaints offline?</h3>
End of explanation
"""


df[(df['online'].notnull()) & (df['offline'].isnull())].count()[0]

"""
Explanation: <h3>How many facilities have complaints and are accurate online?</h3>
End of explanation
"""


df[(df['online'].notnull()) | df['offline'].notnull()].count()[0]

"""
Explanation: <h3>How many facilities have complaints?</h3>
End of explanation
"""


df[(df['offline'].isnull())].count()[0]/df.count()[0]*100

"""
Explanation: <h3>What percent of facilities have accurate records online?</h3>
End of explanation
"""


df[df['offline'].notnull()].sum()['fac_capacity']

"""
Explanation: <h3>What is the total capacity of all facilities with inaccurate records?</h3>
End of explanation
"""


df[df['online'].isnull()].count()[0]

"""
Explanation: <h3>How many facilities appear to have no complaints, whether or not they do?</h3>
End of explanation
"""


over_50 = df[((df['offline']+df['online'])>50)]

over_50['total'] = over_50['online']+over_50['offline']

over_50['pct_offline'] = over_50['offline']/over_50['total']*100

over_50[over_50['facility_name']=='Avamere Health Services of Rogue Valley']

over_50.sort_values('pct_offline',ascending = False).head(10)

"""
Explanation: <h3>What are the ten facilities with >50 complaints that have the highest disparities?</h3>
<i>For graphics</i>
End of explanation
"""


