Ejemplo n.º 1
0
    def _index_incidents(self, start_hour=19):
        # 19 == 12 adjusted for timezone from UTC
        if (
            not hasattr(self, "_incidents_by_date") or
            not hasattr(self, "_incidents_by_type")
        ):
            storage = self.ims.storage
            incidents_by_date = {}
            incidents_by_type = {}

            def dates_from_incident(incident):
                dates = set()

                def add_date(dt, dates=dates, incident=incident):
                    if dt is None:
                        return

                    if dt.hour < start_hour:
                        dates.add(dt.date() - TimeDelta(days=1))
                    else:
                        dates.add(dt.date())

                for entry in incident.report_entries:
                    if not ignore_entry(entry):
                        add_date(entry.created)

                add_date(incident.created)
                #add_date(incident.dispatched)
                #add_date(incident.on_scene)
                #add_date(incident.closed)

                return dates

            for number, etag in storage.list_incidents():
                incident = storage.read_incident_with_number(number)

                if ignore_incident(incident):
                    continue

                for date in dates_from_incident(incident):
                    incidents_by_date.setdefault(date, set()).add(incident)

                if incident.incident_types:
                    for incident_type in incident.incident_types:
                        incidents_by_type.setdefault(
                            incident_type,
                            set()
                        ).add(incident)
                else:
                    incidents_by_type.setdefault(None, set()).add(incident)

            self._incidents_by_date = incidents_by_date
            self._incidents_by_type = incidents_by_type
Ejemplo n.º 2
0
    def incidents_by_shift(self):
        if not hasattr(self, "_incidents_by_shift"):
            storage = self.ims.storage
            incidents_by_shift = {}

            for number, etag in storage.list_incidents():
                incident = storage.read_incident_with_number(number)

                if ignore_incident(incident):
                    continue

                def add(datetime, activity):
                    if datetime is not None:
                        shift = Shift.from_datetime(DirtShift, datetime)
                        incidents_by_activity = incidents_by_shift.setdefault(
                            shift, {}
                        )
                        incidents_by_activity.setdefault(
                            activity, set()
                        ).add(incident)

                add(incident.created, Activity.created)
                add(incident.dispatched, Activity.updated)
                add(incident.on_scene, Activity.updated)
                add(incident.closed, Activity.closed)

                for entry in incident.report_entries:
                    if not ignore_entry(entry):
                        add(entry.created, Activity.updated)

            open_incidents = set()
            for shift in sorted(incidents_by_shift):
                incidents_by_activity = incidents_by_shift[shift]

                created_incidents = incidents_by_activity.get(
                    Activity.created, set()
                )

                open_incidents |= created_incidents
                open_incidents -= incidents_by_activity.get(
                    Activity.closed, set()
                )

                incidents_by_activity[Activity.idle] = (
                    open_incidents - created_incidents
                )

            self._incidents_by_shift = incidents_by_shift

        return self._incidents_by_shift
Ejemplo n.º 3
0
    def _index_incidents(self, number_of_shifts=3):
        if not hasattr(self, "_incidents_by_shift"):
            storage = self.ims.storage
            incidents_by_shift = {} #{"created":[], "closed":[]}

            for number, etag in storage.list_incidents():
                incident = storage.read_incident_with_number(number)

                if ignore_incident(incident):
                    continue

                if incident.created:
                    shift = Shift.from_datetime(DirtShift, incident.created)
                    incidents_by_activity = incidents_by_shift.setdefault(shift, {})
                    incidents_by_activity.setdefault(Activity.created, set()).add(incident)

                if incident.closed:
                    shift = Shift.from_datetime(DirtShift, incident.closed)
                    incidents_by_activity = incidents_by_shift.setdefault(shift, {})
                    incidents_by_activity.setdefault(Activity.closed, set()).add(incident)

            self._incidents_by_shift = incidents_by_shift