Skip to content

Commit

Permalink
Merge branch 'staging' into update-fix/Analytics-data-export-cleanup
Browse files Browse the repository at this point in the history
Updates from airqo staging
  • Loading branch information
NicholasTurner23 committed Dec 10, 2024
2 parents c1cf659 + 9cab881 commit 734dd17
Show file tree
Hide file tree
Showing 15 changed files with 430 additions and 121 deletions.
2 changes: 1 addition & 1 deletion k8s/auth-service/values-prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ app:
replicaCount: 3
image:
repository: eu.gcr.io/airqo-250220/airqo-auth-api
tag: prod-d862897c-1733743392
tag: prod-ee15b958-1733833086
nameOverride: ''
fullnameOverride: ''
podAnnotations: {}
Expand Down
2 changes: 1 addition & 1 deletion k8s/device-registry/values-prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ app:
replicaCount: 3
image:
repository: eu.gcr.io/airqo-250220/airqo-device-registry-api
tag: prod-03a25cf1-1733249950
tag: prod-ee15b958-1733833086
nameOverride: ''
fullnameOverride: ''
podAnnotations: {}
Expand Down
2 changes: 1 addition & 1 deletion k8s/device-registry/values-stage.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ app:
replicaCount: 2
image:
repository: eu.gcr.io/airqo-250220/airqo-stage-device-registry-api
tag: stage-1838aa7a-1733249623
tag: stage-dfe6eb16-1733832983
nameOverride: ''
fullnameOverride: ''
podAnnotations: {}
Expand Down
2 changes: 1 addition & 1 deletion k8s/exceedance/values-prod-airqo.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ app:
configmap: env-exceedance-production
image:
repository: eu.gcr.io/airqo-250220/airqo-exceedance-job
tag: prod-d862897c-1733743392
tag: prod-ee15b958-1733833086
nameOverride: ''
fullnameOverride: ''
2 changes: 1 addition & 1 deletion k8s/exceedance/values-prod-kcca.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ app:
configmap: env-exceedance-production
image:
repository: eu.gcr.io/airqo-250220/kcca-exceedance-job
tag: prod-d862897c-1733743392
tag: prod-ee15b958-1733833086
nameOverride: ''
fullnameOverride: ''
2 changes: 1 addition & 1 deletion k8s/predict/values-prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ images:
predictJob: eu.gcr.io/airqo-250220/airqo-predict-job
trainJob: eu.gcr.io/airqo-250220/airqo-train-job
predictPlaces: eu.gcr.io/airqo-250220/airqo-predict-places-air-quality
tag: prod-d862897c-1733743392
tag: prod-ee15b958-1733833086
api:
name: airqo-prediction-api
label: prediction-api
Expand Down
2 changes: 1 addition & 1 deletion k8s/spatial/values-prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ app:
replicaCount: 3
image:
repository: eu.gcr.io/airqo-250220/airqo-spatial-api
tag: prod-d862897c-1733743392
tag: prod-ee15b958-1733833086
nameOverride: ''
fullnameOverride: ''
podAnnotations: {}
Expand Down
2 changes: 1 addition & 1 deletion k8s/website/values-prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ app:
replicaCount: 3
image:
repository: eu.gcr.io/airqo-250220/airqo-website-api
tag: prod-d862897c-1733743392
tag: prod-ee15b958-1733833086
nameOverride: ''
fullnameOverride: ''
podAnnotations: {}
Expand Down
2 changes: 1 addition & 1 deletion k8s/website/values-stage.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ app:
replicaCount: 2
image:
repository: eu.gcr.io/airqo-250220/airqo-stage-website-api
tag: stage-100bea2d-1733743125
tag: stage-7a1d5dd3-1733836788
nameOverride: ''
fullnameOverride: ''
podAnnotations: {}
Expand Down
2 changes: 1 addition & 1 deletion k8s/workflows/values-prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ images:
initContainer: eu.gcr.io/airqo-250220/airqo-workflows-xcom
redisContainer: eu.gcr.io/airqo-250220/airqo-redis
containers: eu.gcr.io/airqo-250220/airqo-workflows
tag: prod-d862897c-1733743392
tag: prod-ee15b958-1733833086
nameOverride: ''
fullnameOverride: ''
podAnnotations: {}
Expand Down
71 changes: 41 additions & 30 deletions src/device-registry/models/Cohort.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,6 @@ cohortSchema.statics.register = async function(args, next) {
response.errors = { message: error.message };
}

