• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

gcivil-nyu-org / wed-fall24-team4 / #627816045

06 Nov 2024 02:07AM UTC coverage: 86.893%. First build
#627816045

Pull #132

travis-ci

Pull Request #132: Added Reporting functionality

165 of 175 new or added lines in 10 files covered. (94.29%)

716 of 824 relevant lines covered (86.89%)

0.87 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

89.13
/notifications/views.py
1
from django.shortcuts import render
1✔
2
from .models import Notifications
1✔
3
from reporting.models import Report
1✔
4
from django.utils import timezone
1✔
5
from datetime import timedelta
1✔
6
from django.http import JsonResponse
1✔
7
from collections import defaultdict
1✔
8
from .dataclasses import ReportStatusFreqTable, StatusFreqTable
1✔
9

10

11
def inbox(request):
1✔
12
    notification_history = Notifications.objects.all().order_by("-timestamp")
1✔
13
    current_time = timezone.now()
1✔
14
    for record in notification_history:
1✔
NEW
15
        if current_time - record.timestamp >= timedelta(hours=24):
×
NEW
16
            record.active = False
×
NEW
17
            record.save()
×
18
    return render(request, "notifications/inbox.html", {})
1✔
19

20

21
def get_notifications(request):
1✔
22
    notification_history = Notifications.objects.all().order_by("-timestamp")
1✔
23
    current_time = timezone.now()
1✔
24
    relevant_notifications = []
1✔
25

26
    for record in notification_history:
1✔
27
        if current_time - record.timestamp >= timedelta(hours=24):
1✔
28
            break
×
29
        if record.active:
1✔
30
            relevant_notifications.append(
1✔
31
                {"content": record.content, "timestamp": record.timestamp}
32
            )
33

34
    reports = Report.objects.all().order_by("-timestamp")
1✔
35
    active_reports = defaultdict(
1✔
36
        lambda: ReportStatusFreqTable(
37
            active=StatusFreqTable(),
38
            broken=StatusFreqTable(),
39
            maintenance=StatusFreqTable(),
40
        )
41
    )
42
    for report in reports:
1✔
43
        if current_time - report.timestamp >= timedelta(hours=4):
1✔
NEW
44
            break
×
45

46
        report_key = (report.station, report.infrastructure)
1✔
47

48
        if current_time - report.timestamp < timedelta(hours=3):
1✔
49
            if report.status == "active":
1✔
50
                active_reports[report_key].active.count += 1
1✔
51
                active_reports[report_key].active.latest_timestamp = report.timestamp
1✔
52
            elif report.status == "broken":
1✔
53
                active_reports[report_key].broken.count += 1
1✔
54
                active_reports[report_key].broken.latest_timestamp = report.timestamp
1✔
55
            elif report.status == "maintenance":
1✔
56
                active_reports[report_key].maintenance.count += 1
1✔
57
                active_reports[report_key].maintenance.latest_timestamp = (
1✔
58
                    report.timestamp
59
                )
60

61
    for report_key in active_reports:
1✔
62
        count, timestamp, status = active_reports[report_key].get_top_status()
1✔
63
        if count >= 3:
1✔
64
            relevant_notifications.append(
1✔
65
                {
66
                    "content": f"{report_key[0]}'s {report_key[1]} is"
67
                    + f"{' in' if status == 'maintenance' else ''} {status}",
68
                    "timestamp": timestamp,
69
                }
70
            )
71

72
    return JsonResponse({"notifications": relevant_notifications})
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc