def run(self): log.debug("Updating mirror database") geoip = GeoIP(Config.GEOIP_PATH_V4) for status in mirror_statuses( unofficial_mirrors=Config.UNOFFICIAL_MIRRORS): name = status['mirror'] if name == "a.pypi.python.org": # don't include 'a' in the list of mirrors - it's no mirror after all continue time_diff = status['time_diff'] if not isinstance(time_diff, timedelta): continue log.debug(" Processing mirror '%s'", name) record = geoip.record_by_name(name) lat = record['latitude'] lon = record['longitude'] log.debug(" Age: %d, Lat: %0.5f, Lon: %0.5f", time_diff.total_seconds(), lat, lon) try: mirror = Mirror.objects.get(name=name) except ObjectNotFound: mirror = Mirror(name=name) mirror.age = time_diff.total_seconds() mirror.lat = lat mirror.lon = lon mirror.save() self.redis.set(Config.KEY_LAST_UPDATE, time.time()) log.debug("Finished updating mirror database")
from scipy.stats import pearsonr import numpy as np import transform import utils from models import Mirror from datasets import GlucoseData from torch.utils.data import DataLoader cgm_file, meals_file = utils.get_files() train, val = GlucoseData.train_val_split(cgm_file, meals_file, transform=transform.to_tensor) val_dl = DataLoader(val) model = Mirror() amount = 0 acc_pearson = 0.0 for sample in val_dl: out = model(sample['cgm'], sample['meals']) out = out.numpy()[0] target = sample['target'].numpy()[0] corr, _ = pearsonr(out, target) if not np.isnan(corr): amount += 1 acc_pearson += corr total = acc_pearson / amount print(f'{total:.2f} mean pearson correlation') print(f'{len(val) - amount}/{len(val)} were nans') # 0.06 mean pearson correlation