Beispiel #1
0
        public static bool DailyInsightsAreComplete(Insights lifetime, Insights daily, JObject row)
        {
            /**
             * States whether daily feed has caught up to lifetime feed.
             * Note: check can only be performed on metrics that are present both on lifetime and on daily feed.
             */// Current source id
            var id  = lifetime.Source.ColumnDefinition["id"];
            var hid = id.Hash();

            var source_id      = lifetime.Source.Name + "_id";
            var integerMetrics =
                daily.MetricColumns
                .Where(dailyMetric => INTEGER_METRICS.Any(m => m == dailyMetric.Type))
                .Where(dailyMetric => lifetime.MetricColumns.Any(lifetimeMetric => lifetimeMetric.Name == dailyMetric.Name));

            foreach (var metric in integerMetrics)
            {
                bool threeshold;
                using (var connection = new NpgsqlConnection(ConnectionString()))
                    using (var cmd = connection.CreateCommand()) {
                        connection.Open();

                        cmd.CommandText = String.Format(@"
                        SELECT
                            COALESCE(lifetimeTotal.value * 0.9999, 0) <= COALESCE(dailyTotal.value, 0)
                        FROM (
                            SELECT
                                {0} AS value
                            FROM
                                {1}
                            WHERE
                                systime @> NOW() :: timestamp
                                and
                                {3} = @{4}) lifetimeTotal, (
                                SELECT
                                    SUM(value) AS value
                                FROM (
                                    SELECT
                                        {0} AS value
                                    FROM
                                        {2}
                                    WHERE
                                        systime @> NOW() :: timestamp
                                            and
                                        {3} = @{4}) d) dailyTotal
                        ",
                                                        metric.Name,
                                                        lifetime.TableName,
                                                        daily.TableName,
                                                        source_id,
                                                        hid
                                                        );
                        AddParameter(cmd, id, row);
                        threeshold = (bool)cmd.ExecuteScalar();
                    }
                if (!threeshold)
                {
                    return(false);
                }
            }
            // If no metric was checked, we cannot assert the completness of daily insights
            return(integerMetrics.Any());
        }
Beispiel #2
0
 public static void InsertInsights(Insights table, JObject oobj)
 {
     InsertRow(table.TableName, table.ColumnDefinition, oobj);
 }
Beispiel #3
0
 public static Modified CheckInsightDailyMatch(Insights table, JObject row)
 {
     return(CheckLifetimeInsightMatch(table, row, new string[] { table.Source.Name.ToString() + "_id", "date_start", "date_end" }));
 }