Skip to content

Commit

Permalink
feat: add archive listing functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
abhidg committed Dec 21, 2024
1 parent c4046a5 commit d48a584
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 10 deletions.
6 changes: 0 additions & 6 deletions outbreaks/templates/_header.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,3 @@ <h1>{{ description }} Outbreak</h1>
href="mailto:info@global.health">info@global.health</a>). Published on {{ published_date}}.
<a href="https://reports.global.health/{{ name }}/{{ published_date }}.html">Permalink</a>
</p>
<h2>Summary</h2>
{{#info}}
<div class="info">
<p>{{ info }}</p>
</div>
{{/info}}
10 changes: 10 additions & 0 deletions outbreaks/templates/mpox-2024.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@
<a href="https://github.com/globaldothealth/outbreak-data/wiki/GHL2024.D11.1E71">outbreak data</a> page.
</div>

<div id="archive-container">
<ul id="archives">
{{#archives}}
<li><a href="{{ link }}">{{ text }}</a></li>
{{/archives}}
</ul>
</div>

<h2>Summary</h2>

<p class="summary">
<strong>{{ n_confirmed }}</strong> confirmed and <strong>{{ n_suspected }}</strong>
suspected cases as of {{ date }}
Expand Down
4 changes: 3 additions & 1 deletion src/olm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ def main():
report_parser = subparsers.add_parser("report", help="Generate briefing report")
report_parser.add_argument("outbreak", help="Outbreak name")
report_parser.add_argument("--data", help="Data URL")
report_parser.add_argument("-a", "--add-archive", help="Add link to archived reports", action="store_true")
report_parser.add_argument(
"-b", "--bucket", help="S3 bucket to write outbreak report to"
)
Expand Down Expand Up @@ -105,8 +106,9 @@ def main():
case "report":
outbreak = Outbreak(OUTBREAKS_PATH / f"{args.outbreak}.yml", args.data)
outbreak.make_report(
args.add_archive,
args.bucket,
args.cloudfront,
cloudfront_distribution=args.cloudfront,
)
if args.open and (Path(args.outbreak + ".html")).exists():
webbrowser.open("file://" + str(Path.cwd() / (args.outbreak + ".html")))
Expand Down
9 changes: 8 additions & 1 deletion src/olm/outbreaks/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,13 @@
invalidate_cache,
msg_ok,
rename_columns,
get_archives_for_outbreak
)
from ..types import LintResult, RowError
from ..sources import source_databutton, source_google_sheet
from .mpox2024 import mpox_2024_aggregate


REPORT_BUCKET = "reports.global.health"
OUTBREAK_SPECIFIC_METHODS = [mpox_2024_aggregate]
ALLOWED_METHODS = OUTBREAK_SPECIFIC_METHODS + [
get_counts,
Expand Down Expand Up @@ -167,13 +168,16 @@ def lint(self, ignore_fields: list[str] = []) -> LintResult:

def make_report(
self,
add_archive: bool = False,
output_bucket: str | None = None,
cloudfront_distribution: str | None = None,
):
"""Build epidemiological report
Parameters
----------
add_archive
Add links to report archives if True
output_bucket
Output S3 bucket to write result to, in addition to local HTML output
to {outbreak_name}.html
Expand All @@ -195,6 +199,9 @@ def make_report(
"published_date": str(date),
"data_url": self.metadata.get("url", ""),
}
if add_archive:
archives = get_archives_for_outbreak(self.name)
var["archives"] = [ {"link": a, "text": a.removesuffix(".html")} for a in archives]
# read includes from outbreaks/<outbreak>/includes
# each include file must be prefixed by date
var.update(read_includes(self.name, datetime.datetime.utcnow().date()))
Expand Down
10 changes: 10 additions & 0 deletions src/olm/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

pd.options.mode.chained_assignment = None

REPORT_BUCKET = "reports.global.health"
AGE_BINS = [
(0, 0),
(1, 9),
Expand Down Expand Up @@ -144,6 +145,15 @@ def store_s3(
logging.exception("An exception occurred while trying to upload files")
raise

def get_archives_for_outbreak(
outbreak: str,
bucket: str = REPORT_BUCKET
) -> list[str]:
s3 = boto3.resource('s3')
bucket = s3.Bucket(bucket)
return [obj.key.removeprefix(outbreak + "/") for obj in bucket.objects.filter(Prefix=f'{outbreak}/20')]



def invalidate_cache(
distribution_id: str,
Expand Down
13 changes: 11 additions & 2 deletions static/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ div.info {
color: white;
padding: 2px 20px;
background: #20635b;
border-radius: 5px;
}

div.info p {
Expand Down Expand Up @@ -161,11 +160,21 @@ p.print {
display: none;
}

div#data-citation {
div#data-citation, div#archive-container {
padding: 0rem 0.8rem;
border: 2px solid #0e7569
}

div#archive-container h2 {
font-size: 120%;
}
ul#archives {
font-family: monospace;
font-size: 110%;
list-style-type: none;
columns: 3;
}

div#data-citation p {
font-size: 95%;
}
Expand Down

0 comments on commit d48a584

Please sign in to comment.