Skip to content

Commit

Permalink
Merge pull request hodcroftlab#134 from hodcroftlab/feat/last-updated
Browse files Browse the repository at this point in the history
  • Loading branch information
ivan-aksamentov authored Mar 31, 2021
2 parents 2fc7cd5 + f0e988a commit d0ae19b
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 0 deletions.
12 changes: 12 additions & 0 deletions scripts/allClusterDynamics_faster.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
overall_tables_file = "../covariants/cluster_tables/all_tables.tsv"
acknowledgement_folder = "../covariants/acknowledgements/"
acknowledgement_folder_new = "../covariants/web/data/acknowledgements/"
web_data_folder = "../covariants/web/data/"
figure_only_path = "../covariants/figures/"
# This assumes that `covariants` sites next to `ncov`
# Otherwise, modify the paths above to put the files wherever you like.
Expand Down Expand Up @@ -1059,3 +1060,14 @@ def plot_country_data(clusters, proposed_coun_to_plot, print_files, clus_keys):
if do_country:
proposed_coun_to_plot, clus_keys = get_ordered_clusters_to_plot(clusters)
plot_country_data(clusters, proposed_coun_to_plot, print_files, clus_keys)

#if all went well (script got to this point), and did an 'all' run, then print out an update!
from datetime import datetime
update_json = { "lastUpdated" : str(datetime.now().isoformat()) }

if print_files and "all" in clus_answer:
with open(web_data_folder+f'update.json', 'w') as fh:
json.dump(update_json, fh)



1 change: 1 addition & 0 deletions web/data/update.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"lastUpdated": "2021-03-24T14:45:58.499739"}
22 changes: 22 additions & 0 deletions web/src/components/Common/LastUpdated.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import React, { HTMLProps } from 'react'
import styled from 'styled-components'
import classNames from 'classnames'

import { getLastUpdatedDate, getLastUpdatedFull } from 'src/io/getLastUpdatedDate'

const LAST_UPDATED_DATE = `Last updated: ${getLastUpdatedDate()}`
const LAST_UPDATED_FULL = `Last updated on: ${getLastUpdatedFull()}`

const LastUpdatedText = styled.small`
font-size: 0.9rem;
`

export function LastUpdated({ className }: HTMLProps<HTMLParagraphElement>) {
return (
<LastUpdatedText className={classNames(className)}>
<span className="ml-1" title={LAST_UPDATED_FULL}>
{LAST_UPDATED_DATE}
</span>
</LastUpdatedText>
)
}
3 changes: 3 additions & 0 deletions web/src/components/Layout/Layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { ReactComponent as GisaidLogoBase } from 'src/assets/images/GISAID_logo.
import { LinkExternal } from 'src/components/Link/LinkExternal'
import { NavigationBar } from './NavigationBar'
import { FooterContent } from './Footer'
import { LastUpdated } from '../Common/LastUpdated'

const Container = styled(ContainerBase)`
min-height: 100%;
Expand Down Expand Up @@ -83,6 +84,8 @@ export function Layout({ children }: PropsWithChildren<LayoutProps>) {
<GisaidLogo height={20} />
</LinkExternal>
</GisaidText>

<LastUpdated className="d-flex ml-auto" />
</Col>
</Row>

Expand Down
15 changes: 15 additions & 0 deletions web/src/io/getLastUpdatedDate.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { lastUpdated } from 'src/../data/update.json'

import { DateTime } from 'luxon'

export function getLastUpdatedDate() {
const utc = DateTime.fromISO(lastUpdated, { zone: 'UTC' })
const local = utc.toLocal()
return local.toISODate()
}

export function getLastUpdatedFull() {
const utc = DateTime.fromISO(lastUpdated, { zone: 'UTC' })
const local = utc.toLocal()
return `${local.toJSDate().toLocaleString()} (${local.zoneName})`
}

0 comments on commit d0ae19b

Please sign in to comment.