<jupyter_start><jupyter_text>Count of departments in csv<jupyter_code>cols = ['lr_fire', 'lr_size_2', 'lr_size_3', 'mr_fire', 'mr_size_2', 'mr_size_3', 'h.fire', 'h.size2', 'h.size3']

fd_id = 75500

# for xx.size2 (beyond room + beyond floor) you would want
# Sum( xx.fire * xx.size2 ) / sum( xx.fire )
# And for xx.size3 (beyond structure) you would want
# Sum( xx.fire * xx.size2 * xx.size3 ) / sum( xx. fire * xx.size2 )
df['lr_beyond_room'] = df[df['fd_id'] == fd_id].apply(lambda row: row['lr_fire'] * row['lr_size_2'], axis=1)
df['lr_beyond_structure'] = df[df['fd_id'] == fd_id].apply(lambda row: row['lr_fire'] * row['lr_size_2'] * row['lr_size_3'], axis=1)
df['mr_beyond_room'] = df[df['fd_id'] == fd_id].apply(lambda row: row['mr_fire'] * row['mr_size_2'], axis=1)
df['mr_beyond_structure'] = df[df['fd_id'] == fd_id].apply(lambda row: row['mr_fire'] * row['mr_size_2'] * row['mr_size_3'], axis=1)
df['hr_beyond_room'] = df[df['fd_id'] == fd_id].apply(lambda row: row['h.fire'] * row['h.size2'], axis=1)
df['hr_beyond_structure'] = df[df['fd_id'] == fd_id].apply(lambda row: row['h.fire'] * row['h.size2'] * row['h.size3'], axis=1)

cols2 = ['lr_beyond_room', 'lr_beyond_structure', 'mr_beyond_room', 'mr_beyond_structure', 'hr_beyond_room', 'hr_beyond_structure']

sums = df[df['fd_id'] == fd_id].groupby(['fd_id', 'state']).sum()
display(sums[cols])
display(sums[cols2])

print '% of low risk beyond room/floor fires: {}'.format(sums['lr_beyond_room'][0] / sums['lr_fire'][0])
print '% of low risk beyond structure fires: {}'.format(sums['lr_beyond_structure'][0] / sums['lr_beyond_room'][0])
print '% of medium risk beyond room/floor fires: {}'.format(sums['mr_beyond_room'][0] / sums['mr_fire'][0])
print '% of medium risk beyond structure fires: {}'.format(sums['mr_beyond_structure'][0] / sums['mr_beyond_room'][0])
print '% of high risk beyond room/floor fires: {}'.format(sums['hr_beyond_room'][0] / sums['h.fire'][0])
print '% of high risk beyond structure fires: {}'.format(sums['hr_beyond_structure'][0] / sums['hr_beyond_room'][0])

#df[df['fd_id'] == 93345]
#lr_size2 = df[['lr_fire', 'lr_size_2']].apply(lambda row: row['lr_fire'] * row['lr_size_2'])
cols2 = ['lr_size_2', 'mr_size_2', 'h.size2', 'lr_size_3', 'mr_size_3', 'h.size3']

df[df['fd_id'] == 93345].groupby(['fd_id', 'state']).sum()<jupyter_output><empty_output><jupyter_text>CSV counts vs FireCARES count<jupyter_code>db = len(FireDepartment.objects.count())
csv = len(df.groupby(['fd_id', 'state'])[cols].sum())
(db, csv, csv/float(db))  # hit rate<jupyter_output><empty_output><jupyter_text>Community Assessment vs Performance Score<jupyter_code># Has no community fires assessment, but has deaths/injury assessment
q = """
select department_id,
    case when level = 0 then 'ALL LEVELS'
        when level = 1 then 'LOW'
        when level = 2 then 'MEDIUM'
        when level = 4 then 'HIGH'
        when level = 5 then 'UNKNOWN'
    end
from firestation_firedepartmentriskmodels
where risk_model_fires is null and (risk_model_injuries is not null or risk_model_deaths is not null)
"""
pd.read_sql_query(q, connections['default']).to_csv('/tmp/only_deaths_injuries.csv')
#pd.read_sql_query(q, connections['default'])
# Has performance score, but is missing one or more community assessments
q = """
select department_id,
    case when level = 0 then 'ALL LEVELS'
        when level = 1 then 'LOW'
        when level = 2 then 'MEDIUM'
        when level = 4 then 'HIGH'
        when level = 5 then 'UNKNOWN'
    end,
    risk_model_injuries is null as injuries_empty,
    risk_model_deaths is null as deaths_empty,
    risk_model_fires is null as fires_empty,
    risk_model_fires_size1 is null as fires_size1_empty,
    risk_model_fires_size2 is null as fires_size2_empty,
    dist_model_score
from firestation_firedepartmentriskmodels
where
    dist_model_score is not null
        and (risk_model_injuries is null
            or risk_model_deaths is null
            or risk_model_fires is null
            or risk_model_fires_size1 is null
            or risk_model_fires_size2 is null)
        and level != 5
order by department_id
"""
pd.read_sql_query(q, connections['default']).to_csv('/tmp/score_but_no_assessment.csv')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.15983992467043315, 'fraction_numerical': 0.019538606403013182, 'mean_word_length': 5.23935389133627, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '213802', 'license': 'MIT', 'n_tokens_mistral': 1620, 'n_tokens_neox': 1548, 'n_words': 356, 'path': 'scripts/predictions.2015.ipynb', 'repo_name': 'FireCARES/firecares', 'size': '4248'}