return response;

logger.error(`🐛🐛 Internal Server Error ${error.message}`);
next(new HttpError(response.message, response.status, response.errors));
}
Expand Down Expand Up @@ -196,12 +194,22 @@ cohortSchema.statics.list = async function(
foreignField: "cohorts",
as: "devices",
})
.unwind("$devices")
.lookup({
from: "sites",
localField: "devices.site_id",
foreignField: "_id",
as: "devices.site",
.project({
_id: 1,
visibility: 1,
cohort_tags: 1,
cohort_codes: 1,
name: 1,
createdAt: 1,
network: 1,
group: 1,
devices: {
$cond: {
if: { $eq: [{ $size: "$devices" }, 0] },
then: [],
else: "$devices",
},
},
})
.sort({ createdAt: -1 })
.project(inclusionProjection)
Expand All @@ -215,11 +223,10 @@ cohortSchema.statics.list = async function(
createdAt: { $first: "$createdAt" },
network: { $first: "$network" },
group: { $first: "$group" },
numberOfDevices: { $sum: 1 },
devices: { $push: "$devices" },
devices: { $first: "$devices" },
})
.skip(skip ? skip : 0)
.limit(limit ? limit : 1000)
.skip(skip ? parseInt(skip) : 0)
.limit(limit ? parseInt(limit) : 1000)
.allowDiskUse(true);

const cohorts = await pipeline.exec();
Expand All @@ -234,24 +241,28 @@ cohortSchema.statics.list = async function(
network: cohort.network,
createdAt: cohort.createdAt,
group: cohort.group,
numberOfDevices: cohort.numberOfDevices,
devices: cohort.devices.map((device) => ({
_id: device._id,
status: device.status,
name: device.name,
network: device.network,
group: device.group,
device_number: device.device_number,
description: device.description,
long_name: device.long_name,
createdAt: device.createdAt,
host_id: device.host_id,
site: device.site &&
device.site[0] && {
_id: device.site[0]._id,
name: device.site[0].name,
},
})),
numberOfDevices: cohort.devices ? cohort.devices.length : 0,
devices: cohort.devices
? cohort.devices
.filter((device) => Object.keys(device).length > 0)
.map((device) => ({
_id: device._id,
status: device.status,
name: device.name,
network: device.network,
group: device.group,
device_number: device.device_number,
description: device.description,
long_name: device.long_name,
createdAt: device.createdAt,
host_id: device.host_id,
site: device.site &&
device.site[0] && {
_id: device.site[0]._id,
name: device.site[0].name,
},
}))
: [],
}))
.sort((a, b) => new Date(b.createdAt) - new Date(a.createdAt));

Expand Down
94 changes: 86 additions & 8 deletions src/website/apps/event/models.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@

import logging
from django.db import models
from django.contrib.auth import get_user_model
from django_quill.fields import QuillField
from utils.models import BaseModel
from cloudinary.models import CloudinaryField
from cloudinary.uploader import destroy
import logging

User = get_user_model()

# Configure logger
logger = logging.getLogger(__name__)


Expand Down Expand Up @@ -65,7 +62,6 @@ class EventCategory(models.TextChoices):
blank=True,
)

