Ejemplo n.º 1
0
        public void NewContact(HourlyTracerKey key, DateHour time)
        {
            Case matchingCase = null;

            // Adds the new case to the database.

            db.RunInTransaction(() => {
                var exists = db.Find <Contact>(c =>
                                               c.Key == key.Value &&
                                               c.Year == time.Year &&
                                               c.Month == time.Month &&
                                               c.Day == time.Day &&
                                               c.Hour == time.Hour
                                               ) != null;

                if (!exists)
                {
                    Logger.Info(
                        $"New contact: {key.ToHumanReadableString()} at {time}."
                        );

                    db.Insert(new Contact {
                        Key   = key.Value,
                        Year  = time.Year,
                        Month = time.Month,
                        Day   = time.Day,
                        Hour  = time.Hour
                    });

                    // Gets any matching know case

                    matchingCase = db.Find <Case>(ca =>
                                                  ca.Key == key.Value &&
                                                  ca.Year == time.Year &&
                                                  ca.Month == time.Month &&
                                                  ca.Day == time.Day
                                                  );
                }
            });

            // Classifies the newly added case

            if (matchingCase != null)
            {
                lock (Matches) {
                    if (matchingCase.Type == "positive")
                    {
                        Matches.Positives.Add(time);
                    }
                    else
                    {
                        Matches.Symptomatics.Add(time);
                    }
                }

                MatchesChange?.Invoke(this, Matches);
                CurrentInfectionStatusChange?.Invoke(
                    this, CurrentInfectionStatus);
            }
        }
Ejemplo n.º 2
0
        /** Recomputes the match sets based on the current state of the contact
         * database. */
        protected void ComputeMatches()
        {
            var sqlMatches = db.Query <SQLiteMatch>(
                "select ca.type, co.year, co.month, co.day, co.hour " +
                "from contacts as co " +
                "inner join cases as ca " +
                "   on ca.key = co.key " +
                "   and ca.year = co.year " +
                "   and ca.month = co.month " +
                "   and ca.day = co.day " +
                "group by ca.type, co.year, co.month, co.day, co.hour;"
                );

            lock (Matches) {
                Matches.Positives.Clear();
                Matches.Symptomatics.Clear();

                foreach (var sqlMatch in sqlMatches)
                {
                    var time = new DateHour(sqlMatch.Year, sqlMatch.Month,
                                            sqlMatch.Day, sqlMatch.Hour);

                    if (sqlMatch.Type == "positive")
                    {
                        Matches.Positives.Add(time);
                    }
                    else
                    {
                        Matches.Symptomatics.Add(time);
                    }
                }
            }

            MatchesChange?.Invoke(this, Matches);
            CurrentInfectionStatusChange?.Invoke(this, CurrentInfectionStatus);
        }