#!/usr/bin/env python3
import os, re, json
import cgi
from os.path import join
RAO_DATA = '/var/www/reporter.apache.org/data'
user = os.environ['HTTP_X_AUTHENTICATED_USER'] if 'HTTP_X_AUTHENTICATED_USER' in os.environ else ""
m = re.match(r"^([-a-zA-Z0-9_.]+)$", user)
if m:
with open(join(RAO_DATA,"health.json"), "r") as f:
notes = json.load(f)
f.close()
status = [0,0,0,0,0,0]
print ("Content-Type: text/html\r\n\r\n
Community Health Issues
This is a quantitative guideline only. There may be niche cases where the summaries below to not apply.
Scores range from -10.00 (worst possible score) to +10.00 (best possible score), harmonized by 
")
values = ["Super Healthy", "Healthy", "Mostly Okay", "Unhealthy", "Action required!", "URGENT ACTION REQUIRED!"]
xvalues = ["Super Healthy", "Healthy", "Mostly Okay", "Unhealthy", "Action required!", "URGENT ACTION REQUIRED!"]
colors = ["#000070", "#007000", "#407000", "#70500", "#700000", "#A00000"]
for entry in sorted(notes, key=lambda x: x['score'], reverse=True):
s = int(entry['score']/1.80)
if s > 4:
s = 4
s = s + 1
if s < 0:
s = 0
status[s] += 1;
y = 0
for s in status:
xvalues[y] = "%s (%d)" % (values[y], s)
y += 1
print('
' % ( ",".join(str(x) for x in status), "|".join(xvalues)))
for entry in sorted(sorted(notes, key=lambda x: x['group']), key=lambda x: x['score'], reverse=True):
s = int(entry['score']/1.80)
if s > 4:
s = 4
s = s + 1
if s < 0:
s = 0
status[s] += 1;
print("\r" % colors[s])
print( "%s%s: %s%s
\r" % (entry['group'], "" if s >= 4 else "", entry['pmc'], values[s],"" if s >= 4 else "", ))
print( "Health score: %0.2f
\r" % (6.33+((-1 * entry['score'])* (20/12.25))))
for l in entry['notes']:
print("Score note: %s
\r" % l)
print("
\r")
else:
print ("Content-Type: text/html\r\n\r\n")
print("Unknown or invalid user id presented")