# Image fields using CloudinaryField
event_image = CloudinaryField(
'image',
folder='website/uploads/events/images',
Expand Down Expand Up @@ -94,8 +90,18 @@ class Meta:
def __str__(self):
return self.title

def save(self, *args, **kwargs):
is_new = self.pk is None
super().save(*args, **kwargs)
if is_new:
logger.info(f"Created new Event: ID={self.pk}, Title={self.title}")
else:
logger.info(f"Updated Event: ID={self.pk}, Title={self.title}")

def delete(self, *args, **kwargs):
# Delete files from Cloudinary
logger.debug(
f"Attempting to delete Event: ID={self.pk}, Title={self.title}")
# Attempt to delete images from Cloudinary
if self.event_image:
try:
destroy(self.event_image.public_id)
Expand All @@ -112,7 +118,9 @@ def delete(self, *args, **kwargs):
except Exception as e:
logger.error(
f"Error deleting background_image from Cloudinary: {e}")

super().delete(*args, **kwargs)
logger.info(f"Deleted Event: ID={self.pk}, Title={self.title}")


class Inquiry(BaseModel):
Expand All @@ -134,6 +142,22 @@ class Meta:
def __str__(self):
return f"Inquiry - {self.inquiry}"

def save(self, *args, **kwargs):
is_new = self.pk is None
super().save(*args, **kwargs)
if is_new:
logger.info(
f"Created new Inquiry: ID={self.pk}, Inquiry={self.inquiry}")
else:
logger.info(
f"Updated Inquiry: ID={self.pk}, Inquiry={self.inquiry}")

def delete(self, *args, **kwargs):
logger.debug(
f"Attempting to delete Inquiry: ID={self.pk}, Inquiry={self.inquiry}")
super().delete(*args, **kwargs)
logger.info(f"Deleted Inquiry: ID={self.pk}, Inquiry={self.inquiry}")


class Program(BaseModel):
date = models.DateField()
Expand All @@ -153,6 +177,20 @@ class Meta:
def __str__(self):
return f"Program - {self.date}"

def save(self, *args, **kwargs):
is_new = self.pk is None
super().save(*args, **kwargs)
if is_new:
logger.info(f"Created new Program: ID={self.pk}, Date={self.date}")
else:
logger.info(f"Updated Program: ID={self.pk}, Date={self.date}")

def delete(self, *args, **kwargs):
logger.debug(
f"Attempting to delete Program: ID={self.pk}, Date={self.date}")
super().delete(*args, **kwargs)
logger.info(f"Deleted Program: ID={self.pk}, Date={self.date}")


class Session(BaseModel):
start_time = models.TimeField()
Expand All @@ -175,6 +213,23 @@ class Meta:
def __str__(self):
return f"Session - {self.session_title}"

def save(self, *args, **kwargs):
is_new = self.pk is None
super().save(*args, **kwargs)
if is_new:
logger.info(
f"Created new Session: ID={self.pk}, Title={self.session_title}")
else:
logger.info(
f"Updated Session: ID={self.pk}, Title={self.session_title}")

def delete(self, *args, **kwargs):
logger.debug(
f"Attempting to delete Session: ID={self.pk}, Title={self.session_title}")
super().delete(*args, **kwargs)
logger.info(
f"Deleted Session: ID={self.pk}, Title={self.session_title}")


class PartnerLogo(BaseModel):
partner_logo = CloudinaryField(
Expand All @@ -201,7 +256,18 @@ class Meta:
def __str__(self):
return f"Partner - {self.name}"

def save(self, *args, **kwargs):
is_new = self.pk is None
super().save(*args, **kwargs)
if is_new:
logger.info(
f"Created new PartnerLogo: ID={self.pk}, Name={self.name}")
else:
logger.info(f"Updated PartnerLogo: ID={self.pk}, Name={self.name}")

def delete(self, *args, **kwargs):
logger.debug(
f"Attempting to delete PartnerLogo: ID={self.pk}, Name={self.name}")
if self.partner_logo:
try:
destroy(self.partner_logo.public_id)
Expand All @@ -211,6 +277,7 @@ def delete(self, *args, **kwargs):
logger.error(
f"Error deleting partner_logo from Cloudinary: {e}")
super().delete(*args, **kwargs)
logger.info(f"Deleted PartnerLogo: ID={self.pk}, Name={self.name}")


class Resource(BaseModel):
Expand Down Expand Up @@ -239,13 +306,24 @@ class Meta:
def __str__(self):
return f"Resource - {self.title}"

def save(self, *args, **kwargs):
is_new = self.pk is None
super().save(*args, **kwargs)
if is_new:
logger.info(
f"Created new Resource: ID={self.pk}, Title={self.title}")
else:
logger.info(f"Updated Resource: ID={self.pk}, Title={self.title}")

def delete(self, *args, **kwargs):
logger.debug(
f"Attempting to delete Resource: ID={self.pk}, Title={self.title}")
if self.resource:
try:
destroy(self.resource.public_id)
logger.info(
f"Deleted resource from Cloudinary: {self.resource.public_id}")
except Exception as e:
logger.error(
f"Error deleting resource from Cloudinary: {e}")
logger.error(f"Error deleting resource from Cloudinary: {e}")
super().delete(*args, **kwargs)
logger.info(f"Deleted Resource: ID={self.pk}, Title={self.title}")
Loading

0 comments on commit 734dd17

Please sign in to comment.