Closed joostdaniels closed 1 year ago
It looks like the python environment on quasar got munged during a server update. I've switched it to conda and the map should now be correctly updated every hour. The new crontab entry is:
0 * * * * BASH_ENV=~/.bashrc bash -l -c "conda activate;/u/brian/Applications/fathomnet/write_homemap.py /mbari/FathomNet/web/assets/images/homemap.png > /u/brian/Library/Logs/quasar-write_homemap.log 2>&1"
The script to generate the map is:
#!/usr/bin/env python
# REQUIRED:
# - requests
# - matplotlib
# - cartopy
# - datetime
from typing import List, Tuple
import argparse
import cartopy.crs as ccrs
from cartopy.feature.nightshade import Nightshade
import datetime
import pytz
import matplotlib.pyplot as plt
import requests
endpoint = "http://fathomnet.org:8080"
def main(target) -> None:
fig = plt.figure(figsize=(16, 12), edgecolor='w')
ax = fig.add_subplot(1, 1, 1, projection=ccrs.PlateCarree())
date = pytz.utc.localize(datetime.datetime.utcnow())
ax.stock_img()
ax.add_feature(Nightshade(date, alpha=0.2))
positions = averagePositionOfEachUpload()
for p in positions:
plt.plot(p[1], p[0], 'ro', markersize=2, transform=ccrs.PlateCarree())
plt.savefig(target, bbox_inches='tight')
def averagePositionOfEachUpload() -> List[Tuple[float, float]]:
url = f"{endpoint}/stats/list/upload/positions"
r = requests.get(url)
json = r.json()
return [(x['latitude'], x['longitude']) for x in json]
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Write a map of the average position of each upload.')
parser.add_argument('target', type=str, help='The target file to write to.')
args = parser.parse_args()
main(args.target)
Currently pointless to display. Data locations should be represented accurately, and map should not include day/night overlay (unless updated to be accurate). My vote is to remove or move to "about us" page